Commit a61f2fc89a349337a849e4065a387d6d5045a340

Authored by Isaac Lewis
1 parent 3d0157a5

parse logon profile

lib/syspro.rb
... ... @@ -5,6 +5,7 @@ require "logger"
5 5 require "openssl"
6 6  
7 7 require "syspro/api_resource"
  8 +require "syspro/get_logon_profile"
8 9 require "syspro/get_version"
9 10 require "syspro/logoff"
10 11 require "syspro/logon"
... ...
lib/syspro/get_logon_profile.rb 0 → 100644
  1 +module Syspro
  2 + class GetLogonProfile < ApiResource
  3 + def self.get_logon_profile(user_id)
  4 + params = { "UserId" => user_id }
  5 + resp = self.request(:get, resource_url, params)
  6 + parse_response(resp[0])
  7 + end
  8 +
  9 + def resource_url
  10 + "/GetLogonProfile"
  11 + end
  12 +
  13 + def self.parse_response(resp)
  14 + doc = resp.data
  15 +
  16 + user_profile = UserProfile.new(
  17 + doc.xpath("//CompanyName").text,
  18 + doc.xpath("//OperatorCode").text,
  19 + doc.xpath("//OperatorGroup").text,
  20 + doc.xpath("//OperatorEmailAddress").text,
  21 + doc.xpath("//OperatorLocation").text,
  22 + doc.xpath("//OperatorLanguageCode").text,
  23 + doc.xpath("//SystemLanguage").text,
  24 + doc.xpath("//AccountingDate").text,
  25 + doc.xpath("//CompanyDate").text,
  26 + doc.xpath("//DefaultArBranch").text,
  27 + doc.xpath("//DefaultApBranch").text,
  28 + doc.xpath("//DefaultBank").text,
  29 + doc.xpath("//DefaultWarehouse").text,
  30 + doc.xpath("//DefaultCustomer").text,
  31 + doc.xpath("//SystemSiteId").text,
  32 + doc.xpath("//SystemNationalityCode").text,
  33 + doc.xpath("//LocalCurrencyCode").text,
  34 + doc.xpath("//CurrencyDescription").text,
  35 + doc.xpath("//DefaultRequisitionUser").text,
  36 + doc.xpath("//XMLToHTMLTransform").text,
  37 + doc.xpath("//CssStyle").text,
  38 + doc.xpath("//CssSuffix").text,
  39 + doc.xpath("//DecimalFormat").text,
  40 + doc.xpath("//DateFormat").text,
  41 + doc.xpath("//FunctionalRole").text,
  42 + doc.xpath("//DatabaseType").text,
  43 + doc.xpath("//SysproVersion").text,
  44 + doc.xpath("//EnetVersion").text,
  45 + doc.xpath("//SysproServerBitWidth").text,
  46 + )
  47 + end
  48 + private_class_method :parse_response
  49 +
  50 + UserProfile = Struct.new(:company_name, :operator_code, :operator_group, :operator_email_address,
  51 + :operator_location, :operator_language_code, :system_language, :accounting_date,
  52 + :company_date, :default_ar_branch, :default_ap_branch, :default_bank, :default_warehouse,
  53 + :default_customer, :system_site_id, :system_nationality_code, :local_currency_code,
  54 + :currency_description, :default_requisition_user, :xml_to_html_transform, :css_style,
  55 + :css_suffix, :decimal_format, :date_format, :functional_role, :database_type, :syspro_version,
  56 + :enet_version, :syspro_server_bit_width)
  57 + end
  58 +end
  59 +
... ...
lib/syspro/syspro_response.rb
... ... @@ -26,8 +26,8 @@ module Syspro
26 26 # This may throw JSON::ParserError if the response body is not valid JSON.
27 27 def self.from_faraday_hash(http_resp)
28 28 resp = SysproResponse.new
29   - resp.data = Nokogiri::XML(http_resp[:body])
30 29 resp.http_body = http_resp[:body]
  30 + resp.data = Nokogiri::XML(resp.http_body)
31 31 resp.http_headers = http_resp[:headers]
32 32 resp.http_status = http_resp[:status]
33 33 resp.request_id = http_resp[:headers]["Request-Id"]
... ... @@ -39,8 +39,8 @@ module Syspro
39 39 # This may throw JSON::ParserError if the response body is not valid JSON.
40 40 def self.from_faraday_response(http_resp)
41 41 resp = SysproResponse.new
42   - resp.data = Nokogiri::XML(http_resp[:body])
43 42 resp.http_body = http_resp.body
  43 + resp.data = Nokogiri::XML(resp.http_body)
44 44 resp.http_headers = http_resp.headers
45 45 resp.http_status = http_resp.status
46 46 resp.request_id = http_resp.headers["Request-Id"]
... ...