zencoder 2.3.3 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +195 -95
- data/lib/zencoder.rb +7 -8
- data/lib/zencoder/account.rb +5 -8
- data/lib/zencoder/errors.rb +3 -1
- data/lib/zencoder/http.rb +27 -20
- data/lib/zencoder/http/net_http.rb +5 -30
- data/lib/zencoder/http/resources/zencoder_ca_chain.crt +62 -0
- data/lib/zencoder/http/typhoeus.rb +1 -1
- data/lib/zencoder/input.rb +13 -0
- data/lib/zencoder/job.rb +14 -21
- data/lib/zencoder/notification.rb +5 -5
- data/lib/zencoder/output.rb +6 -3
- data/lib/zencoder/report.rb +9 -0
- data/lib/zencoder/resource.rb +76 -0
- data/lib/zencoder/response.rb +1 -1
- data/lib/zencoder/serializer.rb +27 -0
- data/lib/zencoder/version.rb +1 -1
- data/lib/zencoder/zencoder.rb +6 -5
- metadata +15 -26
- data/lib/zencoder/base.rb +0 -82
- data/lib/zencoder/extensions.rb +0 -31
data/README.markdown
CHANGED
@@ -6,23 +6,57 @@ See [http://zencoder.com/docs/api](http://zencoder.com/docs/api) for more detail
|
|
6
6
|
|
7
7
|
Tested on the following versions of Ruby:
|
8
8
|
|
9
|
-
* Ruby 1.8.6-
|
10
|
-
* Ruby 1.8.7-
|
11
|
-
* Ruby 1.
|
12
|
-
* Ruby 1.9.2-
|
13
|
-
* Ruby
|
14
|
-
* Rubinius
|
15
|
-
* jRuby 1.5
|
9
|
+
* Ruby 1.8.6-p420
|
10
|
+
* Ruby 1.8.7-p249
|
11
|
+
* Ruby 1.8.7-p352
|
12
|
+
* Ruby 1.9.2-p290
|
13
|
+
* Ruby 1.9.3-p0
|
14
|
+
* Rubinius 2.0.0dev
|
15
|
+
* jRuby 1.6.5
|
16
|
+
|
17
|
+
## v2.4 WARNING!!!
|
18
|
+
|
19
|
+
Version 2.4 brings some significant changes to the gem, ones which you should be aware of:
|
20
|
+
|
21
|
+
* __Removed dependency on `activesupport`.__ This means that the keys of your hashes should all be symbols except in the case of HTTP headers.
|
22
|
+
* __Added dependency on `multi_json`__. This gem allows encoding and decoding to and from JSON without all the baggage of `activesupport`.
|
23
|
+
* __Removed support for XML requests.__ Since we're doing all the encoding and decoding in the gem, it didn't make sense to support it any longer. You could still conceivably do this with the gem, but you'd need to encode and decode to and from XML yourself and pass appropriate headers. Let us know if this is a problem for you.
|
24
|
+
* __Using header authentication by default.__ Zencoder has always allowed the passing of the API key as an HTTP header (`Zencoder-Api-Key`), but in this library we've traditionally merged it in with your requests. In at least one case this would result in messy deserialization and serialization of parameters. Using this alternative authentication method clears up this problem.
|
25
|
+
* __Some actions only work on future versions of the API.__ See the section titled `APIv2` below.
|
26
|
+
* __Now defaults to API v2.__ If you'd like to continue using API v1, you should change the base_url as outlined in the section titled `APIv2` below.
|
27
|
+
* __The Zencoder SSL CA chain is now bundled.__ Previously when you used the default HTTP backend (Net::HTTP), we would try to detect the CA path on your system and use it. This led to some frustration for some users and was generally unreliable. We now bundle our SSL CA chain in the library which should make integration easier. Please note that if you were using `Zencoder::HTTP::NetHTTP.root_cert_paths` or `Zencoder::HTTP::NetHTTP.skip_setting_root_cert_path`, they have been removed.
|
28
|
+
|
29
|
+
## APIv2
|
30
|
+
|
31
|
+
With the release of version two of the Zencoder API, there are some new methods available to you.
|
32
|
+
|
33
|
+
* Zencoder::Job.progress(job\_id)
|
34
|
+
* Zencoder::Input.details(input\_id)
|
35
|
+
* Zencoder::Input.progress(input\_id)
|
36
|
+
* Zencoder::Output.details(output\_id)
|
37
|
+
* Zencoder::Report.minutes(:from => "2011-01-01", :to => "2011-03-01")
|
38
|
+
|
39
|
+
These new methods will not work with newer versions of the API. Please see the [Zencoder documentation](https://app.zencoder.com/docs) and our [blog post on the subject](http://blog.zencoder.com/2012/01/05/announcing-zencoder-api-v2/) for more information on APIv2.
|
40
|
+
|
41
|
+
If you'd like to use the new version of the library but continue using APIv1 until you work through any integration troubles, you can do the following:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
Zencoder.base_url = "https://app.zencoder.com/api/v1"
|
45
|
+
```
|
16
46
|
|
17
47
|
## Getting Started
|
18
48
|
|
19
49
|
The first thing you'll need to interact with the Zencoder API is your API key. You can use your API key in one of three ways. The first and easiest is to set it and forget it on the Zencoder module like so:
|
20
50
|
|
21
|
-
|
51
|
+
```ruby
|
52
|
+
Zencoder.api_key = 'abcd1234'
|
53
|
+
```
|
22
54
|
|
23
55
|
Alternatively, you can use an environment variable:
|
24
56
|
|
25
|
-
|
57
|
+
```ruby
|
58
|
+
ENV['ZENCODER_API_KEY'] = 'abcd1234'
|
59
|
+
```
|
26
60
|
|
27
61
|
You can also pass your API key in every request, but who wants to do that?
|
28
62
|
|
@@ -32,22 +66,28 @@ All calls in the Zencoder library either raise Zencoder::HTTPError or return a Z
|
|
32
66
|
|
33
67
|
A Zencoder::Response can be used as follows:
|
34
68
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
69
|
+
```ruby
|
70
|
+
response = Zencoder::Job.list
|
71
|
+
response.success? # => true if the response code was 200 through 299
|
72
|
+
response.code # => 200
|
73
|
+
response.body # => the JSON-parsed body or raw body if unparseable
|
74
|
+
response.raw_body # => the body pre-JSON-parsing
|
75
|
+
response.raw_response # => the raw Net::HTTP or Typhoeus response (see below for how to use Typhoeus)
|
76
|
+
```
|
41
77
|
|
42
78
|
### Parameters
|
43
79
|
|
44
|
-
When sending API request parameters you can specify them as a non-string object, which we'll then serialize to JSON
|
80
|
+
When sending API request parameters you can specify them as a non-string object, which we'll then serialize to JSON:
|
45
81
|
|
46
|
-
|
82
|
+
```ruby
|
83
|
+
Zencoder::Job.create({:input => 's3://bucket/key.mp4'})
|
84
|
+
```
|
47
85
|
|
48
86
|
Or you can specify them as a string, which we'll just pass along as the request body:
|
49
87
|
|
50
|
-
|
88
|
+
```ruby
|
89
|
+
Zencoder::Job.create('{"input": "s3://bucket/key.mp4"}')
|
90
|
+
```
|
51
91
|
|
52
92
|
## Jobs
|
53
93
|
|
@@ -57,63 +97,117 @@ There's more you can do on jobs than anything else in the API. The following met
|
|
57
97
|
|
58
98
|
The hash you pass to the `create` method should be encodable to the [JSON you would pass to the Job creation API call on Zencoder](http://zencoder.com/docs/api/#encoding-job). We'll auto-populate your API key if you've set it already.
|
59
99
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
100
|
+
```ruby
|
101
|
+
Zencoder::Job.create({:input => 's3://bucket/key.mp4'})
|
102
|
+
Zencoder::Job.create({:input => 's3://bucket/key.mp4',
|
103
|
+
:outputs => [{:label => 'vp8 for the web',
|
104
|
+
:url => 's3://bucket/key_output.webm'}]})
|
105
|
+
Zencoder::Job.create({:input => 's3://bucket/key.mp4', :api_key => 'abcd1234'})
|
106
|
+
```
|
65
107
|
|
66
108
|
This returns a Zencoder::Response object. The body includes a Job ID, and one or more Output IDs (one for every output file created).
|
67
109
|
|
68
|
-
|
69
|
-
|
70
|
-
|
110
|
+
```ruby
|
111
|
+
response = Zencoder::Job.create({:input => 's3://bucket/key.mp4'})
|
112
|
+
response.code # => 201
|
113
|
+
response.body['id'] # => 12345
|
114
|
+
```
|
71
115
|
|
72
116
|
### list
|
73
117
|
|
74
118
|
By default the jobs listing is paginated with 50 jobs per page and sorted by ID in descending order. You can pass two parameters to control the paging: `page` and `per_page`.
|
75
119
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
120
|
+
```ruby
|
121
|
+
Zencoder::Job.list
|
122
|
+
Zencoder::Job.list(:per_page => 10)
|
123
|
+
Zencoder::Job.list(:per_page => 10, :page => 2)
|
124
|
+
Zencoder::Job.list(:per_page => 10, :page => 2, :api_key => 'abcd1234')
|
125
|
+
```
|
80
126
|
|
81
127
|
### details
|
82
128
|
|
83
129
|
The number passed to `details` is the ID of a Zencoder job.
|
84
130
|
|
85
|
-
|
86
|
-
|
131
|
+
```ruby
|
132
|
+
Zencoder::Job.details(1)
|
133
|
+
Zencoder::Job.details(1, :api_key => 'abcd1234')
|
134
|
+
```
|
135
|
+
|
136
|
+
### progress
|
137
|
+
|
138
|
+
The number passed to `progress` is the ID of a Zencoder job.
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
Zencoder::Job.progress(1)
|
142
|
+
Zencoder::Job.progress(1, :api_key => 'abcd1234')
|
143
|
+
```
|
87
144
|
|
88
145
|
### resubmit
|
89
146
|
|
90
147
|
The number passed to `resubmit` is the ID of a Zencoder job.
|
91
148
|
|
92
|
-
|
93
|
-
|
149
|
+
```ruby
|
150
|
+
Zencoder::Job.resubmit(1)
|
151
|
+
Zencoder::Job.resubmit(1, :api_key => 'abcd1234')
|
152
|
+
```
|
94
153
|
|
95
154
|
### cancel
|
96
155
|
|
97
156
|
The number passed to `cancel` is the ID of a Zencoder job.
|
98
157
|
|
99
|
-
|
100
|
-
|
158
|
+
```ruby
|
159
|
+
Zencoder::Job.cancel(1)
|
160
|
+
Zencoder::Job.cancel(1, :api_key => 'abcd1234')
|
161
|
+
```
|
101
162
|
|
102
163
|
### delete
|
103
164
|
|
104
165
|
The number passed to `delete` is the ID of a Zencoder job.
|
105
166
|
|
106
|
-
|
107
|
-
|
167
|
+
```ruby
|
168
|
+
Zencoder::Job.delete(1)
|
169
|
+
Zencoder::Job.delete(1, :api_key => 'abcd1234')
|
170
|
+
```
|
171
|
+
|
172
|
+
## Inputs
|
173
|
+
|
174
|
+
### details
|
175
|
+
|
176
|
+
The number passed to `details` is the ID of a Zencoder input.
|
177
|
+
|
178
|
+
```ruby
|
179
|
+
Zencoder::Input.details(1)
|
180
|
+
Zencoder::Input.details(1, :api_key => 'abcd1234')
|
181
|
+
```
|
182
|
+
|
183
|
+
### progress
|
184
|
+
|
185
|
+
The number passed to `progress` is the ID of a Zencoder input.
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
Zencoder::Input.progress(1)
|
189
|
+
Zencoder::Input.progress(1, :api_key => 'abcd1234')
|
190
|
+
```
|
108
191
|
|
109
192
|
## Outputs
|
110
193
|
|
194
|
+
### details
|
195
|
+
|
196
|
+
The number passed to `details` is the ID of a Zencoder output.
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
Zencoder::Output.details(1)
|
200
|
+
Zencoder::Output.details(1, :api_key => 'abcd1234')
|
201
|
+
```
|
202
|
+
|
111
203
|
### progress
|
112
204
|
|
113
205
|
*Important:* the number passed to `progress` is the output file ID, not the Job ID.
|
114
206
|
|
115
|
-
|
116
|
-
|
207
|
+
```ruby
|
208
|
+
Zencoder::Output.progress(1)
|
209
|
+
Zencoder::Output.progress(1, :api_key => 'abcd1234')
|
210
|
+
```
|
117
211
|
|
118
212
|
## Notifications
|
119
213
|
|
@@ -121,11 +215,13 @@ The number passed to `delete` is the ID of a Zencoder job.
|
|
121
215
|
|
122
216
|
By default the jobs listing is paginated with 50 jobs per page and sorted by ID in descending order. You can pass three parameters to control the paging: `page`, `per_page`, and `since_id`. Passing `since_id` will return notifications for jobs created after the job with the given ID.
|
123
217
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
218
|
+
```ruby
|
219
|
+
Zencoder::Notification.list
|
220
|
+
Zencoder::Notification.list(:per_page => 10)
|
221
|
+
Zencoder::Notification.list(:per_page => 10, :page => 2)
|
222
|
+
Zencoder::Notification.list(:per_page => 10, :page => 2, :since_id => 20)
|
223
|
+
Zencoder::Notification.list(:api_key => 'abcd1234')
|
224
|
+
```
|
129
225
|
|
130
226
|
## Accounts
|
131
227
|
|
@@ -133,31 +229,49 @@ By default the jobs listing is paginated with 50 jobs per page and sorted by ID
|
|
133
229
|
|
134
230
|
The hash you pass to the `create` method should be encodable to the [JSON you would pass to the Account creation API call on Zencoder](http://zencoder.com/docs/api/#accounts). No API key is required for this call, of course.
|
135
231
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
232
|
+
```ruby
|
233
|
+
Zencoder::Account.create({:terms_of_service => 1,
|
234
|
+
:email => 'bob@example.com'})
|
235
|
+
Zencoder::Account.create({:terms_of_service => 1,
|
236
|
+
:email => 'bob@example.com',
|
237
|
+
:password => 'abcd1234',
|
238
|
+
:affiliate_code => 'abcd1234'})
|
239
|
+
```
|
142
240
|
|
143
241
|
### details
|
144
242
|
|
145
|
-
|
146
|
-
|
243
|
+
```ruby
|
244
|
+
Zencoder::Account.details
|
245
|
+
Zencoder::Account.details(:api_key => 'abcd1234')
|
246
|
+
```
|
147
247
|
|
148
248
|
### integration
|
149
249
|
|
150
250
|
This will put your account into integration mode (site-wide).
|
151
251
|
|
152
|
-
|
153
|
-
|
252
|
+
```ruby
|
253
|
+
Zencoder::Account.integration
|
254
|
+
Zencoder::Account.integration(:api_key => 'abcd1234')
|
255
|
+
```
|
154
256
|
|
155
257
|
### live
|
156
258
|
|
157
259
|
This will put your account into live mode (site-wide).
|
158
260
|
|
159
|
-
|
160
|
-
|
261
|
+
```ruby
|
262
|
+
Zencoder::Account.live
|
263
|
+
Zencoder::Account.live(:api_key => 'abcd1234')
|
264
|
+
```
|
265
|
+
|
266
|
+
## Reports
|
267
|
+
|
268
|
+
### minutes
|
269
|
+
|
270
|
+
This will list the minutes used for your account within a certain, configurable range.
|
271
|
+
|
272
|
+
```ruby
|
273
|
+
Zencoder::Report.minutes(:from => "2011-10-30", :to => "2011-11-24")
|
274
|
+
```
|
161
275
|
|
162
276
|
## Advanced HTTP
|
163
277
|
|
@@ -165,11 +279,13 @@ This will put your account into live mode (site-wide).
|
|
165
279
|
|
166
280
|
By default this library will use Net::HTTP to make all API calls. You can change the backend or add your own:
|
167
281
|
|
168
|
-
|
169
|
-
|
282
|
+
```ruby
|
283
|
+
require 'typhoeus'
|
284
|
+
Zencoder::HTTP.http_backend = Zencoder::HTTP::Typhoeus
|
170
285
|
|
171
|
-
|
172
|
-
|
286
|
+
require 'my_favorite_http_library'
|
287
|
+
Zencoder::HTTP.http_backend = MyFavoriteHTTPBackend
|
288
|
+
```
|
173
289
|
|
174
290
|
See the HTTP backends in this library to get started on your own.
|
175
291
|
|
@@ -177,55 +293,39 @@ See the HTTP backends in this library to get started on your own.
|
|
177
293
|
|
178
294
|
A secondary options hash can be passed to any method call which will then be passed on to the HTTP backend. You can pass `timeout` (in milliseconds), `headers`, and `params` (will be added to the query string) to any of the backends. If you are using Typhoeus, see their documentation for further options. In the following example the timeout is set to one second:
|
179
295
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
### Format
|
296
|
+
```ruby
|
297
|
+
Zencoder::Job.create({:input => 's3://bucket/key.mp4'}, {:timeout => 1000})
|
298
|
+
```
|
184
299
|
|
185
|
-
By default we'll send and receive JSON for all our communication. If you would rather use XML then you can pass :format => :xml in the secondary options hash.
|
186
|
-
|
187
|
-
Zencoder::Job.create({:input => 's3://bucket/key.mp4'}, {:format => :xml})
|
188
300
|
|
189
301
|
### SSL Verification
|
190
302
|
|
191
|
-
We
|
303
|
+
We will use our bundled SSL CA chain for SSL peer verification which should almost always work without a hitch. However, if you'd like to skip SSL verification you can pass an option in the secondary options hash.
|
192
304
|
|
193
305
|
**NOTE: WE HIGHLY DISCOURAGE THIS! THIS WILL LEAVE YOU VULNERABLE TO MAN-IN-THE-MIDDLE ATTACKS!**
|
194
306
|
|
195
|
-
|
307
|
+
```ruby
|
308
|
+
Zencoder::Job.create({:input => 's3://bucket/key.mp4'}, {:skip_ssl_verify => true})
|
309
|
+
```
|
196
310
|
|
197
311
|
Alternatively you can add it to the default options.
|
198
312
|
|
199
|
-
|
313
|
+
```ruby
|
314
|
+
Zencoder::HTTP.default_options.merge!(:skip_ssl_verify => true)
|
315
|
+
```
|
200
316
|
|
201
317
|
### Default Options
|
202
318
|
|
203
319
|
Default options are passed to the HTTP backend. These can be retrieved and modified.
|
204
320
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
The Net::HTTP backend will do its best to locate your local SSL certs to allow SSL verification. For a list of paths that are checked, see `Zencoder::HTTP::NetHTTP.root_cert_paths`. Feel free to add your own at runtime. Let us know if we're missing a common location.
|
212
|
-
|
213
|
-
Zencoder::HTTP::NetHTTP.root_cert_paths << '/my/custom/cert/path'
|
214
|
-
|
215
|
-
If the ruby installed on your system is already aware of where your root cert path is and/or you would like us to NOT set it, you can do the following.
|
216
|
-
|
217
|
-
Zencoder::HTTP::NetHTTP.skip_setting_root_cert_path = true
|
218
|
-
|
219
|
-
## Advanced JSON and XML
|
220
|
-
|
221
|
-
### Alternate JSON and XML Libraries
|
222
|
-
|
223
|
-
This library uses the `activesupport` gem to encode and decode JSON. The latest versions of ActiveSupport allow you to change the libraries used to decode JSON and XML.
|
224
|
-
|
225
|
-
You can change the JSON decoding backend for ActiveSupport in Rails 2.3 like so:
|
321
|
+
```ruby
|
322
|
+
Zencoder::HTTP.default_options = {:timeout => 3000,
|
323
|
+
:headers => {'Accept' => 'application/json',
|
324
|
+
'Content-Type' => 'application/json'}}
|
325
|
+
```
|
226
326
|
|
227
|
-
|
327
|
+
## Advanced JSON
|
228
328
|
|
229
|
-
|
329
|
+
### Alternate JSON Libraries
|
230
330
|
|
231
|
-
|
331
|
+
This library uses the `multi_json` gem to encode and decode JSON. This fantastic gem lets you swap out the JSON backend at will and includes a working JSON encoder/decoder. You can check the [MultiJson](https://github.com/intridea/multi_json) project for more information on how to accomplish this.
|
data/lib/zencoder.rb
CHANGED
@@ -3,22 +3,21 @@ require 'cgi'
|
|
3
3
|
require 'net/https'
|
4
4
|
require 'timeout'
|
5
5
|
|
6
|
-
#
|
7
|
-
|
8
|
-
require 'active_support/all' # Screw it
|
9
|
-
rescue LoadError
|
10
|
-
require 'active_support' # JSON and XML parsing/encoding
|
11
|
-
end
|
6
|
+
# JSON serialization
|
7
|
+
require 'multi_json'
|
12
8
|
|
13
9
|
# Zencoder
|
14
|
-
require 'zencoder/
|
10
|
+
require 'zencoder/version'
|
11
|
+
require 'zencoder/serializer'
|
15
12
|
require 'zencoder/zencoder'
|
16
|
-
require 'zencoder/
|
13
|
+
require 'zencoder/resource'
|
17
14
|
require 'zencoder/http/net_http'
|
18
15
|
require 'zencoder/http/typhoeus'
|
19
16
|
require 'zencoder/http'
|
20
17
|
require 'zencoder/errors'
|
18
|
+
require 'zencoder/report'
|
21
19
|
require 'zencoder/job'
|
20
|
+
require 'zencoder/input'
|
22
21
|
require 'zencoder/output'
|
23
22
|
require 'zencoder/account'
|
24
23
|
require 'zencoder/notification'
|
data/lib/zencoder/account.rb
CHANGED
@@ -1,23 +1,20 @@
|
|
1
1
|
module Zencoder
|
2
|
-
class Account <
|
2
|
+
class Account < Resource
|
3
3
|
|
4
4
|
def self.create(params={}, options={})
|
5
|
-
|
5
|
+
post("/account", params, options)
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.details(options={})
|
9
|
-
|
10
|
-
HTTP.get("#{options[:base_url] || base_url}/account", merge_params(options, params))
|
9
|
+
get("/account", options)
|
11
10
|
end
|
12
11
|
|
13
12
|
def self.integration(options={})
|
14
|
-
|
15
|
-
HTTP.get("#{options[:base_url] || base_url}/account/integration", merge_params(options, params))
|
13
|
+
put("/account/integration", nil, options)
|
16
14
|
end
|
17
15
|
|
18
16
|
def self.live(options={})
|
19
|
-
|
20
|
-
HTTP.get("#{options[:base_url] || base_url}/account/live", merge_params(options, params))
|
17
|
+
put("/account/live", nil, options)
|
21
18
|
end
|
22
19
|
|
23
20
|
end
|
data/lib/zencoder/errors.rb
CHANGED
@@ -15,7 +15,9 @@ module Zencoder
|
|
15
15
|
|
16
16
|
def backtrace
|
17
17
|
if @error
|
18
|
-
@error.backtrace
|
18
|
+
error_backtrace = ["--- Backtrace from #{@error.class} ---"] + (@error.backtrace || [])
|
19
|
+
wrapper_backtrace = ["--- Backtrace from #{self.class} ---"] + (super || [])
|
20
|
+
error_backtrace + wrapper_backtrace
|
19
21
|
else
|
20
22
|
super
|
21
23
|
end
|
data/lib/zencoder/http.rb
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
module Zencoder
|
2
|
-
class HTTP
|
2
|
+
class HTTP
|
3
3
|
|
4
|
-
|
4
|
+
CA_CHAIN_PATH = File.expand_path(File.join(File.dirname(__FILE__), "http", "resources", "zencoder_ca_chain.crt"))
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
include Zencoder::Serializer
|
7
|
+
|
8
|
+
attr_accessor :url, :options, :method
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :default_options, :http_backend
|
12
|
+
end
|
8
13
|
|
9
14
|
self.http_backend = NetHTTP
|
10
15
|
|
11
16
|
self.default_options = {:timeout => 10000,
|
12
|
-
:headers => {'Accept'
|
13
|
-
'Content-Type' => 'application/json'
|
17
|
+
:headers => {'Accept' => 'application/json',
|
18
|
+
'Content-Type' => 'application/json',
|
19
|
+
'User-Agent' => "Zencoder-rb v#{Zencoder::GEM_VERSION}"}}
|
14
20
|
|
15
21
|
def initialize(method, url, options={})
|
16
22
|
self.method = method
|
17
23
|
self.url = url
|
18
|
-
self.format = options.delete(:format)
|
19
24
|
self.options = options
|
20
|
-
self.body = options.delete(:body)
|
21
25
|
end
|
22
26
|
|
23
27
|
def self.post(url, body, options={})
|
@@ -43,29 +47,32 @@ module Zencoder
|
|
43
47
|
end
|
44
48
|
|
45
49
|
def options=(value)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
50
|
+
value ||= {}
|
51
|
+
|
52
|
+
# Hacky, deeper hash merge
|
53
|
+
default_options.keys.each do |key|
|
54
|
+
if value.has_key?(key)
|
55
|
+
if value[key].is_a?(Hash) && default_options[key].is_a?(Hash)
|
56
|
+
value[key] = default_options[key].merge(value[key])
|
57
|
+
end
|
58
|
+
else
|
59
|
+
value[key] = default_options[key]
|
60
|
+
end
|
61
|
+
end
|
51
62
|
|
52
|
-
options
|
63
|
+
@options = value
|
53
64
|
end
|
54
65
|
|
55
66
|
def options
|
56
67
|
@options || self.options = default_options
|
57
68
|
end
|
58
69
|
|
59
|
-
def format
|
60
|
-
@format ||= :json
|
61
|
-
end
|
62
|
-
|
63
70
|
def http_backend
|
64
71
|
self.class.http_backend
|
65
72
|
end
|
66
73
|
|
67
74
|
def default_options
|
68
|
-
self.class.default_options
|
75
|
+
self.class.default_options
|
69
76
|
end
|
70
77
|
|
71
78
|
|
@@ -76,7 +83,7 @@ module Zencoder
|
|
76
83
|
response.code = http_response.code
|
77
84
|
|
78
85
|
begin
|
79
|
-
response.body = decode(http_response.body.to_s
|
86
|
+
response.body = decode(http_response.body.to_s)
|
80
87
|
rescue StandardError # Hack! Returns different exceptions depending on the decoding engine
|
81
88
|
response.body = http_response.body
|
82
89
|
end
|
@@ -1,27 +1,9 @@
|
|
1
|
-
# Ruby's Net/HTTP Sucks
|
2
|
-
# Borrowed root cert checking from http://redcorundum.blogspot.com/2008/03/ssl-certificates-and-nethttps.html
|
3
|
-
|
4
1
|
module Zencoder
|
5
|
-
class HTTP
|
2
|
+
class HTTP
|
6
3
|
class NetHTTP
|
7
4
|
|
8
5
|
attr_accessor :method, :url, :uri, :body, :params, :headers, :timeout, :skip_ssl_verify, :options
|
9
6
|
|
10
|
-
cattr_accessor :root_cert_paths
|
11
|
-
cattr_accessor :skip_setting_root_cert_path
|
12
|
-
|
13
|
-
self.root_cert_paths = ['/etc/ssl/certs',
|
14
|
-
'/var/ssl',
|
15
|
-
'/usr/share/ssl',
|
16
|
-
'/usr/ssl',
|
17
|
-
'/etc/ssl',
|
18
|
-
'/usr/local/openssl',
|
19
|
-
'/usr/lib/ssl',
|
20
|
-
'/System/Library/OpenSSL',
|
21
|
-
'/etc/openssl',
|
22
|
-
'/usr/local/ssl',
|
23
|
-
'/etc/pki/tls']
|
24
|
-
|
25
7
|
def initialize(method, url, options)
|
26
8
|
@method = method
|
27
9
|
@url = url
|
@@ -73,14 +55,13 @@ module Zencoder
|
|
73
55
|
|
74
56
|
if u.scheme == 'https'
|
75
57
|
http.use_ssl = true
|
76
|
-
root_cert_path = locate_root_cert_path
|
77
58
|
|
78
|
-
if
|
79
|
-
http.
|
59
|
+
if skip_ssl_verify
|
60
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
61
|
+
else
|
62
|
+
http.ca_file = Zencoder::HTTP::CA_CHAIN_PATH
|
80
63
|
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
81
64
|
http.verify_depth = 5
|
82
|
-
else
|
83
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
84
65
|
end
|
85
66
|
end
|
86
67
|
|
@@ -131,12 +112,6 @@ module Zencoder
|
|
131
112
|
Net::HTTP.const_get(method.to_s.capitalize)
|
132
113
|
end
|
133
114
|
|
134
|
-
def locate_root_cert_path
|
135
|
-
self.class.root_cert_paths.detect do |root_cert_path|
|
136
|
-
File.directory?(root_cert_path)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
115
|
end
|
141
116
|
end
|
142
117
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDJzCCApCgAwIBAgIBATANBgkqhkiG9w0BAQQFADCBzjELMAkGA1UEBhMCWkEx
|
3
|
+
FTATBgNVBAgTDFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJQ2FwZSBUb3duMR0wGwYD
|
4
|
+
VQQKExRUaGF3dGUgQ29uc3VsdGluZyBjYzEoMCYGA1UECxMfQ2VydGlmaWNhdGlv
|
5
|
+
biBTZXJ2aWNlcyBEaXZpc2lvbjEhMB8GA1UEAxMYVGhhd3RlIFByZW1pdW0gU2Vy
|
6
|
+
dmVyIENBMSgwJgYJKoZIhvcNAQkBFhlwcmVtaXVtLXNlcnZlckB0aGF3dGUuY29t
|
7
|
+
MB4XDTk2MDgwMTAwMDAwMFoXDTIwMTIzMTIzNTk1OVowgc4xCzAJBgNVBAYTAlpB
|
8
|
+
MRUwEwYDVQQIEwxXZXN0ZXJuIENhcGUxEjAQBgNVBAcTCUNhcGUgVG93bjEdMBsG
|
9
|
+
A1UEChMUVGhhd3RlIENvbnN1bHRpbmcgY2MxKDAmBgNVBAsTH0NlcnRpZmljYXRp
|
10
|
+
b24gU2Vydm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i4ZBp6fmw8U+E3KHNgf7KXUwefU/ltWJTS
|
57
|
+
r41tiGeA5u2ylc9yMcqlHHK6XALnZELn+aks1joNrI1CqiQBOeacPwGFVw1Yh0X4
|
58
|
+
04Wqk2kmhXBIgD8SFcd5tB8FLztimQIDAQABMA0GCSqGSIb3DQEBBAUAA4GBAG3r
|
59
|
+
GwnpXtlR22ciYaQqPEh346B8pt5zohQDhT37qw4wxYMWM4ETCJ57NE7fQMh017l9
|
60
|
+
3PR2VX2bY1QY6fDq81yx2YtCHrnAlU66+tXifPVoYb+O7AWXX1uw16OFNMQkpw0P
|
61
|
+
lZPvy5TYnh+dXIVtx6quTx8itc2VrbqnzPmrC3p/
|
62
|
+
-----END CERTIFICATE-----
|
data/lib/zencoder/job.rb
CHANGED
@@ -1,40 +1,33 @@
|
|
1
1
|
module Zencoder
|
2
|
-
class Job <
|
2
|
+
class Job < Resource
|
3
3
|
|
4
4
|
def self.create(params={}, options={})
|
5
|
-
|
6
|
-
HTTP.post("#{options[:base_url] || base_url}/jobs",
|
7
|
-
encode(params, options[:format]),
|
8
|
-
options)
|
5
|
+
post("/jobs", params, options)
|
9
6
|
end
|
10
7
|
|
11
8
|
def self.list(options={})
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
options = options.dup
|
10
|
+
params = { :page => options.delete(:page) || 1,
|
11
|
+
:per_page => options.delete(:per_page) || 50,
|
12
|
+
:state => options.delete(:state) }
|
16
13
|
|
17
|
-
|
14
|
+
get("/jobs", merge_params(options, params))
|
18
15
|
end
|
19
16
|
|
20
17
|
def self.details(job_id, options={})
|
21
|
-
|
22
|
-
HTTP.get("#{options[:base_url] || base_url}/jobs/#{job_id}", merge_params(options, params))
|
18
|
+
get("/jobs/#{job_id}", options)
|
23
19
|
end
|
24
20
|
|
25
|
-
def self.
|
26
|
-
|
27
|
-
HTTP.get("#{options[:base_url] || base_url}/jobs/#{job_id}/resubmit", merge_params(options, params))
|
21
|
+
def self.progress(job_id, options={})
|
22
|
+
get("/jobs/#{job_id}/progress", options)
|
28
23
|
end
|
29
24
|
|
30
|
-
def self.
|
31
|
-
|
32
|
-
HTTP.get("#{options[:base_url] || base_url}/jobs/#{job_id}/cancel", merge_params(options, params))
|
25
|
+
def self.resubmit(job_id, options={})
|
26
|
+
put("/jobs/#{job_id}/resubmit", nil, options)
|
33
27
|
end
|
34
28
|
|
35
|
-
def self.
|
36
|
-
|
37
|
-
HTTP.delete("#{options[:base_url] || base_url}/jobs/#{job_id}", merge_params(options, params))
|
29
|
+
def self.cancel(job_id, options={})
|
30
|
+
put("/jobs/#{job_id}/cancel", nil, options)
|
38
31
|
end
|
39
32
|
|
40
33
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Zencoder
|
2
|
-
class Notification <
|
2
|
+
class Notification < Resource
|
3
3
|
|
4
4
|
def self.list(options={})
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
options = options.dup
|
6
|
+
params = {:page => options.delete(:page) || 1,
|
7
|
+
:per_page => options.delete(:per_page) || 50 }
|
8
8
|
|
9
|
-
|
9
|
+
get("/notifications", merge_params(options, params))
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
data/lib/zencoder/output.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
module Zencoder
|
2
|
-
class Output <
|
2
|
+
class Output < Resource
|
3
|
+
|
4
|
+
def self.details(output_id, options={})
|
5
|
+
get("/outputs/#{output_id}", options)
|
6
|
+
end
|
3
7
|
|
4
8
|
def self.progress(output_id, options={})
|
5
|
-
|
6
|
-
HTTP.get("#{options[:base_url] || base_url}/outputs/#{output_id}/progress", merge_params(options, params))
|
9
|
+
get("/outputs/#{output_id}/progress", options)
|
7
10
|
end
|
8
11
|
|
9
12
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Zencoder
|
2
|
+
class Resource
|
3
|
+
|
4
|
+
include Zencoder::Serializer
|
5
|
+
|
6
|
+
def self.api_key
|
7
|
+
Zencoder.api_key
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.base_url
|
11
|
+
Zencoder.base_url
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.post(path, params={}, options={})
|
15
|
+
options = options.dup
|
16
|
+
url = url_for(path, options)
|
17
|
+
body = encode(params)
|
18
|
+
options = add_api_key_header(options)
|
19
|
+
HTTP.post(url, body, options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.put(path, params={}, options={})
|
23
|
+
options = options.dup
|
24
|
+
url = url_for(path, options)
|
25
|
+
body = encode(params)
|
26
|
+
options = add_api_key_header(options)
|
27
|
+
HTTP.put(url, body, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get(path, options={})
|
31
|
+
options = options.dup
|
32
|
+
url = url_for(path, options)
|
33
|
+
options = add_api_key_header(options)
|
34
|
+
HTTP.get(url, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.delete(path, options={})
|
38
|
+
options = options.dup
|
39
|
+
url = url_for(path)
|
40
|
+
options = add_api_key_header(options)
|
41
|
+
HTTP.delete(url, options)
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def self.url_for(path, options={})
|
48
|
+
File.join((options[:base_url] || base_url).to_s, path.to_s)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.add_api_key_header(options)
|
52
|
+
effective_api_key = options.delete(:api_key) || api_key
|
53
|
+
|
54
|
+
if effective_api_key
|
55
|
+
if options[:headers]
|
56
|
+
options[:headers] = options[:headers].dup
|
57
|
+
else
|
58
|
+
options[:headers] = {}
|
59
|
+
end
|
60
|
+
options[:headers]["Zencoder-Api-Key"] = effective_api_key
|
61
|
+
end
|
62
|
+
|
63
|
+
options
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.merge_params(options, params)
|
67
|
+
if options[:params]
|
68
|
+
options[:params] = options[:params].merge(params)
|
69
|
+
options
|
70
|
+
else
|
71
|
+
options.merge(:params => params)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
data/lib/zencoder/response.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Zencoder
|
2
|
+
module Serializer
|
3
|
+
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def self.included(klass)
|
7
|
+
klass.extend(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def encode(content)
|
11
|
+
if content.is_a?(String) || content.nil?
|
12
|
+
content
|
13
|
+
else
|
14
|
+
MultiJson.encode(content)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def decode(content)
|
19
|
+
if content.is_a?(String)
|
20
|
+
MultiJson.decode(content)
|
21
|
+
else
|
22
|
+
content
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/zencoder/version.rb
CHANGED
data/lib/zencoder/zencoder.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
module Zencoder
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
class << self
|
4
|
+
attr_accessor :api_key, :base_url
|
5
|
+
end
|
5
6
|
|
6
7
|
self.api_key = nil
|
7
|
-
self.base_url = 'https://app.zencoder.com/api'
|
8
|
+
self.base_url = 'https://app.zencoder.com/api/v2'
|
8
9
|
|
9
10
|
def self.api_key
|
10
|
-
|
11
|
+
@api_key || ENV['ZENCODER_API_KEY']
|
11
12
|
end
|
12
13
|
|
13
14
|
def self.base_url(env=nil)
|
14
|
-
|
15
|
+
@base_url
|
15
16
|
end
|
16
17
|
|
17
18
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zencoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 2.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 2.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nathan Sutton
|
@@ -16,10 +16,10 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2012-01-05 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: multi_json
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
36
|
+
name: shoulda
|
37
37
|
prerelease: false
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
segments:
|
45
45
|
- 0
|
46
46
|
version: "0"
|
47
|
-
type: :
|
47
|
+
type: :development
|
48
48
|
version_requirements: *id002
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
|
-
name:
|
50
|
+
name: mocha
|
51
51
|
prerelease: false
|
52
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
@@ -61,7 +61,7 @@ dependencies:
|
|
61
61
|
type: :development
|
62
62
|
version_requirements: *id003
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
|
-
name:
|
64
|
+
name: webmock
|
65
65
|
prerelease: false
|
66
66
|
requirement: &id004 !ruby/object:Gem::Requirement
|
67
67
|
none: false
|
@@ -74,20 +74,6 @@ dependencies:
|
|
74
74
|
version: "0"
|
75
75
|
type: :development
|
76
76
|
version_requirements: *id004
|
77
|
-
- !ruby/object:Gem::Dependency
|
78
|
-
name: webmock
|
79
|
-
prerelease: false
|
80
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ">="
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
hash: 3
|
86
|
-
segments:
|
87
|
-
- 0
|
88
|
-
version: "0"
|
89
|
-
type: :development
|
90
|
-
version_requirements: *id005
|
91
77
|
description: Zencoder <http://zencoder.com> integration library.
|
92
78
|
email: info@zencoder.com
|
93
79
|
executables: []
|
@@ -98,16 +84,19 @@ extra_rdoc_files: []
|
|
98
84
|
|
99
85
|
files:
|
100
86
|
- lib/zencoder/account.rb
|
101
|
-
- lib/zencoder/base.rb
|
102
87
|
- lib/zencoder/errors.rb
|
103
|
-
- lib/zencoder/extensions.rb
|
104
88
|
- lib/zencoder/http/net_http.rb
|
89
|
+
- lib/zencoder/http/resources/zencoder_ca_chain.crt
|
105
90
|
- lib/zencoder/http/typhoeus.rb
|
106
91
|
- lib/zencoder/http.rb
|
92
|
+
- lib/zencoder/input.rb
|
107
93
|
- lib/zencoder/job.rb
|
108
94
|
- lib/zencoder/notification.rb
|
109
95
|
- lib/zencoder/output.rb
|
96
|
+
- lib/zencoder/report.rb
|
97
|
+
- lib/zencoder/resource.rb
|
110
98
|
- lib/zencoder/response.rb
|
99
|
+
- lib/zencoder/serializer.rb
|
111
100
|
- lib/zencoder/version.rb
|
112
101
|
- lib/zencoder/zencoder.rb
|
113
102
|
- lib/zencoder.rb
|
data/lib/zencoder/base.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
module Zencoder
|
2
|
-
class Base
|
3
|
-
|
4
|
-
def self.api_key
|
5
|
-
Zencoder.api_key
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.base_url
|
9
|
-
Zencoder.base_url
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.encode(content, format=nil)
|
13
|
-
if content.is_a?(String)
|
14
|
-
content
|
15
|
-
elsif format.to_s == 'xml'
|
16
|
-
if content.is_a?(Hash) && content.keys.size == 1
|
17
|
-
content[content.keys.first].to_xml(:root => content.keys.first)
|
18
|
-
else
|
19
|
-
content.to_xml
|
20
|
-
end
|
21
|
-
else
|
22
|
-
content.to_json
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def encode(content, format=nil)
|
27
|
-
self.class.encode(content, format)
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.decode(content, format=nil)
|
31
|
-
if content.is_a?(String)
|
32
|
-
if format.to_s == 'xml'
|
33
|
-
Hash.from_xml(content)
|
34
|
-
else
|
35
|
-
ActiveSupport::JSON.decode(content)
|
36
|
-
end
|
37
|
-
else
|
38
|
-
content
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def decode(content, format=nil)
|
43
|
-
self.class.decode(content, format)
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
protected
|
48
|
-
|
49
|
-
def self.apply_api_key(params, format=nil)
|
50
|
-
if api_key
|
51
|
-
decoded_params = decode(params, format).with_indifferent_access
|
52
|
-
|
53
|
-
if decoded_params[:api_request]
|
54
|
-
decoded_params[:api_request] = decoded_params[:api_request].with_indifferent_access
|
55
|
-
end
|
56
|
-
|
57
|
-
if format.to_s == 'xml'
|
58
|
-
if !(decoded_params[:api_request] && decoded_params[:api_request][:api_key])
|
59
|
-
decoded_params[:api_request] ||= {}.with_indifferent_access
|
60
|
-
decoded_params[:api_request][:api_key] = api_key
|
61
|
-
end
|
62
|
-
else
|
63
|
-
decoded_params['api_key'] = api_key unless decoded_params['api_key']
|
64
|
-
end
|
65
|
-
|
66
|
-
decoded_params
|
67
|
-
else
|
68
|
-
params
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.merge_params(options, params)
|
73
|
-
if options[:params]
|
74
|
-
options[:params] = options[:params].merge(params)
|
75
|
-
options
|
76
|
-
else
|
77
|
-
options.merge(:params => params)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
end
|
data/lib/zencoder/extensions.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
unless Hash.method_defined?(:recursive_with_indifferent_access)
|
2
|
-
class Hash
|
3
|
-
def recursive_with_indifferent_access
|
4
|
-
hash = with_indifferent_access
|
5
|
-
|
6
|
-
hash.each do |key, value|
|
7
|
-
if value.is_a?(Hash) || value.is_a?(Array)
|
8
|
-
hash[key] = value.recursive_with_indifferent_access
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
hash
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
unless Array.method_defined?(:recursive_with_indifferent_access)
|
18
|
-
class Array
|
19
|
-
def recursive_with_indifferent_access
|
20
|
-
array = dup
|
21
|
-
|
22
|
-
array.each_with_index do |value, index|
|
23
|
-
if value.is_a?(Hash) || value.is_a?(Array)
|
24
|
-
array[index] = value.recursive_with_indifferent_access
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
array
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|