From dc8aa5b675b8f9d5a3aa9f60101185bf0ad9f9fc Mon Sep 17 00:00:00 2001 From: Joe Weakley Date: Fri, 6 Apr 2018 12:06:42 -0700 Subject: [PATCH] Rubocop corrections --- .rubocop.yml | 4 ++++ bin/console | 7 ++++--- lib/syspro.rb | 80 +++++++++++++++++++++++++++++++++++++++++--------------------------------------- lib/syspro/api_operations/query.rb | 14 +++++++------- lib/syspro/api_operations/request.rb | 5 +++-- lib/syspro/api_resource.rb | 10 ++++++---- lib/syspro/business_objects/combrw.rb | 21 +++++++++++++-------- lib/syspro/business_objects/comfch.rb | 21 +++++++++++++-------- lib/syspro/business_objects/comfnd.rb | 17 ++++++++--------- lib/syspro/business_objects/parsers/combrw_parser.rb | 33 +++++++++++++++------------------ lib/syspro/business_objects/parsers/comfch_parser.rb | 7 ++++--- lib/syspro/business_objects/parsers/comfnd_parser.rb | 21 ++++++++++----------- lib/syspro/errors.rb | 7 ++++--- lib/syspro/get_logon_profile.rb | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------- lib/syspro/get_version.rb | 7 ++++--- lib/syspro/logoff.rb | 10 ++++++---- lib/syspro/logon.rb | 15 ++++++++------- lib/syspro/singleton_api_resource.rb | 9 +++++++-- lib/syspro/syspro_client.rb | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------- lib/syspro/syspro_object.rb | 19 ++++++++++--------- lib/syspro/syspro_response.rb | 9 ++++++--- lib/syspro/util.rb | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------ lib/syspro/version.rb | 4 +++- test/client_test.rb | 24 +++++++++++++++--------- test/logoff_test.rb | 22 ++++++++++++++-------- test/logon_test.rb | 28 +++++++++++++++++++--------- test/query_test.rb | 44 +++++++++++++++++++++++--------------------- test/syspro_test.rb | 4 +++- test/test_helper.rb | 10 ++++++---- 29 files changed, 468 insertions(+), 320 deletions(-) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..dd58c60 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,4 @@ +AllCops: + Exclude: + - Gemfile* + - syspro-ruby.gemspec diff --git a/bin/console b/bin/console index 151318a..a2bdfa5 100755 --- a/bin/console +++ b/bin/console @@ -1,7 +1,8 @@ #!/usr/bin/env ruby +# frozen_string_literal: true -require "bundler/setup" -require "syspro" -require "pry" +require 'bundler/setup' +require 'syspro' +require 'pry' Pry.start diff --git a/lib/syspro.rb b/lib/syspro.rb index 0065e21..46e947d 100644 --- a/lib/syspro.rb +++ b/lib/syspro.rb @@ -1,35 +1,38 @@ -require "cgi" -require "faraday" -require "json" -require "logger" -require "openssl" - -require "syspro/api_resource" -require "syspro/errors" -require "syspro/get_logon_profile" -require "syspro/get_version" -require "syspro/logoff" -require "syspro/logon" -require "syspro/syspro_client" -require "syspro/singleton_api_resource" -require "syspro/syspro_object" -require "syspro/syspro_response" -require "syspro/util" -require "syspro/version" - -require "syspro/api_operations/request" -require "syspro/api_operations/query" - -require "syspro/business_objects/combrw" -require "syspro/business_objects/comfch" -require "syspro/business_objects/comfnd" - -require "syspro/business_objects/parsers/combrw_parser" -require "syspro/business_objects/parsers/comfch_parser" -require "syspro/business_objects/parsers/comfnd_parser" - +# frozen_string_literal: true + +require 'cgi' +require 'faraday' +require 'json' +require 'logger' +require 'openssl' + +require 'syspro/api_resource' +require 'syspro/errors' +require 'syspro/get_logon_profile' +require 'syspro/get_version' +require 'syspro/logoff' +require 'syspro/logon' +require 'syspro/syspro_client' +require 'syspro/singleton_api_resource' +require 'syspro/syspro_object' +require 'syspro/syspro_response' +require 'syspro/util' +require 'syspro/version' + +require 'syspro/api_operations/request' +require 'syspro/api_operations/query' + +require 'syspro/business_objects/combrw' +require 'syspro/business_objects/comfch' +require 'syspro/business_objects/comfnd' + +require 'syspro/business_objects/parsers/combrw_parser' +require 'syspro/business_objects/parsers/comfch_parser' +require 'syspro/business_objects/parsers/comfnd_parser' + +# Main Module module Syspro - @api_base = "http://syspro.wildlandlabs.com:90/SYSPROWCFService/Rest" + @api_base = 'http://syspro.wildlandlabs.com:90/SYSPROWCFService/Rest' @open_timeout = 30 @read_timeout = 80 @@ -69,14 +72,13 @@ module Syspro def self.log_level=(val) # Backwards compatibility for values that we briefly allowed - if val == "debug" - val = LEVEL_DEBUG - elsif val == "info" - val = LEVEL_INFO - end - + val = LEVEL_DEBUG if val == 'debug' + val = LEVEL_INFO if val == 'info' if !val.nil? && ![LEVEL_DEBUG, LEVEL_ERROR, LEVEL_INFO].include?(val) - raise ArgumentError, "log_level should only be set to `nil`, `debug` or `info`" + raise( + ArgumentError, + 'log_level should only be set to `nil`, `debug` or `info`' + ) end @log_level = val end @@ -104,5 +106,5 @@ module Syspro @max_network_retries = val.to_i end - Syspro.log_level = ENV["SYSPRO_LOG"] unless ENV["SYSPRO_LOG"].nil? + Syspro.log_level = ENV['SYSPRO_LOG'] unless ENV['SYSPRO_LOG'].nil? end diff --git a/lib/syspro/api_operations/query.rb b/lib/syspro/api_operations/query.rb index d2522d7..610238b 100644 --- a/lib/syspro/api_operations/query.rb +++ b/lib/syspro/api_operations/query.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Syspro module ApiOperations module Query @@ -5,26 +7,25 @@ module Syspro include Request def browse(params) - request(:get, "/Query/Browse", params) + request(:get, '/Query/Browse', params) end def fetch(params) - request(:get, "/Query/Fetch", params) + request(:get, '/Query/Fetch', params) end def query(params) - request(:get, "/Query/Query", params) + request(:get, '/Query/Query', params) end - def find - end + def find; end private def warn_on_opts_in_params(params) Util::OPTS_USER_SPECIFIED.each do |opt| if params.key?(opt) - $stderr.puts("WARNING: #{opt} should be in opts instead of params.") + warn("WARNING: #{opt} should be in opts instead of params.") end end end @@ -43,4 +44,3 @@ module Syspro end end end - diff --git a/lib/syspro/api_operations/request.rb b/lib/syspro/api_operations/request.rb index 7bbb2a0..c42e9ff 100644 --- a/lib/syspro/api_operations/request.rb +++ b/lib/syspro/api_operations/request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Syspro module ApiOperations module Request @@ -28,7 +30,7 @@ module Syspro def warn_on_opts_in_params(params) Util::OPTS_USER_SPECIFIED.each do |opt| if params.key?(opt) - $stderr.puts("WARNING: #{opt} should be in opts instead of params.") + warn("WARNING: #{opt} should be in opts instead of params.") end end end @@ -40,4 +42,3 @@ module Syspro end end end - diff --git a/lib/syspro/api_resource.rb b/lib/syspro/api_resource.rb index 1858f7f..19a30c5 100644 --- a/lib/syspro/api_resource.rb +++ b/lib/syspro/api_resource.rb @@ -1,17 +1,19 @@ -require "syspro/syspro_object" -require "syspro/api_operations/request" +# frozen_string_literal: true + +require 'syspro/syspro_object' +require 'syspro/api_operations/request' module Syspro class ApiResource < SysproObject include Syspro::ApiOperations::Request def self.class_name - name.split("::")[-1] + name.split('::')[-1] end def self.resource_url if self == ApiResource - raise NotImplementedError, "APIResource is an abstract class. You should perform actions on its subclasses (Charge, Customer, etc.)" + raise NotImplementedError, 'APIResource is an abstract class. You should perform actions on its subclasses (Charge, Customer, etc.)' end "/#{CGI.escape(class_name.downcase)}" end diff --git a/lib/syspro/business_objects/combrw.rb b/lib/syspro/business_objects/combrw.rb index 83360dc..5a8787f 100644 --- a/lib/syspro/business_objects/combrw.rb +++ b/lib/syspro/business_objects/combrw.rb @@ -1,5 +1,7 @@ -require "syspro/business_objects/parsers/combrw_parser" -require "erb" +# frozen_string_literal: true + +require 'syspro/business_objects/parsers/combrw_parser' +require 'erb' module Syspro module BusinessObjects @@ -12,13 +14,19 @@ module Syspro def call(user_id) xml_in = template.result(binding) - params = { "UserId" => user_id, "XmlIn" => xml_in } + params = { 'UserId' => user_id, 'XmlIn' => xml_in } resp = ComBrw.browse(params) parse_response(resp) end def template - ERB.new File.read(File.expand_path("schemas/combrw.xml.erb", File.dirname(__FILE__))), nil, "%" + ERB.new( + File.read( + File.expand_path('schemas/combrw.xml.erb', File.dirname(__FILE__)) + ), + nil, + '%' + ) end def parse_response(resp) @@ -29,11 +37,8 @@ module Syspro def handle_errors(resp) body = resp[0].http_body - if body.match(/^(ERROR)/) - raise SysproError, body - end + raise SysproError, body if body =~ /^(ERROR)/ end end end end - diff --git a/lib/syspro/business_objects/comfch.rb b/lib/syspro/business_objects/comfch.rb index a6e4e1e..66ce6ea 100644 --- a/lib/syspro/business_objects/comfch.rb +++ b/lib/syspro/business_objects/comfch.rb @@ -1,5 +1,7 @@ -require "syspro/business_objects/parsers/comfch_parser" -require "erb" +# frozen_string_literal: true + +require 'syspro/business_objects/parsers/comfch_parser' +require 'erb' module Syspro module BusinessObjects @@ -12,13 +14,19 @@ module Syspro def call(user_id) xml_in = template.result(binding) - params = { "UserId" => user_id, "XmlIn" => xml_in } + params = { 'UserId' => user_id, 'XmlIn' => xml_in } resp = ComFch.fetch(params) parse_response(resp) end def template - ERB.new File.read(File.expand_path("schemas/comfch.xml.erb", File.dirname(__FILE__))), nil, "%" + ERB.new( + File.read( + File.expand_path('schemas/comfch.xml.erb', File.dirname(__FILE__)) + ), + nil, + '%' + ) end def parse_response(resp) @@ -29,11 +37,8 @@ module Syspro def handle_errors(resp) body = resp[0].http_body - if body.match(/^(ERROR)/) - raise SysproError, body - end + raise SysproError, body if body =~ /^(ERROR)/ end end end end - diff --git a/lib/syspro/business_objects/comfnd.rb b/lib/syspro/business_objects/comfnd.rb index 81bf8c7..ec5589e 100644 --- a/lib/syspro/business_objects/comfnd.rb +++ b/lib/syspro/business_objects/comfnd.rb @@ -1,5 +1,7 @@ -require "syspro/business_objects/parsers/comfnd_parser" -require "erb" +# frozen_string_literal: true + +require 'syspro/business_objects/parsers/comfnd_parser' +require 'erb' module Syspro module BusinessObjects @@ -12,14 +14,14 @@ module Syspro def call(user_id) xml_in = template.result(binding) - business_object = "COMFND" - params = { "UserId" => user_id, "BusinessObject" => business_object, "XmlIn" => xml_in } + business_object = 'COMFND' + params = { 'UserId' => user_id, 'BusinessObject' => business_object, 'XmlIn' => xml_in } resp = ComFnd.query(params) parse_response(resp) end def template - ERB.new File.read(File.expand_path("schemas/comfnd.xml.erb", File.dirname(__FILE__))), nil, "%" + ERB.new File.read(File.expand_path('schemas/comfnd.xml.erb', File.dirname(__FILE__))), nil, '%' end def parse_response(resp) @@ -30,11 +32,8 @@ module Syspro def handle_errors(resp) body = resp[0].http_body - if body.match(/^(ERROR)/) - raise SysproError, body - end + raise SysproError, body if body =~ /^(ERROR)/ end end end end - diff --git a/lib/syspro/business_objects/parsers/combrw_parser.rb b/lib/syspro/business_objects/parsers/combrw_parser.rb index b651a1e..4176fd3 100644 --- a/lib/syspro/business_objects/parsers/combrw_parser.rb +++ b/lib/syspro/business_objects/parsers/combrw_parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Syspro module BusinessObjects module Parsers @@ -9,41 +11,37 @@ module Syspro end def parse - next_prev_key = doc.first_element_child.xpath("NextPrevKey") - next_prev_key_obj = next_prev_key.children.map { |el| - if el.name == "text" - next - end + next_prev_key = doc.first_element_child.xpath('NextPrevKey') + next_prev_key_obj = next_prev_key.children.map do |el| + next if el.name == 'text' { name: el.name, text: el.text } - }.compact + end.compact - header_details = doc.first_element_child.xpath("HeaderDetails") - header_details_obj = header_details.children.map { |el| - if el.name == "text" - next - end + header_details = doc.first_element_child.xpath('HeaderDetails') + header_details_obj = header_details.children.map do |el| + next if el.name == 'text' { name: el.name, text: el.text } - }.compact + end.compact rows = doc.first_element_child.xpath('Row') - rows_obj = rows.map { |el| - el.elements.map { |inner| + rows_obj = rows.flat_map do |el| + el.elements.map do |inner| { name: inner.name, value: inner.xpath('Value').text, data_type: inner.xpath('DataType').text } - } - }.flatten(1).compact + end + end.compact BrowseObject.new( - doc.first_element_child.xpath("Title").text, + doc.first_element_child.xpath('Title').text, rows_obj, next_prev_key_obj, header_details_obj @@ -55,4 +53,3 @@ module Syspro end end end - diff --git a/lib/syspro/business_objects/parsers/comfch_parser.rb b/lib/syspro/business_objects/parsers/comfch_parser.rb index 0bad7a0..dd40db4 100644 --- a/lib/syspro/business_objects/parsers/comfch_parser.rb +++ b/lib/syspro/business_objects/parsers/comfch_parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Syspro module BusinessObjects module Parsers @@ -11,9 +13,9 @@ module Syspro def parse table_name = doc.first_element_child.name columns = doc.first_element_child.elements - columns_obj = columns.map { |el| + columns_obj = columns.map do |el| { name: el.name, value: el.children.text } - }.compact + end.compact FetchObject.new( table_name, @@ -26,4 +28,3 @@ module Syspro end end end - diff --git a/lib/syspro/business_objects/parsers/comfnd_parser.rb b/lib/syspro/business_objects/parsers/comfnd_parser.rb index 78a5fde..4621524 100644 --- a/lib/syspro/business_objects/parsers/comfnd_parser.rb +++ b/lib/syspro/business_objects/parsers/comfnd_parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Syspro module BusinessObjects module Parsers @@ -9,26 +11,24 @@ module Syspro end def parse - header_details = doc.first_element_child.xpath("HeaderDetails") - header_details_obj = header_details.children.map { |el| - if el.name == "text" - next - end + header_details = doc.first_element_child.xpath('HeaderDetails') + header_details_obj = header_details.children.map do |el| + next if el.name == 'text' { name: el.name, text: el.text } - }.compact + end.compact rows = doc.first_element_child.xpath('Row') - rows_obj = rows.map { |el| - el.elements.map { |inner| + rows_obj = rows.flat_map do |el| + el.elements.map do |inner| { name: inner.name, value: inner.children.text } - } - }.flatten(1).compact + end + end.compact QueryObject.new( header_details_obj, @@ -42,4 +42,3 @@ module Syspro end end end - diff --git a/lib/syspro/errors.rb b/lib/syspro/errors.rb index 7515992..98f3ca4 100644 --- a/lib/syspro/errors.rb +++ b/lib/syspro/errors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Syspro class SysproError < StandardError attr_reader :message, :response, :code, :http_body, :http_headers, @@ -16,8 +18,8 @@ module Syspro end def to_s - status_string = @http_status.nil? ? "" : "(Status #{@http_status}) " - id_string = @request_id.nil? ? "" : "(Request #{@request_id}) " + status_string = @http_status.nil? ? '' : "(Status #{@http_status}) " + id_string = @request_id.nil? ? '' : "(Request #{@request_id}) " "#{status_string}#{id_string}#{@message}" end end @@ -30,5 +32,4 @@ module Syspro class ApiError < SysproError end - end diff --git a/lib/syspro/get_logon_profile.rb b/lib/syspro/get_logon_profile.rb index 12e8dda..6ef49e4 100644 --- a/lib/syspro/get_logon_profile.rb +++ b/lib/syspro/get_logon_profile.rb @@ -1,59 +1,84 @@ +# frozen_string_literal: true + module Syspro class GetLogonProfile < ApiResource def self.get_logon_profile(user_id) - params = { "UserId" => user_id } - resp = self.request(:get, resource_url, params) + params = { 'UserId' => user_id } + resp = request(:get, resource_url, params) parse_response(resp[0]) end def resource_url - "/GetLogonProfile" + '/GetLogonProfile' end - def self.parse_response(resp) + def self.parse_response(resp) # rubocop:disable Metrics/MethodLength doc = resp.data 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, + 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) + 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/get_version.rb b/lib/syspro/get_version.rb index 4413bfc..25d259c 100644 --- a/lib/syspro/get_version.rb +++ b/lib/syspro/get_version.rb @@ -1,15 +1,16 @@ +# frozen_string_literal: true + module Syspro class GetVersion < ApiResource def self.get_version - resp = self.request(:get, resource_url) + resp = request(:get, resource_url) VersionObject.new(resp[0].http_body) end def resource_url - "/GetVersion" + '/GetVersion' end VersionObject = Struct.new(:version) end end - diff --git a/lib/syspro/logoff.rb b/lib/syspro/logoff.rb index 6ce10d4..84f9bd4 100644 --- a/lib/syspro/logoff.rb +++ b/lib/syspro/logoff.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + module Syspro class Logoff < ApiResource def self.logoff(user_id) - params = { "UserId" => user_id } - resp = self.request(:get, resource_url, params) + params = { 'UserId' => user_id } + resp = request(:get, resource_url, params) - if resp[0].http_body == "0" + if resp[0].http_body == '0' true else resp[0].http_body @@ -12,7 +14,7 @@ module Syspro end def resource_url - "/Logoff" + '/Logoff' end end end diff --git a/lib/syspro/logon.rb b/lib/syspro/logon.rb index 371067e..eb0f1dc 100644 --- a/lib/syspro/logon.rb +++ b/lib/syspro/logon.rb @@ -1,21 +1,22 @@ +# frozen_string_literal: true + module Syspro class Logon < ApiResource def self.logon(username, password, company_id, company_password = nil) params = { - "Operator" => username, - "OperatorPassword" => password, - "CompanyId" => company_id, - "CompanyPassword" => company_password + 'Operator' => username, + 'OperatorPassword' => password, + 'CompanyId' => company_id, + 'CompanyPassword' => company_password } - resp = self.request(:get, resource_url, params) + resp = request(:get, resource_url, params) UserIdObject.new(resp[0].http_body) end def resource_url - "/Logon" + '/Logon' end UserIdObject = Struct.new(:guid) end end - diff --git a/lib/syspro/singleton_api_resource.rb b/lib/syspro/singleton_api_resource.rb index 8eabfda..18dc5fa 100644 --- a/lib/syspro/singleton_api_resource.rb +++ b/lib/syspro/singleton_api_resource.rb @@ -1,10 +1,15 @@ -require_relative "api_resource" +# frozen_string_literal: true + +require_relative 'api_resource' module Syspro class SingletonAPIResource < ApiResource def self.resource_url if self == SingletonAPIResource - raise NotImplementedError, "SingletonAPIResource is an abstract class. You should perform actions on its subclasses (Customer, etc.)" + raise( + NotImplementedError, + 'SingletonAPIResource is an abstract class. You should perform actions on its subclasses (Customer, etc.)' # rubocop:disable Metrics/LineLength + ) end "/#{CGI.escape(class_name.downcase)}" end diff --git a/lib/syspro/syspro_client.rb b/lib/syspro/syspro_client.rb index 5cdf978..b2c5fbc 100644 --- a/lib/syspro/syspro_client.rb +++ b/lib/syspro/syspro_client.rb @@ -1,5 +1,8 @@ +# frozen_string_literal: true + module Syspro - class SysproClient + # This class is the main syspro client + class SysproClient # rubocop:disable Metrics/ClassLength attr_accessor :conn, :api_base @verify_ssl_warned = false @@ -13,7 +16,7 @@ module Syspro Syspro::Logon.logon(username, password, company_id, company_password) end - def get_syspro_version + def get_syspro_version # rubocop:disable Naming/AccessorMethodName Syspro::GetVersion.get_version end @@ -22,13 +25,13 @@ module Syspro end def self.default_client - Thread.current[:syspro_client_default_client] ||= SysproClient.new(default_conn) + Thread.current[:syspro_client_default_client] ||= SysproClient.new(default_conn) # rubocop:disable Metrics/LineLength end # A default Faraday connection to be used when one isn't configured. This # object should never be mutated, and instead instantiating your own # connection and wrapping it in a SysproClient object should be preferred. - def self.default_conn + def self.default_conn # rubocop:disable Metrics/MethodLength # We're going to keep connections around so that we can take advantage # of connection re-use, so make sure that we have a separate connection # object per thread. @@ -40,20 +43,21 @@ module Syspro c.adapter Faraday.default_adapter end - # For now, we're not verifying SSL certificates. The warning will appear. - #if Syspro.verify_ssl_certs - #conn.ssl.verify = true - #conn.ssl.cert_store = Syspro.ca_store - #else + # For now, we're not verifying SSL certificates. + # The warning will appear. + # if Syspro.verify_ssl_certs + # conn.ssl.verify = true + # conn.ssl.cert_store = Syspro.ca_store + # else conn.ssl.verify = false unless @verify_ssl_warned @verify_ssl_warned = true - $stderr.puts("WARNING: Running without SSL cert verification. " \ - "You should never do this in production. " \ + warn('WARNING: Running without SSL cert verification. ' \ + 'You should never do this in production. ' \ "Execute 'Syspro.verify_ssl_certs = true' to enable verification.") end - #end + # end conn end @@ -77,9 +81,9 @@ module Syspro end end - def execute_request(method, path, user_id: nil, api_base: nil, headers: {}, params: {}) + def execute_request(method, path, user_id: nil, api_base: nil, headers: {}, params: {}) # rubocop:disable Metrics/LineLength, Metrics/MethodLength api_base ||= Syspro.api_base - user_id ||= "" + user_id ||= '' params = Util.objects_to_ids(params) url = api_url(path, api_base) @@ -91,7 +95,7 @@ module Syspro when :get, :head, :delete query_params = params else - body = if headers[:content_type] && headers[:content_type] == "multipart/form-data" + body = if headers[:content_type] && headers[:content_type] == 'multipart/form-data' # rubocop:disable Metrics/LineLength params else Util.encode_parameters(params) @@ -108,7 +112,7 @@ module Syspro context.method = method context.path = path context.user_id = user_id - context.query_params = query_params ? Util.encode_parameters(query_params) : nil + context.query_params = query_params ? Util.encode_parameters(query_params) : nil # rubocop:disable Metrics/LineLength http_resp = execute_request_with_rescues(api_base, context) do conn.run_request(method, url, body, headers) do |req| @@ -135,22 +139,22 @@ module Syspro http_status: status, http_body: body) end - def api_url(url = "", api_base = nil) + def api_url(url = '', api_base = nil) (api_base || Syspro.api_base) + url end - def request_headers(method) + def request_headers(_method) user_agent = "Syspro/7 RubyBindings/#{Syspro::VERSION}" headers = { - "User-Agent" => user_agent, - "Content-Type" => "application/x-www-form-urlencoded", + 'User-Agent' => user_agent, + 'Content-Type' => 'application/x-www-form-urlencoded' } headers end - def execute_request_with_rescues(api_base, context) + def execute_request_with_rescues(api_base, context) # rubocop:disable Metrics/LineLength, Metrics/MethodLength num_retries = 0 begin request_start = Time.now @@ -159,8 +163,8 @@ module Syspro log_response(context, request_start, resp.status, resp.body) # We rescue all exceptions from a request so that we have an easy spot to - # implement our retry logic across the board. We'll re-raise if it's a type - # of exception that we didn't expect to handle. + # implement our retry logic across the board. We'll re-raise if it's a + # type of exception that we didn't expect to handle. rescue StandardError => e if e.respond_to?(:response) && e.response log_response(context, request_start, @@ -193,36 +197,36 @@ module Syspro resp end - def handle_network_error(e, context, num_retries, api_base = nil) - Util.log_error("Syspro network error", + def handle_network_error(e, context, num_retries, api_base = nil) # rubocop:disable Metrics/LineLength, Metrics/MethodLength, Naming/UncommunicativeMethodParamName + Util.log_error('Syspro network error', error_message: e.message, request_id: context.request_id) case e when Faraday::ConnectionFailed - message = "Unexpected error communicating when trying to connect to Syspro." + message = 'Unexpected error communicating when trying to connect to Syspro.' # rubocop:disable Metrics/LineLength when Faraday::SSLError - message = "Could not establish a secure connection to Syspro." + message = 'Could not establish a secure connection to Syspro.' when Faraday::TimeoutError api_base ||= Syspro.api_base message = "Could not connect to Syspro (#{api_base}). " \ - "Please check your internet connection and try again. " \ - "If this problem persists, you should check your Syspro service status." + 'Please check your internet connection and try again. ' \ + 'If this problem persists, you should check your Syspro service status.' # rubocop:disable Metrics/LineLength else - message = "Unexpected error communicating with Syspro. " \ - "If this problem persists, talk to your Syspro implementation team." + message = 'Unexpected error communicating with Syspro. ' \ + 'If this problem persists, talk to your Syspro implementation team.' end - message += " Request was retried #{num_retries} times." if num_retries > 0 + message += " Request was retried #{num_retries} times." if num_retries.positive? # rubocop:disable Metrics/LineLength raise ApiConnectionError, message + "\n\n(Network error: #{e.message})" end - def self.should_retry?(e, num_retries) + def self.should_retry?(e, num_retries) # rubocop:disable Metrics/LineLength, Naming/UncommunicativeMethodParamName return false if num_retries >= Syspro.max_network_retries # Retry on timeout-related problems (either on open or read). @@ -242,20 +246,20 @@ module Syspro end def log_request(context, num_retries) - Util.log_info("Request to Syspro API", + Util.log_info('Request to Syspro API', account: context.account, api_version: context.api_version, method: context.method, num_retries: num_retries, path: context.path) - Util.log_debug("Request details", + Util.log_debug('Request details', body: context.body, query_params: context.query_params) end private :log_request - def log_response(context, request_start, status, body) - Util.log_info("Response from Syspro API", + def log_response(context, request_start, status, body) # rubocop:disable Metrics/LineLength, Metrics/MethodLength + Util.log_info('Response from Syspro API', account: context.account, api_version: context.api_version, elapsed: Time.now - request_start, @@ -263,14 +267,14 @@ module Syspro path: context.path, request_id: context.request_id, status: status) - Util.log_debug("Response details", + Util.log_debug('Response details', body: body, request_id: context.request_id) end private :log_response - def log_response_error(context, request_start, e) - Util.log_error("Request error", + def log_response_error(context, request_start, e) # rubocop:disable Metrics/LineLength, Naming/UncommunicativeMethodParamName + Util.log_error('Request error', elapsed: Time.now - request_start, error_message: e.message, method: context.method, @@ -278,12 +282,12 @@ module Syspro end private :log_response_error - def handle_error_response(http_resp, context) + def handle_error_response(http_resp, context) # rubocop:disable Metrics/LineLength, Metrics/MethodLength begin resp = SysproResponse.from_faraday_hash(http_resp) error_data = resp.data[:error] - raise SysproError, "Indeterminate error" unless error_data + raise SysproError, 'Indeterminate error' unless error_data rescue Nokogiri::XML::SyntaxError, SysproError raise general_api_error(http_resp[:status], http_resp[:body]) end @@ -316,56 +320,55 @@ module Syspro # in so that we can generate a rich user agent header to help debug # integrations. class SystemProfiler - def self.uname - if File.exist?("/proc/version") - File.read("/proc/version").strip + def self.uname # rubocop:disable Metrics/MethodLength + if File.exist?('/proc/version') + File.read('/proc/version').strip else - case RbConfig::CONFIG["host_os"] + case RbConfig::CONFIG['host_os'] when /linux|darwin|bsd|sunos|solaris|cygwin/i uname_from_system when /mswin|mingw/i uname_from_system_ver else - "unknown platform" + 'unknown platform' end end end def self.uname_from_system - (`uname -a 2>/dev/null` || "").strip + (`uname -a 2>/dev/null` || '').strip rescue Errno::ENOENT - "uname executable not found" + 'uname executable not found' rescue Errno::ENOMEM # couldn't create subprocess - "uname lookup failed" + 'uname lookup failed' end def self.uname_from_system_ver - (`ver` || "").strip + (`ver` || '').strip rescue Errno::ENOENT - "ver executable not found" + 'ver executable not found' rescue Errno::ENOMEM # couldn't create subprocess - "uname lookup failed" + 'uname lookup failed' end def initialize @uname = self.class.uname end - def user_agent - lang_version = "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})" + def user_agent # rubocop:disable Metrics/MethodLength + lang_version = "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})" # rubocop:disable Metrics/LineLength { application: Syspro.app_info, bindings_version: Syspro::VERSION, - lang: "ruby", + lang: 'ruby', lang_version: lang_version, platform: RUBY_PLATFORM, - engine: defined?(RUBY_ENGINE) ? RUBY_ENGINE : "", + engine: defined?(RUBY_ENGINE) ? RUBY_ENGINE : '', uname: @uname, - hostname: Socket.gethostname, + hostname: Socket.gethostname }.delete_if { |_k, v| v.nil? } end end end end - diff --git a/lib/syspro/syspro_object.rb b/lib/syspro/syspro_object.rb index 016510f..6a88859 100644 --- a/lib/syspro/syspro_object.rb +++ b/lib/syspro/syspro_object.rb @@ -1,4 +1,7 @@ +# frozen_string_literal: true + module Syspro + # This class represents a syspro response class SysproObject include Enumerable @@ -18,7 +21,8 @@ module Syspro # considered to be equal if they have the same set of values and each one # of those values is the same. def ==(other) - other.is_a?(SysproObject) && @values == other.instance_variable_get(:@values) + other.is_a?(SysproObject) && + @values == other.instance_variable_get(:@values) end def to_s(*_args) @@ -26,8 +30,8 @@ module Syspro end def inspect - id_string = respond_to?(:id) && !id.nil? ? " id=#{id}" : "" - "#<#{self.class}:0x#{object_id.to_s(16)}#{id_string}> JSON: " + JSON.pretty_generate(@values) + id_string = respond_to?(:id) && !id.nil? ? " id=#{id}" : '' + "#<#{self.class}:0x#{object_id.to_s(16)}#{id_string}> JSON: " + JSON.pretty_generate(@values) # rubocop:disable Metrics/LineLength end def keys @@ -38,9 +42,9 @@ module Syspro @values.values end - def to_hash + def to_hash # rubocop:disable Metrics/MethodLength maybe_to_hash = lambda do |value| - value && value.respond_to?(:to_hash) ? value.to_hash : value + value&.respond_to?(:to_hash) ? value.to_hash : value end @values.each_with_object({}) do |(key, value), acc| @@ -57,11 +61,9 @@ module Syspro @values.each(&blk) end - private - # Produces a deep copy of the given object including support for arrays, # hashes, and SysproObjects. - def self.deep_copy(obj) + def self.deep_copy(obj) # rubocop:disable Metrics/MethodLength case obj when Array obj.map { |e| deep_copy(e) } @@ -82,6 +84,5 @@ module Syspro end end private_class_method :deep_copy - end end diff --git a/lib/syspro/syspro_response.rb b/lib/syspro/syspro_response.rb index 91958da..46b222e 100644 --- a/lib/syspro/syspro_response.rb +++ b/lib/syspro/syspro_response.rb @@ -1,6 +1,9 @@ -require "nokogiri" +# frozen_string_literal: true + +require 'nokogiri' module Syspro + # This class represents a syspro response class SysproResponse attr_accessor :data, :http_body, :http_headers, :http_status, :request_id @@ -12,7 +15,7 @@ module Syspro 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"] + resp.request_id = http_resp[:headers]['Request-Id'] resp end @@ -23,7 +26,7 @@ module Syspro 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"] + resp.request_id = http_resp.headers['Request-Id'] resp end end diff --git a/lib/syspro/util.rb b/lib/syspro/util.rb index eebf93c..9af2109 100644 --- a/lib/syspro/util.rb +++ b/lib/syspro/util.rb @@ -1,5 +1,8 @@ +# frozen_string_literal: true + module Syspro - class Util + # Utillity class + class Util # rubocop:disable Metrics/ClassLength # Options that a user is allowed to specify. OPTS_USER_SPECIFIED = Set[ :user_id @@ -17,8 +20,7 @@ module Syspro OPTS_USER_SPECIFIED + Set[:client] ).freeze - - def self.objects_to_ids(h) + def self.objects_to_ids(h) # rubocop:disable Metrics/MethodLength, Metrics/LineLength, Naming/UncommunicativeMethodParamName case h when ApiResource h.id @@ -45,13 +47,17 @@ module Syspro # * +data+ - Hash of fields and values to be converted into a SysproObject. # * +opts+ - Options for +SysproObject+ like an API key that will be reused # on subsequent API calls. - def self.convert_to_syspro_object(data, opts = {}) + def self.convert_to_syspro_object(data, opts = {}) # rubocop:disable Metrics/LineLength, Metrics/MethodLength case data when Array data.map { |i| convert_to_syspro_object(i, opts) } when Hash - # Try converting to a known object class. If none available, fall back to generic SysproObject - object_classes.fetch(data[:object], SysproObject).construct_from(data, opts) + # Try converting to a known object class. + # If none available, fall back to generic SysproObject + object_classes.fetch( + data[:object], + SysproObject + ).construct_from(data, opts) else data end @@ -66,7 +72,7 @@ module Syspro when Hash opts.clone else - raise TypeError, "normalize_opts expects a string or a hash" + raise TypeError, 'normalize_opts expects a string or a hash' end end @@ -78,7 +84,7 @@ module Syspro def self.normalize_headers(headers) headers.each_with_object({}) do |(k, v), new_headers| if k.is_a?(Symbol) - k = titlecase_parts(k.to_s.tr("_", "-")) + k = titlecase_parts(k.to_s.tr('_', '-')) elsif k.is_a?(String) k = titlecase_parts(k) end @@ -89,10 +95,10 @@ module Syspro def self.encode_parameters(params) Util.flatten_params(params) - .map { |k, v| "#{url_encode(k)}=#{url_encode(v)}" }.join("&") + .map { |k, v| "#{url_encode(k)}=#{url_encode(v)}" }.join('&') end - def self.flatten_params(params, parent_key = nil) + def self.flatten_params(params, parent_key = nil) # rubocop:disable Metrics/LineLength, Metrics/MethodLength result = [] # do not sort the final output because arrays (and arrays of hashes @@ -113,26 +119,41 @@ module Syspro end def self.log_error(message, data = {}) - if !Syspro.logger.nil? || - !Syspro.log_level.nil? && Syspro.log_level <= Syspro::LEVEL_ERROR - log_internal(message, data, color: :cyan, - level: Syspro::LEVEL_ERROR, logger: Syspro.logger, out: $stderr) + if !Syspro.logger.nil? || !Syspro.log_level.nil? && Syspro.log_level <= Syspro::LEVEL_ERROR # rubocop:disable Style/GuardClause, Metrics/LineLength + log_internal( + message, + data, + color: :cyan, + level: Syspro::LEVEL_ERROR, + logger: Syspro.logger, + out: $stderr + ) end end def self.log_info(message, data = {}) - if !Syspro.logger.nil? || - !Syspro.log_level.nil? && Syspro.log_level <= Syspro::LEVEL_INFO - log_internal(message, data, color: :cyan, - level: Syspro::LEVEL_INFO, logger: Syspro.logger, out: $stdout) + if !Syspro.logger.nil? || !Syspro.log_level.nil? && Syspro.log_level <= Syspro::LEVEL_INFO # rubocop:disable Style/GuardClause, Metrics/LineLength + log_internal( + message, + data, + color: :cyan, + level: Syspro::LEVEL_INFO, + logger: Syspro.logger, + out: $stdout + ) end end def self.log_debug(message, data = {}) - if !Syspro.logger.nil? || - !Syspro.log_level.nil? && Syspro.log_level <= Syspro::LEVEL_DEBUG - log_internal(message, data, color: :blue, - level: Syspro::LEVEL_DEBUG, logger: Syspro.logger, out: $stdout) + if !Syspro.logger.nil? || !Syspro.log_level.nil? && Syspro.log_level <= Syspro::LEVEL_DEBUG # rubocop:disable Style/GuardClause, Metrics/LineLength + log_internal( + message, + data, + color: :blue, + level: Syspro::LEVEL_DEBUG, + logger: Syspro.logger, + out: $stdout + ) end end @@ -141,8 +162,47 @@ module Syspro # Don't use strict form encoding by changing the square bracket control # characters back to their literals. This is fine by the server, and # makes these parameter strings easier to read. - gsub("%5B", "[").gsub("%5D", "]") + gsub('%5B', '[').gsub('%5D', ']') end + + # TODO: Make these named required arguments when we drop support for Ruby + # 2.0. + def self.log_internal(message, data = {}, color: nil, level: nil, logger: nil, out: nil) # rubocop:disable Metrics/LineLength, Metrics/AbcSize, Metrics/MethodLength, Metrics/ParameterLists + data_str = data.reject { |_k, v| v.nil? }.map do |(k, v)| + format( + '%s=%s', # rubocop:disable Style/FormatStringToken + colorize(k, color, !out.nil? && out.isatty), + wrap_logfmt_value(v) + ) + end.join(' ') + + if !logger.nil? + # the library's log levels are mapped to the same values as the + # standard library's logger + logger.log( + level, + format( + 'message=%s %s', # rubocop:disable Style/FormatStringToken + wrap_logfmt_value(message), + data_str + ) + ) + elsif out.isatty + out.puts format( + '%s %s %s', # rubocop:disable Style/FormatStringToken + colorize(level_name(level)[0, 4].upcase, color, out.isatty), + message, + data_str + ) + else + out.puts format( + 'message=%s level=%s %s', # rubocop:disable Style/FormatStringToken + wrap_logfmt_value(message), + level_name(level), + data_str + ) + end + end + private_class_method :log_internal end end - diff --git a/lib/syspro/version.rb b/lib/syspro/version.rb index 91cd027..5b8acb6 100644 --- a/lib/syspro/version.rb +++ b/lib/syspro/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Syspro - VERSION = "0.1.0" + VERSION = '0.1.0' end diff --git a/test/client_test.rb b/test/client_test.rb index 659e15b..395923b 100644 --- a/test/client_test.rb +++ b/test/client_test.rb @@ -1,19 +1,25 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class SysproClientTest < Minitest::Test + extend Minitest::Spec::DSL + + let(:client) { ::Syspro::SysproClient.new } + def test_get_syspro_version - client = ::Syspro::SysproClient.new - assert_match (/(\d+\.)?(\d+\.)?(\d+\.)?(\d+)/), client.get_syspro_version.version + assert_match( + /(\d+\.)?(\d+\.)?(\d+\.)?(\d+)/, + client.get_syspro_version.version + ) end def test_client_block_execution - client = ::Syspro::SysproClient.new - - version, resp = client.request { + version, resp = client.request do Syspro::GetVersion.get_version - } + end - assert_match version.version, resp.http_body - assert_match (/(\d+\.)?(\d+\.)?(\d+\.)?(\d+)/), version.version + assert_match(version.version, resp.http_body) + assert_match(/(\d+\.)?(\d+\.)?(\d+\.)?(\d+)/, version.version) end end diff --git a/test/logoff_test.rb b/test/logoff_test.rb index 93092ac..5d336f2 100644 --- a/test/logoff_test.rb +++ b/test/logoff_test.rb @@ -1,18 +1,24 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class LogoffTest < Minitest::Test - def test_successful_logoff - username = "wland" - password = "piperita2016" - company = "L" - company_password = "" + extend Minitest::Spec::DSL + + let(:username) { 'wland' } + let(:password) { 'piperita2016' } + let(:company) { 'L' } + let(:company_password) { '' } + def test_successful_logoff uid = Syspro::Logon.logon(username, password, company, company_password) assert_equal true, Syspro::Logoff.logoff(uid.guid) end def test_logoff_error - assert_kind_of String, Syspro::Logoff.logoff('1BB5B3050954BB459A5D034DB5CC386980') + assert_kind_of( + String, + Syspro::Logoff.logoff('1BB5B3050954BB459A5D034DB5CC386980') + ) end end - diff --git a/test/logon_test.rb b/test/logon_test.rb index 8e34233..89a8779 100644 --- a/test/logon_test.rb +++ b/test/logon_test.rb @@ -1,14 +1,24 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class LogonTest < Minitest::Test - def test_logon - username = "wland" - password = "piperita2016" - company = "L" - company_password = "" - client = ::Syspro::SysproClient.new + extend Minitest::Spec::DSL + + let(:username) { 'wland' } + let(:password) { 'piperita2016' } + let(:company) { 'L' } + let(:company_password) { '' } - assert_match (/([A-Z0-9]{33})\w/), client.logon(username, password, company, company_password).guid + def test_logon + assert_match( + /([A-Z0-9]{33})\w/, + ::Syspro::SysproClient.new.logon( + username, + password, + company, + company_password + ).guid + ) end end - diff --git a/test/query_test.rb b/test/query_test.rb index f892c7a..d840223 100644 --- a/test/query_test.rb +++ b/test/query_test.rb @@ -1,18 +1,20 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class QueryTest < Minitest::Test - def test_query_browse - user_id = Syspro::Logon.logon("wland", "piperita2016", "L", "") + def test_query_browse # rubocop:disable Metrics/MethodLength + user_id = Syspro::Logon.logon('wland', 'piperita2016', 'L', '') combrw = Syspro::BusinessObjects::ComBrw.new - combrw.browse_name = "InvMaster" - combrw.start_condition = "" + combrw.browse_name = 'InvMaster' + combrw.start_condition = '' combrw.return_rows = 5 combrw.filters = [] - combrw.table_name = "InvMaster" - combrw.title = "StockCodes" + combrw.table_name = 'InvMaster' + combrw.title = 'StockCodes' combrw.columns = [ - {name: "StockCode"} + { name: 'StockCode' } ] browse_result = combrw.call(user_id.guid) @@ -20,26 +22,26 @@ class QueryTest < Minitest::Test refute_nil browse_result end - def test_query_query - user_id = Syspro::Logon.logon("wland", "piperita2016", "L", "") + def test_query_query # rubocop:disable Metrics/MethodLength + user_id = Syspro::Logon.logon('wland', 'piperita2016', 'L', '') comfnd = Syspro::BusinessObjects::ComFnd.new - comfnd.table_name = "InvMaster" + comfnd.table_name = 'InvMaster' comfnd.return_rows = 5 comfnd.columns = [ { - name: "StockCode" + name: 'StockCode' } ] comfnd.expressions = [ { - andor: "And", - column: "StockCode", - condition: "EQ", - value: "02" + andor: 'And', + column: 'StockCode', + condition: 'EQ', + value: '02' } ] - comfnd.order_by = "StockCode" + comfnd.order_by = 'StockCode' query_result = comfnd.call(user_id.guid) @@ -47,14 +49,14 @@ class QueryTest < Minitest::Test end def test_query_fetch - user_id = Syspro::Logon.logon("wland", "piperita2016", "L", "") + user_id = Syspro::Logon.logon('wland', 'piperita2016', 'L', '') comfch = Syspro::BusinessObjects::ComFch.new - comfch.table_name = "InvMaster" - comfch.key = "02" + comfch.table_name = 'InvMaster' + comfch.key = '02' comfch.optional_keys = [] comfch.full_key_provided = false - comfch.default_type = "" + comfch.default_type = '' comfch.espresso_fetch = true fetch_result = comfch.call(user_id.guid) diff --git a/test/syspro_test.rb b/test/syspro_test.rb index 3439b45..6c47b22 100644 --- a/test/syspro_test.rb +++ b/test/syspro_test.rb @@ -1,4 +1,6 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class SysproTest < Minitest::Test def test_that_it_has_a_version_number diff --git a/test/test_helper.rb b/test/test_helper.rb index 522c564..4f58449 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,5 +1,7 @@ -$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) -require "syspro" +# frozen_string_literal: true -require "pry" -require "minitest/autorun" +$LOAD_PATH.unshift File.expand_path('../lib', __dir__) +require 'syspro' + +require 'pry' +require 'minitest/autorun' -- libgit2 0.21.4