authentise 0.2.0 → 0.2.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: b5c482f7dd3c413ce5388825d6e8f166b1fe3e1c
4
- data.tar.gz: 1d396496e639f998e7b367a2a21710a27ae65eaf
3
+ metadata.gz: 3aef31bbee80882d5a0fb9cc9f8886618a6a1392
4
+ data.tar.gz: 5ab1be6cb10ae50d499c3b36c016625a78933042
5
5
  SHA512:
6
- metadata.gz: ea354a546c8a850305183e55728b10d090bb17ce600dc1f9c2942c03b1317bb9c9ed44610181efb4585031e684c08f7d707b29fcf66d3e8086e208010ceef08b
7
- data.tar.gz: 554da033fd57e3b024b3d264a4e4195a4d9ae88f54fe6dcabef9860a9ba7e6690bd321302691192f33ee345e197d1ca695aff6e0be179c5996dd95f725bd6a22
6
+ metadata.gz: 76767cfbb943f34a0c6adff9360a520cc2038dddb4f2a245837735c32b3875a72f016be95dd4f1464d85a6e8b6a04f2f8a4fc16664f23f98b362b13e9717b263
7
+ data.tar.gz: b00686d2645056043d11342547711b2de495d0e96f658de7b4d4d7d30a36091abcda194caddbce63e0f34995f7d8f6301a6aa4a258297b10a83e8f1c24cf2b73
@@ -11,6 +11,13 @@ module Authentise
11
11
  # 404 Error
12
12
  class NotFoundError < Error; end
13
13
 
14
+ # Other response codes
15
+ class UnknownResponseCodeError < Error
16
+ def initialize(code, message)
17
+ super("(#{code}) #{message}")
18
+ end
19
+ end
20
+
14
21
  module_function
15
22
 
16
23
  # DEPRECATED, use Authentise::API::Print.create_token(…)
@@ -20,21 +20,25 @@ module Authentise
20
20
  print_value_currency: print_value_currency,
21
21
  partner_job_id: partner_job_id,
22
22
  }.to_json
23
- options = {
24
- content_type: :json,
25
- accept: :json,
26
- open_timeout: 2,
27
- timeout: 2,
28
- }
29
- RestClient.post(url, body, options) do |response, _request, _result|
23
+ RestClient.post(url, body, rest_client_options) do |response, _, _|
30
24
  if response.code == 201
31
25
  { url: response.headers[:x_token_location] }
32
26
  else
33
- fail API::Error, response
27
+ fail UnknownResponseCodeError.new(response.code, response)
34
28
  end
35
29
  end
36
30
  end
37
31
 
32
+ private
33
+
34
+ def rest_client_options
35
+ {
36
+ content_type: :json,
37
+ accept: :json,
38
+ open_timeout: 2,
39
+ timeout: 2,
40
+ }
41
+ end
38
42
  end
39
43
  end
40
44
  end
@@ -32,7 +32,7 @@ module Authentise
32
32
  uuid: json["uuid"],
33
33
  }
34
34
  else
35
- fail API::Error, json["message"]
35
+ fail UnknownResponseCodeError.new(response.code, response)
36
36
  end
37
37
  end
38
38
  end
@@ -58,8 +58,7 @@ module Authentise
58
58
  token: response.cookies["session"],
59
59
  }
60
60
  else
61
- json = JSON.parse(response)
62
- fail API::Error, json["message"]
61
+ fail UnknownResponseCodeError.new(response.code, response)
63
62
  end
64
63
  end
65
64
  end
@@ -46,7 +46,7 @@ module Authentise
46
46
  upload_url: response.headers[:x_upload_location],
47
47
  }
48
48
  else
49
- fail API::Error, JSON.parse(response)["message"]
49
+ fail UnknownResponseCodeError.new(response.code, response)
50
50
  end
51
51
  end
52
52
  end
@@ -62,7 +62,7 @@ module Authentise
62
62
  if response.code == 200
63
63
  true
64
64
  else
65
- fail API::Error, response
65
+ fail UnknownResponseCodeError.new(response.code, response)
66
66
  end
67
67
  end
68
68
  end
@@ -81,9 +81,9 @@ module Authentise
81
81
  if response.code == 200
82
82
  parse_model(response, url)
83
83
  elsif response.code == 404
84
- fail Authentise::API::NotFoundError
84
+ fail NotFoundError
85
85
  else
86
- fail Authentise::API::Error, "Error #{response.code}"
86
+ fail UnknownResponseCodeError.new(response.code, response)
87
87
  end
88
88
  end
89
89
  end
@@ -177,7 +177,7 @@ module Authentise
177
177
  url: response.headers[:location],
178
178
  }
179
179
  else
180
- fail API::Error, JSON.parse(response)["message"]
180
+ fail UnknownResponseCodeError.new(response.code, response)
181
181
  end
182
182
  end
183
183
  end
@@ -196,9 +196,9 @@ module Authentise
196
196
  if response.code == 200
197
197
  parse_snapshot(response)
198
198
  elsif response.code == 404
199
- fail Authentise::API::NotFoundError
199
+ fail NotFoundError
200
200
  else
201
- fail Authentise::API::Error, "Error #{response.code}"
201
+ fail UnknownResponseCodeError.new(response.code, response)
202
202
  end
203
203
  end
204
204
  end
@@ -1,3 +1,3 @@
1
1
  module Authentise
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -2,6 +2,11 @@ require "spec_helper"
2
2
  require "authentise/api/print"
3
3
 
4
4
  describe Authentise::API::Print do
5
+ before do
6
+ @response_error_body = {
7
+ message: "Some test error",
8
+ }.to_json
9
+ end
5
10
 
6
11
  describe "create_token" do
7
12
  it "returns a token_url" do
@@ -41,13 +46,15 @@ describe Authentise::API::Print do
41
46
 
42
47
  it "raises errors" do
43
48
  stub_request(:post, "https://print.authentise.com/token/")
44
- .to_return(status: 400, body: "Some test error")
49
+ .to_return(status: 400, body: @response_error_body)
45
50
 
46
- assert_raises Authentise::API::Error do
51
+ err = assert_raises Authentise::API::UnknownResponseCodeError do
47
52
  Authentise::API::Print.create_token(
48
53
  model_url: "http://example.com/model/42",
49
54
  )
50
55
  end
56
+
57
+ err.message.must_equal('(400) {"message":"Some test error"}')
51
58
  end
52
59
  end
53
60
  end
@@ -50,7 +50,7 @@ describe Authentise::API::Users do
50
50
  .with(body: @request_body, headers: @request_headers)
51
51
  .to_return(status: 400, body: @response_error_body)
52
52
 
53
- assert_raises Authentise::API::Error do
53
+ err = assert_raises Authentise::API::UnknownResponseCodeError do
54
54
  Authentise::API::Users.create_user(
55
55
  email: "test@example.com",
56
56
  name: "Test User",
@@ -58,6 +58,8 @@ describe Authentise::API::Users do
58
58
  password: "password",
59
59
  )
60
60
  end
61
+
62
+ err.message.must_equal('(400) {"message":"Some test error"}')
61
63
  end
62
64
  end
63
65
 
@@ -97,12 +99,14 @@ describe Authentise::API::Users do
97
99
  stub_request(:post, "https://users.authentise.com/sessions/")
98
100
  .to_return(status: 400, body: @response_error_body)
99
101
 
100
- assert_raises Authentise::API::Error do
102
+ err = assert_raises Authentise::API::UnknownResponseCodeError do
101
103
  Authentise::API::Users.create_session(
102
104
  username: "testuser",
103
105
  password: "password",
104
106
  )
105
107
  end
108
+
109
+ err.message.must_equal('(400) {"message":"Some test error"}')
106
110
  end
107
111
  end
108
112
  end
@@ -44,12 +44,14 @@ describe Authentise::API::Warehouse do
44
44
  .with(body: @request_body.to_json, headers: @request_headers)
45
45
  .to_return(status: 400, body: @response_error_body)
46
46
 
47
- assert_raises Authentise::API::Error do
47
+ err = assert_raises Authentise::API::UnknownResponseCodeError do
48
48
  Authentise::API::Warehouse.create_model(
49
49
  name: "Test",
50
50
  session_token: "f45k",
51
51
  )
52
52
  end
53
+
54
+ err.message.must_equal('(400) {"message":"Some test error"}')
53
55
  end
54
56
  end
55
57
 
@@ -78,12 +80,14 @@ describe Authentise::API::Warehouse do
78
80
  stub_request(:put, "https://example.com/")
79
81
  .to_return(status: 400, body: @response_error_body)
80
82
 
81
- assert_raises Authentise::API::Error do
83
+ err = assert_raises Authentise::API::UnknownResponseCodeError do
82
84
  Authentise::API::Warehouse.put_file(
83
85
  url: "https://example.com/",
84
86
  path: "spec/fixtures/example.stl",
85
87
  )
86
88
  end
89
+
90
+ err.message.must_equal('(400) {"message":"Some test error"}')
87
91
  end
88
92
  end
89
93
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authentise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sunny Ripert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-31 00:00:00.000000000 Z
11
+ date: 2015-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client