diff --git a/lib/syspro.rb b/lib/syspro.rb index 681e812..270eb20 100644 --- a/lib/syspro.rb +++ b/lib/syspro.rb @@ -5,6 +5,7 @@ require "logger" require "openssl" require "syspro/api_resource" +require "syspro/get_logon_profile" require "syspro/get_version" require "syspro/logoff" require "syspro/logon" diff --git a/lib/syspro/get_logon_profile.rb b/lib/syspro/get_logon_profile.rb new file mode 100644 index 0000000..21f6ced --- /dev/null +++ b/lib/syspro/get_logon_profile.rb @@ -0,0 +1,59 @@ +module Syspro + class GetLogonProfile < ApiResource + def self.get_logon_profile(user_id) + params = { "UserId" => user_id } + resp = self.request(:get, resource_url, params) + parse_response(resp[0]) + end + + def resource_url + "/GetLogonProfile" + end + + def self.parse_response(resp) + doc = resp.data + + user_profile = UserProfile.new( + doc.xpath("//CompanyName").text, + doc.xpath("//OperatorCode").text, + doc.xpath("//OperatorGroup").text, + doc.xpath("//OperatorEmailAddress").text, + doc.xpath("//OperatorLocation").text, + doc.xpath("//OperatorLanguageCode").text, + doc.xpath("//SystemLanguage").text, + doc.xpath("//AccountingDate").text, + doc.xpath("//CompanyDate").text, + doc.xpath("//DefaultArBranch").text, + doc.xpath("//DefaultApBranch").text, + doc.xpath("//DefaultBank").text, + doc.xpath("//DefaultWarehouse").text, + doc.xpath("//DefaultCustomer").text, + doc.xpath("//SystemSiteId").text, + doc.xpath("//SystemNationalityCode").text, + doc.xpath("//LocalCurrencyCode").text, + doc.xpath("//CurrencyDescription").text, + doc.xpath("//DefaultRequisitionUser").text, + doc.xpath("//XMLToHTMLTransform").text, + doc.xpath("//CssStyle").text, + doc.xpath("//CssSuffix").text, + doc.xpath("//DecimalFormat").text, + doc.xpath("//DateFormat").text, + doc.xpath("//FunctionalRole").text, + doc.xpath("//DatabaseType").text, + doc.xpath("//SysproVersion").text, + doc.xpath("//EnetVersion").text, + doc.xpath("//SysproServerBitWidth").text, + ) + end + private_class_method :parse_response + + UserProfile = Struct.new(:company_name, :operator_code, :operator_group, :operator_email_address, + :operator_location, :operator_language_code, :system_language, :accounting_date, + :company_date, :default_ar_branch, :default_ap_branch, :default_bank, :default_warehouse, + :default_customer, :system_site_id, :system_nationality_code, :local_currency_code, + :currency_description, :default_requisition_user, :xml_to_html_transform, :css_style, + :css_suffix, :decimal_format, :date_format, :functional_role, :database_type, :syspro_version, + :enet_version, :syspro_server_bit_width) + end +end + diff --git a/lib/syspro/syspro_response.rb b/lib/syspro/syspro_response.rb index 2344d6b..a9c92d4 100644 --- a/lib/syspro/syspro_response.rb +++ b/lib/syspro/syspro_response.rb @@ -26,8 +26,8 @@ module Syspro # This may throw JSON::ParserError if the response body is not valid JSON. def self.from_faraday_hash(http_resp) resp = SysproResponse.new - resp.data = Nokogiri::XML(http_resp[:body]) resp.http_body = http_resp[:body] + resp.data = Nokogiri::XML(resp.http_body) resp.http_headers = http_resp[:headers] resp.http_status = http_resp[:status] resp.request_id = http_resp[:headers]["Request-Id"] @@ -39,8 +39,8 @@ module Syspro # This may throw JSON::ParserError if the response body is not valid JSON. def self.from_faraday_response(http_resp) resp = SysproResponse.new - resp.data = Nokogiri::XML(http_resp[:body]) resp.http_body = http_resp.body + resp.data = Nokogiri::XML(resp.http_body) resp.http_headers = http_resp.headers resp.http_status = http_resp.status resp.request_id = http_resp.headers["Request-Id"] -- libgit2 0.21.4