Skip to content

Commit

Permalink
Merge pull request #4 from mlibrary/ox-to-activesupport
Browse files Browse the repository at this point in the history
uses activesupport the turn xml into hash
  • Loading branch information
niquerio authored Oct 21, 2021
2 parents c7063d2 + 50a6eab commit 1d41c63
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
36 changes: 24 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion alma_rest_client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 6 additions & 11 deletions lib/alma_rest_client.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/alma_rest_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module AlmaRestClient
VERSION = "1.0.1"
VERSION = "1.1.0"
end

0 comments on commit 1d41c63

Please sign in to comment.