transloadit 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 709626bb099cd40ada8a3224b687fbf39ffb557d
4
+ data.tar.gz: d8ba3b52509a6d1232c4de7164ad9fbadcbac2f7
5
+ SHA512:
6
+ metadata.gz: 79b3fc7ca14d347b55376a4e5dc8d5858cc7cfa3fe7e77195fae0f08c7127c58fc98cceb987e22ba4107b2a2d694bfc8e8e0da877bfbb18cdc3af821b525bee2
7
+ data.tar.gz: 3730079c2989d9586f8d0be352fd0b29bf81156e8d85caeee49b06602dc9a449172d4b656efbd5a08d68359f2b3d64af160975002eecbb4b1d45a6d541181e23
data/.travis.yml CHANGED
@@ -9,4 +9,4 @@ rvm:
9
9
  - rbx-19mode
10
10
  - jruby-18mode
11
11
  - jruby-19mode
12
- script: "bundle exec rake test"
12
+ script: "COVERAGE=false bundle exec rake test"
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
- ### 1.0.6 / 2013-04-22 ###
1
+ ### 1.1.1 / 2013-06-25 ###
2
+
3
+ * request.get with secret (thanks @miry for the patch)
4
+
5
+ ### 1.1.0 / 2013-04-22 ###
2
6
 
3
7
  * We now have more statuses available in the response:
4
8
  * finished? to check if processing is finished
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  [![Build Status](https://travis-ci.org/transloadit/ruby-sdk.png?branch=master)](https://travis-ci.org/transloadit/ruby-sdk)
2
+ [![Code Climate](https://codeclimate.com/github/transloadit/ruby-sdk.png)](https://codeclimate.com/github/transloadit/ruby-sdk)
3
+ [![Dependency Status](https://gemnasium.com/transloadit/ruby-sdk.png)](https://gemnasium.com/transloadit/ruby-sdk)
2
4
 
3
5
  # transloadit
4
6
 
data/lib/transloadit.rb CHANGED
@@ -10,19 +10,19 @@ class Transloadit
10
10
  autoload :Response, 'transloadit/response'
11
11
  autoload :Step, 'transloadit/step'
12
12
  autoload :VERSION, 'transloadit/version'
13
-
13
+
14
14
  # @return [String] your Transloadit auth key
15
15
  attr_accessor :key
16
-
16
+
17
17
  # @return [String] your Transloadit auth secret, for signing requests
18
18
  attr_accessor :secret
19
-
19
+
20
20
  # @return [Integer] the duration in seconds that signed API requests
21
21
  # generated from this instance remain valid
22
22
  attr_accessor :duration
23
-
23
+
24
24
  attr_accessor :max_size
25
-
25
+
26
26
  #
27
27
  # Creates a new instance of the Transloadit API.
28
28
  #
@@ -39,10 +39,10 @@ class Transloadit
39
39
  self.secret = options[:secret]
40
40
  self.duration = options[:duration] || 5 * 60
41
41
  self.max_size = options[:max_size]
42
-
42
+
43
43
  _ensure_key_provided
44
44
  end
45
-
45
+
46
46
  #
47
47
  # Creates a Transloadit::Step describing a step in an upload assembly.
48
48
  #
@@ -56,7 +56,7 @@ class Transloadit
56
56
  def step(name, robot, options = {})
57
57
  Transloadit::Step.new(name, robot, options)
58
58
  end
59
-
59
+
60
60
  #
61
61
  # Creates a Transloadit::Assembly ready to be sent to the REST API.
62
62
  #
@@ -74,14 +74,14 @@ class Transloadit
74
74
  def assembly(options = {})
75
75
  Transloadit::Assembly.new(self, options)
76
76
  end
77
-
77
+
78
78
  #
79
79
  # @return [String] a human-readable version of the Transloadit.
80
80
  #
81
81
  def inspect
82
82
  self.to_hash.inspect
83
83
  end
84
-
84
+
85
85
  #
86
86
  # @return [Hash] a Transloadit-compatible Hash of the instance's contents
87
87
  #
@@ -91,16 +91,16 @@ class Transloadit
91
91
  result.update(:expires => _generate_expiry) unless self.secret.nil?
92
92
  result
93
93
  end
94
-
94
+
95
95
  #
96
96
  # @return [String] JSON-encoded String containing the object's hash contents
97
97
  #
98
98
  def to_json
99
99
  MultiJson.dump(self.to_hash)
100
100
  end
101
-
101
+
102
102
  private
103
-
103
+
104
104
  #
105
105
  # Raises an ArgumentError if no {#key} has been assigned.
106
106
  #
@@ -109,7 +109,7 @@ class Transloadit
109
109
  raise ArgumentError, 'an authentication key must be provided'
110
110
  end
111
111
  end
112
-
112
+
113
113
  #
114
114
  # Generates an API-compatible request expiration timestamp. Uses the
115
115
  # current instance's duration.
@@ -13,10 +13,10 @@ require 'transloadit'
13
13
  class Transloadit::Assembly
14
14
  # @return [Transloadit] the associated Transloadit instance
15
15
  attr_reader :transloadit
16
-
16
+
17
17
  # @return [Hash] the options describing the Assembly
18
18
  attr_accessor :options
19
-
19
+
20
20
  #
21
21
  # Creates a new Assembly authenticated using the given +transloadit+
22
22
  # instance.
@@ -29,14 +29,14 @@ class Transloadit::Assembly
29
29
  self.transloadit = transloadit
30
30
  self.options = options
31
31
  end
32
-
32
+
33
33
  #
34
34
  # @return [Hash] the processing steps, formatted for sending to Transloadit
35
35
  #
36
36
  def steps
37
37
  _wrap_steps_in_hash options[:steps]
38
38
  end
39
-
39
+
40
40
  #
41
41
  # Submits the assembly for processing. Accepts as many IO objects as you
42
42
  # wish to process in the assembly. The last argument is an optional Hash
@@ -53,28 +53,28 @@ class Transloadit::Assembly
53
53
  params = _extract_options!(ios)
54
54
  payload = { :params => self.to_hash.update(params) }
55
55
  payload.merge!(self.options[:fields]) if self.options[:fields]
56
-
56
+
57
57
  # update the payload with file entries
58
58
  ios.each_with_index {|f, i| payload.update :"file_#{i}" => f }
59
-
59
+
60
60
  # find a bored instance
61
61
  Transloadit::Request.bored!
62
-
62
+
63
63
  # create the request
64
64
  request = Transloadit::Request.new '/assemblies',
65
65
  self.transloadit.secret
66
-
66
+
67
67
  # post the request, extend it with the Assembly extensions
68
68
  request.post(payload).extend!(Transloadit::Response::Assembly)
69
69
  end
70
-
70
+
71
71
  #
72
72
  # @return [String] a human-readable version of the Assembly
73
73
  #
74
74
  def inspect
75
75
  self.to_hash.inspect
76
76
  end
77
-
77
+
78
78
  #
79
79
  # @return [Hash] a Transloadit-compatible Hash of the Assembly's contents
80
80
  #
@@ -84,20 +84,20 @@ class Transloadit::Assembly
84
84
  :steps => self.steps
85
85
  ).delete_if {|k,v| v.nil? || k == :fields}
86
86
  end
87
-
87
+
88
88
  #
89
89
  # @return [String] JSON-encoded String containing the Assembly's contents
90
90
  #
91
91
  def to_json
92
92
  MultiJson.dump(self.to_hash)
93
93
  end
94
-
94
+
95
95
  protected
96
-
96
+
97
97
  attr_writer :transloadit
98
-
98
+
99
99
  private
100
-
100
+
101
101
  #
102
102
  # Returns a Transloadit-compatible Hash wrapping the +steps+ passed to it.
103
103
  # Accepts any supported format the +steps+ could come in.
@@ -114,7 +114,7 @@ class Transloadit::Assembly
114
114
  steps.inject({}) {|h, s| h.update s }
115
115
  end
116
116
  end
117
-
117
+
118
118
  #
119
119
  # Extracts the last argument from a set of arguments if it's a hash.
120
120
  # Otherwise, returns an empty hash.
@@ -11,19 +11,19 @@ require 'openssl'
11
11
  class Transloadit::Request
12
12
  # The default Transloadit API endpoint.
13
13
  API_ENDPOINT = URI.parse('http://api2.transloadit.com/')
14
-
14
+
15
15
  # The default headers to send to the API.
16
16
  API_HEADERS = { 'User-Agent' => %{Transloadit Ruby SDK #{Transloadit::VERSION}} }
17
-
17
+
18
18
  # The HMAC algorithm used for calculation request signatures.
19
19
  HMAC_ALGORITHM = OpenSSL::Digest::Digest.new('sha1')
20
-
20
+
21
21
  # @return [String] the API endpoint for the request
22
22
  attr_reader :url
23
-
23
+
24
24
  # @return [String] the authentication secret to sign the request with
25
25
  attr_accessor :secret
26
-
26
+
27
27
  #
28
28
  # Automatically sets the API endpoint to the server with the most free
29
29
  # resources. This is called automatically the first time a request is made.
@@ -31,7 +31,7 @@ class Transloadit::Request
31
31
  def self.bored!
32
32
  self.api self.bored
33
33
  end
34
-
34
+
35
35
  #
36
36
  # Prepares a request against an endpoint URL, optionally with an encryption
37
37
  # secret. If only a path is passed, the API will automatically determine the
@@ -45,7 +45,7 @@ class Transloadit::Request
45
45
  self.url = URI.parse(url.to_s)
46
46
  self.secret = secret
47
47
  end
48
-
48
+
49
49
  #
50
50
  # Performs an HTTP GET to the request's URL. Takes an optional hash of
51
51
  # query params.
@@ -58,7 +58,7 @@ class Transloadit::Request
58
58
  self.api[url.path + self.to_query(params)].get(API_HEADERS)
59
59
  end
60
60
  end
61
-
61
+
62
62
  #
63
63
  # Performs an HTTP DELETE to the request's URL. Takes an optional hash of
64
64
  # query params.
@@ -71,7 +71,7 @@ class Transloadit::Request
71
71
  self.api[url.path + self.to_query(params)].delete(API_HEADERS)
72
72
  end
73
73
  end
74
-
74
+
75
75
  #
76
76
  # Performs an HTTP POST to the request's URL. Takes an optional hash
77
77
  # containing the form-encoded payload.
@@ -84,18 +84,18 @@ class Transloadit::Request
84
84
  self.api[url.path].post(self.to_payload(payload), API_HEADERS)
85
85
  end
86
86
  end
87
-
87
+
88
88
  #
89
89
  # @return [String] a human-readable version of the prepared Request
90
90
  #
91
91
  def inspect
92
92
  self.url.to_s.inspect
93
93
  end
94
-
94
+
95
95
  protected
96
-
96
+
97
97
  attr_writer :url
98
-
98
+
99
99
  #
100
100
  # Locates the API server with the smallest job queue.
101
101
  #
@@ -104,7 +104,7 @@ class Transloadit::Request
104
104
  def self.bored
105
105
  self.new(API_ENDPOINT + '/instances/bored').get['api2_host']
106
106
  end
107
-
107
+
108
108
  #
109
109
  # Sets or retrieves the base URI of the API endpoint.
110
110
  #
@@ -119,7 +119,7 @@ class Transloadit::Request
119
119
  @api = RestClient::Resource.new(uri) if uri
120
120
  @api ||= RestClient::Resource.new(self.bored)
121
121
  end
122
-
122
+
123
123
  #
124
124
  # Retrieves the current API endpoint. If the URL of the request contains a
125
125
  # hostname, then the hostname is used as the base endpoint of the API.
@@ -135,7 +135,7 @@ class Transloadit::Request
135
135
  end
136
136
  end
137
137
  end
138
-
138
+
139
139
  #
140
140
  # Updates the POST payload passed to be compliant with the Transloadit API
141
141
  # spec. JSONifies the value for the +params+ key and signs the request with
@@ -147,14 +147,14 @@ class Transloadit::Request
147
147
  def to_payload(payload = nil)
148
148
  return {} if payload.nil?
149
149
  return {} if payload.respond_to?(:empty?) and payload.empty?
150
-
150
+
151
151
  # TODO: refactor this, don't update a hash that's not ours
152
152
  payload.update :params => MultiJson.dump(payload[:params])
153
153
  payload.update :signature => self.signature(payload[:params])
154
154
  payload.delete :signature if payload[:signature].nil?
155
155
  payload
156
156
  end
157
-
157
+
158
158
  #
159
159
  # Updates the GET/DELETE params hash to be compliant with the Transloadit
160
160
  # API by URI escaping and encoding the params hash, and attaching a
@@ -166,16 +166,19 @@ class Transloadit::Request
166
166
  def to_query(params = nil)
167
167
  return '' if params.nil?
168
168
  return '' if params.respond_to?(:empty?) and params.empty?
169
-
169
+
170
170
  escape = Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")
171
+ params_in_json = MultiJson.dump(params)
172
+ uri_params = URI.escape(params_in_json, escape)
173
+
171
174
  params = {
172
- :params => URI.escape(MultiJson.dump(params), escape),
173
- :signature => self.signature(params)
175
+ :params => uri_params,
176
+ :signature => self.signature(params_in_json)
174
177
  }
175
-
178
+
176
179
  '?' + params.map {|k,v| "#{k}=#{v}" if v }.compact.join('&')
177
180
  end
178
-
181
+
179
182
  #
180
183
  # Wraps a request's results in a Transloadit::Response, even if an exception
181
184
  # is raised by RestClient.
@@ -185,7 +188,7 @@ class Transloadit::Request
185
188
  rescue RestClient::Exception => e
186
189
  Transloadit::Response.new e.response
187
190
  end
188
-
191
+
189
192
  #
190
193
  # Computes the HMAC digest of the params hash, if a secret was given to the
191
194
  # instance.
@@ -196,9 +199,9 @@ class Transloadit::Request
196
199
  def signature(params)
197
200
  self.class._hmac(self.secret, params) if self.secret.to_s.length > 0
198
201
  end
199
-
202
+
200
203
  private
201
-
204
+
202
205
  #
203
206
  # Computes an HMAC digest from the key and message.
204
207
  #
@@ -5,7 +5,7 @@ require 'delegate'
5
5
 
6
6
  class Transloadit::Response < Delegator
7
7
  autoload :Assembly, 'transloadit/response/assembly'
8
-
8
+
9
9
  #
10
10
  # Creates an enhanced response wrapped around a RestClient response.
11
11
  #
@@ -14,7 +14,7 @@ class Transloadit::Response < Delegator
14
14
  def initialize(response)
15
15
  self.__setobj__(response)
16
16
  end
17
-
17
+
18
18
  #
19
19
  # Returns the attribute from the JSON response.
20
20
  #
@@ -24,7 +24,7 @@ class Transloadit::Response < Delegator
24
24
  def [](attribute)
25
25
  self.body[attribute.to_s]
26
26
  end
27
-
27
+
28
28
  #
29
29
  # Returns the parsed JSON body.
30
30
  #
@@ -33,7 +33,7 @@ class Transloadit::Response < Delegator
33
33
  def body
34
34
  MultiJson.load self.__getobj__.body
35
35
  end
36
-
36
+
37
37
  #
38
38
  # Inspects the body of the response.
39
39
  #
@@ -42,7 +42,7 @@ class Transloadit::Response < Delegator
42
42
  def inspect
43
43
  self.body.inspect
44
44
  end
45
-
45
+
46
46
  #
47
47
  # Chainably extends the response with additional methods. Used to add
48
48
  # context-specific functionality to a response.
@@ -54,9 +54,9 @@ class Transloadit::Response < Delegator
54
54
  self.extend(mod)
55
55
  self
56
56
  end
57
-
57
+
58
58
  protected
59
-
59
+
60
60
  #
61
61
  # The object to delegate method calls to.
62
62
  #
@@ -65,7 +65,7 @@ class Transloadit::Response < Delegator
65
65
  def __getobj__
66
66
  @response
67
67
  end
68
-
68
+
69
69
  #
70
70
  # Sets the object to delegate method calls to.
71
71
  #
@@ -75,7 +75,7 @@ class Transloadit::Response < Delegator
75
75
  def __setobj__(response)
76
76
  @response = response
77
77
  end
78
-
78
+
79
79
  #
80
80
  # Replaces the object this instance delegates to with the one the other
81
81
  # object uses.
@@ -11,13 +11,13 @@ require 'transloadit'
11
11
  class Transloadit::Step
12
12
  # @return [String] the name to give the step
13
13
  attr_accessor :name
14
-
14
+
15
15
  # @return [String] the robot to use
16
16
  attr_reader :robot
17
-
17
+
18
18
  # @return [Hash] the robot's options
19
19
  attr_accessor :options
20
-
20
+
21
21
  #
22
22
  # Creates a new Step with the given +robot+.
23
23
  #
@@ -31,7 +31,7 @@ class Transloadit::Step
31
31
  self.robot = robot
32
32
  self.options = options
33
33
  end
34
-
34
+
35
35
  #
36
36
  # Specifies that this Step should process the provided +input+ instead of
37
37
  # the output of the Step before it.
@@ -50,36 +50,36 @@ class Transloadit::Step
50
50
  #
51
51
  def use(input)
52
52
  self.options.delete(:use) and return if input.nil?
53
-
53
+
54
54
  self.options[:use] = case input
55
55
  when Symbol then input.inspect
56
56
  when Array then input.map {|i| i.name }
57
57
  else [ input.name ]
58
58
  end
59
59
  end
60
-
60
+
61
61
  #
62
62
  # @return [String] a human-readable version of the Step
63
63
  #
64
64
  def inspect
65
65
  self.to_hash[self.name].inspect
66
66
  end
67
-
67
+
68
68
  #
69
69
  # @return [Hash] a Transloadit-compatible Hash of the Step's contents
70
70
  #
71
71
  def to_hash
72
72
  { self.name => options.merge(:robot => self.robot) }
73
73
  end
74
-
74
+
75
75
  #
76
76
  # @return [String] JSON-encoded String containing the Step's hash contents
77
77
  #
78
78
  def to_json
79
79
  MultiJson.dump(self.to_hash)
80
80
  end
81
-
81
+
82
82
  protected
83
-
83
+
84
84
  attr_writer :robot
85
85
  end
@@ -1,3 +1,3 @@
1
1
  class Transloadit
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
@@ -70,4 +70,39 @@ http_interactions:
70
70
  string: ! '{"ok":"BORED_INSTANCE_FOUND","host":"jane.transloadit.com","api2_host":"jane.transloadit.com"}'
71
71
  http_version: '1.1'
72
72
  recorded_at: Fri, 08 Mar 2013 15:13:10 GMT
73
+ - request:
74
+ method: get
75
+ uri: http://api2.transloadit.com/instances/bored?params=%7B%22params%22:%7B%22foo%22:%22bar%22%7D%7D&signature=78f291e3038e3eeb82d9f79e11a68fe7b858ee97
76
+ body:
77
+ encoding: US-ASCII
78
+ string: ''
79
+ headers:
80
+ Accept:
81
+ - ! '*/*; q=0.5, application/xml'
82
+ Accept-Encoding:
83
+ - gzip, deflate
84
+ User-Agent:
85
+ - Transloadit Ruby SDK 0.1.2
86
+ response:
87
+ status:
88
+ code: 200
89
+ message: OK
90
+ headers:
91
+ Access-Control-Allow-Headers:
92
+ - X-Requested-With, Content-Type, Accept, Content-Length
93
+ Access-Control-Allow-Methods:
94
+ - POST, GET, PUT, DELETE, OPTIONS
95
+ Access-Control-Allow-Origin:
96
+ - ! '*'
97
+ Content-Type:
98
+ - text/plain
99
+ Content-Length:
100
+ - '94'
101
+ Connection:
102
+ - keep-alive
103
+ body:
104
+ encoding: UTF-8
105
+ string: ! '{"ok":"BORED_INSTANCE_FOUND","host":"jane.transloadit.com","api2_host":"jane.transloadit.com"}'
106
+ http_version: '1.1'
107
+ recorded_at: Fri, 08 Mar 2013 15:13:10 GMT
73
108
  recorded_with: VCR 2.4.0
data/test/test_helper.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
  $:.unshift File.expand_path('../../lib', __FILE__)
3
3
 
4
- require 'simplecov'
5
-
6
- SimpleCov.start { add_filter '/test/' }
4
+ if ENV['COVERAGE'] != 'false'
5
+ require 'simplecov'
6
+ SimpleCov.start { add_filter '/test/' }
7
+ end
7
8
 
8
9
  require 'minitest/autorun'
9
10
  require 'transloadit'
@@ -7,29 +7,29 @@ describe Transloadit do
7
7
  @duration = 10
8
8
  @max_size = 100
9
9
  end
10
-
10
+
11
11
  it 'must allow initialization' do
12
12
  t = Transloadit.new(:key => @key, :secret => @secret)
13
13
  t.must_be_kind_of Transloadit
14
14
  end
15
-
15
+
16
16
  it 'must not be initialized with no arguments' do
17
17
  lambda { Transloadit.new }.must_raise ArgumentError
18
18
  end
19
-
19
+
20
20
  it 'must require a key' do
21
21
  lambda { Transloadit.new(:secret => @secret) }.must_raise ArgumentError
22
22
  end
23
-
23
+
24
24
  it 'must not require a secret' do
25
25
  t = Transloadit.new(:key => @key)
26
26
  t.must_be_kind_of Transloadit
27
27
  end
28
-
28
+
29
29
  it 'must provide a default duration' do
30
30
  Transloadit.new(:key => @key).duration.wont_be_nil
31
31
  end
32
-
32
+
33
33
  describe 'when initialized' do
34
34
  before do
35
35
  @transloadit = Transloadit.new(
@@ -39,75 +39,75 @@ describe Transloadit do
39
39
  :max_size => @max_size
40
40
  )
41
41
  end
42
-
42
+
43
43
  it 'must allow access to the key' do
44
44
  @transloadit.key.must_equal @key
45
45
  end
46
-
46
+
47
47
  it 'must allow access to the secret' do
48
48
  @transloadit.secret.must_equal @secret
49
49
  end
50
-
50
+
51
51
  it 'must allow access to the duration' do
52
52
  @transloadit.duration.must_equal @duration
53
53
  end
54
-
54
+
55
55
  it 'must allow access to the max_size' do
56
56
  @transloadit.max_size.must_equal @max_size
57
57
  end
58
-
58
+
59
59
  it 'must create steps' do
60
60
  step = @transloadit.step('resize', '/image/resize', :width => 320)
61
-
61
+
62
62
  step.must_be_kind_of Transloadit::Step
63
63
  step.name. must_equal 'resize'
64
64
  step.robot. must_equal '/image/resize'
65
65
  step.options.must_equal :width => 320
66
66
  end
67
-
68
- it 'must create assemblies' do
67
+
68
+ it 'must create assemblies' do
69
69
  step = @transloadit.step(nil, nil)
70
70
  assembly = @transloadit.assembly :steps => step
71
-
71
+
72
72
  assembly.must_be_kind_of Transloadit::Assembly
73
73
  assembly.steps.must_equal step.to_hash
74
74
  end
75
-
75
+
76
76
  it 'must create assemblies with multiple steps' do
77
77
  steps = [
78
78
  @transloadit.step(nil, nil),
79
79
  @transloadit.step(nil, nil),
80
80
  ]
81
-
81
+
82
82
  assembly = @transloadit.assembly :steps => steps
83
83
  assembly.steps.must_equal steps.inject({}) {|h,s| h.merge s }
84
84
  end
85
-
85
+
86
86
  it 'must inspect like a hash' do
87
87
  @transloadit.inspect.must_equal @transloadit.to_hash.inspect
88
88
  end
89
-
89
+
90
90
  it 'must produce Transloadit-compatible hash output' do
91
91
  @transloadit.to_hash[:key] .must_equal @key
92
92
  @transloadit.to_hash[:max_size].must_equal @max_size
93
93
  @transloadit.to_hash[:expires] .
94
94
  must_match %r{\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}\+00:00}
95
95
  end
96
-
96
+
97
97
  it 'must produce Transloadit-compatible JSON output' do
98
98
  @transloadit.to_json.must_equal MultiJson.dump(@transloadit.to_hash)
99
99
  end
100
100
  end
101
-
101
+
102
102
  describe 'with no secret' do
103
103
  before do
104
104
  @transloadit = Transloadit.new(:key => @key)
105
105
  end
106
-
106
+
107
107
  it 'must not include a secret in its hash output' do
108
108
  @transloadit.to_hash.keys.wont_include :secret
109
109
  end
110
-
110
+
111
111
  it 'must not include a secret in its JSON output' do
112
112
  @transloadit.to_json.must_equal MultiJson.dump(@transloadit.to_hash)
113
113
  end
@@ -4,51 +4,51 @@ describe Transloadit::Assembly do
4
4
  before do
5
5
  @transloadit = Transloadit.new(:key => '')
6
6
  end
7
-
7
+
8
8
  it 'must allow initialization' do
9
9
  Transloadit::Assembly.new(@transloadit).
10
10
  must_be_kind_of Transloadit::Assembly
11
11
  end
12
-
12
+
13
13
  describe 'when initialized' do
14
- before do
14
+ before do
15
15
  @step = @transloadit.step 'thumbs', '/video/thumbs'
16
16
  @redirect = 'http://foo.bar/'
17
-
17
+
18
18
  @assembly = Transloadit::Assembly.new @transloadit,
19
19
  :steps => @step,
20
20
  :redirect_url => @redirect
21
21
  end
22
-
22
+
23
23
  it 'must store a pointer to the transloadit instance' do
24
24
  @assembly.transloadit.must_equal @transloadit
25
25
  end
26
-
26
+
27
27
  it 'must remember the options passed' do
28
28
  @assembly.options.must_equal(
29
29
  :steps => @step,
30
30
  :redirect_url => @redirect
31
31
  )
32
32
  end
33
-
33
+
34
34
  it 'must wrap its step in a hash' do
35
35
  @assembly.steps.must_equal @step.to_hash
36
36
  end
37
-
37
+
38
38
  it 'must not wrap a nil step' do
39
39
  @assembly.options[:steps] = nil
40
40
  @assembly.steps.must_equal nil
41
41
  end
42
-
42
+
43
43
  it 'must not wrap a hash step' do
44
44
  @assembly.options[:steps] = { :foo => 1 }
45
45
  @assembly.steps.must_equal :foo => 1
46
46
  end
47
-
47
+
48
48
  it 'must inspect like a hash' do
49
49
  @assembly.inspect.must_equal @assembly.to_hash.inspect
50
50
  end
51
-
51
+
52
52
  it 'must produce Transloadit-compatible hash output' do
53
53
  @assembly.to_hash.must_equal(
54
54
  :auth => @transloadit.to_hash,
@@ -56,11 +56,11 @@ describe Transloadit::Assembly do
56
56
  :redirect_url => @redirect
57
57
  )
58
58
  end
59
-
59
+
60
60
  it 'must produce Transloadit-compatible JSON output' do
61
61
  @assembly.to_json.must_equal MultiJson.dump(@assembly.to_hash)
62
62
  end
63
-
63
+
64
64
  it 'must submit files for upload' do
65
65
  VCR.use_cassette 'submit_assembly' do
66
66
  response = @assembly.submit! open('lib/transloadit/version.rb')
@@ -110,16 +110,16 @@ describe Transloadit::Assembly do
110
110
  end
111
111
  end
112
112
  end
113
-
113
+
114
114
  describe 'with multiple steps' do
115
115
  before do
116
116
  @encode = @transloadit.step 'encode', '/video/encode'
117
117
  @thumbs = @transloadit.step 'thumbs', '/video/thumbs'
118
-
118
+
119
119
  @assembly = Transloadit::Assembly.new @transloadit,
120
120
  :steps => [ @encode, @thumbs ]
121
121
  end
122
-
122
+
123
123
  it 'must wrap its steps into one hash' do
124
124
  @assembly.to_hash[:steps].keys.must_include @encode.name
125
125
  @assembly.to_hash[:steps].keys.must_include @thumbs.name
@@ -2,46 +2,64 @@ require 'test_helper'
2
2
 
3
3
  describe Transloadit::Request do
4
4
  REQUEST_URI = 'http://api2.jane.transloadit.com/assemblies/76fe5df1c93a0a530f3e583805cf98b4'
5
-
5
+
6
6
  before do
7
7
  # reset the API endpoint between tests
8
8
  Transloadit::Request.api Transloadit::Request::API_ENDPOINT
9
9
  end
10
-
10
+
11
11
  it 'must allow initialization' do
12
12
  request = Transloadit::Request.new '/'
13
13
  request.must_be_kind_of Transloadit::Request
14
14
  end
15
-
15
+
16
16
  it 'must locate bored instances' do
17
17
  VCR.use_cassette 'fetch_bored' do
18
18
  Transloadit::Request.bored!.
19
19
  wont_equal Transloadit::Request::API_ENDPOINT.host
20
20
  end
21
21
  end
22
-
22
+
23
23
  describe 'when performing a GET' do
24
24
  before do
25
25
  @request = Transloadit::Request.new('instances/bored')
26
26
  end
27
-
27
+
28
28
  it 'must inspect to the API URL' do
29
29
  @request.inspect.must_equal @request.url.to_s.inspect
30
30
  end
31
-
31
+
32
32
  it 'must perform a GET against the resource' do
33
33
  VCR.use_cassette 'fetch_bored' do
34
34
  @request.get(:params => { :foo => 'bar'})['ok'].
35
35
  must_equal 'BORED_INSTANCE_FOUND'
36
36
  end
37
37
  end
38
+
39
+ describe 'with secret' do
40
+ before do
41
+ @request.secret = "tehsupersecrettoken"
42
+ end
43
+
44
+ it 'must inspect to the API URL' do
45
+ @request.inspect.must_equal @request.url.to_s.inspect
46
+ end
47
+
48
+ it 'must perform a GET against the resource' do
49
+ VCR.use_cassette 'fetch_bored' do
50
+ @request.get(:params => { :foo => 'bar'})['ok'].
51
+ must_equal 'BORED_INSTANCE_FOUND'
52
+ end
53
+ end
54
+
55
+ end
38
56
  end
39
-
57
+
40
58
  describe 'when performing a POST' do
41
59
  before do
42
- @request = Transloadit::Request.new('assemblies', '')
60
+ @request = Transloadit::Request.new('assemblies', 'secret')
43
61
  end
44
-
62
+
45
63
  it 'must perform a POST against the resource' do
46
64
  VCR.use_cassette 'post_assembly' do
47
65
  @request.post(:params => {
@@ -5,7 +5,7 @@ describe Transloadit::Step do
5
5
  Transloadit::Step.new('store', '/s3/store').
6
6
  must_be_kind_of Transloadit::Step
7
7
  end
8
-
8
+
9
9
  describe 'when initialized' do
10
10
  before do
11
11
  @name = 'store'
@@ -13,21 +13,21 @@ describe Transloadit::Step do
13
13
  @key = 'aws-access-key-id'
14
14
  @secret = 'aws-secret-access-key'
15
15
  @bucket = 's3-bucket-name'
16
-
16
+
17
17
  @step = Transloadit::Step.new @name, @robot,
18
18
  :key => @key,
19
19
  :secret => @secret,
20
20
  :bucket => @bucket
21
21
  end
22
-
22
+
23
23
  it 'should use the name given' do
24
24
  @step.name.must_equal @name
25
25
  end
26
-
26
+
27
27
  it 'must remember the type' do
28
28
  @step.robot.must_equal @robot
29
29
  end
30
-
30
+
31
31
  it 'must remember the parameters' do
32
32
  @step.options.must_equal(
33
33
  :key => @key,
@@ -35,11 +35,11 @@ describe Transloadit::Step do
35
35
  :bucket => @bucket
36
36
  )
37
37
  end
38
-
38
+
39
39
  it 'must inspect like a hash' do
40
40
  @step.inspect.must_equal @step.to_hash[@step.name].inspect
41
41
  end
42
-
42
+
43
43
  it 'must produce Transloadit-compatible hash output' do
44
44
  @step.to_hash.must_equal(
45
45
  @step.name => {
@@ -50,45 +50,45 @@ describe Transloadit::Step do
50
50
  }
51
51
  )
52
52
  end
53
-
53
+
54
54
  it 'must produce Transloadit-compatible JSON output' do
55
55
  @step.to_json.must_equal MultiJson.dump(@step.to_hash)
56
56
  end
57
57
  end
58
-
58
+
59
59
  describe 'when using alternative inputs' do
60
60
  before do
61
61
  @step = Transloadit::Step.new 'resize', '/image/resize'
62
62
  end
63
-
63
+
64
64
  it 'must allow using the original file as input' do
65
65
  @step.use(:original).must_equal ':original'
66
66
  @step.options[:use] .must_equal ':original'
67
67
  end
68
-
68
+
69
69
  it 'must allow using another step' do
70
70
  input = Transloadit::Step.new 'thumbnail', '/video/thumbnail'
71
-
71
+
72
72
  @step.use(input). must_equal [ input.name ]
73
73
  @step.options[:use].must_equal [ input.name ]
74
74
  end
75
-
75
+
76
76
  it 'must allow using multiple steps' do
77
77
  inputs = [
78
78
  Transloadit::Step.new('thumbnail', '/video/thumbnail'),
79
79
  Transloadit::Step.new('resize', '/image/resize')
80
80
  ]
81
-
81
+
82
82
  @step.use(inputs). must_equal inputs.map {|i| i.name }
83
83
  @step.options[:use].must_equal inputs.map {|i| i.name }
84
84
  end
85
-
85
+
86
86
  it 'must allow using nothing' do
87
87
  @step.use :original
88
88
  @step.use(nil).must_equal nil
89
89
  @step.options.keys.wont_include(:use)
90
90
  end
91
-
91
+
92
92
  it 'must include the used steps in the hash output' do
93
93
  @step.use(:original). must_equal ':original'
94
94
  @step.to_hash[@step.name][:use].must_equal ':original'
data/transloadit.gemspec CHANGED
@@ -6,31 +6,31 @@ Gem::Specification.new do |gem|
6
6
  gem.name = 'transloadit'
7
7
  gem.version = Transloadit::VERSION
8
8
  gem.platform = Gem::Platform::RUBY
9
-
9
+
10
10
  gem.authors = [ "Stephen Touset", "Robin Mehner" ]
11
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'
15
15
  gem.description = 'The transloadit gem allows you to automate uploading files through the Transloadit REST API'
16
-
16
+
17
17
  gem.required_rubygems_version = '>= 1.3.6'
18
18
  gem.rubyforge_project = 'transloadit'
19
-
19
+
20
20
  gem.files = `git ls-files`.split("\n")
21
21
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
22
  gem.require_paths = %w{ lib }
23
-
23
+
24
24
  gem.add_dependency 'rest-client'
25
25
  gem.add_dependency 'multi_json'
26
-
26
+
27
27
  gem.add_development_dependency 'rake'
28
28
  gem.add_development_dependency 'minitest' # needed for < 1.9.2
29
29
  gem.add_development_dependency 'simplecov'
30
-
30
+
31
31
  gem.add_development_dependency 'vcr'
32
32
  gem.add_development_dependency 'webmock'
33
-
33
+
34
34
  gem.add_development_dependency 'yard'
35
35
  gem.add_development_dependency 'kramdown' # for YARD rdoc formatting
36
36
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transloadit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 1.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Stephen Touset
@@ -10,12 +9,11 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-04-22 00:00:00.000000000 Z
12
+ date: 2013-06-25 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rest-client
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
18
  - - '>='
21
19
  - !ruby/object:Gem::Version
@@ -23,7 +21,6 @@ dependencies:
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
25
  - - '>='
29
26
  - !ruby/object:Gem::Version
@@ -31,7 +28,6 @@ dependencies:
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: multi_json
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
32
  - - '>='
37
33
  - !ruby/object:Gem::Version
@@ -39,7 +35,6 @@ dependencies:
39
35
  type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
39
  - - '>='
45
40
  - !ruby/object:Gem::Version
@@ -47,7 +42,6 @@ dependencies:
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: rake
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
46
  - - '>='
53
47
  - !ruby/object:Gem::Version
@@ -55,7 +49,6 @@ dependencies:
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
53
  - - '>='
61
54
  - !ruby/object:Gem::Version
@@ -63,7 +56,6 @@ dependencies:
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: minitest
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
60
  - - '>='
69
61
  - !ruby/object:Gem::Version
@@ -71,7 +63,6 @@ dependencies:
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
67
  - - '>='
77
68
  - !ruby/object:Gem::Version
@@ -79,7 +70,6 @@ dependencies:
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: simplecov
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
74
  - - '>='
85
75
  - !ruby/object:Gem::Version
@@ -87,7 +77,6 @@ dependencies:
87
77
  type: :development
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
81
  - - '>='
93
82
  - !ruby/object:Gem::Version
@@ -95,7 +84,6 @@ dependencies:
95
84
  - !ruby/object:Gem::Dependency
96
85
  name: vcr
97
86
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
87
  requirements:
100
88
  - - '>='
101
89
  - !ruby/object:Gem::Version
@@ -103,7 +91,6 @@ dependencies:
103
91
  type: :development
104
92
  prerelease: false
105
93
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
94
  requirements:
108
95
  - - '>='
109
96
  - !ruby/object:Gem::Version
@@ -111,7 +98,6 @@ dependencies:
111
98
  - !ruby/object:Gem::Dependency
112
99
  name: webmock
113
100
  requirement: !ruby/object:Gem::Requirement
114
- none: false
115
101
  requirements:
116
102
  - - '>='
117
103
  - !ruby/object:Gem::Version
@@ -119,7 +105,6 @@ dependencies:
119
105
  type: :development
120
106
  prerelease: false
121
107
  version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
108
  requirements:
124
109
  - - '>='
125
110
  - !ruby/object:Gem::Version
@@ -127,7 +112,6 @@ dependencies:
127
112
  - !ruby/object:Gem::Dependency
128
113
  name: yard
129
114
  requirement: !ruby/object:Gem::Requirement
130
- none: false
131
115
  requirements:
132
116
  - - '>='
133
117
  - !ruby/object:Gem::Version
@@ -135,7 +119,6 @@ dependencies:
135
119
  type: :development
136
120
  prerelease: false
137
121
  version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
122
  requirements:
140
123
  - - '>='
141
124
  - !ruby/object:Gem::Version
@@ -143,7 +126,6 @@ dependencies:
143
126
  - !ruby/object:Gem::Dependency
144
127
  name: kramdown
145
128
  requirement: !ruby/object:Gem::Requirement
146
- none: false
147
129
  requirements:
148
130
  - - '>='
149
131
  - !ruby/object:Gem::Version
@@ -151,7 +133,6 @@ dependencies:
151
133
  type: :development
152
134
  prerelease: false
153
135
  version_requirements: !ruby/object:Gem::Requirement
154
- none: false
155
136
  requirements:
156
137
  - - '>='
157
138
  - !ruby/object:Gem::Version
@@ -196,30 +177,26 @@ files:
196
177
  - transloadit.gemspec
197
178
  homepage: http://github.com/transloadit/ruby-sdk/
198
179
  licenses: []
180
+ metadata: {}
199
181
  post_install_message:
200
182
  rdoc_options: []
201
183
  require_paths:
202
184
  - lib
203
185
  required_ruby_version: !ruby/object:Gem::Requirement
204
- none: false
205
186
  requirements:
206
187
  - - '>='
207
188
  - !ruby/object:Gem::Version
208
189
  version: '0'
209
- segments:
210
- - 0
211
- hash: -1627827986787108787
212
190
  required_rubygems_version: !ruby/object:Gem::Requirement
213
- none: false
214
191
  requirements:
215
192
  - - '>='
216
193
  - !ruby/object:Gem::Version
217
194
  version: 1.3.6
218
195
  requirements: []
219
196
  rubyforge_project: transloadit
220
- rubygems_version: 1.8.25
197
+ rubygems_version: 2.0.2
221
198
  signing_key:
222
- specification_version: 3
199
+ specification_version: 4
223
200
  summary: Official Ruby gem for Transloadit
224
201
  test_files:
225
202
  - test/fixtures/cassettes/cancel_assembly.yml