nypl_sierra_api_client 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nypl_sierra_api_client.rb +21 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f83a3d06d4010dd2b229b09358e70ff5c4afadbffb92c0d6407b6cf79b41d7dc
|
4
|
+
data.tar.gz: 2dab1288ee02fe238c9517a4bddb7ddcde36dc3a036ed61890c57854186d0dc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a349f8a998f13cce0180ecce092f79601c06cc376059fc349add4e98d802532bc8dcf487c0dd2ce574bffa16e70e2c6bce9f4a50e92f392258670a63eb3157af
|
7
|
+
data.tar.gz: 46cb45de0dbb360f12177af4d51102d84e056f7f223d6545a3ff3bc5d1a700f1c5a06115747b00cb6583283a2f28367e95cd8851a25bf90d7205807e9fe09987
|
@@ -8,18 +8,25 @@ require_relative 'sierra_api_response'
|
|
8
8
|
|
9
9
|
class SierraApiClient
|
10
10
|
def initialize(config = {})
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
config_defaults = {
|
12
|
+
env: {
|
13
|
+
base_url: 'SIERRA_API_BASE_URL',
|
14
|
+
client_id: 'SIERRA_OAUTH_ID',
|
15
|
+
client_secret: 'SIERRA_OAUTH_SECRET',
|
16
|
+
oauth_url: 'SIERRA_OAUTH_URL'
|
17
|
+
},
|
18
|
+
static: {
|
19
|
+
log_level: 'info'
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
@config = config_defaults[:env].map {|k,v| [k, ENV[k]]}.to_h
|
24
|
+
.merge config_defaults[:static]
|
25
|
+
.merge config
|
26
|
+
|
27
|
+
config_defaults[:env].each do |key, value|
|
28
|
+
raise SierraApiClient.new "Missing config: neither config.#{key} nor ENV.#{value} are set" unless @config[key]
|
29
|
+
end
|
23
30
|
end
|
24
31
|
|
25
32
|
def get (path, options = {})
|
@@ -58,7 +65,7 @@ class SierraApiClient
|
|
58
65
|
request_headers['Content-Type'] = options[:headers]['Content-Type'] unless options.dig(:headers, 'Content-Type').nil?
|
59
66
|
|
60
67
|
# Create HTTP::Get or HTTP::Post
|
61
|
-
request = Net::HTTP.const_get(method.capitalize).new(uri
|
68
|
+
request = Net::HTTP.const_get(method.capitalize).new(uri, request_headers)
|
62
69
|
|
63
70
|
# Add bearer token header
|
64
71
|
request['Authorization'] = "Bearer #{@access_token}" if options[:authenticated]
|
@@ -87,7 +94,7 @@ class SierraApiClient
|
|
87
94
|
@access_token = nil
|
88
95
|
raise SierraApiClientTokenError.new("Got a 401: #{response.body}")
|
89
96
|
end
|
90
|
-
|
97
|
+
|
91
98
|
SierraApiResponse.new(response)
|
92
99
|
end
|
93
100
|
|