From fe91127115ba4d1929b3b8aad5950d7ca0351574 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Thu, 21 Oct 2021 12:46:59 -0400 Subject: [PATCH 1/2] uses activesupport the turn xml into hash --- Gemfile.lock | 36 ++++++++++++++++++++++++------------ alma_rest_client.gemspec | 3 ++- lib/alma_rest_client.rb | 17 ++++++----------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index e1d4239..2373253 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,31 +2,40 @@ PATH remote: . specs: alma_rest_client (1.0.1) + activesupport (~> 6.0, >= 4.2) httparty - ox GEM remote: https://rubygems.org/ specs: - addressable (2.7.0) + activesupport (6.1.4.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) byebug (11.1.3) + concurrent-ruby (1.1.9) crack (0.4.5) rexml diff-lcs (1.4.4) - docile (1.3.5) + docile (1.4.0) hashdiff (1.0.1) - httparty (0.18.1) + httparty (0.20.0) mime-types (~> 3.0) multi_xml (>= 0.5.2) + i18n (1.8.10) + concurrent-ruby (~> 1.0) mime-types (3.3.1) mime-types-data (~> 3.2015) - mime-types-data (3.2021.0212) + mime-types-data (3.2021.0901) + minitest (5.14.4) multi_xml (0.6.0) - ox (2.14.1) public_suffix (4.0.6) rake (12.3.3) - rexml (3.2.4) + rexml (3.2.5) rspec (3.10.0) rspec-core (~> 3.10.0) rspec-expectations (~> 3.10.0) @@ -36,20 +45,23 @@ GEM rspec-expectations (3.10.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) - rspec-mocks (3.10.1) + rspec-mocks (3.10.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) - rspec-support (3.10.1) + rspec-support (3.10.2) simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) - simplecov_json_formatter (0.1.2) - webmock (3.11.1) - addressable (>= 2.3.6) + simplecov_json_formatter (0.1.3) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) + webmock (3.14.0) + addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) + zeitwerk (2.5.1) PLATFORMS ruby diff --git a/alma_rest_client.gemspec b/alma_rest_client.gemspec index 535c500..568dc0e 100644 --- a/alma_rest_client.gemspec +++ b/alma_rest_client.gemspec @@ -28,7 +28,8 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_runtime_dependency "httparty" - spec.add_runtime_dependency "ox" + spec.add_runtime_dependency "activesupport", '>= 4.2', '~> 6.0' + spec.add_development_dependency "byebug" spec.add_development_dependency "rspec" diff --git a/lib/alma_rest_client.rb b/lib/alma_rest_client.rb index 8ba9c48..d9efe94 100644 --- a/lib/alma_rest_client.rb +++ b/lib/alma_rest_client.rb @@ -1,6 +1,6 @@ require "alma_rest_client/version" -require "ox" require 'httparty' +require 'active_support/core_ext/hash/conversions' module AlmaRestClient class Error < StandardError; end @@ -29,12 +29,6 @@ def initialize() end end - ##requires valid json for the body - #def put(url, body) - #self.class.headers 'Content-Type' => 'application/json' - #self.class.put(url, { body: body } ) - #end - #record_key is the key that holds the array of items def get_all(url:, record_key:, limit: 100, query: {}) try_count = 1 @@ -73,10 +67,11 @@ def report_loop(path:,limit:,col_names:) if response.code != 200 return Response.new(code: 500, message: 'Could not retrieve report.') end - xml = Ox.load(response.parsed_response["anies"].first, mode: :hash, symbolize_keys: false) + xml_string = response.parsed_response["anies"].first + xml = Hash.from_xml(xml_string) query[:token] = xml["QueryResult"]["ResumptionToken"] - col_raw = xml["QueryResult"]["ResultXml"]["rowset"]["xsd:schema"][1]["xsd:complexType"][1]["xsd:sequence"]["xsd:element"] - col_raw.each {|x| columns[x.first["name"]] = x.first["saw-sql:columnHeading"] } + col_raw = xml["QueryResult"]["ResultXml"]["rowset"]["schema"]["complexType"]["sequence"]["element"] + col_raw.each {|x| columns[x["name"]] = x["saw-sql:columnHeading"] } loop do rows = xml["QueryResult"]["ResultXml"]["rowset"]["Row"] @@ -91,7 +86,7 @@ def report_loop(path:,limit:,col_names:) else response = get("/analytics/reports", query: query) if response.code == 200 - xml = Ox.load(response.parsed_response["anies"].first, mode: :hash, symbolize_keys: false) + xml = Hash.from_xml(response.parsed_response["anies"].first) else return Response.new(code: 500, message: 'Could not retrieve report.') end From 50a6eab99ed1e70cd8a3b0a383261aa984e7e209 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Thu, 21 Oct 2021 12:50:58 -0400 Subject: [PATCH 2/2] updated version --- lib/alma_rest_client/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/alma_rest_client/version.rb b/lib/alma_rest_client/version.rb index 38d8738..06e3a43 100644 --- a/lib/alma_rest_client/version.rb +++ b/lib/alma_rest_client/version.rb @@ -1,3 +1,3 @@ module AlmaRestClient - VERSION = "1.0.1" + VERSION = "1.1.0" end