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 +4 -4
- data/lib/authentise/api.rb +7 -0
- data/lib/authentise/api/print.rb +12 -8
- data/lib/authentise/api/users.rb +2 -3
- data/lib/authentise/api/warehouse.rb +7 -7
- data/lib/authentise/version.rb +1 -1
- data/spec/api/print_spec.rb +9 -2
- data/spec/api/users_spec.rb +6 -2
- data/spec/api/warehouse_spec.rb +6 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3aef31bbee80882d5a0fb9cc9f8886618a6a1392
|
4
|
+
data.tar.gz: 5ab1be6cb10ae50d499c3b36c016625a78933042
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76767cfbb943f34a0c6adff9360a520cc2038dddb4f2a245837735c32b3875a72f016be95dd4f1464d85a6e8b6a04f2f8a4fc16664f23f98b362b13e9717b263
|
7
|
+
data.tar.gz: b00686d2645056043d11342547711b2de495d0e96f658de7b4d4d7d30a36091abcda194caddbce63e0f34995f7d8f6301a6aa4a258297b10a83e8f1c24cf2b73
|
data/lib/authentise/api.rb
CHANGED
@@ -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(…)
|
data/lib/authentise/api/print.rb
CHANGED
@@ -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
|
-
|
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
|
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
|
data/lib/authentise/api/users.rb
CHANGED
@@ -32,7 +32,7 @@ module Authentise
|
|
32
32
|
uuid: json["uuid"],
|
33
33
|
}
|
34
34
|
else
|
35
|
-
fail
|
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
|
-
|
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
|
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
|
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
|
84
|
+
fail NotFoundError
|
85
85
|
else
|
86
|
-
fail
|
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
|
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
|
199
|
+
fail NotFoundError
|
200
200
|
else
|
201
|
-
fail
|
201
|
+
fail UnknownResponseCodeError.new(response.code, response)
|
202
202
|
end
|
203
203
|
end
|
204
204
|
end
|
data/lib/authentise/version.rb
CHANGED
data/spec/api/print_spec.rb
CHANGED
@@ -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:
|
49
|
+
.to_return(status: 400, body: @response_error_body)
|
45
50
|
|
46
|
-
assert_raises Authentise::API::
|
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
|
data/spec/api/users_spec.rb
CHANGED
@@ -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::
|
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::
|
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
|
data/spec/api/warehouse_spec.rb
CHANGED
@@ -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::
|
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::
|
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.
|
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-
|
11
|
+
date: 2015-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|