hydra-remote_identifier 0.6.0 → 0.6.1

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
  SHA1:
3
- metadata.gz: 99922dd154a6430c8dd64418d60db843a3f1082a
4
- data.tar.gz: 0e6d029a6ae54490e3d5b6270469eb6a4ee57932
3
+ metadata.gz: 6ac8dc0f0b85926cf288ac03f12db9d73214dd6c
4
+ data.tar.gz: 3c4ae6364a1f553290673f61bbb2eb22eaafd514
5
5
  SHA512:
6
- metadata.gz: f22cacf89302908db05f330156f84f9a4145881b113ae1571e3e92338d3e8456e91b550af7860a53a74e39e9ab13f45ce7c05ad6ca3d02d11f968e405fcfd47f
7
- data.tar.gz: 234cbd5325b35472d2d003f22bf5bc6ed3527b397548777cc643a5baaf7f29465962eab419dc808f1189fa09015cb88964829245af6c9ea875da4ad49e8c5e29
6
+ metadata.gz: 252283bc9042efb903196966abb512d0dca158bb879f31f7774fd0849687af7a9e0e1157d57b9d7809ad3f799c01891cecba1aa6ad1c5bf3ecb3e2abd594b51e
7
+ data.tar.gz: c283ff802068b8eb57cc5a52d5a13d4dcc32997f8682c3b56eb5d1452c727dd161191dbacb169cb904e85d87438847d97e6687121ca9f562684fec3550190eda
@@ -4,4 +4,43 @@ module Hydra::RemoteIdentifier
4
4
  super(errors.join(". ") << '.')
5
5
  end
6
6
  end
7
+
8
+ class RemoteServiceError < RuntimeError
9
+ def initialize(exception, uri, payload)
10
+ @exception = exception
11
+ @uri = uri
12
+ @payload = payload
13
+ end
14
+
15
+ def to_s
16
+ text = ""
17
+ text << "response.code: #{response_code.inspect}\n"
18
+ text << "response.body: #{response_body.inspect}\n"
19
+ text << "\n"
20
+ text << "request.uri: #{request_sanitized_uri.inspect}\n"
21
+ text << "request.payload: #{request_sanitized_paylod.inspect}\n"
22
+ end
23
+
24
+ private
25
+ def request_sanitized_paylod
26
+ @payload
27
+ end
28
+
29
+ def request_sanitized_uri
30
+ uri = URI.parse(@uri.to_s)
31
+ x = "#{uri.scheme}://"
32
+ x << "xxx:xxx@" if uri.user || uri.password
33
+ x << File.join(uri.host, uri.path)
34
+ x << '?' << uri.query if uri.query
35
+ x
36
+ end
37
+
38
+ def response_code
39
+ @exception.http_code rescue NoMethodError @exception.to_s
40
+ end
41
+
42
+ def response_body
43
+ @exception.http_body rescue NoMethodError 'unknown'
44
+ end
45
+ end
7
46
  end
@@ -49,6 +49,8 @@ module Hydra::RemoteIdentifier
49
49
  response = RestClient.post(uri_for_create.to_s, data, content_type: 'text/plain')
50
50
  matched_data = /\Asuccess:(.*)(?<doi>doi:[^\|]*)(.*)\Z/.match(response.body)
51
51
  matched_data[:doi].strip
52
+ rescue RestClient::Exception => e
53
+ raise(RemoteServiceError.new(e, uri_for_create, payload))
52
54
  end
53
55
 
54
56
  def data_for_create(payload)
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module RemoteIdentifier
3
- VERSION = "0.6.0"
3
+ VERSION = "0.6.1"
4
4
  end
5
5
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require File.expand_path('../../../../../lib/hydra/remote_identifier/exceptions', __FILE__)
3
+ module Hydra::RemoteIdentifier
4
+ describe RemoteServiceError do
5
+ let(:payload) { "This is my payload!" }
6
+ let(:uri) { URI.parse('http://username:password@hello-world.com/path/to/resource?show=1') }
7
+ let(:exception) { double(http_code: '400 Bad Request', http_body: 'This is the raw response') }
8
+ subject { RemoteServiceError.new(exception, uri, payload) }
9
+
10
+ let(:expected_message) {
11
+ x = []
12
+ x << 'response.code: "400 Bad Request"'
13
+ x << 'response.body: "This is the raw response"'
14
+ x << ''
15
+ x << 'request.uri: "http://xxx:xxx@hello-world.com/path/to/resource?show=1"'
16
+ x << 'request.payload: "This is my payload!"'
17
+ x << ''
18
+ x.join("\n")
19
+ }
20
+
21
+ its(:to_s) { should eq(expected_message) }
22
+ end
23
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-remote_identifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-15 00:00:00.000000000 Z
11
+ date: 2013-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -121,6 +121,7 @@ files:
121
121
  - spec/fixtures/cassettes/doi-create.yml
122
122
  - spec/fixtures/cassettes/doi-integration.yml
123
123
  - spec/lib/hydra/remote_identifier/configuration_spec.rb
124
+ - spec/lib/hydra/remote_identifier/exceptions_spec.rb
124
125
  - spec/lib/hydra/remote_identifier/mapper_spec.rb
125
126
  - spec/lib/hydra/remote_identifier/minter_spec.rb
126
127
  - spec/lib/hydra/remote_identifier/minting_coordinator_spec.rb
@@ -158,6 +159,7 @@ test_files:
158
159
  - spec/fixtures/cassettes/doi-create.yml
159
160
  - spec/fixtures/cassettes/doi-integration.yml
160
161
  - spec/lib/hydra/remote_identifier/configuration_spec.rb
162
+ - spec/lib/hydra/remote_identifier/exceptions_spec.rb
161
163
  - spec/lib/hydra/remote_identifier/mapper_spec.rb
162
164
  - spec/lib/hydra/remote_identifier/minter_spec.rb
163
165
  - spec/lib/hydra/remote_identifier/minting_coordinator_spec.rb