transloadit 1.0.5 → 1.0.6

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.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,20 @@
1
+ ### 1.0.6 / 2013-04-22 ###
2
+
3
+ * We now have more statuses available in the response:
4
+ * finished? to check if processing is finished
5
+ * error? to check if processing failed with errors
6
+ * canceled? to check if processing was canceled
7
+ * aborted? to check if processing was aborted
8
+ * executing? to check if processing is still executing
9
+ * uploading? to check if the upload is still going
10
+ * Please use `finished?` to check if procssing is finished and `completed?` to
11
+ check if completed successfully
12
+
1
13
  ### 1.0.5 / 2013-03-13 ###
2
14
 
3
15
  * Use MultiJSON so everyone can use the JSON parser they like. (thanks @kselden for the patch)
16
+ * Switch to Kramdown for RDoc formatting
17
+ * Support jRuby 1.8/1.9 and MRI 2.0.0 too
4
18
 
5
19
  ### 1.0.4 / 2013-03-06 ###
6
20
 
data/README.md CHANGED
@@ -63,6 +63,17 @@ assembly = transloadit.assembly(
63
63
  )
64
64
 
65
65
  response = assembly.submit! open('lolcat.jpg')
66
+
67
+ # loop until processing is finished
68
+ until response.finished?
69
+ sleep 1; response.reload! # you'll want to implement a timeout in your production app
70
+ end
71
+
72
+ if response.error?
73
+ # handle error
74
+ else
75
+ # handle other cases
76
+ end
66
77
  ```
67
78
 
68
79
  When the `submit!` method returns, the file has been uploaded but may not yet
@@ -80,11 +91,17 @@ response[:assembly_url] # => 'http://api2.vivian.transloadit.com/assemblies/9bd7
80
91
  response[:bytes_expected] # => 92933
81
92
  response[:bytes_received] # => 92933
82
93
 
83
- # checks if all processing has been completed
84
- response.completed? # => false
94
+ # checks if all processing has been finished
95
+ response.finished? # => false
85
96
 
86
97
  # cancels further processing on the assembly
87
98
  response.cancel! # => true
99
+
100
+ # checks if processing was succesfully completed
101
+ response.completed? # => true
102
+
103
+ # checks if the processing returned with an error
104
+ response.error? # => false
88
105
  ```
89
106
 
90
107
  It's important to note that none of these queries are "live" (with the
@@ -4,12 +4,36 @@ module Transloadit::Response::Assembly
4
4
  def reload!
5
5
  self.replace Transloadit::Request.new(self['assembly_url']).get
6
6
  end
7
-
7
+
8
8
  def cancel!
9
9
  self.replace Transloadit::Request.new(self['assembly_url']).delete
10
10
  end
11
-
11
+
12
+ def aborted?
13
+ self['ok'] == 'REQUEST_ABORTED'
14
+ end
15
+
16
+ def canceled?
17
+ self['ok'] == 'ASSEMBLY_CANCELED'
18
+ end
19
+
12
20
  def completed?
13
21
  self['ok'] == 'ASSEMBLY_COMPLETED'
14
22
  end
23
+
24
+ def error?
25
+ self['error'] != nil
26
+ end
27
+
28
+ def executing?
29
+ self['ok'] == 'ASSEMBLY_EXECUTING'
30
+ end
31
+
32
+ def finished?
33
+ aborted? || canceled? || completed? || error?
34
+ end
35
+
36
+ def uploading?
37
+ self['ok'] == 'ASSEMBLY_UPLOADING'
38
+ end
15
39
  end
@@ -1,4 +1,3 @@
1
1
  class Transloadit
2
- # The current version of Transloadit.
3
- VERSION = '1.0.5'
2
+ VERSION = '1.0.6'
4
3
  end
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api2.jane.transloadit.com/assemblies/76fe5df1c93a0a530f3e583805cf98b4
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Content-Type:
20
+ - text/plain
21
+ Access-Control-Allow-Origin:
22
+ - ! '*'
23
+ Access-Control-Allow-Methods:
24
+ - POST, GET, PUT, DELETE, OPTIONS
25
+ Access-Control-Allow-Headers:
26
+ - X-Requested-With, Content-Type, Accept, Content-Length
27
+ Transfer-Encoding:
28
+ - chunked
29
+ body:
30
+ encoding: UTF-8
31
+ string: ! '{"ok":"REQUEST_ABORTED","message":"The upload connection was closed or timed out before receiving all data.","assembly_id":"76fe5df1c93a0a530f3e583805cf98b4","assembly_url":"http://api2.jane.transloadit.com/assemblies/76fe5df1c93a0a530f3e583805cf98b4","bytes_received":95355,"bytes_expected":95355,"client_agent":"Transloadit
32
+ Ruby SDK 0.1.2","client_ip":"74.95.29.209","client_referer":null,"start_date":"2011/02/21
33
+ 15:54:17 GMT","upload_duration":0.394,"execution_duration":0.006,"fields":{},"uploads":[{"id":"0767b43537389a177a1be96ab06e8a4b","name":"test.png","basename":"test","ext":"png","size":95010,"mime":"image/jpeg","type":"image","field":"file_0","original_id":"0767b43537389a177a1be96ab06e8a4b","url":"http://tmp.jane.transloadit.com/upload/bf7801cb21fb96cbafd403467244d125.png","meta":{"width":640,"height":480,"date_recorded":null,"date_file_created":null,"date_file_modified":"2011/02/21
34
+ 15:54:17 GMT","title":null,"description":null,"location":null,"city":null,"state":null,"country":null,"country_code":null,"keywords":"Photo
35
+ Booth","aperture":null,"exposure_compensation":null,"exposure_mode":null,"exposure_time":null,"flash":null,"focal_length":null,"f_number":null,"iso":null,"light_value":null,"metering_mode":null,"shutter_speed":null,"white_balance":null,"device_name":null,"device_vendor":null,"device_software":null,"latitude":null,"longitude":null,"frame_count":null}}],"results":{}}'
36
+ http_version: '1.1'
37
+ recorded_at: Fri, 08 Mar 2013 15:13:10 GMT
38
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api2.jane.transloadit.com/assemblies/76fe5df1c93a0a530f3e583805cf98b4
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Content-Type:
20
+ - text/plain
21
+ Access-Control-Allow-Origin:
22
+ - ! '*'
23
+ Access-Control-Allow-Methods:
24
+ - POST, GET, PUT, DELETE, OPTIONS
25
+ Access-Control-Allow-Headers:
26
+ - X-Requested-With, Content-Type, Accept, Content-Length
27
+ Transfer-Encoding:
28
+ - chunked
29
+ body:
30
+ encoding: UTF-8
31
+ string: ! '{"ok":"ASSEMBLY_CANCELED","message":"The assembly is still in the process of being uploaded.","error": "INVALID_FORM_DATA", "assembly_id":"76fe5df1c93a0a530f3e583805cf98b4","assembly_url":"http://api2.jane.transloadit.com/assemblies/76fe5df1c93a0a530f3e583805cf98b4","bytes_received":95355,"bytes_expected":95355,"client_agent":"Transloadit
32
+ Ruby SDK 0.1.2","client_ip":"74.95.29.209","client_referer":null,"start_date":"2011/02/21
33
+ 15:54:17 GMT","upload_duration":0.394,"execution_duration":0.006,"fields":{},"uploads":[{"id":"0767b43537389a177a1be96ab06e8a4b","name":"test.png","basename":"test","ext":"png","size":95010,"mime":"image/jpeg","type":"image","field":"file_0","original_id":"0767b43537389a177a1be96ab06e8a4b","url":"http://tmp.jane.transloadit.com/upload/bf7801cb21fb96cbafd403467244d125.png","meta":{"width":640,"height":480,"date_recorded":null,"date_file_created":null,"date_file_modified":"2011/02/21
34
+ 15:54:17 GMT","title":null,"description":null,"location":null,"city":null,"state":null,"country":null,"country_code":null,"keywords":"Photo
35
+ Booth","aperture":null,"exposure_compensation":null,"exposure_mode":null,"exposure_time":null,"flash":null,"focal_length":null,"f_number":null,"iso":null,"light_value":null,"metering_mode":null,"shutter_speed":null,"white_balance":null,"device_name":null,"device_vendor":null,"device_software":null,"latitude":null,"longitude":null,"frame_count":null}}],"results":{}}'
36
+ http_version: '1.1'
37
+ recorded_at: Fri, 08 Mar 2013 15:13:10 GMT
38
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api2.jane.transloadit.com/assemblies/76fe5df1c93a0a530f3e583805cf98b4
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Content-Type:
20
+ - text/plain
21
+ Access-Control-Allow-Origin:
22
+ - ! '*'
23
+ Access-Control-Allow-Methods:
24
+ - POST, GET, PUT, DELETE, OPTIONS
25
+ Access-Control-Allow-Headers:
26
+ - X-Requested-With, Content-Type, Accept, Content-Length
27
+ Transfer-Encoding:
28
+ - chunked
29
+ body:
30
+ encoding: UTF-8
31
+ string: ! '{"ok":"ASSEMBLY_EXECUTING","message":"The assembly is currently being executed.","assembly_id":"76fe5df1c93a0a530f3e583805cf98b4","assembly_url":"http://api2.jane.transloadit.com/assemblies/76fe5df1c93a0a530f3e583805cf98b4","bytes_received":95355,"bytes_expected":95355,"client_agent":"Transloadit
32
+ Ruby SDK 0.1.2","client_ip":"74.95.29.209","client_referer":null,"start_date":"2011/02/21
33
+ 15:54:17 GMT","upload_duration":0.394,"execution_duration":0.006,"fields":{},"uploads":[{"id":"0767b43537389a177a1be96ab06e8a4b","name":"test.png","basename":"test","ext":"png","size":95010,"mime":"image/jpeg","type":"image","field":"file_0","original_id":"0767b43537389a177a1be96ab06e8a4b","url":"http://tmp.jane.transloadit.com/upload/bf7801cb21fb96cbafd403467244d125.png","meta":{"width":640,"height":480,"date_recorded":null,"date_file_created":null,"date_file_modified":"2011/02/21
34
+ 15:54:17 GMT","title":null,"description":null,"location":null,"city":null,"state":null,"country":null,"country_code":null,"keywords":"Photo
35
+ Booth","aperture":null,"exposure_compensation":null,"exposure_mode":null,"exposure_time":null,"flash":null,"focal_length":null,"f_number":null,"iso":null,"light_value":null,"metering_mode":null,"shutter_speed":null,"white_balance":null,"device_name":null,"device_vendor":null,"device_software":null,"latitude":null,"longitude":null,"frame_count":null}}],"results":{}}'
36
+ http_version: '1.1'
37
+ recorded_at: Fri, 08 Mar 2013 15:13:10 GMT
38
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api2.jane.transloadit.com/assemblies/76fe5df1c93a0a530f3e583805cf98b4
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Content-Type:
20
+ - text/plain
21
+ Access-Control-Allow-Origin:
22
+ - ! '*'
23
+ Access-Control-Allow-Methods:
24
+ - POST, GET, PUT, DELETE, OPTIONS
25
+ Access-Control-Allow-Headers:
26
+ - X-Requested-With, Content-Type, Accept, Content-Length
27
+ Transfer-Encoding:
28
+ - chunked
29
+ body:
30
+ encoding: UTF-8
31
+ string: ! '{"ok":"ASSEMBLY_UPLOADING","message":"The assembly is still in the process of being uploaded.","assembly_id":"76fe5df1c93a0a530f3e583805cf98b4","assembly_url":"http://api2.jane.transloadit.com/assemblies/76fe5df1c93a0a530f3e583805cf98b4","bytes_received":95355,"bytes_expected":95355,"client_agent":"Transloadit
32
+ Ruby SDK 0.1.2","client_ip":"74.95.29.209","client_referer":null,"start_date":"2011/02/21
33
+ 15:54:17 GMT","upload_duration":0.394,"execution_duration":0.006,"fields":{},"uploads":[{"id":"0767b43537389a177a1be96ab06e8a4b","name":"test.png","basename":"test","ext":"png","size":95010,"mime":"image/jpeg","type":"image","field":"file_0","original_id":"0767b43537389a177a1be96ab06e8a4b","url":"http://tmp.jane.transloadit.com/upload/bf7801cb21fb96cbafd403467244d125.png","meta":{"width":640,"height":480,"date_recorded":null,"date_file_created":null,"date_file_modified":"2011/02/21
34
+ 15:54:17 GMT","title":null,"description":null,"location":null,"city":null,"state":null,"country":null,"country_code":null,"keywords":"Photo
35
+ Booth","aperture":null,"exposure_compensation":null,"exposure_mode":null,"exposure_time":null,"flash":null,"focal_length":null,"f_number":null,"iso":null,"light_value":null,"metering_mode":null,"shutter_speed":null,"white_balance":null,"device_name":null,"device_vendor":null,"device_software":null,"latitude":null,"longitude":null,"frame_count":null}}],"results":{}}'
36
+ http_version: '1.1'
37
+ recorded_at: Fri, 08 Mar 2013 15:13:10 GMT
38
+ recorded_with: VCR 2.4.0
@@ -2,25 +2,25 @@ require 'test_helper'
2
2
 
3
3
  describe Transloadit::Response do
4
4
  REQUEST_URI = 'http://api2.jane.transloadit.com/assemblies/76fe5df1c93a0a530f3e583805cf98b4'
5
-
5
+
6
6
  it 'must allow delegate initialization' do
7
7
  response = Transloadit::Response.new('test')
8
8
  response.class.must_equal Transloadit::Response
9
9
  end
10
-
10
+
11
11
  describe 'when initialized' do
12
12
  before do
13
- VCR.use_cassette 'fetch_assembly' do
13
+ VCR.use_cassette 'fetch_assembly_ok' do
14
14
  @response = Transloadit::Response.new(
15
15
  RestClient::Resource.new(REQUEST_URI).get
16
16
  )
17
17
  end
18
18
  end
19
-
19
+
20
20
  it 'must parse the body' do
21
21
  @response.body.must_be_kind_of Hash
22
22
  end
23
-
23
+
24
24
  it 'must allow access to body attributes' do
25
25
  %w{ ok message assembly_id assembly_url }.each do |attribute|
26
26
  @response[attribute].must_equal @response.body[attribute]
@@ -32,43 +32,95 @@ describe Transloadit::Response do
32
32
  @response[attribute].must_equal @response.body[attribute.to_s]
33
33
  end
34
34
  end
35
-
35
+
36
36
  it 'must inspect as the body' do
37
37
  @response.inspect.must_equal @response.body.inspect
38
38
  end
39
39
  end
40
-
40
+
41
41
  describe 'when extended as an assembly' do
42
42
  before do
43
- VCR.use_cassette 'fetch_assembly' do
43
+ VCR.use_cassette 'fetch_assembly_ok' do
44
44
  @response = Transloadit::Response.new(
45
45
  RestClient::Resource.new(REQUEST_URI).get
46
46
  ).extend!(Transloadit::Response::Assembly)
47
47
  end
48
48
  end
49
-
49
+
50
50
  it 'must allow checking for completion' do
51
51
  @response.completed?.must_equal true
52
+ @response.finished?.must_equal true
53
+ @response.error?.must_equal false
52
54
  end
53
-
55
+
54
56
  # TODO: can this be tested better?
55
57
  it 'must allow reloading the assembly' do
56
- VCR.use_cassette 'fetch_assembly', :allow_playback_repeats => true do
58
+ VCR.use_cassette 'fetch_assembly_ok', :allow_playback_repeats => true do
57
59
  @response.send(:__getobj__).
58
60
  wont_be_same_as @response.reload!.send(:__getobj__)
59
-
61
+
60
62
  @response.object_id.
61
63
  must_equal @response.reload!.object_id
62
64
  end
63
65
  end
64
-
66
+
65
67
  it 'must allow canceling' do
66
68
  VCR.use_cassette 'cancel_assembly' do
67
69
  @response.cancel!
68
-
70
+
69
71
  @response.completed?.must_equal false
70
72
  @response['ok'] .must_equal 'ASSEMBLY_CANCELED'
73
+ @response.canceled?.must_equal true
74
+ @response.finished?.must_equal true
75
+ end
76
+ end
77
+ end
78
+
79
+ describe 'statuses' do
80
+ it 'must allow checking for upload' do
81
+ VCR.use_cassette 'fetch_assembly_uploading' do
82
+ @response = Transloadit::Response.new(
83
+ RestClient::Resource.new(REQUEST_URI).get
84
+ ).extend!(Transloadit::Response::Assembly)
85
+ end
86
+
87
+ @response.finished?.must_equal false
88
+ @response.uploading?.must_equal true
89
+ @response.error?.must_equal false
90
+ end
91
+
92
+ it 'must allow to check for executing' do
93
+ VCR.use_cassette 'fetch_assembly_executing' do
94
+ @response = Transloadit::Response.new(
95
+ RestClient::Resource.new(REQUEST_URI).get
96
+ ).extend!(Transloadit::Response::Assembly)
97
+ end
98
+
99
+ @response.finished?.must_equal false
100
+ @response.executing?.must_equal true
101
+ @response.error?.must_equal false
102
+ end
103
+
104
+ it 'must allow to check for aborted' do
105
+ VCR.use_cassette 'fetch_assembly_aborted' do
106
+ @response = Transloadit::Response.new(
107
+ RestClient::Resource.new(REQUEST_URI).get
108
+ ).extend!(Transloadit::Response::Assembly)
109
+ end
110
+
111
+ @response.finished?.must_equal true
112
+ @response.aborted?.must_equal true
113
+ end
114
+
115
+ it 'must allow to check for errors' do
116
+ VCR.use_cassette 'fetch_assembly_errors' do
117
+ @response = Transloadit::Response.new(
118
+ RestClient::Resource.new(REQUEST_URI).get
119
+ ).extend!(Transloadit::Response::Assembly)
71
120
  end
121
+
122
+ @response.error?.must_equal true
123
+ @response.finished?.must_equal true
72
124
  end
73
125
  end
74
126
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transloadit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-13 00:00:00.000000000 Z
13
+ date: 2013-04-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -179,7 +179,11 @@ files:
179
179
  - lib/transloadit/step.rb
180
180
  - lib/transloadit/version.rb
181
181
  - test/fixtures/cassettes/cancel_assembly.yml
182
- - test/fixtures/cassettes/fetch_assembly.yml
182
+ - test/fixtures/cassettes/fetch_assembly_aborted.yml
183
+ - test/fixtures/cassettes/fetch_assembly_errors.yml
184
+ - test/fixtures/cassettes/fetch_assembly_executing.yml
185
+ - test/fixtures/cassettes/fetch_assembly_ok.yml
186
+ - test/fixtures/cassettes/fetch_assembly_uploading.yml
183
187
  - test/fixtures/cassettes/fetch_bored.yml
184
188
  - test/fixtures/cassettes/post_assembly.yml
185
189
  - test/fixtures/cassettes/submit_assembly.yml
@@ -210,13 +214,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
214
  version: 1.3.6
211
215
  requirements: []
212
216
  rubyforge_project: transloadit
213
- rubygems_version: 1.8.24
217
+ rubygems_version: 1.8.23
214
218
  signing_key:
215
219
  specification_version: 3
216
220
  summary: Official Ruby gem for Transloadit
217
221
  test_files:
218
222
  - test/fixtures/cassettes/cancel_assembly.yml
219
- - test/fixtures/cassettes/fetch_assembly.yml
223
+ - test/fixtures/cassettes/fetch_assembly_aborted.yml
224
+ - test/fixtures/cassettes/fetch_assembly_errors.yml
225
+ - test/fixtures/cassettes/fetch_assembly_executing.yml
226
+ - test/fixtures/cassettes/fetch_assembly_ok.yml
227
+ - test/fixtures/cassettes/fetch_assembly_uploading.yml
220
228
  - test/fixtures/cassettes/fetch_bored.yml
221
229
  - test/fixtures/cassettes/post_assembly.yml
222
230
  - test/fixtures/cassettes/submit_assembly.yml