transloadit 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ ### 1.0.1 / 2011-02-08 ###
2
+
3
+ [Full list of changes](https://github.com/transloadit/ruby-sdk/compare/v1.0.0...v1.0.1)
4
+
5
+ * Enhancements
6
+ * support custom form fields for Transloadit::Assembly
7
+
8
+ * New Maintainers
9
+ * Robin Mehner <robin@coding-robin.de>
10
+
11
+ ### 1.0.0 / 2011-09-06 ###
12
+
13
+ * Initial release
data/README.md CHANGED
@@ -9,23 +9,29 @@ you to automate uploading files through the Transloadit REST API.
9
9
 
10
10
  ## Install
11
11
 
12
- gem install transloadit
12
+ ```bash
13
+ gem install transloadit
14
+ ```
13
15
 
14
16
  ## Getting started
15
17
 
16
18
  To get started, you need to require the 'transloadit' gem:
17
19
 
18
- $ irb -rubygems
19
- >> require 'transloadit'
20
- => true
20
+ ```bash
21
+ $ irb -rubygems
22
+ >> require 'transloadit'
23
+ => true
24
+ ```
21
25
 
22
26
  Then create a Transloadit instance, which will maintain your authentication
23
27
  credentials and allow us to make requests to the API.
24
28
 
25
- transloadit = Transloadit.new(
26
- :key => 'transloadit-auth-key',
27
- :secret => 'transloadit-auth-secret'
28
- )
29
+ ```ruby
30
+ transloadit = Transloadit.new(
31
+ :key => 'transloadit-auth-key',
32
+ :secret => 'transloadit-auth-secret'
33
+ )
34
+ ```
29
35
 
30
36
  ### 1. Resize and store an image
31
37
 
@@ -35,51 +41,59 @@ and store the result on [Amazon S3](http://aws.amazon.com/s3/).
35
41
  First, we create two steps: one to resize the image to 320x240, and another to
36
42
  store the image in our S3 bucket.
37
43
 
38
- resize = transloadit.step 'resize', '/image/resize',
39
- :width => 320,
40
- :height => 240
44
+ ```ruby
45
+ resize = transloadit.step 'resize', '/image/resize',
46
+ :width => 320,
47
+ :height => 240
41
48
 
42
- store = transloadit.step 'store', '/s3/store',
43
- :key => 'aws-access-key-id',
44
- :secret => 'aws-secret-access-key',
45
- :bucket => 's3-bucket-name'
49
+ store = transloadit.step 'store', '/s3/store',
50
+ :key => 'aws-access-key-id',
51
+ :secret => 'aws-secret-access-key',
52
+ :bucket => 's3-bucket-name'
53
+ ```
46
54
 
47
55
  Now that we have the steps, we create an assembly (which is just a request to
48
56
  process a file or set of files) and let Transloadit do the rest.
49
57
 
50
- assembly = transloadit.assembly(
51
- :steps => [ resize, store ]
52
- )
53
-
54
- response = assembly.submit! open('lolcat.jpg')
58
+ ```ruby
59
+ assembly = transloadit.assembly(
60
+ :steps => [ resize, store ]
61
+ )
62
+
63
+ response = assembly.submit! open('lolcat.jpg')
64
+ ```
55
65
 
56
66
  When the `submit!` method returns, the file has been uploaded but may not yet
57
67
  be done processing. We can use the returned object to check if processing has
58
68
  completed, or examine other attributes of the request.
59
69
 
60
- # returns the unique API ID of the assembly
61
- response[:assembly_id] # => '9bd733a...'
62
-
63
- # returns the API URL endpoint for the assembly
64
- response[:assembly_url] # => 'http://api2.vivian.transloadit.com/assemblies/9bd733a...'
65
-
66
- # checks how many bytes were expected / received by transloadit
67
- response[:bytes_expected] # => 92933
68
- response[:bytes_received] # => 92933
69
-
70
- # checks if all processing has been completed
71
- response.completed? # => false
72
-
73
- # cancels further processing on the assembly
74
- response.cancel! # => true
70
+ ```ruby
71
+ # returns the unique API ID of the assembly
72
+ response[:assembly_id] # => '9bd733a...'
73
+
74
+ # returns the API URL endpoint for the assembly
75
+ response[:assembly_url] # => 'http://api2.vivian.transloadit.com/assemblies/9bd733a...'
76
+
77
+ # checks how many bytes were expected / received by transloadit
78
+ response[:bytes_expected] # => 92933
79
+ response[:bytes_received] # => 92933
80
+
81
+ # checks if all processing has been completed
82
+ response.completed? # => false
83
+
84
+ # cancels further processing on the assembly
85
+ response.cancel! # => true
86
+ ```
75
87
 
76
88
  It's important to note that none of these queries are "live" (with the
77
89
  exception of the `cancel!` method). They all check the response given by the
78
90
  API at the time the assembly was created. You have to explicitly ask the
79
91
  assembly to reload its results from the API.
80
92
 
81
- # reloads the response's contents from the REST API
82
- response.reload!
93
+ ```ruby
94
+ # reloads the response's contents from the REST API
95
+ response.reload!
96
+ ```
83
97
 
84
98
  In general, you use hash accessor syntax to query any direct attribute from
85
99
  the [response](http://transloadit.com/docs/assemblies#response-format).
@@ -93,30 +107,34 @@ Transloadit HTTP API.
93
107
  Multiple files can be given to the `submit!` method in order to upload more
94
108
  than one file in the same request. You can also pass a single step for the
95
109
  `steps` parameter, without having to wrap it in an Array.
96
-
97
- assembly = transloadit.assembly(steps: store)
98
-
99
- response = assembly.submit!(
100
- open('puppies.jpg'),
101
- open('kittens.jpg'),
102
- open('ferrets.jpg')
103
- )
110
+
111
+ ```ruby
112
+ assembly = transloadit.assembly(steps: store)
113
+
114
+ response = assembly.submit!(
115
+ open('puppies.jpg'),
116
+ open('kittens.jpg'),
117
+ open('ferrets.jpg')
118
+ )
119
+ ```
104
120
 
105
121
  ### 3. Parallel Assembly
106
122
 
107
123
  Transloadit allows you to perform several processing steps in parallel. You
108
- simply need to `use` other steps. Following
124
+ simply need to `use` other steps. Following
109
125
  [their example](http://transloadit.com/docs/assemblies#special-parameters):
110
126
 
111
- encode = transloadit.step 'encode', '/video/encode', { ... }
112
- thumbs = transloadit.step 'thumbs', '/video/thumbs', { ... }
113
- export = transloadit.step 'store', '/s3/store', { ... }
114
-
115
- export.use [ encode, thumbs ]
116
-
117
- transloadit.assembly(
118
- :steps => [ encode, thumbs, export ]
119
- ).submit! open('ninja-cat.mpg')
127
+ ```ruby
128
+ encode = transloadit.step 'encode', '/video/encode', { ... }
129
+ thumbs = transloadit.step 'thumbs', '/video/thumbs', { ... }
130
+ export = transloadit.step 'store', '/s3/store', { ... }
131
+
132
+ export.use [ encode, thumbs ]
133
+
134
+ transloadit.assembly(
135
+ :steps => [ encode, thumbs, export ]
136
+ ).submit! open('ninja-cat.mpg')
137
+ ```
120
138
 
121
139
  You can also tell a step to use the original uploaded file by passing the
122
140
  Symbol `:original` instead of another step.
@@ -124,6 +142,32 @@ Symbol `:original` instead of another step.
124
142
  Check the YARD documentation for more information on using
125
143
  [use](http://rubydoc.info/gems/transloadit/frames/Transloadit/Step#use-instance_method).
126
144
 
145
+ ### 4. Using a Template
146
+
147
+ Transloadit allows you to use custom [templates](http://transloadit.com/docs/templates)
148
+ for recurring encoding tasks. In order to use these do the following:
149
+
150
+ ```ruby
151
+ transloadit.assembly(
152
+ :template_id => 'YOUR_TEMPLATE_ID'
153
+ ).submit! open('ninja-cat.mpg')
154
+ ```
155
+
156
+ You can use your steps together with this template and even use variables.
157
+ The [Transloadit documentation](http://transloadit.com/docs/templates#passing-variables-into-a-template) has some nice
158
+ examples for that.
159
+
160
+ ### 5. Using fields
161
+
162
+ Transloadit allows you to submit form field values that you'll get back in the
163
+ notification. This is quite handy if you want to add additional custom meta data
164
+ to the upload itself. You can use fields like the following:
165
+
166
+ ```ruby
167
+ transloadit.assembly(
168
+ :fields => {:tag => 'ninjacats'}
169
+ ).submit! open('ninja-cat.mpg')
170
+ ```
127
171
  ## Documentation
128
172
 
129
173
  Up-to-date YARD documentation is automatically generated. You can view the
@@ -52,6 +52,7 @@ class Transloadit::Assembly
52
52
  def submit!(*ios)
53
53
  params = _extract_options!(ios)
54
54
  payload = { :params => self.to_hash.update(params) }
55
+ payload.merge!(self.options[:fields]) if self.options[:fields]
55
56
 
56
57
  # update the payload with file entries
57
58
  ios.each_with_index {|f, i| payload.update :"file_#{i}" => f }
@@ -81,7 +82,7 @@ class Transloadit::Assembly
81
82
  self.options.merge(
82
83
  :auth => self.transloadit.to_hash,
83
84
  :steps => self.steps
84
- ).delete_if {|k,v| v.nil? }
85
+ ).delete_if {|k,v| v.nil? || k == :fields}
85
86
  end
86
87
 
87
88
  #
@@ -190,7 +190,7 @@ class Transloadit::Request
190
190
  # Computes the HMAC digest of the params hash, if a secret was given to the
191
191
  # instance.
192
192
  #
193
- # @param [Hash] params the payload to sign
193
+ # @param [String] params the JSON encoded payload to sign
194
194
  # @return [String] the HMAC signature for the params
195
195
  #
196
196
  def signature(params)
@@ -1,4 +1,4 @@
1
1
  class Transloadit
2
2
  # The current version of Transloadit.
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  end
@@ -68,6 +68,47 @@ describe Transloadit::Assembly do
68
68
  response.headers[:location].must_match %r{^http://foo.bar/}
69
69
  end
70
70
  end
71
+
72
+ describe 'with additional parameters' do
73
+ include WebMock::API
74
+
75
+ before do
76
+ stub_request(:post, 'jane.transloadit.com/assemblies')
77
+ end
78
+
79
+ after do
80
+ WebMock.reset!
81
+ end
82
+
83
+ it 'must allow to send a template id along' do
84
+ VCR.use_cassette 'fetch_bored' do
85
+ Transloadit::Assembly.new(
86
+ @transloadit,
87
+ :template_id => 'TEMPLATE_ID'
88
+ ).submit!
89
+
90
+ assert_requested(:post, 'jane.transloadit.com/assemblies') do |req|
91
+ values = values_from_post_body(req.body)
92
+ JSON.parse(values['params'])['template_id'].must_equal 'TEMPLATE_ID'
93
+ end
94
+ end
95
+ end
96
+
97
+ it 'must allow to send the fields hash' do
98
+ VCR.use_cassette 'fetch_bored' do
99
+ Transloadit::Assembly.new(
100
+ @transloadit,
101
+ :fields => {:tag => 'ninja-cat'}
102
+ ).submit!
103
+
104
+ assert_requested(:post, 'jane.transloadit.com/assemblies') do |req|
105
+ values = values_from_post_body(req.body)
106
+ values['tag'].must_equal 'ninja-cat'
107
+ JSON.parse(values['params'])['fields'].must_be_nil
108
+ end
109
+ end
110
+ end
111
+ end
71
112
  end
72
113
 
73
114
  describe 'with multiple steps' do
@@ -85,3 +126,7 @@ describe Transloadit::Assembly do
85
126
  end
86
127
  end
87
128
  end
129
+
130
+ def values_from_post_body(body)
131
+ Addressable::URI.parse('?' + URI.decode(body)).query_values
132
+ end
data/transloadit.gemspec CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |gem|
7
7
  gem.version = Transloadit::VERSION
8
8
  gem.platform = Gem::Platform::RUBY
9
9
 
10
- gem.authors = %w{ Stephen Touset }
11
- gem.email = %w{ stephen@touset.org }
10
+ gem.authors = [ "Stephen Touset", "Robin Mehner" ]
11
+ gem.email = %w{ stephen@touset.org robin@coding-robin.de }
12
12
  gem.homepage = 'http://github.com/transloadit/ruby-sdk/'
13
13
 
14
14
  gem.summary = 'Official Ruby gem for Transloadit'
metadata CHANGED
@@ -1,129 +1,127 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: transloadit
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
4
5
  prerelease:
5
- version: 1.0.0
6
6
  platform: ruby
7
- authors:
8
- - Stephen
9
- - Touset
7
+ authors:
8
+ - Stephen Touset
9
+ - Robin Mehner
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2011-06-09 00:00:00 -04:00
15
- default_executable:
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
13
+ date: 2011-08-02 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
18
16
  name: rest-client
19
- prerelease: false
20
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &70165484171720 !ruby/object:Gem::Requirement
21
18
  none: false
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
25
- version: "0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
26
23
  type: :runtime
27
- version_requirements: *id001
28
- - !ruby/object:Gem::Dependency
29
- name: json
30
24
  prerelease: false
31
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *70165484171720
26
+ - !ruby/object:Gem::Dependency
27
+ name: json
28
+ requirement: &70165484170960 !ruby/object:Gem::Requirement
32
29
  none: false
33
- requirements:
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: "0"
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
37
34
  type: :runtime
38
- version_requirements: *id002
39
- - !ruby/object:Gem::Dependency
40
- name: rake
41
35
  prerelease: false
42
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *70165484170960
37
+ - !ruby/object:Gem::Dependency
38
+ name: rake
39
+ requirement: &70165484169980 !ruby/object:Gem::Requirement
43
40
  none: false
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: "0"
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
48
45
  type: :development
49
- version_requirements: *id003
50
- - !ruby/object:Gem::Dependency
51
- name: minitest
52
46
  prerelease: false
53
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *70165484169980
48
+ - !ruby/object:Gem::Dependency
49
+ name: minitest
50
+ requirement: &70165484169000 !ruby/object:Gem::Requirement
54
51
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- version: "0"
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
59
56
  type: :development
60
- version_requirements: *id004
61
- - !ruby/object:Gem::Dependency
62
- name: simplecov
63
57
  prerelease: false
64
- requirement: &id005 !ruby/object:Gem::Requirement
58
+ version_requirements: *70165484169000
59
+ - !ruby/object:Gem::Dependency
60
+ name: simplecov
61
+ requirement: &70165484167640 !ruby/object:Gem::Requirement
65
62
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
70
67
  type: :development
71
- version_requirements: *id005
72
- - !ruby/object:Gem::Dependency
73
- name: vcr
74
68
  prerelease: false
75
- requirement: &id006 !ruby/object:Gem::Requirement
69
+ version_requirements: *70165484167640
70
+ - !ruby/object:Gem::Dependency
71
+ name: vcr
72
+ requirement: &70165484166920 !ruby/object:Gem::Requirement
76
73
  none: false
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: "0"
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
81
78
  type: :development
82
- version_requirements: *id006
83
- - !ruby/object:Gem::Dependency
84
- name: webmock
85
79
  prerelease: false
86
- requirement: &id007 !ruby/object:Gem::Requirement
80
+ version_requirements: *70165484166920
81
+ - !ruby/object:Gem::Dependency
82
+ name: webmock
83
+ requirement: &70165484166120 !ruby/object:Gem::Requirement
87
84
  none: false
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: "0"
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
92
89
  type: :development
93
- version_requirements: *id007
94
- - !ruby/object:Gem::Dependency
95
- name: yard
96
90
  prerelease: false
97
- requirement: &id008 !ruby/object:Gem::Requirement
91
+ version_requirements: *70165484166120
92
+ - !ruby/object:Gem::Dependency
93
+ name: yard
94
+ requirement: &70165484165280 !ruby/object:Gem::Requirement
98
95
  none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: "0"
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
103
100
  type: :development
104
- version_requirements: *id008
105
- - !ruby/object:Gem::Dependency
106
- name: rdiscount
107
101
  prerelease: false
108
- requirement: &id009 !ruby/object:Gem::Requirement
102
+ version_requirements: *70165484165280
103
+ - !ruby/object:Gem::Dependency
104
+ name: rdiscount
105
+ requirement: &70165484163840 !ruby/object:Gem::Requirement
109
106
  none: false
110
- requirements:
111
- - - ">="
112
- - !ruby/object:Gem::Version
113
- version: "0"
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
114
111
  type: :development
115
- version_requirements: *id009
116
- description: The transloadit gem allows you to automate uploading files through the Transloadit REST API
117
- email:
112
+ prerelease: false
113
+ version_requirements: *70165484163840
114
+ description: The transloadit gem allows you to automate uploading files through the
115
+ Transloadit REST API
116
+ email:
118
117
  - stephen@touset.org
118
+ - robin@coding-robin.de
119
119
  executables: []
120
-
121
120
  extensions: []
122
-
123
121
  extra_rdoc_files: []
124
-
125
- files:
122
+ files:
126
123
  - .gitignore
124
+ - CHANGELOG.md
127
125
  - Gemfile
128
126
  - README.md
129
127
  - Rakefile
@@ -146,35 +144,31 @@ files:
146
144
  - test/unit/transloadit/test_response.rb
147
145
  - test/unit/transloadit/test_step.rb
148
146
  - transloadit.gemspec
149
- has_rdoc: true
150
147
  homepage: http://github.com/transloadit/ruby-sdk/
151
148
  licenses: []
152
-
153
149
  post_install_message:
154
150
  rdoc_options: []
155
-
156
- require_paths:
151
+ require_paths:
157
152
  - lib
158
- required_ruby_version: !ruby/object:Gem::Requirement
153
+ required_ruby_version: !ruby/object:Gem::Requirement
159
154
  none: false
160
- requirements:
161
- - - ">="
162
- - !ruby/object:Gem::Version
163
- version: "0"
164
- required_rubygems_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
160
  none: false
166
- requirements:
167
- - - ">="
168
- - !ruby/object:Gem::Version
161
+ requirements:
162
+ - - ! '>='
163
+ - !ruby/object:Gem::Version
169
164
  version: 1.3.6
170
165
  requirements: []
171
-
172
166
  rubyforge_project: transloadit
173
- rubygems_version: 1.6.2
167
+ rubygems_version: 1.8.5
174
168
  signing_key:
175
169
  specification_version: 3
176
170
  summary: Official Ruby gem for Transloadit
177
- test_files:
171
+ test_files:
178
172
  - test/fixtures/cassettes/cancel_assembly.yml
179
173
  - test/fixtures/cassettes/fetch_assembly.yml
180
174
  - test/fixtures/cassettes/fetch_bored.yml