authentise 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +65 -25
- data/lib/authentise/api/print.rb +38 -0
- data/lib/authentise/api/users.rb +64 -0
- data/lib/authentise/api/warehouse.rb +258 -0
- data/lib/authentise/api.rb +23 -13
- data/lib/authentise/configuration.rb +10 -0
- data/lib/authentise/model.rb +88 -0
- data/lib/authentise/print.rb +37 -0
- data/lib/authentise/session.rb +25 -0
- data/lib/authentise/upload.rb +1 -0
- data/lib/authentise/user.rb +35 -0
- data/lib/authentise/version.rb +1 -1
- data/lib/authentise.rb +4 -0
- data/spec/api/print_spec.rb +53 -0
- data/spec/api/users_spec.rb +108 -0
- data/spec/api/warehouse_spec.rb +330 -0
- data/spec/api_spec.rb +10 -16
- data/spec/fixtures/example.stl +1 -0
- data/spec/model_spec.rb +135 -0
- data/spec/print_spec.rb +46 -0
- data/spec/session_spec.rb +30 -0
- data/spec/upload_spec.rb +26 -22
- data/spec/user_spec.rb +44 -0
- metadata +25 -2
@@ -0,0 +1,37 @@
|
|
1
|
+
require "authentise/api/print"
|
2
|
+
|
3
|
+
module Authentise
|
4
|
+
# Represents a streaming print iframe request
|
5
|
+
class Print
|
6
|
+
attr_accessor :model_url,
|
7
|
+
:receiver_email,
|
8
|
+
:print_value,
|
9
|
+
:print_value_currency,
|
10
|
+
:partner_job_id
|
11
|
+
|
12
|
+
def initialize(model_url: nil,
|
13
|
+
receiver_email: nil,
|
14
|
+
print_value: nil,
|
15
|
+
print_value_currency: nil,
|
16
|
+
partner_job_id: nil)
|
17
|
+
@model_url = model_url
|
18
|
+
@receiver_email = receiver_email
|
19
|
+
@print_value = print_value
|
20
|
+
@print_value_currency = print_value_currency
|
21
|
+
@partner_job_id = partner_job_id
|
22
|
+
end
|
23
|
+
|
24
|
+
def url
|
25
|
+
@url ||= begin
|
26
|
+
response = API::Print.create_token(
|
27
|
+
model_url: model_url,
|
28
|
+
receiver_email: receiver_email,
|
29
|
+
print_value: print_value,
|
30
|
+
print_value_currency: print_value_currency,
|
31
|
+
partner_job_id: partner_job_id,
|
32
|
+
)
|
33
|
+
response[:url]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "authentise/api/users"
|
2
|
+
|
3
|
+
module Authentise
|
4
|
+
# Represents a user's session to use the API with a session cookie
|
5
|
+
class Session
|
6
|
+
attr_reader :username,
|
7
|
+
:password,
|
8
|
+
:token
|
9
|
+
|
10
|
+
def initialize(username: nil,
|
11
|
+
password: nil)
|
12
|
+
@username = username
|
13
|
+
@password = password
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
response = API::Users.create_session(
|
18
|
+
username: username,
|
19
|
+
password: password,
|
20
|
+
)
|
21
|
+
@token = response[:token]
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/authentise/upload.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "authentise/api"
|
2
|
+
|
3
|
+
module Authentise
|
4
|
+
# Represents a user that can use the API
|
5
|
+
class User
|
6
|
+
attr_reader :email,
|
7
|
+
:name,
|
8
|
+
:username,
|
9
|
+
:password,
|
10
|
+
:url,
|
11
|
+
:uuid
|
12
|
+
|
13
|
+
def initialize(email: nil,
|
14
|
+
name: nil,
|
15
|
+
username: nil,
|
16
|
+
password: nil)
|
17
|
+
@email = email
|
18
|
+
@name = name
|
19
|
+
@username = username
|
20
|
+
@password = password
|
21
|
+
end
|
22
|
+
|
23
|
+
def create
|
24
|
+
response = API::Users.create_user(
|
25
|
+
email: email,
|
26
|
+
name: name,
|
27
|
+
username: username,
|
28
|
+
password: password,
|
29
|
+
)
|
30
|
+
@url = response[:url]
|
31
|
+
@uuid = response[:uuid]
|
32
|
+
true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/authentise/version.rb
CHANGED
data/lib/authentise.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "authentise/api/print"
|
3
|
+
|
4
|
+
describe Authentise::API::Print do
|
5
|
+
|
6
|
+
describe "create_token" do
|
7
|
+
it "returns a token_url" do
|
8
|
+
request_headers = {
|
9
|
+
"Accept" => "application/json",
|
10
|
+
"Content-Type" => "application/json",
|
11
|
+
}
|
12
|
+
request_body = {
|
13
|
+
api_key: "test",
|
14
|
+
model: "http://example.com/model/42",
|
15
|
+
receiver_email: "example@example.com",
|
16
|
+
print_value: 42,
|
17
|
+
print_value_currency: "EUR",
|
18
|
+
partner_job_id: 43,
|
19
|
+
}.to_json
|
20
|
+
|
21
|
+
response_headers = {
|
22
|
+
"X-Token-Location" => "http://example.com/token",
|
23
|
+
}
|
24
|
+
|
25
|
+
stub_request(:post, "https://print.authentise.com/token/")
|
26
|
+
.with(body: request_body, headers: request_headers)
|
27
|
+
.to_return(status: 201, headers: response_headers)
|
28
|
+
|
29
|
+
returned = Authentise::API::Print.create_token(
|
30
|
+
model_url: "http://example.com/model/42",
|
31
|
+
receiver_email: "example@example.com",
|
32
|
+
print_value: 42,
|
33
|
+
print_value_currency: "EUR",
|
34
|
+
partner_job_id: 43,
|
35
|
+
)
|
36
|
+
|
37
|
+
returned.must_equal(
|
38
|
+
url: "http://example.com/token",
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "raises errors" do
|
43
|
+
stub_request(:post, "https://print.authentise.com/token/")
|
44
|
+
.to_return(status: 400, body: "Some test error")
|
45
|
+
|
46
|
+
assert_raises Authentise::API::Error do
|
47
|
+
Authentise::API::Print.create_token(
|
48
|
+
model_url: "http://example.com/model/42",
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "authentise/api/users"
|
3
|
+
|
4
|
+
describe Authentise::API::Users do
|
5
|
+
before do
|
6
|
+
@response_error_body = {
|
7
|
+
message: "Some test error",
|
8
|
+
}.to_json
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "create_user" do
|
12
|
+
before do
|
13
|
+
@request_body = {
|
14
|
+
email: "test@example.com",
|
15
|
+
name: "Test User",
|
16
|
+
username: "testuser",
|
17
|
+
password: "password",
|
18
|
+
}
|
19
|
+
@request_headers = {
|
20
|
+
"Accept" => "application/json",
|
21
|
+
"Content-Type" => "application/x-www-form-urlencoded",
|
22
|
+
}
|
23
|
+
@response_body = {
|
24
|
+
name: "Test User",
|
25
|
+
username: "testuser",
|
26
|
+
uri: "https://example.com/user/1111",
|
27
|
+
uuid: "1111",
|
28
|
+
}.to_json
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns url and uuid" do
|
32
|
+
stub_request(:post, "https://users.authentise.com/users/")
|
33
|
+
.with(body: @request_body, headers: @request_headers)
|
34
|
+
.to_return(status: 201, body: @response_body)
|
35
|
+
|
36
|
+
returned = Authentise::API::Users.create_user(
|
37
|
+
email: "test@example.com",
|
38
|
+
name: "Test User",
|
39
|
+
username: "testuser",
|
40
|
+
password: "password",
|
41
|
+
)
|
42
|
+
returned.must_equal(
|
43
|
+
url: "https://example.com/user/1111",
|
44
|
+
uuid: "1111",
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "raises errors" do
|
49
|
+
stub_request(:post, "https://users.authentise.com/users/")
|
50
|
+
.with(body: @request_body, headers: @request_headers)
|
51
|
+
.to_return(status: 400, body: @response_error_body)
|
52
|
+
|
53
|
+
assert_raises Authentise::API::Error do
|
54
|
+
Authentise::API::Users.create_user(
|
55
|
+
email: "test@example.com",
|
56
|
+
name: "Test User",
|
57
|
+
username: "testuser",
|
58
|
+
password: "password",
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "create_session" do
|
65
|
+
before do
|
66
|
+
@request_body = {
|
67
|
+
username: "testuser",
|
68
|
+
password: "password",
|
69
|
+
}
|
70
|
+
@request_headers = {
|
71
|
+
"Accept" => "application/json",
|
72
|
+
"Content-Type" => "application/x-www-form-urlencoded",
|
73
|
+
}
|
74
|
+
@response_headers = {
|
75
|
+
"Set-Cookie" => "session=f4242aef; " \
|
76
|
+
"expires=Thu, 27-Apr-2017 08:49:20 GMT; " \
|
77
|
+
"path=/; " \
|
78
|
+
"domain=authentise.com",
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
it "returns a token" do
|
83
|
+
stub_request(:post, "https://users.authentise.com/sessions/")
|
84
|
+
.with(body: @request_body, headers: @request_headers)
|
85
|
+
.to_return(status: 201, body: "", headers: @response_headers)
|
86
|
+
|
87
|
+
returned = Authentise::API::Users.create_session(
|
88
|
+
username: "testuser",
|
89
|
+
password: "password",
|
90
|
+
)
|
91
|
+
returned.must_equal(
|
92
|
+
token: "f4242aef",
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "raises errors" do
|
97
|
+
stub_request(:post, "https://users.authentise.com/sessions/")
|
98
|
+
.to_return(status: 400, body: @response_error_body)
|
99
|
+
|
100
|
+
assert_raises Authentise::API::Error do
|
101
|
+
Authentise::API::Users.create_session(
|
102
|
+
username: "testuser",
|
103
|
+
password: "password",
|
104
|
+
)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,330 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "authentise/api/warehouse"
|
3
|
+
|
4
|
+
describe Authentise::API::Warehouse do
|
5
|
+
before do
|
6
|
+
@response_error_body = {
|
7
|
+
message: "Some test error",
|
8
|
+
}.to_json
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "post_model" do
|
12
|
+
before do
|
13
|
+
@request_body = {
|
14
|
+
"name" => "Test",
|
15
|
+
}
|
16
|
+
@request_headers = {
|
17
|
+
"Accept" => "application/json",
|
18
|
+
"Content-Type" => "application/json",
|
19
|
+
"Cookie" => "session=f45k",
|
20
|
+
}
|
21
|
+
@response_headers = {
|
22
|
+
"Location" => "http://example.com/1",
|
23
|
+
"X-Upload-Location" => "http://example.com/2",
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns locations" do
|
28
|
+
stub_request(:post, "https://models.authentise.com/model/")
|
29
|
+
.with(body: @request_body.to_json, headers: @request_headers)
|
30
|
+
.to_return(status: 201, headers: @response_headers)
|
31
|
+
|
32
|
+
returned = Authentise::API::Warehouse.create_model(
|
33
|
+
name: "Test",
|
34
|
+
session_token: "f45k",
|
35
|
+
)
|
36
|
+
returned.must_equal(
|
37
|
+
model_url: "http://example.com/1",
|
38
|
+
upload_url: "http://example.com/2",
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "raises errors" do
|
43
|
+
stub_request(:post, "https://models.authentise.com/model/")
|
44
|
+
.with(body: @request_body.to_json, headers: @request_headers)
|
45
|
+
.to_return(status: 400, body: @response_error_body)
|
46
|
+
|
47
|
+
assert_raises Authentise::API::Error do
|
48
|
+
Authentise::API::Warehouse.create_model(
|
49
|
+
name: "Test",
|
50
|
+
session_token: "f45k",
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "put_file" do
|
57
|
+
before do
|
58
|
+
@request_body = "contents of example.stl\n"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns true" do
|
62
|
+
request_headers = {
|
63
|
+
'Content-Type' => 'application/octet-stream',
|
64
|
+
}
|
65
|
+
stub_request(:put, "https://example.com/")
|
66
|
+
.with(body: @request_body, headers: request_headers)
|
67
|
+
.to_return(status: 200)
|
68
|
+
|
69
|
+
response = Authentise::API::Warehouse.put_file(
|
70
|
+
url: "https://example.com/",
|
71
|
+
path: "spec/fixtures/example.stl",
|
72
|
+
)
|
73
|
+
|
74
|
+
response.must_equal(true)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "raises errors" do
|
78
|
+
stub_request(:put, "https://example.com/")
|
79
|
+
.to_return(status: 400, body: @response_error_body)
|
80
|
+
|
81
|
+
assert_raises Authentise::API::Error do
|
82
|
+
Authentise::API::Warehouse.put_file(
|
83
|
+
url: "https://example.com/",
|
84
|
+
path: "spec/fixtures/example.stl",
|
85
|
+
)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "get_model" do
|
91
|
+
before do
|
92
|
+
@url = "https://models.authentise.com/model/424242/"
|
93
|
+
@request_headers = {
|
94
|
+
"Accept" => "application/json",
|
95
|
+
"Content-Type" => "application/json",
|
96
|
+
"Cookie" => "session=f56",
|
97
|
+
}
|
98
|
+
@response_body = {
|
99
|
+
name: "Test",
|
100
|
+
status: "processing",
|
101
|
+
snapshot: "http://example.com/snapshot",
|
102
|
+
content: "http://example.com/content",
|
103
|
+
"analyses.manifold" => true,
|
104
|
+
created: "2015-05-29 16:12:12.991340",
|
105
|
+
updated: "2015-05-29 16:12:13.991340",
|
106
|
+
parents: ["http://example.com/model/1", "http://example.com/model/2"],
|
107
|
+
children: ["http://example.com/model/1"],
|
108
|
+
}.to_json
|
109
|
+
end
|
110
|
+
|
111
|
+
it "returns a model" do
|
112
|
+
stub_request(:get, @url)
|
113
|
+
.with(headers: @request_headers)
|
114
|
+
.to_return(body: @response_body, status: 200)
|
115
|
+
|
116
|
+
response = Authentise::API::Warehouse.get_model(url: @url,
|
117
|
+
session_token: "f56")
|
118
|
+
response.must_equal(
|
119
|
+
url: @url,
|
120
|
+
uuid: "424242",
|
121
|
+
name: "Test",
|
122
|
+
status: "processing",
|
123
|
+
snapshot_url: "http://example.com/snapshot",
|
124
|
+
content_url: "http://example.com/content",
|
125
|
+
manifold: true,
|
126
|
+
created_at: Time.local(2015, 5, 29, 16, 12, 12, 991_340),
|
127
|
+
updated_at: Time.local(2015, 5, 29, 16, 12, 13, 991_340),
|
128
|
+
parents_urls: ["http://example.com/model/1",
|
129
|
+
"http://example.com/model/2"],
|
130
|
+
children_urls: ["http://example.com/model/1"],
|
131
|
+
)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "accepts a uuid instead of a url" do
|
135
|
+
stub_request(:get, @url)
|
136
|
+
.with(headers: @request_headers)
|
137
|
+
.to_return(body: @response_body, status: 200)
|
138
|
+
|
139
|
+
response = Authentise::API::Warehouse.get_model(uuid: "424242",
|
140
|
+
session_token: "f56")
|
141
|
+
response.must_equal(
|
142
|
+
url: @url,
|
143
|
+
uuid: "424242",
|
144
|
+
name: "Test",
|
145
|
+
status: "processing",
|
146
|
+
snapshot_url: "http://example.com/snapshot",
|
147
|
+
content_url: "http://example.com/content",
|
148
|
+
manifold: true,
|
149
|
+
created_at: Time.local(2015, 5, 29, 16, 12, 12, 991_340),
|
150
|
+
updated_at: Time.local(2015, 5, 29, 16, 12, 13, 991_340),
|
151
|
+
parents_urls: ["http://example.com/model/1",
|
152
|
+
"http://example.com/model/2"],
|
153
|
+
children_urls: ["http://example.com/model/1"],
|
154
|
+
)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "raises errors" do
|
158
|
+
stub_request(:get, @url)
|
159
|
+
.to_return(body: "", status: 404)
|
160
|
+
|
161
|
+
assert_raises Authentise::API::NotFoundError do
|
162
|
+
Authentise::API::Warehouse.get_model(url: @url,
|
163
|
+
session_token: "f56")
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# describe "get_models" do
|
169
|
+
# before do
|
170
|
+
# @request_headers = {
|
171
|
+
# "Accept" => "application/json",
|
172
|
+
# "Content-Type" => "application/json",
|
173
|
+
# "Cookie" => "session=e56",
|
174
|
+
# }
|
175
|
+
# @response_body = [{
|
176
|
+
# name: "Test",
|
177
|
+
# status: "processing",
|
178
|
+
# snapshot: "http://example.com/snapshot",
|
179
|
+
# content: "http://example.com/content",
|
180
|
+
# "analyses.manifold" => true,
|
181
|
+
# created: "2015-05-29 16:12:12.991340",
|
182
|
+
# updated: "2015-05-29 16:12:13.991340",
|
183
|
+
# parents: ["http://example.com/model/1", "http://example.com/model/2"],
|
184
|
+
# children: ["http://example.com/model/1"],
|
185
|
+
# }].to_json
|
186
|
+
# end
|
187
|
+
|
188
|
+
# it "returns models" do
|
189
|
+
# stub_request(:get, "https://models.authentise.com/model/").
|
190
|
+
# with(headers: @request_headers)
|
191
|
+
# .to_return(body: @response_body, status: 200)
|
192
|
+
|
193
|
+
# response = Authentise::API::Warehouse.get_models(session_token: "e56")
|
194
|
+
# response.must_equal [
|
195
|
+
# {
|
196
|
+
# name: "Test",
|
197
|
+
# status: "processing",
|
198
|
+
# snapshot_url: "http://example.com/snapshot",
|
199
|
+
# content_url: "http://example.com/content",
|
200
|
+
# manifold: true,
|
201
|
+
# created_at: Time.local(2015, 5, 29, 16, 12, 12, 991340),
|
202
|
+
# updated_at: Time.local(2015, 5, 29, 16, 12, 13, 991340),
|
203
|
+
# parents_urls: ["http://example.com/model/1",
|
204
|
+
# "http://example.com/model/2"],
|
205
|
+
# children_urls: ["http://example.com/model/1"]
|
206
|
+
# }
|
207
|
+
# ]
|
208
|
+
# end
|
209
|
+
|
210
|
+
# it "adds query parameters" do
|
211
|
+
# skip
|
212
|
+
# end
|
213
|
+
|
214
|
+
# it "raises errors" do
|
215
|
+
# skip
|
216
|
+
# end
|
217
|
+
# end
|
218
|
+
|
219
|
+
describe "create_snapshot" do
|
220
|
+
before do
|
221
|
+
@request_body = {
|
222
|
+
samples: 1,
|
223
|
+
layer: 10,
|
224
|
+
color: "#ff7f00",
|
225
|
+
height: 480,
|
226
|
+
width: 640,
|
227
|
+
x: 0,
|
228
|
+
y: 1,
|
229
|
+
z: 2,
|
230
|
+
u: 3,
|
231
|
+
v: 4,
|
232
|
+
w: 5,
|
233
|
+
callback: { url: "http://my.example.com/processing/done",
|
234
|
+
method: "POST" },
|
235
|
+
}
|
236
|
+
@request_headers = {
|
237
|
+
"Accept" => "application/json",
|
238
|
+
"Content-Type" => "application/json",
|
239
|
+
"Cookie" => "session=f00",
|
240
|
+
}
|
241
|
+
end
|
242
|
+
|
243
|
+
it "returns snapshot data" do
|
244
|
+
response_headers = {
|
245
|
+
"Location" => "http://example.com/model/4242/snapshot/1212/",
|
246
|
+
}
|
247
|
+
|
248
|
+
stub_request(:post, "https://models.authentise.com/model/4242/snapshot/")
|
249
|
+
.with(body: @request_body, headers: @request_headers)
|
250
|
+
.to_return(status: 201, headers: response_headers)
|
251
|
+
|
252
|
+
response = Authentise::API::Warehouse.create_snapshot(
|
253
|
+
session_token: "f00",
|
254
|
+
model_uuid: "4242",
|
255
|
+
samples: 1,
|
256
|
+
layer: 10,
|
257
|
+
color: "#ff7f00",
|
258
|
+
height: 480,
|
259
|
+
width: 640,
|
260
|
+
x: 0,
|
261
|
+
y: 1,
|
262
|
+
z: 2,
|
263
|
+
u: 3,
|
264
|
+
v: 4,
|
265
|
+
w: 5,
|
266
|
+
callback: { url: "http://my.example.com/processing/done",
|
267
|
+
method: "POST" },
|
268
|
+
)
|
269
|
+
|
270
|
+
response.must_equal(
|
271
|
+
url: "http://example.com/model/4242/snapshot/1212/",
|
272
|
+
)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
describe "get_snapshot" do
|
277
|
+
before do
|
278
|
+
@request_headers = {
|
279
|
+
"Accept" => "application/json",
|
280
|
+
"Content-Type" => "application/json",
|
281
|
+
"Cookie" => "session=z90",
|
282
|
+
}
|
283
|
+
@response_body = {
|
284
|
+
status: "snapshot_rendering",
|
285
|
+
samples: 1,
|
286
|
+
layer: 1,
|
287
|
+
color: "#ff7f00",
|
288
|
+
height: 480,
|
289
|
+
width: 640,
|
290
|
+
x: 0,
|
291
|
+
y: 1,
|
292
|
+
z: 2,
|
293
|
+
u: 3,
|
294
|
+
v: 4,
|
295
|
+
w: 5,
|
296
|
+
slice_height: nil,
|
297
|
+
created: "2015-05-13 22:18:22.658536",
|
298
|
+
content: "https://example.com/content_url",
|
299
|
+
}.to_json
|
300
|
+
end
|
301
|
+
|
302
|
+
it "returns snapshot data" do
|
303
|
+
stub_request(:get, "https://models.authentise.com/model/42/snapshot/43/")
|
304
|
+
.with(headers: @request_headers)
|
305
|
+
.to_return(status: 200, body: @response_body)
|
306
|
+
|
307
|
+
response = Authentise::API::Warehouse.get_snapshot(
|
308
|
+
url: "https://models.authentise.com/model/42/snapshot/43/",
|
309
|
+
session_token: "z90",
|
310
|
+
)
|
311
|
+
response.must_equal(
|
312
|
+
status: "snapshot_rendering",
|
313
|
+
samples: 1,
|
314
|
+
layer: 1,
|
315
|
+
color: "#ff7f00",
|
316
|
+
height: 480,
|
317
|
+
width: 640,
|
318
|
+
x: 0,
|
319
|
+
y: 1,
|
320
|
+
z: 2,
|
321
|
+
u: 3,
|
322
|
+
v: 4,
|
323
|
+
w: 5,
|
324
|
+
slice_height: nil,
|
325
|
+
created_at: Time.local(2015, 05, 13, 22, 18, 22, 658_536),
|
326
|
+
content_url: "https://example.com/content_url",
|
327
|
+
)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
data/spec/api_spec.rb
CHANGED
@@ -3,7 +3,9 @@ require "spec_helper"
|
|
3
3
|
describe Authentise::API do
|
4
4
|
describe ".create_token" do
|
5
5
|
it "returns a token from the API" do
|
6
|
-
|
6
|
+
api_url = "https://widget.sendshapes.com:3443/api3/" \
|
7
|
+
"api_create_partner_token?api_key=test"
|
8
|
+
stub_request(:get, api_url)
|
7
9
|
.to_return(status: 200, body: '{"data":{"token":"meh"}}')
|
8
10
|
|
9
11
|
Authentise::API.create_token.must_equal "meh"
|
@@ -18,12 +20,8 @@ describe Authentise::API do
|
|
18
20
|
"print_value_currency" => "EUR",
|
19
21
|
"receiver_email" => "example@example.com",
|
20
22
|
"stl_file" => "",
|
21
|
-
"token"=>"meh"}
|
22
|
-
request_headers = { "Accept" => "application/json"
|
23
|
-
"Accept-Encoding" => "gzip, deflate",
|
24
|
-
"Content-Length" => "110",
|
25
|
-
"Content-Type" => "application/x-www-form-urlencoded",
|
26
|
-
"User-Agent" => "Ruby"}
|
23
|
+
"token" => "meh" }
|
24
|
+
request_headers = { "Accept" => "application/json" }
|
27
25
|
|
28
26
|
response_body = '{"data":{"ssl_token_link":"https://bah"}}'
|
29
27
|
|
@@ -57,13 +55,9 @@ describe Authentise::API do
|
|
57
55
|
|
58
56
|
describe ".get_status" do
|
59
57
|
it "returns a status hash" do
|
60
|
-
api_url = "https://widget.sendshapes.com:3443/api3/
|
61
|
-
|
62
|
-
|
63
|
-
"print_value_currency" => "EUR",
|
64
|
-
"receiver_email" => "example@example.com",
|
65
|
-
"stl_file" => "",
|
66
|
-
"token"=>"meh"}
|
58
|
+
api_url = "https://widget.sendshapes.com:3443/api3/" \
|
59
|
+
"api_get_partner_print_status?api_key=test&token=meh"
|
60
|
+
|
67
61
|
response_body = {
|
68
62
|
status: { code: "ok" },
|
69
63
|
data: {
|
@@ -71,7 +65,7 @@ describe Authentise::API do
|
|
71
65
|
printing_percentage: 20,
|
72
66
|
minutes_left: nil,
|
73
67
|
message: nil,
|
74
|
-
}
|
68
|
+
},
|
75
69
|
}
|
76
70
|
|
77
71
|
stub_request(:get, api_url)
|
@@ -82,7 +76,7 @@ describe Authentise::API do
|
|
82
76
|
printing_job_status_name: "warming_up",
|
83
77
|
printing_percentage: 20,
|
84
78
|
minutes_left: nil,
|
85
|
-
message: nil
|
79
|
+
message: nil,
|
86
80
|
)
|
87
81
|
end
|
88
82
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
contents of example.stl
|