aaww 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/lib/aaww.rb +2 -0
- data/lib/aaww/progress.rb +12 -0
- data/lib/aaww/status.rb +15 -0
- data/lib/aaww/transaction.rb +20 -1
- data/lib/aaww/version.rb +1 -1
- data/test/api_responses/print_status_with_print_not_started.yml +113 -0
- data/test/api_responses/print_status_without_print.yml +74 -0
- data/test/minitest_helper.rb +1 -0
- data/test/test_progress.rb +19 -0
- data/test/test_status.rb +27 -0
- data/test/test_transaction.rb +74 -2
- metadata +11 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e5ad2f487e73f48de2d2d86cbba1f06590333d0
|
4
|
+
data.tar.gz: 0b053cac59c6dc049d14cad04bc23e3eca90d332
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 109495be5ca51e793a649475a84d3147c2de8130012e94ef0abaf17a84f9de1ace09effc3edd3d4b2dacd797014fbc9e5716438d6f4d2afe3069698c40c8b50a
|
7
|
+
data.tar.gz: ab1a834ed942ab94382a59b1028d318c8822ae9c53d9537990fb320cadca386cdc043878ade1cd5095e331519dff36653c5c3fb28659feeac73cea0027cdfacb
|
data/README.md
CHANGED
@@ -42,6 +42,24 @@ Then, you can access the token links created by Authentise with:
|
|
42
42
|
transaction.link
|
43
43
|
transaction.ssl_link
|
44
44
|
|
45
|
+
### Checking status
|
46
|
+
|
47
|
+
You can access the status of the current transaction with:
|
48
|
+
|
49
|
+
transaction.status
|
50
|
+
|
51
|
+
This is the status of the last API call. If you want to check the current print
|
52
|
+
status, call `check_print_status!`. Then you can see if there's any error or
|
53
|
+
progress:
|
54
|
+
|
55
|
+
transaction.check_print_status!
|
56
|
+
transaction.status.ok? # true
|
57
|
+
transaction.progress.minutes_left # 15
|
58
|
+
|
59
|
+
Be careful with making consecutive calls to `check_print_status!` without
|
60
|
+
waiting at least 15 seconds, because it can be interpreted as
|
61
|
+
[abuse](http://authentise.com/api-start#status).
|
62
|
+
|
45
63
|
## Contributing
|
46
64
|
|
47
65
|
1. Fork it ( https://github.com/lainventoria/aaww/fork )
|
data/lib/aaww.rb
CHANGED
data/lib/aaww/status.rb
ADDED
data/lib/aaww/transaction.rb
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
module Aaww
|
2
2
|
class Transaction
|
3
3
|
include ActiveModel::Model
|
4
|
+
extend Forwardable
|
4
5
|
|
5
|
-
attr_accessor :key, :token, :file, :email, :value, :job_id, :link,
|
6
|
+
attr_accessor :key, :token, :file, :email, :value, :job_id, :link,
|
7
|
+
:ssl_link, :status, :progress
|
8
|
+
|
9
|
+
def_delegators :status, :ok?, :error?
|
6
10
|
|
7
11
|
# Creates a single unique token for this transaction
|
8
12
|
# Returns Token
|
9
13
|
# GET /api3/api_create_partner_token?api_key={key}
|
10
14
|
def create_token
|
11
15
|
response = Aaww.get '/api3/api_create_partner_token', query: { api_key: key }
|
16
|
+
self.status = Status.new response['status']
|
12
17
|
self.token = response['data']['token']
|
13
18
|
response
|
14
19
|
end
|
@@ -29,6 +34,7 @@ module Aaww
|
|
29
34
|
create_token if token.nil?
|
30
35
|
|
31
36
|
response = Aaww.post '/api3/api_upload_partner_stl', query: upload_query
|
37
|
+
self.status = Status.new response['status']
|
32
38
|
self.link = response['data']['token_link']
|
33
39
|
self.ssl_link = response['data']['ssl_token_link']
|
34
40
|
response
|
@@ -42,5 +48,18 @@ module Aaww
|
|
42
48
|
partner_job_id: job_id,
|
43
49
|
stl_file: file }.reject { |_, value| value.nil? }
|
44
50
|
end
|
51
|
+
|
52
|
+
# Returns a detailed print status for a specific token
|
53
|
+
# Returns Print Status
|
54
|
+
# GET /api3/api_get_partner_print_status?api_key={key}&token={token}"
|
55
|
+
# TODO enforce 15 seconds API restriction
|
56
|
+
def check_print_status!
|
57
|
+
if token
|
58
|
+
response = Aaww.get '/api3/api_get_partner_print_status', query: { api_key: key, token: token }
|
59
|
+
self.status = Status.new response['status']
|
60
|
+
self.progress = Progress.new response['data']
|
61
|
+
response
|
62
|
+
end
|
63
|
+
end
|
45
64
|
end
|
46
65
|
end
|
data/lib/aaww/version.rb
CHANGED
@@ -0,0 +1,113 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://widget.sendshapes.com:3443/api3/api_create_partner_token?api_key=fake_test_key
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx/1.4.6 (Ubuntu)
|
23
|
+
Date:
|
24
|
+
- Fri, 30 Jan 2015 21:44:13 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/json
|
27
|
+
Transfer-Encoding:
|
28
|
+
- chunked
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Vary:
|
32
|
+
- Accept-Encoding
|
33
|
+
body:
|
34
|
+
encoding: UTF-8
|
35
|
+
string: '{"data":{"token":"fake_test_token"},"status":{"code":"ok"}}'
|
36
|
+
http_version:
|
37
|
+
recorded_at: Fri, 30 Jan 2015 21:39:20 GMT
|
38
|
+
- request:
|
39
|
+
method: post
|
40
|
+
uri: https://widget.sendshapes.com:3443/api3/api_upload_partner_stl
|
41
|
+
body:
|
42
|
+
encoding: US-ASCII
|
43
|
+
string: ''
|
44
|
+
headers:
|
45
|
+
Accept-Encoding:
|
46
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
47
|
+
Accept:
|
48
|
+
- "*/*"
|
49
|
+
User-Agent:
|
50
|
+
- Ruby
|
51
|
+
Content-Type:
|
52
|
+
- multipart/form-data; boundary=-----------RubyMultipartPost
|
53
|
+
Content-Length:
|
54
|
+
- '1320'
|
55
|
+
response:
|
56
|
+
status:
|
57
|
+
code: 200
|
58
|
+
message: OK
|
59
|
+
headers:
|
60
|
+
Server:
|
61
|
+
- nginx/1.4.6 (Ubuntu)
|
62
|
+
Date:
|
63
|
+
- Fri, 30 Jan 2015 21:44:14 GMT
|
64
|
+
Content-Type:
|
65
|
+
- application/json
|
66
|
+
Transfer-Encoding:
|
67
|
+
- chunked
|
68
|
+
Connection:
|
69
|
+
- keep-alive
|
70
|
+
Vary:
|
71
|
+
- Accept-Encoding
|
72
|
+
body:
|
73
|
+
encoding: UTF-8
|
74
|
+
string: '{"status":{"code":"ok"},"data":{"token_link":"http:\/\/tokens.sendshapes.com\/?token=fake_test_token","ssl_token_link":"https:\/\/tokens.sendshapes.com\/?token=fake_test_token"}}'
|
75
|
+
http_version:
|
76
|
+
recorded_at: Fri, 30 Jan 2015 21:39:21 GMT
|
77
|
+
- request:
|
78
|
+
method: get
|
79
|
+
uri: https://widget.sendshapes.com:3443/api3/api_get_partner_print_status?api_key=fake_test_key&token=fake_test_token
|
80
|
+
body:
|
81
|
+
encoding: US-ASCII
|
82
|
+
string: ''
|
83
|
+
headers:
|
84
|
+
Accept-Encoding:
|
85
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
86
|
+
Accept:
|
87
|
+
- "*/*"
|
88
|
+
User-Agent:
|
89
|
+
- Ruby
|
90
|
+
response:
|
91
|
+
status:
|
92
|
+
code: 200
|
93
|
+
message: OK
|
94
|
+
headers:
|
95
|
+
Server:
|
96
|
+
- nginx/1.4.6 (Ubuntu)
|
97
|
+
Date:
|
98
|
+
- Fri, 30 Jan 2015 21:44:15 GMT
|
99
|
+
Content-Type:
|
100
|
+
- application/json
|
101
|
+
Transfer-Encoding:
|
102
|
+
- chunked
|
103
|
+
Connection:
|
104
|
+
- keep-alive
|
105
|
+
Vary:
|
106
|
+
- Accept-Encoding
|
107
|
+
body:
|
108
|
+
encoding: UTF-8
|
109
|
+
string: '{"status":{"description":"System error","code":"error","extended_description":"Reciever
|
110
|
+
job 6110 is not yet available\n"}}'
|
111
|
+
http_version:
|
112
|
+
recorded_at: Fri, 30 Jan 2015 21:39:22 GMT
|
113
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,74 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://widget.sendshapes.com:3443/api3/api_create_partner_token?api_key=fake_test_key
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx/1.4.6 (Ubuntu)
|
23
|
+
Date:
|
24
|
+
- Fri, 30 Jan 2015 21:34:46 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/json
|
27
|
+
Transfer-Encoding:
|
28
|
+
- chunked
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Vary:
|
32
|
+
- Accept-Encoding
|
33
|
+
body:
|
34
|
+
encoding: UTF-8
|
35
|
+
string: '{"status":{"code":"ok"},"data":{"token":"fake_test_token"}}'
|
36
|
+
http_version:
|
37
|
+
recorded_at: Fri, 30 Jan 2015 21:29:52 GMT
|
38
|
+
- request:
|
39
|
+
method: get
|
40
|
+
uri: https://widget.sendshapes.com:3443/api3/api_get_partner_print_status?api_key=fake_test_key&token=fake_test_token
|
41
|
+
body:
|
42
|
+
encoding: US-ASCII
|
43
|
+
string: ''
|
44
|
+
headers:
|
45
|
+
Accept-Encoding:
|
46
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
47
|
+
Accept:
|
48
|
+
- "*/*"
|
49
|
+
User-Agent:
|
50
|
+
- Ruby
|
51
|
+
response:
|
52
|
+
status:
|
53
|
+
code: 200
|
54
|
+
message: OK
|
55
|
+
headers:
|
56
|
+
Server:
|
57
|
+
- nginx/1.4.6 (Ubuntu)
|
58
|
+
Date:
|
59
|
+
- Fri, 30 Jan 2015 21:34:47 GMT
|
60
|
+
Content-Type:
|
61
|
+
- application/json
|
62
|
+
Transfer-Encoding:
|
63
|
+
- chunked
|
64
|
+
Connection:
|
65
|
+
- keep-alive
|
66
|
+
Vary:
|
67
|
+
- Accept-Encoding
|
68
|
+
body:
|
69
|
+
encoding: UTF-8
|
70
|
+
string: '{"status":{"description":"System error","extended_description":"token
|
71
|
+
does not have print order associated\n","code":"error"}}'
|
72
|
+
http_version:
|
73
|
+
recorded_at: Fri, 30 Jan 2015 21:29:53 GMT
|
74
|
+
recorded_with: VCR 2.9.3
|
data/test/minitest_helper.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
describe Aaww::Progress do
|
4
|
+
describe 'without progress' do
|
5
|
+
subject { Aaww::Progress.new }
|
6
|
+
|
7
|
+
it 'doesnt show progress' do
|
8
|
+
subject.wont_be :any?
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'with progress' do
|
13
|
+
subject { Aaww::Progress.new printing_percentage: '20' }
|
14
|
+
|
15
|
+
it 'show progress' do
|
16
|
+
subject.must_be :any?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/test/test_status.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
describe Aaww::Status do
|
4
|
+
describe 'without errors' do
|
5
|
+
subject { Aaww::Status.new code: 'ok' }
|
6
|
+
|
7
|
+
it 'is ok' do
|
8
|
+
subject.must_be :ok?
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'wont have errors' do
|
12
|
+
subject.wont_be :error?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'with errors' do
|
17
|
+
subject { Aaww::Status.new code: 'error' }
|
18
|
+
|
19
|
+
it 'wont be ok' do
|
20
|
+
subject.wont_be :ok?
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'has errors' do
|
24
|
+
subject.must_be :error?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/test/test_transaction.rb
CHANGED
@@ -16,7 +16,11 @@ describe Aaww::Transaction do
|
|
16
16
|
|
17
17
|
it 'returns the response' do
|
18
18
|
@response.must_be_instance_of Hash
|
19
|
-
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'saves the status' do
|
22
|
+
subject.status.must_be_instance_of Aaww::Status
|
23
|
+
subject.must_be :ok?
|
20
24
|
end
|
21
25
|
|
22
26
|
it 'saves the token for future use' do
|
@@ -34,7 +38,11 @@ describe Aaww::Transaction do
|
|
34
38
|
|
35
39
|
it 'returns the response' do
|
36
40
|
@response.must_be_instance_of Hash
|
37
|
-
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'saves the status' do
|
44
|
+
subject.status.must_be_instance_of Aaww::Status
|
45
|
+
subject.must_be :ok?
|
38
46
|
end
|
39
47
|
|
40
48
|
it 'saves the file' do
|
@@ -80,6 +88,11 @@ describe Aaww::Transaction do
|
|
80
88
|
@response['status']['code'].must_equal 'ok'
|
81
89
|
end
|
82
90
|
|
91
|
+
it 'saves the status' do
|
92
|
+
subject.status.must_be_instance_of Aaww::Status
|
93
|
+
subject.must_be :ok?
|
94
|
+
end
|
95
|
+
|
83
96
|
it 'saves the link' do
|
84
97
|
subject.link.must_equal @response['data']['token_link']
|
85
98
|
end
|
@@ -108,4 +121,63 @@ describe Aaww::Transaction do
|
|
108
121
|
end
|
109
122
|
end
|
110
123
|
end
|
124
|
+
|
125
|
+
describe 'check_print_status!' do
|
126
|
+
subject do
|
127
|
+
Aaww::Transaction.new key: 'fake_test_key',
|
128
|
+
file: sample_stl, email: 'email@example.com', value: 1, job_id: 69
|
129
|
+
end
|
130
|
+
|
131
|
+
describe 'without print job' do
|
132
|
+
before do
|
133
|
+
VCR.use_cassette 'print_status_without_print' do
|
134
|
+
subject.create_token
|
135
|
+
@response = subject.check_print_status!
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'fails' do
|
140
|
+
@response.must_be_instance_of Hash
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'saves the status' do
|
144
|
+
subject.status.must_be_instance_of Aaww::Status
|
145
|
+
subject.must_be :error?
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'doesnt show any progress' do
|
149
|
+
subject.progress.must_be_instance_of Aaww::Progress
|
150
|
+
subject.progress.wont_be :any?
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'gives an error message' do
|
154
|
+
subject.status.description.must_equal @response['status']['description']
|
155
|
+
subject.status.extended_description.must_equal @response['status']['extended_description']
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe 'with print job not started' do
|
160
|
+
before do
|
161
|
+
VCR.use_cassette 'print_status_with_print_not_started' do
|
162
|
+
subject.upload!
|
163
|
+
@response = subject.check_print_status!
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'saves the status' do
|
168
|
+
subject.status.must_be_instance_of Aaww::Status
|
169
|
+
subject.must_be :error?
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'doesnt show any progress' do
|
173
|
+
subject.progress.must_be_instance_of Aaww::Progress
|
174
|
+
subject.progress.wont_be :any?
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'gives an error message' do
|
178
|
+
subject.status.description.must_equal @response['status']['description']
|
179
|
+
subject.status.extended_description.must_equal @response['status']['extended_description']
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
111
183
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aaww
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- La Inventoría
|
@@ -137,13 +137,19 @@ files:
|
|
137
137
|
- Rakefile
|
138
138
|
- aaww.gemspec
|
139
139
|
- lib/aaww.rb
|
140
|
+
- lib/aaww/progress.rb
|
141
|
+
- lib/aaww/status.rb
|
140
142
|
- lib/aaww/transaction.rb
|
141
143
|
- lib/aaww/version.rb
|
142
144
|
- test/api_responses/create_token.yml
|
145
|
+
- test/api_responses/print_status_with_print_not_started.yml
|
146
|
+
- test/api_responses/print_status_without_print.yml
|
143
147
|
- test/api_responses/upload.yml
|
144
148
|
- test/fixtures/sample.stl
|
145
149
|
- test/minitest_helper.rb
|
146
150
|
- test/test_aaww.rb
|
151
|
+
- test/test_progress.rb
|
152
|
+
- test/test_status.rb
|
147
153
|
- test/test_transaction.rb
|
148
154
|
homepage: http://github.com/lainventoria/aaww
|
149
155
|
licenses:
|
@@ -171,8 +177,12 @@ specification_version: 4
|
|
171
177
|
summary: A simple Authentise API Wrapper
|
172
178
|
test_files:
|
173
179
|
- test/api_responses/create_token.yml
|
180
|
+
- test/api_responses/print_status_with_print_not_started.yml
|
181
|
+
- test/api_responses/print_status_without_print.yml
|
174
182
|
- test/api_responses/upload.yml
|
175
183
|
- test/fixtures/sample.stl
|
176
184
|
- test/minitest_helper.rb
|
177
185
|
- test/test_aaww.rb
|
186
|
+
- test/test_progress.rb
|
187
|
+
- test/test_status.rb
|
178
188
|
- test/test_transaction.rb
|