alma_rest_api 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/alma_rest_api.rb +31 -10
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d8430b1c5aef44f5448afc788e60a7046473ffc
4
- data.tar.gz: 9a137737bdd71e9a0d23937cc5370daf1353954f
3
+ metadata.gz: 1d61375252e2027bb3aff882c28b6cb9801d2e5d
4
+ data.tar.gz: a12866dcb65e95512f3d368cd4881b01b7a383c6
5
5
  SHA512:
6
- metadata.gz: 8556eb1b1f8e4c4a22eda42b0b9c4479d05075aa4538a07cc775cca38d3da5eeeb5b70f753fcf04bae719ab58c9a7d7ea8f0247e428bb5d7bead019e01e9a6c1
7
- data.tar.gz: f1905c5732536657570c6bb1e060e09eedef40765090b33b301e4731d1e6028a9bc88f6f3a49d0542175bdd3844c70a3bc07efdba7057a118e46e1926a03d128
6
+ metadata.gz: 92cfcd61cb6dcd96264935fe8dd661eb05a74f980a7ed57cfd0311baef9827694975752b647f9e5e2b07aaae88f8e162445866f01b22ece2dd4eef4367e2fbd5
7
+ data.tar.gz: bb97b8014ebfb2bd925fe25c93f24fff188bb1f46ecad3ace2b9a8f403f80fc52e184221d77475b2bbf1b20136374b9dad91083fc70ee8c782d5d3391b805a48
@@ -19,9 +19,13 @@ module AlmaRestApi
19
19
  begin
20
20
  response =
21
21
  RestClient.get uri(uri),
22
- accept: :json,
22
+ accept: configuration.format,
23
23
  authorization: 'apikey ' + configuration.api_key
24
- return JSON.parse(response.body)
24
+ if configuration.format == :"application/xml"
25
+ return Nokogiri::XML.parse(response.body)
26
+ else
27
+ return JSON.parse(response.body)
28
+ end
25
29
  rescue => e
26
30
  raise AlmaApiError, parse_error(e.response)
27
31
  end
@@ -32,11 +36,15 @@ module AlmaRestApi
32
36
  begin
33
37
  response =
34
38
  RestClient.put uri(uri),
35
- data.to_json,
36
- accept: :json,
39
+ configuration.format == :"application/xml" ? data.to_xml : data.to_json,
40
+ accept: configuration.format,
37
41
  authorization: 'apikey ' + configuration.api_key,
38
- content_type: :json
39
- return JSON.parse(response.body)
42
+ content_type: configuration.format
43
+ if configuration.format == :"application/xml"
44
+ return Nokogiri::XML.parse(response.body)
45
+ else
46
+ return JSON.parse(response.body)
47
+ end
40
48
  rescue => e
41
49
  raise AlmaApiError, parse_error(e.response)
42
50
  end
@@ -47,11 +55,15 @@ module AlmaRestApi
47
55
  begin
48
56
  response =
49
57
  RestClient.post uri(uri),
50
- data.to_json,
51
- accept: :json,
58
+ configuration.format == :"application/xml" ? data.to_xml : data.to_json,
59
+ accept: configuration.format,
52
60
  authorization: 'apikey ' + configuration.api_key,
53
- content_type: :json
54
- return JSON.parse(response.body)
61
+ content_type: configuration.format
62
+ if configuration.format == :"application/xml"
63
+ return Nokogiri::XML.parse(response.body)
64
+ else
65
+ return JSON.parse(response.body)
66
+ end
55
67
  rescue => e
56
68
  raise AlmaApiError, parse_error(e.response)
57
69
  end
@@ -77,6 +89,7 @@ module AlmaRestApi
77
89
 
78
90
  def check_config
79
91
  raise NoApiKeyError if configuration.api_key.nil? || configuration.api_key.empty?
92
+ raise InvalidApiFormatError unless [:json, :"application/xml"].include? configuration.format
80
93
  end
81
94
 
82
95
  def parse_error(err)
@@ -108,10 +121,12 @@ end
108
121
  class Configuration
109
122
  attr_accessor :api_key
110
123
  attr_accessor :api_path
124
+ attr_accessor :format
111
125
 
112
126
  def initialize
113
127
  @api_key = ENV['ALMA_APIKEY']
114
128
  @api_path = ENV['ALMA_APIPATH'] || "https://api-na.hosted.exlibrisgroup.com/almaws/v1"
129
+ @format = ENV['ALMA_FORMAT'] || :json
115
130
  end
116
131
  end
117
132
 
@@ -121,6 +136,12 @@ class NoApiKeyError < StandardError
121
136
  end
122
137
  end
123
138
 
139
+ class InvalidApiFormatError < StandardError
140
+ def initialize(msg="API format must be :json or :\"application/xml\"")
141
+ super
142
+ end
143
+ end
144
+
124
145
  class AlmaApiError < StandardError
125
146
  def initialize(msg)
126
147
  msg = "Unknown error from Alma" if msg.empty?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alma_rest_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Weisman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-17 00:00:00.000000000 Z
11
+ date: 2019-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client