telestream_cloud 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +1 -0
- data/Gemfile +2 -0
- data/LICENSE +20 -0
- data/README.md +357 -0
- data/Rakefile +9 -0
- data/lib/telestream_cloud.rb +30 -0
- data/lib/telestream_cloud/api_authentication.rb +66 -0
- data/lib/telestream_cloud/base.rb +111 -0
- data/lib/telestream_cloud/config.rb +87 -0
- data/lib/telestream_cloud/connection.rb +101 -0
- data/lib/telestream_cloud/errors.rb +17 -0
- data/lib/telestream_cloud/faraday.rb +84 -0
- data/lib/telestream_cloud/flip.rb +9 -0
- data/lib/telestream_cloud/modules/associations.rb +55 -0
- data/lib/telestream_cloud/modules/builders.rb +45 -0
- data/lib/telestream_cloud/modules/destroyers.rb +25 -0
- data/lib/telestream_cloud/modules/factory_connection.rb +7 -0
- data/lib/telestream_cloud/modules/finders.rb +68 -0
- data/lib/telestream_cloud/modules/router.rb +62 -0
- data/lib/telestream_cloud/modules/updatable.rb +31 -0
- data/lib/telestream_cloud/modules/video_state.rb +16 -0
- data/lib/telestream_cloud/proxies/encoding_scope.rb +56 -0
- data/lib/telestream_cloud/proxies/profile_scope.rb +7 -0
- data/lib/telestream_cloud/proxies/proxy.rb +27 -0
- data/lib/telestream_cloud/proxies/scope.rb +94 -0
- data/lib/telestream_cloud/proxies/video_scope.rb +28 -0
- data/lib/telestream_cloud/resources/encoding.rb +47 -0
- data/lib/telestream_cloud/resources/factory.rb +72 -0
- data/lib/telestream_cloud/resources/profile.rb +22 -0
- data/lib/telestream_cloud/resources/resource.rb +48 -0
- data/lib/telestream_cloud/resources/video.rb +39 -0
- data/lib/telestream_cloud/telestream_cloud.rb +69 -0
- data/lib/telestream_cloud/upload_session.rb +102 -0
- data/lib/telestream_cloud/version.rb +3 -0
- data/spec/cloud_spec.rb +132 -0
- data/spec/encoding_spec.rb +260 -0
- data/spec/heroku_spec.rb +32 -0
- data/spec/panda_spec.rb +206 -0
- data/spec/profile_spec.rb +117 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/video_spec.rb +399 -0
- data/telestream_cloud.gemspec +30 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5dc2f13d4e17fe9964e6e290c5ceac66423355b3
|
4
|
+
data.tar.gz: 0fde90a8a2260b9e942315ab7396ccb7296bd8e9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a5a925523a87ec792fcd7ea053b460417acca47162439608af56bd433cc49711af782880c17a66254e70383851b4a3dfbefbd22b45b043831ced59b234169a1d
|
7
|
+
data.tar.gz: ecd712a9a7c57afdf4f648545e24549cc486af3eece50a8ca77fb13eeefe68acca28a7fd1c12618c6dd5992f150560e22d0a5444f4bee85517b9d6a3ed16baf8
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 Telestream Cloud
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,357 @@
|
|
1
|
+
# TelestreamCloud
|
2
|
+
|
3
|
+
TelestreamCloud gem provides an interface to access the [TelestreamCloud](http://cloud.telestream.net) API from Ruby.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
gem install telestream_cloud
|
9
|
+
|
10
|
+
## How to use it
|
11
|
+
|
12
|
+
require 'rubygems'
|
13
|
+
require 'telestream_cloud'
|
14
|
+
|
15
|
+
## Faraday Adapter
|
16
|
+
The gem automatically detects http libraries and sets the default adapter
|
17
|
+
You can just set the default Panda adapter if you are not happy with the current one.
|
18
|
+
|
19
|
+
TelestreamCloud.default_adapter = :excon
|
20
|
+
|
21
|
+
For rails 4, try the net_http adapter. This fixes disable_ssl_peer_verification related errors caused by the default adapter.
|
22
|
+
|
23
|
+
TelestreamCloud.default_adapter = :net_http
|
24
|
+
|
25
|
+
### Creating an instance of the client
|
26
|
+
```ruby
|
27
|
+
TelestreamCloud.configure do
|
28
|
+
access_key "your_access_key"
|
29
|
+
secret_key "your_secret_key"
|
30
|
+
# api_host "api.cloud.telestream.net" # this will be set bu default
|
31
|
+
end
|
32
|
+
```
|
33
|
+
or
|
34
|
+
```ruby
|
35
|
+
TelestreamCloud.configure({:access_key => ....})
|
36
|
+
```
|
37
|
+
|
38
|
+
If your account uses a different region, set your `api_host` accordingly:
|
39
|
+
|
40
|
+
| Region | api_host |
|
41
|
+
|---|---|
|
42
|
+
| gce-us | api.cloud.pandastream.net |
|
43
|
+
| us | api-us-east.cloud.telestream.net|
|
44
|
+
| eu | api-eu-west.cloud.telestream.net |
|
45
|
+
|
46
|
+
### Inside a Rails app with a main account or using Heroku Addon
|
47
|
+
|
48
|
+
Heroku will store your credentials as an environment variable called PANDASTREAM_URL. You can find more information on [Heroku config variable docs](http://docs.heroku.com/config-vars)
|
49
|
+
|
50
|
+
If you use a config file like `config/panda.yml` to support multiple environments, do the following in your `config/initializers/panda.rb` :
|
51
|
+
|
52
|
+
TelestreamCloud.configure((ENV['PANDASTREAM_URL'] || YAML::load_file(File.join(File.dirname(__FILE__),"..", "panda.yml"))[Rails.env]))
|
53
|
+
|
54
|
+
See the [Rails How-to](https://cloud.telestream.net/docs#rails) for more details.
|
55
|
+
|
56
|
+
### Creating an instance using ONLY with Heroku Addon
|
57
|
+
|
58
|
+
If you don't use a config file and want to simply be setup, do the following (works only on heroku):
|
59
|
+
|
60
|
+
TelestreamCloud.configure_heroku
|
61
|
+
|
62
|
+
### Typical usage
|
63
|
+
After initializing your client, you can now select resouce that you want to use. Currently supported resources are:
|
64
|
+
* `:flip`
|
65
|
+
* additional resources will be available soon, stay tuned ;)
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
flip = TelestreamCloud.resources :flip
|
69
|
+
```
|
70
|
+
|
71
|
+
### Factories
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
# Accessing Factories
|
75
|
+
factories = flip.factories.all
|
76
|
+
|
77
|
+
factories.each do |f|
|
78
|
+
puts "Id: #{f.id}, name: #{f.name}"
|
79
|
+
end
|
80
|
+
|
81
|
+
# Accessing specific Factory
|
82
|
+
f1 = flip.factories.all[0]
|
83
|
+
# or
|
84
|
+
f2 = flip.factories.find('factory_id')
|
85
|
+
```
|
86
|
+
|
87
|
+
### Videos
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
# Retrieving videos
|
91
|
+
videos = factory.videos.all
|
92
|
+
videos.first.id
|
93
|
+
=> "abcde"
|
94
|
+
|
95
|
+
videos = factory.videos.all(:page => 2, :per_page => 20)
|
96
|
+
# or
|
97
|
+
videos = factory.videos.page(1).per_page(20)
|
98
|
+
videos.size
|
99
|
+
=> 20
|
100
|
+
|
101
|
+
# Note: maximum :per_page is 100. That's also the default value
|
102
|
+
|
103
|
+
# Get attributes
|
104
|
+
video.attributes
|
105
|
+
=> {
|
106
|
+
"id"=>"1234",
|
107
|
+
"original_filename"=>"panda.mp4",
|
108
|
+
"source_url"=>"http://www.example.com/original_video.mp4",
|
109
|
+
"extname"=>".mp4",
|
110
|
+
"duration"=>14010,
|
111
|
+
"audio_codec"=>"aac",
|
112
|
+
"video_codec"=>"h264",
|
113
|
+
"file_size" => "44000",
|
114
|
+
"width"=>300,
|
115
|
+
"height"=>240,
|
116
|
+
"fps"=>29,
|
117
|
+
"status"=>"success",
|
118
|
+
"created_at"=>"2010/01/13 16:45:29 +0000",
|
119
|
+
"updated_at"=>"2010/01/13 16:45:35 +0000"
|
120
|
+
}
|
121
|
+
|
122
|
+
# Creating videos from source_url
|
123
|
+
video = factory.videos.create(:source_url => "http://mywebsite.com/myvideo.mp4")
|
124
|
+
|
125
|
+
# Creating videos from local file
|
126
|
+
video = factory.videos.create(:file => File.new("/path/to/my/movie.mp4"))
|
127
|
+
|
128
|
+
# Encode video with selected profiles only
|
129
|
+
video = factory.videos.create(:file => File.new("/path/to/my/movie.mp4"),
|
130
|
+
:profiles => "h264,webm")
|
131
|
+
|
132
|
+
# Deleting videos
|
133
|
+
video = factory.videos.find('video-id')
|
134
|
+
video.delete
|
135
|
+
=> true
|
136
|
+
```
|
137
|
+
|
138
|
+
### Encodings
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
# Find one encoding
|
142
|
+
encoding = factory.encodings.find('encoding-id')
|
143
|
+
|
144
|
+
# Find all encodings for one video
|
145
|
+
video = factory.videos.find('video-id')
|
146
|
+
encodings = video.encodings.all
|
147
|
+
|
148
|
+
# Find all encodings in one Factory
|
149
|
+
encodings = factory.encodings.all
|
150
|
+
|
151
|
+
# Using page/per_page
|
152
|
+
encodings = factory.encodings.page(1).per_page(5)
|
153
|
+
|
154
|
+
# Get only successful encodings
|
155
|
+
encodings = factory.encodings.all(:status => "success")
|
156
|
+
|
157
|
+
# Access encoding attributes
|
158
|
+
encoding.attributes
|
159
|
+
=> { ... }
|
160
|
+
|
161
|
+
encoding.encoding_progress
|
162
|
+
=> 60
|
163
|
+
|
164
|
+
encoding.success?
|
165
|
+
=> true
|
166
|
+
|
167
|
+
encoding.processing?
|
168
|
+
=> false
|
169
|
+
|
170
|
+
encoding.fail?
|
171
|
+
=> false
|
172
|
+
|
173
|
+
# Get screenshot url
|
174
|
+
encoding.screenshots[0]
|
175
|
+
=> http://s3.amazonaws.com/bucket/abcde.jpg
|
176
|
+
|
177
|
+
# Create new encoding for a video that already exists
|
178
|
+
encoding = factory.encodings.create(:video_id => 1234, :profile_id => 6789)
|
179
|
+
# or
|
180
|
+
video.encodings.create(:profile_id => 6789)
|
181
|
+
|
182
|
+
# Delete encoding
|
183
|
+
encoding = factory.encodings.find('encoding-id')
|
184
|
+
encoding.delete
|
185
|
+
=> true
|
186
|
+
```
|
187
|
+
### Profiles
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
# Find a profile
|
191
|
+
profile = factory.profiles.find("profile-id")
|
192
|
+
|
193
|
+
# Get all profiles
|
194
|
+
profiles = factory.profiles.all
|
195
|
+
|
196
|
+
# Create new profile
|
197
|
+
profile = factory.profiles.create(:preset_name => "h264")
|
198
|
+
profile = factory.profiles.create(:command => "ffmpeg -i $input_file$ -y $output_file$", ....)
|
199
|
+
|
200
|
+
# Update a profile
|
201
|
+
profile = factory.profiles.find("profile-id")
|
202
|
+
profile.width = 800
|
203
|
+
profile.height = 600
|
204
|
+
profile.save
|
205
|
+
=> true
|
206
|
+
|
207
|
+
# Delete a profile
|
208
|
+
profile = factory.profiles.find("profile-id")
|
209
|
+
profile.delete
|
210
|
+
=> true
|
211
|
+
```
|
212
|
+
|
213
|
+
## Binding the client to one Factory only
|
214
|
+
|
215
|
+
You can also initialize the client with a specific factory_id. This way you can work with Videos, Encodings and Profiles directly (within the Factory you selected)
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
TelestreamCloud.configure do
|
219
|
+
access_key "your_access_key"
|
220
|
+
secret_key "your_secret_key"
|
221
|
+
factory_id "factory_id"
|
222
|
+
end
|
223
|
+
|
224
|
+
# Get all videos in your factory
|
225
|
+
videos = TelestreamCloud::Video.all
|
226
|
+
|
227
|
+
# Find Video by id
|
228
|
+
factory = TelestreamCloud::Video.find('video-id')
|
229
|
+
|
230
|
+
# Create new Video
|
231
|
+
video = TelestreamCloud::Video.create(:source_url => "http://mywebsite.com/myvideo.mp4")
|
232
|
+
|
233
|
+
# Create new encoding
|
234
|
+
encoding = TelestreamCloud::Encoding.create(:video_id => 1234, :profile_id => 6789)
|
235
|
+
|
236
|
+
# Delete Profile (the same can be done for Videos and Encodings)
|
237
|
+
TelestreamCloud::Profile.delete('profile-id')
|
238
|
+
|
239
|
+
```
|
240
|
+
|
241
|
+
|
242
|
+
## Generating signatures
|
243
|
+
|
244
|
+
All requests to TelestreamCloud are signed using HMAC-SHA256, based on a timestamp and your secret key. This is handled transparently. However, sometimes you will want to generate only this signature, in order to make a request by means other than this library. This is the case when using the [JavaScript panda_uploader](http://github.com/pandastream/panda_uploader).
|
245
|
+
|
246
|
+
To do this, a method `signed_params()` is supported:
|
247
|
+
```ruby
|
248
|
+
TelestreamCloud.signed_params('POST', '/videos.json')
|
249
|
+
# => {'access_key' => '8df50af4-074f-11df-b278-1231350015b1',
|
250
|
+
# 'factory_id' => 'your-factory-id',
|
251
|
+
# 'signature' => 'yRUZhcsYgnG+8jV5yrnWjLoRwzeJShdcdUoejjaRp6I=',
|
252
|
+
# 'timestamp' => '2016-01-28T11:42:46.262935Z'}
|
253
|
+
|
254
|
+
TelestreamCloud.signed_params('GET', '/videos.json', {'some_params' => 'some_value'})
|
255
|
+
# => {'access_key' => '8df50af4-074f-11df-b278-1231350015b1',
|
256
|
+
# 'factory_id' => 'your-factory-id',
|
257
|
+
# 'signature' => '7glFUWlcSgvBm5BmOLghRNeqLNbof20jYCRgk9cJOi8=',
|
258
|
+
# 'some_param' => 'some_value',
|
259
|
+
# 'timestamp' => '2016-01-28T11:43:20.066141Z'}
|
260
|
+
```
|
261
|
+
## Low level API calls
|
262
|
+
|
263
|
+
You can also make direct calls to TelestreamCloud REST API.
|
264
|
+
|
265
|
+
For calls to endpoints other than `/factories.json`, you need to provide `factory_id` when initializing the client.
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
```ruby
|
270
|
+
# Posting a video
|
271
|
+
TelestreamCloud.post('/videos.json', {:file => File.new("/path/to/your/movie.mp4")})
|
272
|
+
|
273
|
+
TelestreamCloud.post('/videos.json', {:source_url => 'http://www.example.com/original_video.mp4'})
|
274
|
+
=>{"duration"=>nil,
|
275
|
+
"created_at"=>"2010/01/15 14:48:42 +0000",
|
276
|
+
"original_filename"=>"panda.mp4",
|
277
|
+
"updated_at"=>"2010/01/15 14:48:42 +0000",
|
278
|
+
"source_url"=>"http://www.example.com/original_video.mp4",
|
279
|
+
"id"=>"12fce296-01e5-11df-ae37-12313902cc92",
|
280
|
+
"extname"=>".mp4",
|
281
|
+
"audio_codec"=>nil,
|
282
|
+
"height"=>nil,
|
283
|
+
"upload_redirect_url"=>nil,
|
284
|
+
"fps"=>nil,
|
285
|
+
"video_codec"=>nil,
|
286
|
+
"status"=>"processing",
|
287
|
+
"width"=>nil}
|
288
|
+
|
289
|
+
# Getting all videos
|
290
|
+
TelestreamCloud.get('/videos.json')
|
291
|
+
=> [{"duration"=>14010,
|
292
|
+
"created_at"=>"2010/01/13 16:45:29 +0000",
|
293
|
+
"original_filename"=>"panda.mp4",
|
294
|
+
"updated_at"=>"2010/01/13 16:45:35 +0000",
|
295
|
+
"source_url"=>"http://www.example.com/original_video.mp4",
|
296
|
+
"id"=>"0ee6b656-0063-11df-a433-1231390041c1",
|
297
|
+
"extname"=>".mp4",
|
298
|
+
"audio_codec"=>"aac",
|
299
|
+
"height"=>240,
|
300
|
+
"upload_redirect_url"=>nil,
|
301
|
+
"fps"=>29,
|
302
|
+
"video_codec"=>"h264",
|
303
|
+
"status"=>"success",
|
304
|
+
"width"=>300}]
|
305
|
+
|
306
|
+
# Getting video encodings
|
307
|
+
TelestreamCloud.get('/videos/0ee6b656-0063-11df-a433-1231390041c1/encodings.json')
|
308
|
+
=> [{"encoder_id"=>nil,
|
309
|
+
"created_at"=>"2010/01/13 16:45:30 +0000",
|
310
|
+
"video_id"=>"0ee6b656-0063-11df-a433-1231390041c1",
|
311
|
+
"video_url"=>
|
312
|
+
"http://s3.amazonaws.com/panda-videos/0f815986-0063-11df-a433-1231390041c1.flv",
|
313
|
+
"started_encoding_at"=>"2010/01/13 16:47:35 +0000",
|
314
|
+
"updated_at"=>"2010/01/13 16:47:40 +0000",
|
315
|
+
"extname"=>".flv",
|
316
|
+
"encoding_progress"=>87,
|
317
|
+
"encoding_time"=>3,
|
318
|
+
"id"=>"0f815986-0063-11df-a433-1231390041c1",
|
319
|
+
"height"=>240,
|
320
|
+
"status"=>"success",
|
321
|
+
"profile_id"=>"00182830-0063-11df-8c8a-1231390041c1",
|
322
|
+
"width"=>300}]
|
323
|
+
|
324
|
+
# Deleting an encoding
|
325
|
+
TelestreamCloud.delete('/encodings/0f815986-0063-11df-a433-1231390041c1.json')
|
326
|
+
|
327
|
+
# Deleting a video
|
328
|
+
TelestreamCloud.delete('/videos/0ee6b656-0063-11df-a433-1231390041c1.json')
|
329
|
+
```
|
330
|
+
## Use bundler to setup the test environment
|
331
|
+
```ruby
|
332
|
+
bundler install
|
333
|
+
rake spec
|
334
|
+
```
|
335
|
+
|
336
|
+
### Resumable upload
|
337
|
+
```ruby
|
338
|
+
us = TelestreamCloud::UploadSession.new("movie.mp4", profiles: "webm")
|
339
|
+
|
340
|
+
retry_count = 0
|
341
|
+
begin
|
342
|
+
us.start()
|
343
|
+
rescue Exception => e
|
344
|
+
while retru_count < 5 and us.status != "success"
|
345
|
+
begin
|
346
|
+
sleep(5)
|
347
|
+
us.resume()
|
348
|
+
rescue Exception => e
|
349
|
+
retry_count += 1
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|
353
|
+
```
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
Copyright (c) 2016 Telestream Cloud. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'telestream_cloud/version'
|
2
|
+
require 'telestream_cloud/api_authentication'
|
3
|
+
require 'telestream_cloud/connection'
|
4
|
+
require 'telestream_cloud/config'
|
5
|
+
require 'telestream_cloud/modules/router'
|
6
|
+
require 'telestream_cloud/modules/finders'
|
7
|
+
require 'telestream_cloud/modules/builders'
|
8
|
+
require 'telestream_cloud/modules/destroyers'
|
9
|
+
require 'telestream_cloud/modules/associations'
|
10
|
+
require 'telestream_cloud/modules/updatable'
|
11
|
+
require 'telestream_cloud/modules/video_state'
|
12
|
+
require 'telestream_cloud/modules/factory_connection'
|
13
|
+
require 'telestream_cloud/proxies/proxy'
|
14
|
+
require 'telestream_cloud/proxies/scope'
|
15
|
+
require 'telestream_cloud/proxies/encoding_scope'
|
16
|
+
require 'telestream_cloud/proxies/video_scope'
|
17
|
+
require 'telestream_cloud/proxies/profile_scope'
|
18
|
+
require 'telestream_cloud/errors'
|
19
|
+
require 'telestream_cloud/base'
|
20
|
+
require 'telestream_cloud/resources/resource'
|
21
|
+
require 'telestream_cloud/resources/factory'
|
22
|
+
require 'telestream_cloud/resources/encoding'
|
23
|
+
require 'telestream_cloud/resources/profile'
|
24
|
+
require 'telestream_cloud/resources/video'
|
25
|
+
|
26
|
+
require 'telestream_cloud/flip'
|
27
|
+
require 'telestream_cloud/telestream_cloud'
|
28
|
+
require 'telestream_cloud/faraday'
|
29
|
+
require 'telestream_cloud/upload_session'
|
30
|
+
|