preservation-client 2.2.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2b61bc152d52b868d7274c7e29753dca42e4547f04c836766922bad0eca4ed9
4
- data.tar.gz: 36f04a3919075d95729a6b74108f4acb9c5bb68f6625e4fc0e6b5a19f16fc52d
3
+ metadata.gz: dfb058593a0636a69c8a496a846dbfdcee34ebe79475545c80999642dffc5ffd
4
+ data.tar.gz: c0c4a0d3c0994116ff61648fcba67575adcc144edaacac0e6986dc81cf4fd117
5
5
  SHA512:
6
- metadata.gz: 7750ce3cd4ef6df3ffe47dfb8b1f693894dff7dc9ad776ade1d703447c8dc52ce00464ac780d9870c93dfbf5dddbe9bd5b7a6977aeebb80876112aa31e5773b4
7
- data.tar.gz: 3a280db80ba0163894c8510238af78337866e853f09d3a528e097046d7f7c44d5f8f69805d5d67e993eafb76fc0cff9f3d53ca63ed1549941b3d72ceb7ff69fb
6
+ metadata.gz: d742c45557b5bd9e2c8bcdee76bd24149ab6b4b225772cbbbcb7ab1f1e35a28b6f6951869c9a4e3443970562824a824dd9cdc83f06a4499fbdcdf560f992d79a
7
+ data.tar.gz: 8d0983ba3bc0d3c0def903983a118a462b496b1397d5b235c08bca37a63186a3a169fca293657acaa0c8039b52480d13f7485d2d29ba65bbba48248510e70f22
@@ -8,7 +8,7 @@ env:
8
8
  - "RAILS_VERSION=5.2.3"
9
9
  - "RAILS_VERSION=6.0.0"
10
10
 
11
- before_install: gem install bundler -v 2.0.2
11
+ before_install: gem install bundler -v 2.1.2
12
12
 
13
13
  before_script:
14
14
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
data/README.md CHANGED
@@ -37,7 +37,7 @@ end
37
37
  private
38
38
 
39
39
  def client
40
- @client ||= Preservation::Client.configure(url: Settings.preservation_catalog.url)
40
+ @client ||= Preservation::Client.configure(url: Settings.preservation_catalog.url, token: Settings.preservation_catalog.token)
41
41
  end
42
42
  ```
43
43
 
@@ -47,7 +47,7 @@ OR
47
47
  require 'preservation/client'
48
48
 
49
49
  def initialize
50
- Preservation::Client.configure(url: Settings.preservation_catalog.url)
50
+ Preservation::Client.configure(url: Settings.preservation_catalog.url, token: Settings.preservation_catalog.token)
51
51
  end
52
52
 
53
53
  def do_the_thing
@@ -55,7 +55,9 @@ def do_the_thing
55
55
  end
56
56
  ```
57
57
 
58
- Note that the client may **not** be used without first having been configured, and the `url` keyword is **required**.
58
+ Note that the client may **not** be used without first having been configured, and both the `url` and `token` keywords are **required**.
59
+
60
+ See https://github.com/sul-dlss/preservation_catalog#api for info on obtaining a valid API token.
59
61
 
60
62
  Note that the preservation service is behind a firewall.
61
63
 
@@ -27,6 +27,7 @@ module Preservation
27
27
  class ConnectionFailedError < Error; end
28
28
 
29
29
  DEFAULT_API_VERSION = 'v1'
30
+ TOKEN_HEADER = 'Authorization'
30
31
 
31
32
  include Singleton
32
33
 
@@ -42,8 +43,10 @@ module Preservation
42
43
 
43
44
  class << self
44
45
  # @param [String] url
45
- def configure(url:)
46
+ # @param [String] token a bearer token for HTTP authentication
47
+ def configure(url:, token:)
46
48
  instance.url = url
49
+ instance.token = token
47
50
 
48
51
  # Force connection to be re-established when `.configure` is called
49
52
  instance.connection = nil
@@ -54,7 +57,7 @@ module Preservation
54
57
  delegate :objects, :update, to: :instance
55
58
  end
56
59
 
57
- attr_writer :url, :connection
60
+ attr_writer :url, :connection, :token
58
61
  delegate :update, to: :catalog
59
62
 
60
63
  private
@@ -63,6 +66,10 @@ module Preservation
63
66
  @url || raise(Error, 'url has not yet been configured')
64
67
  end
65
68
 
69
+ def token
70
+ @token || raise(Error, 'auth token has not been configured')
71
+ end
72
+
66
73
  def connection
67
74
  @connection ||= Faraday.new(url) do |builder|
68
75
  builder.use ErrorFaradayMiddleware
@@ -70,6 +77,7 @@ module Preservation
70
77
  builder.use Faraday::Response::RaiseError # raise exceptions on 40x, 50x responses
71
78
  builder.adapter Faraday.default_adapter
72
79
  builder.headers[:user_agent] = user_agent
80
+ builder.headers[TOKEN_HEADER] = "Bearer #{token}"
73
81
  end
74
82
  end
75
83
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Preservation
4
4
  class Client
5
- VERSION = '2.2.0'
5
+ VERSION = '3.0.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: preservation-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naomi Dushay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-15 00:00:00.000000000 Z
11
+ date: 2020-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -225,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
225
  - !ruby/object:Gem::Version
226
226
  version: '0'
227
227
  requirements: []
228
- rubygems_version: 3.0.3
228
+ rubygems_version: 3.1.2
229
229
  signing_key:
230
230
  specification_version: 4
231
231
  summary: A thin client for getting info from SDR preservation.