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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nypl_sierra_api_client.rb +21 -14
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97ad20a44e5b1d4dc53174144e79f4aa629e1d94e9921c0ef70d25d39833caa3
4
- data.tar.gz: 8052d7fc2ca5d8dc05b4499155987b3715c6a55d73334f9b4252aefa42fe97d8
3
+ metadata.gz: f83a3d06d4010dd2b229b09358e70ff5c4afadbffb92c0d6407b6cf79b41d7dc
4
+ data.tar.gz: 2dab1288ee02fe238c9517a4bddb7ddcde36dc3a036ed61890c57854186d0dc0
5
5
  SHA512:
6
- metadata.gz: 6a517f2d692e88148538d832a007202e5fed71633585e67df3f08812fd7cd1b1e6c33a4d7bdd41869ab99db4cfaee1710b5981d29527cbb8e762e3d6b65bd7a3
7
- data.tar.gz: 7da59ea28ed543feb1f1aca8d36868c82faa65ca2901893c498d5762f1bd3f5f8137101b604118515f2e1c1a09bc21ffdae440983e055f053b375cd8861999b4
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
- @config = {
12
- base_url: ENV['SIERRA_API_BASE_URL'],
13
- client_id: ENV['SIERRA_OAUTH_ID'],
14
- client_secret: ENV['SIERRA_OAUTH_SECRET'],
15
- oauth_url: ENV['SIERRA_OAUTH_URL'],
16
- log_level: 'info'
17
- }.merge config
18
-
19
- raise SierraApiClientError.new 'Missing config: neither config.base_url nor ENV.SIERRA_API_BASE_URL are set' unless @config[:base_url]
20
- raise SierraApiClientError.new 'Missing config: neither config.client_id nor ENV.SIERRA_OAUTH_ID are set' unless @config[:client_id]
21
- raise SierraApiClientError.new 'Missing config: neither config.client_secret nor ENV.SIERRA_OAUTH_SECRET are set ' unless @config[:client_secret]
22
- raise SierraApiClientError.new 'Missing config: neither config.oauth_url nor ENV.SIERRA_OAUTH_URL are set ' unless @config[:oauth_url]
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.path, request_headers)
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nypl_sierra_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - nonword