moovatom 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +342 -177
- data/Rakefile +9 -0
- data/lib/moovatom/version.rb +1 -1
- data/lib/moovatom.rb +198 -116
- data/moovatom.gemspec +2 -2
- data/spec/cancel_spec.rb +106 -0
- data/spec/details_spec.rb +103 -0
- data/spec/encode_spec.rb +103 -0
- data/spec/fixtures/cancel.json +4 -0
- data/spec/fixtures/cancel.xml +1 -1
- data/spec/fixtures/detail.json +69 -0
- data/spec/fixtures/detail.xml +1 -1
- data/spec/fixtures/encode.json +4 -0
- data/spec/fixtures/encode.xml +1 -1
- data/spec/fixtures/player_error.json +4 -0
- data/spec/fixtures/player_error.xml +5 -0
- data/spec/fixtures/player_success.json +5 -0
- data/spec/fixtures/player_success.xml +6 -0
- data/spec/fixtures/status_error.json +7 -0
- data/spec/fixtures/status_error.xml +1 -1
- data/spec/fixtures/status_success.json +7 -0
- data/spec/fixtures/status_success.xml +1 -1
- data/spec/init_spec.rb +79 -0
- data/spec/player_spec.rb +156 -0
- data/spec/status_spec.rb +107 -0
- metadata +41 -13
- data/spec/request_spec.rb +0 -73
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,235 +1,400 @@
|
|
1
|
-
|
2
|
-
============
|
1
|
+
![Moovatom Logo](http://www.moovatom.com/static/img/site_images/moovatom_logo.png)
|
3
2
|
|
4
|
-
|
3
|
+
*__NOTE:__ As of version 0.2.0 this gem no longer supports v1 of the Moovatom API. That version has been deprecated. It is highly recommended that you move to the new v2 API as soon as possible.*
|
4
|
+
|
5
|
+
# Overview
|
6
|
+
|
7
|
+
This gem provides access to the Moovatom online video processing and streaming service. It provides all the necessary attributes and methods for:
|
5
8
|
|
9
|
+
1. Starting a new video encoding process
|
10
|
+
2. Getting the status of a current encoding
|
11
|
+
3. Getting the details of a completed encoding
|
12
|
+
4. Canceling an encoding job
|
13
|
+
5. Editing the attributes of your video player
|
6
14
|
|
7
|
-
|
8
|
-
===
|
15
|
+
Installing the gem is done through the usual `gem install moovatom` command, or by adding the following line to your project's Gemfile:
|
9
16
|
|
10
|
-
|
17
|
+
```
|
18
|
+
gem "moovatom", "~> 0.2.0"
|
19
|
+
```
|
20
|
+
|
21
|
+
The entire library is wrapped in a module named MoovAtom. Inside that module is a single class named MoovEngine. This class defines one constant, 12 instance variables and five action methods that interact with Moovatom's RESTful API. The constant `API_URL` defines the URL to which the JSON or XML requests must be POST'd. The 12 instance variables are:
|
22
|
+
|
23
|
+
1. `@uuid`
|
24
|
+
2. `@username`
|
25
|
+
3. `@userkey`
|
26
|
+
4. `@content_type`
|
27
|
+
5. `@title`
|
28
|
+
6. `@blurb`
|
29
|
+
7. `@sourcefile`
|
30
|
+
8. `@callbackurl`
|
31
|
+
9. `@format`
|
32
|
+
10. `@player`
|
33
|
+
11. `@action`
|
34
|
+
12. `@response`
|
11
35
|
|
36
|
+
The last 2 are readable only. `@response` will always contain the last response received from the Moovatom servers and `@action` will be set by each of the action methods explained below. `@player` is a struct object (technically an OpenStruct) that provides access to the player attributes for your video. The remaining nine instance variables are writeable and correspond to the attributes of the video you want to control as well as your specific Moovatom account credentials. These attributes can be set in a number of ways depending upon the needs of your specific application.
|
12
37
|
|
13
|
-
|
14
|
-
========
|
15
|
-
This library is wrapped in a module named MoovAtom. Inside the module there is a single class named MoovEngine. So to instantiate a new object to communicate with the MoovAtom API you simply need to call:
|
38
|
+
Instantiating a new (empty) object to communicate with the MoovAtom API is as simple as:
|
16
39
|
|
40
|
+
```ruby
|
41
|
+
require 'moovatom'
|
42
|
+
me = MoovAtom::MoovEngine.new
|
17
43
|
```
|
18
|
-
|
19
|
-
|
44
|
+
|
45
|
+
Of course you could simplify the above code if you plan on creating a lot of MoovEngine objects by including the MoovAtom module first:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
require 'moovatom'
|
49
|
+
include MoovAtom
|
50
|
+
|
51
|
+
me1 = MoovEngine.new
|
52
|
+
|
53
|
+
...thousands of lines of code...
|
54
|
+
|
55
|
+
me2 = MoovEngine.new
|
56
|
+
|
57
|
+
...thousands of lines of code...
|
58
|
+
|
59
|
+
me3 = MoovEngine.new
|
60
|
+
|
61
|
+
etc...
|
20
62
|
```
|
21
63
|
|
22
|
-
|
64
|
+
The object created in the code above isn't very useful though. A MoovEngine object created without any arguments will, however, receive a few default values. `@content_type` will be initialized with a value of 'video', `@format` will be set to 'json' and `@player` will be initialized as an empty struct if no argument or block parameters are provided. The remaining nine instance variables need to be set with the credentials for your Moovatom account and the specifics about the video you wish to control. Aside from creating an empty object, as we did above, I've tried to include as much flexibility as I could when it comes to creating a new MoovEngine object. You can pass one or two hashes to the initialize method containing the values you wish to be set for either player or video attributes. The first hash will be used to setup video attributes and your Moovatom account credentials. The second hash is used to initialize an OpenStruct object of player attributes.
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
You can pass literal hashes:
|
68
|
+
me = MoovAtom::MoovEngine.new({uuid: 'j9i8h7g6f5e4d3c2b1a'}, {height: '480'})
|
23
69
|
|
70
|
+
But it may be more readable to create the hashes first and then pass them:
|
71
|
+
vattrs = {uuid: 'j9i8h7g6f5e4d3c2b1a', username: 'USERNAME', etc...}
|
72
|
+
pattrs = {width: "720", height: "480", etc...}
|
73
|
+
me = MoovAtom::MoovEngine.new(vattrs, pattrs)
|
24
74
|
```
|
25
|
-
|
26
|
-
|
27
|
-
|
75
|
+
|
76
|
+
The initialize method will first create an OpenStruct object using the values from the second hash if it was supplied and then iterate over the first hash and set each instance variable to the values provided. In addition to supplying a hash you can also pass a block:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
me = MoovAtom::MoovEngine.new do |me|
|
80
|
+
me.uuid = 'j9i8h7g6f5e4d3c2b1a'
|
81
|
+
me.username = 'USERNAME'
|
82
|
+
me.userkey = 'a1b2c3d4e5f6g7h8i9j'
|
83
|
+
me.player.height = "480"
|
84
|
+
me.player.width = "720"
|
85
|
+
etc...
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
The initialize method yields _self_ giving the block access to the internal state of your new MoovEngine object. Because the hash arguments are processed first you can also combine both techniques for maximum flexibility:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
me = MoovAtom::MoovEngine.new({uuid: 'j9i8h7g6f5e4d3c2b1a'}, {width: '720'}) do |me|
|
93
|
+
me.userkey = 'a1b2c3d4e5f6g7h8i9j'
|
94
|
+
me.title = 'Dolphin Training'
|
95
|
+
me.blurb = 'How to train your dolphin like a pro.'
|
96
|
+
me.sourcefile = 'http://example.com/dolphin.mp4'
|
97
|
+
me.callbackurl = 'http://example.com/moovatom_callback'
|
98
|
+
me.player.height = "480"
|
99
|
+
end
|
28
100
|
```
|
29
101
|
|
30
|
-
|
102
|
+
The gem has been designed to be highly customizable. You are free to create a single instance and reuse it throughout your code, changing the attributes each time you need to work with a different video, or multiple instances representing individual videos if that's what your application requires, it's completely up to you.
|
103
|
+
|
104
|
+
# Action Methods
|
105
|
+
|
106
|
+
The MoovEngine class has five methods that have been designed to interact directly with the RESTful API implemented by Moovatom's servers:
|
107
|
+
|
108
|
+
1. `get_details()` will return details about an encoded video
|
109
|
+
2. `get_status()` will return the status of a video (e.g. - whether or not encoding has completed)
|
110
|
+
3. `encode()` will start a new encoding job
|
111
|
+
4. `cancel()` will cancel an __unfinished__ encoding job
|
112
|
+
5. `edit_player()` changes the attributes of your video's online player
|
113
|
+
|
114
|
+
Each of these methods are almost identical. They all accept a hash/block argument syntax similar to the initialize method. The main difference is that the action methods will accept only one hash and a block. This allows you to easily reuse a MoovEngine object to request information about different videos. The five action methods are able to be used and reused because they share a method that handles the heavy lifting when building and sending the request to Moovatom: `send_request()`. The `send_request()` method takes every instance variable (including player attributes) and creates a hash of the key/value attributes for your video. It then uses the `@format` and `@action` instance variables to build and POST the appropriate request to the Moovatom servers. If the response is successful it will parse it into either JSON or XML and store it in the `@response` instance variable. If the response is anything other than "200 OK" the raw Net::HTTPResponse object will be passed through and stored in `@response`. This allows you and your app to determine how best to handle the specific error response.
|
115
|
+
|
116
|
+
For more specific information about the Moovatom API please see the [documentation](http://moovatom.com/support/v2/api.html).
|
117
|
+
|
118
|
+
## Details
|
119
|
+
|
120
|
+
Getting the details of a video you've uploaded to your Moovatom account is as simple as creating a MoovEngine object and populating it with your credentials and the specifics of the video you'd like to access:
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
me = MoovAtom::MoovEngine.new(uuid: 'j9i8h7g6f5e4d3c2b1a') do |me|
|
124
|
+
me.username = 'USERNAME'
|
125
|
+
me.userkey = 'a1b2c3d4e5f6g7h8i9j'
|
126
|
+
end
|
127
|
+
|
128
|
+
me.get_details
|
129
|
+
|
130
|
+
if me.response["uuid"] == 'j9i8h7g6f5e4d3c2b1a'
|
131
|
+
video = Video.find(params[:id])
|
132
|
+
video.update_attributes(me.response)
|
133
|
+
else
|
134
|
+
"...gracefully fail or raise an exception here..."
|
135
|
+
end
|
136
|
+
```
|
31
137
|
|
32
|
-
|
138
|
+
A details request will POST the __uuid__, __username__ and __userkey__ instance variables from your MoovEngine object using the `send_request()` method. If successful `@response` will contain either a JSON or XML formatted object (depending on the value of `@format`) ready to be queried and used. The example above shows how you can pass a hash, a block or both to the method. The remaining four action methods all accept the same style of argument passing.
|
33
139
|
|
34
|
-
|
140
|
+
*Successful get_details() JSON Response:*
|
35
141
|
|
36
142
|
```
|
37
|
-
|
143
|
+
{
|
144
|
+
"uuid": "UUID",
|
145
|
+
"media_type": "video",
|
146
|
+
"embed_code": "EMBED CODE SMART SWITCHING FOR AUTOMATIC MOBILE AND WEB SUPPORT.",
|
147
|
+
"iframe_target": "http://www.moovatom.com/media/embed/ID",
|
148
|
+
"original_download": "http://www.moovatom.com/media/download/orig/UUID",
|
149
|
+
"versions": [
|
150
|
+
{
|
151
|
+
"name": "mobile",
|
152
|
+
"type": "video/mp4",
|
153
|
+
"holdframe_download": "http://www.moovatom.com/PATH_TO_FILE",
|
154
|
+
"thumbnail_download": "http://www.moovatom.com/PATH_TO_FILE",
|
155
|
+
"holdframe_serve": "http://static.moovatom.com/PATH_TO_FILE",
|
156
|
+
"thumbnail_serve": "http://static.moovatom.com/PATH_TO_FILE",
|
157
|
+
"rtmp_stream": "rtmp://media.moovatom.com/PATH_TO_FILE",
|
158
|
+
"http_stream": "http://media.moovatom.com:1935/PATH_TO_FILE",
|
159
|
+
"rtsp_stream": "rtsp://media.moovatom.com:1935/PATH_TO_FILE",
|
160
|
+
"download": "http://www.moovatom.com/PATH_TO_FILE"
|
161
|
+
},
|
162
|
+
{
|
163
|
+
"name": "mobile_large",
|
164
|
+
"type": "video/mp4",
|
165
|
+
"holdframe_download": "http://www.moovatom.com/PATH_TO_FILE",
|
166
|
+
"thumbnail_download": "http://www.moovatom.com/PATH_TO_FILE",
|
167
|
+
"holdframe_serve": "http://static.moovatom.com/PATH_TO_FILE",
|
168
|
+
"thumbnail_serve": "http://static.moovatom.com/PATH_TO_FILE",
|
169
|
+
"rtmp_stream": "rtmp://media.moovatom.com/PATH_TO_FILE",
|
170
|
+
"http_stream": "http://media.moovatom.com:1935/PATH_TO_FILE",
|
171
|
+
"rtsp_stream": "rtsp://media.moovatom.com:1935/PATH_TO_FILE",
|
172
|
+
"download": "http://www.moovatom.com/PATH_TO_FILE"
|
173
|
+
},
|
174
|
+
{
|
175
|
+
"name": "small",
|
176
|
+
"type": "video/mp4",
|
177
|
+
"holdframe_download": "http://www.moovatom.com/PATH_TO_FILE",
|
178
|
+
"thumbnail_download": "http://www.moovatom.com/PATH_TO_FILE",
|
179
|
+
"holdframe_serve": "http://static.moovatom.com/PATH_TO_FILE",
|
180
|
+
"thumbnail_serve": "http://static.moovatom.com/PATH_TO_FILE",
|
181
|
+
"rtmp_stream": "rtmp://media.moovatom.com/PATH_TO_FILE",
|
182
|
+
"http_stream": "http://media.moovatom.com:1935/PATH_TO_FILE",
|
183
|
+
"rtsp_stream": "rtsp://media.moovatom.com:1935/PATH_TO_FILE",
|
184
|
+
"download": "http://www.moovatom.com/PATH_TO_FILE"
|
185
|
+
},
|
186
|
+
{
|
187
|
+
"name": "medium",
|
188
|
+
"type": "video/mp4",
|
189
|
+
"holdframe_download": "http://www.moovatom.com/PATH_TO_FILE",
|
190
|
+
"thumbnail_download": "http://www.moovatom.com/PATH_TO_FILE",
|
191
|
+
"holdframe_serve": "http://static.moovatom.com/PATH_TO_FILE",
|
192
|
+
"thumbnail_serve": "http://static.moovatom.com/PATH_TO_FILE",
|
193
|
+
"rtmp_stream": "rtmp://media.moovatom.com/PATH_TO_FILE",
|
194
|
+
"http_stream": "http://media.moovatom.com:1935/PATH_TO_FILE",
|
195
|
+
"rtsp_stream": "rtsp://media.moovatom.com:1935/PATH_TO_FILE",
|
196
|
+
"download": "http://www.moovatom.com/PATH_TO_FILE"
|
197
|
+
},
|
198
|
+
{
|
199
|
+
"name": "large",
|
200
|
+
"type": "video/mp4",
|
201
|
+
"holdframe_download": "http://www.moovatom.com/PATH_TO_FILE",
|
202
|
+
"thumbnail_download": "http://www.moovatom.com/PATH_TO_FILE",
|
203
|
+
"holdframe_serve": "http://static.moovatom.com/PATH_TO_FILE",
|
204
|
+
"thumbnail_serve": "http://static.moovatom.com/PATH_TO_FILE",
|
205
|
+
"rtmp_stream": "rtmp://media.moovatom.com/PATH_TO_FILE",
|
206
|
+
"http_stream": "http://media.moovatom.com:1935/PATH_TO_FILE",
|
207
|
+
"rtsp_stream": "rtsp://media.moovatom.com:1935/PATH_TO_FILE",
|
208
|
+
"download": "http://www.moovatom.com/PATH_TO_FILE"
|
209
|
+
}
|
210
|
+
]
|
211
|
+
}
|
38
212
|
```
|
39
213
|
|
40
|
-
There is a single module constant named `API_URL` that defines the URL to which the XML requests must be POST'd. There are eight writable instance variables and one readable variable. The single readable variable is `@xml_response`. It's responsible for holding the last response received from MoovAtom's servers. The other variables are as follows:
|
41
214
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
4. `@content_type`
|
46
|
-
5. `@title`
|
47
|
-
6. `@blurb`
|
48
|
-
7. `@sourcefile`
|
49
|
-
8. `@callbackurl`
|
215
|
+
## Status
|
216
|
+
|
217
|
+
The `get_status()` method allows you to query a video that has begun encoding to check its progress.
|
50
218
|
|
51
|
-
|
219
|
+
```ruby
|
220
|
+
me = MoovAtom::MoovEngine.new(uuid: 'j9i8h7g6f5e4d3c2b1a') do |me|
|
221
|
+
me.username = 'USERNAME'
|
222
|
+
me.userkey = 'a1b2c3d4e5f6g7h8i9j'
|
223
|
+
end
|
224
|
+
|
225
|
+
me.get_status
|
226
|
+
|
227
|
+
unless me.response["processing"]
|
228
|
+
me.get_details
|
229
|
+
|
230
|
+
if me.response["uuid"] == 'j9i8h7g6f5e4d3c2b1a'
|
231
|
+
video = Video.find(params[:id])
|
232
|
+
video.update_attributes(me.response)
|
233
|
+
else
|
234
|
+
"...gracefully fail or raise an exception here..."
|
235
|
+
end
|
236
|
+
end
|
237
|
+
```
|
238
|
+
|
239
|
+
A status request will POST the __uuid__, __username__ and __userkey__ instance variables from your MoovEngine object using the `send_request()` method. The `@response` variable will contain either a success or error response:
|
240
|
+
|
241
|
+
*Status Success Response:*
|
52
242
|
|
53
243
|
```
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
244
|
+
{
|
245
|
+
"uuid": "UUID",
|
246
|
+
"processing": true,
|
247
|
+
"percent_complete": 75,
|
248
|
+
"error":
|
249
|
+
}
|
58
250
|
```
|
59
251
|
|
60
|
-
|
252
|
+
*Status Error Response:*
|
61
253
|
|
62
254
|
```
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
255
|
+
{
|
256
|
+
"uuid": "UUID",
|
257
|
+
"processing": false,
|
258
|
+
"percent_complete": 100,
|
259
|
+
"error": "This was not a recognized format."
|
260
|
+
}
|
68
261
|
```
|
69
262
|
|
70
|
-
|
71
|
-
========
|
72
|
-
To start a new encoding on Moovatom's servers you need to create a `MoovAtom::MoovEngine` object populated with the following information:
|
263
|
+
## Encode
|
73
264
|
|
265
|
+
You can start a new encoding on the Moovatom servers through the `encode()` method.
|
266
|
+
|
267
|
+
```ruby
|
268
|
+
me = MoovAtom::MoovEngine.new(userkey: 'a1b2c3d4e5f6g7h8i9j') do |me|
|
269
|
+
me.username = 'USERNAME'
|
270
|
+
me.title = 'Dolphin Training'
|
271
|
+
me.blurb = 'How to train your dolphin like a pro.'
|
272
|
+
me.sourcefile = 'http://example.com/dolphin.mp4'
|
273
|
+
me.callbackurl = 'http://example.com/moovatom_callback'
|
274
|
+
end
|
275
|
+
|
276
|
+
me.encode
|
74
277
|
```
|
75
|
-
new_conn = MoovAtom::MoovEngine.new
|
76
278
|
|
77
|
-
|
78
|
-
new_conn.userkey = "MOOVATOM_USERKEY"
|
79
|
-
new_conn.title = "The Greatest Movie Ever"
|
80
|
-
new_conn.blurb = "The gratest movie ever made!"
|
81
|
-
new_conn.sourcefile = "http://example.com/greatest_movie_ever.mp4"
|
82
|
-
new_conn.callbackurl = "/moovatom_callback"
|
279
|
+
An encode request will POST the __username__, __userkey__, __content type__, __title__, __blurb__, __sourcefile__ and __callbackurl__ instance variables from your MoovEngine object using the `send_request()` method. The body of the Moovatom response will contain the uuid assigned by Moovatom's servers to this new video as well as a message stating whether or not your job was started successfully:
|
83
280
|
|
84
|
-
|
281
|
+
*Encode Started Response:*
|
282
|
+
|
283
|
+
```
|
284
|
+
{
|
285
|
+
"uuid": "UUID",
|
286
|
+
"message": "Your job was started successfully."
|
287
|
+
}
|
85
288
|
```
|
86
289
|
|
87
|
-
|
290
|
+
After a successful response the `@uuid` variable of your MoovEngine object will be set to the uuid assigned by Moovatom. The encode action implemented on Moovatom's servers differs slightly from the other four actions. Once the encoding is complete Moovatom's servers will send a response to the call back URL you set in the `@callbackurl` instance variable. Your app should define a controller (or url handler if it's a [Sinatra](http://www.sinatrarb.com/) app) that will process these callbacks to save/update the video's details in your database. The body of the callback sent by Moovatom looks exactly like the response from a `get_details()` request.
|
88
291
|
|
89
|
-
|
90
|
-
======
|
91
|
-
To retrieve the status of an existing encoding on Moovatom's servers you need a `MoovAtom::MoovEngine` object populated with the following information:
|
292
|
+
Additionally, the video you are uploading to Moovatom must be in a __publicly accessibly location__. Moovatom will attempt to transfer that video from the url you define in the `@sourcefile` instance variable. The ability to upload a video directly is planned for a future version of the API and this gem.
|
92
293
|
|
294
|
+
For more specific information about the Moovatom API please see the [documentation](http://moovatom.com/support/v2/api.html).
|
295
|
+
|
296
|
+
## Cancel
|
297
|
+
|
298
|
+
If you decide, for whatever reason, that you no longer need or want a specific video on Moovatom you can cancel its encoding anytime __before it finishes__ using the `cancel()` method. A cancel request will POST the __uuid__, __username__ and __userkey__ instance variables from your MoovEngine object using the `send_request()` method. The body of the Moovatom response will contain a message telling you whether or not you successfully cancelled your video:
|
299
|
+
|
300
|
+
```ruby
|
301
|
+
me = MoovAtom::MoovEngine.new(uuid: 'j9i8h7g6f5e4d3c2b1a') do |me|
|
302
|
+
me.username = 'USERNAME'
|
303
|
+
me.userkey = 'a1b2c3d4e5f6g7h8i9j'
|
304
|
+
end
|
305
|
+
|
306
|
+
me.get_status
|
307
|
+
|
308
|
+
if me.response['processing']
|
309
|
+
me.cancel
|
310
|
+
else
|
311
|
+
"...gracefully fail or raise an exception here..."
|
312
|
+
end
|
93
313
|
```
|
94
|
-
new_conn = MoovAtom::MoovEngine.new
|
95
314
|
|
96
|
-
|
97
|
-
new_conn.userkey = "MOOVATOM_USERKEY"
|
98
|
-
new_conn.uuid = "UUID_OF_VIDEO"
|
315
|
+
*Example cancel request response:*
|
99
316
|
|
100
|
-
response = new_conn.status
|
101
317
|
```
|
318
|
+
{
|
319
|
+
"uuid": "UUID",
|
320
|
+
"message": "This job was successfully cancelled."
|
321
|
+
}
|
322
|
+
```
|
323
|
+
|
324
|
+
*__NOTE:__ There is currently no way to delete a video from your Moovatom account that has completed encoding without manually logging in and deleting it yourself. The ability to delete through the API will be available in the future.*
|
102
325
|
|
103
|
-
|
326
|
+
## Edit Player
|
104
327
|
|
105
|
-
|
328
|
+
The true power of Moovatom's streaming service becomes apparent only after you've placed a video on your site through their iframe code. But sometimes you need a little more control over how your video plays and what it looks like. This is where the `edit_player()` action method comes in. There are 17 attributes you can control through the API (shown here with their default values):
|
106
329
|
|
107
330
|
```
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
331
|
+
height: 480
|
332
|
+
width: 720
|
333
|
+
auto_play: False
|
334
|
+
sharing_enabled: True
|
335
|
+
show_hold_image: True
|
336
|
+
watermark: http://www.example.com/path/to/watermark.png
|
337
|
+
watermark_url: http://www.example.com
|
338
|
+
show_watermark: True
|
339
|
+
watermark_opacity: 0.8
|
340
|
+
background_color: #000000
|
341
|
+
duration_color: #FFFFFF
|
342
|
+
buffer_color: #6C9CBC
|
343
|
+
volume_color: #000000
|
344
|
+
volume_slider_color: #000000
|
345
|
+
button_color: #889AA4
|
346
|
+
button_over_color: #92B2BD
|
347
|
+
time_color: #01DAFF
|
115
348
|
```
|
116
349
|
|
117
|
-
|
350
|
+
The `edit_player()` method accepts the same hash/block argument syntax as the first four action methods, however, it takes the hash you pass and merges those attributes into any previous ones supplied in the second hash passed to the initialize method. Since the `@player` instance variable is just an OpenStruct object you can set any of the attributes above manually or through a block as well.
|
351
|
+
|
352
|
+
```ruby
|
353
|
+
Variables can be set manually, with a hash or a block or both:
|
354
|
+
|
355
|
+
me.player.watermark = "http://www.example.com/path/to/watermark.png"
|
356
|
+
me.player.watermark_url = "http://www.example.com"
|
357
|
+
me.player.show_watermark = true
|
118
358
|
|
359
|
+
me.edit_player(width: "800", height: "500") do |me|
|
360
|
+
me.player.time_color = "#12EBGG"
|
361
|
+
end
|
119
362
|
```
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
363
|
+
|
364
|
+
You can always add an attribute to your player struct by calling into it through the player instance variable:
|
365
|
+
|
366
|
+
```ruby
|
367
|
+
me = MoovAtom::MoovEngine.new
|
368
|
+
me.player.height = "480"
|
369
|
+
me.player.width = "720"
|
370
|
+
me.player.auto_play = false
|
371
|
+
me.player.sharing_enabled = true
|
372
|
+
me.player.watermark_opacity = "0.8"
|
373
|
+
me.player.background_color = "#000000"
|
374
|
+
me.player.duration_color = "#FFFFFF"
|
375
|
+
me.player.volume_color = "#000000"
|
376
|
+
me.player.button_color = "#889AA4"
|
377
|
+
me.player.time_color = "#01DAFF"
|
127
378
|
```
|
128
379
|
|
129
|
-
|
130
|
-
=======
|
131
|
-
When you need to get the details about an encoding that has finished on Moovatom's server you need a `MoovAtom::MoovEngine` object populated with the following information:
|
380
|
+
Since `@player` is implemented an an OpenStruct object it will create the attributes dynamically as you need them. This way only the attributes you wish to alter will be sent in your requests.
|
132
381
|
|
133
|
-
|
134
|
-
new_conn = MoovAtom::MoovEngine.new
|
382
|
+
For more specific information about the Moovatom API please see the [documentation](http://moovatom.com/support/v2/api.html).
|
135
383
|
|
136
|
-
|
137
|
-
new_conn.userkey = "MOOVATOM_USERKEY"
|
138
|
-
new_conn.uuid = "UUID_OF_VIDEO"
|
384
|
+
# Testing
|
139
385
|
|
140
|
-
|
141
|
-
```
|
386
|
+
Development of this gem was done on Ruby 1.9.2-p290. There should be no problems on 1.9.3. I haven't tried it on Ruby 1.8.7, but you shouldn't be using 1.8.7 anyways. :-)
|
142
387
|
|
143
|
-
|
388
|
+
This gem uses [Minitest](https://github.com/seattlerb/minitest), [Turn](https://github.com/TwP/turn) and [Fakeweb](https://github.com/chrisk/fakeweb) to implement specs for each of the above request methods, pretty colorized output and for mocking up a connection to the API.
|
144
389
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
<version>
|
155
|
-
<name>mobile</name>
|
156
|
-
<type>video/mp4</type>
|
157
|
-
<holdframe_download>http://www.moovatom.com/PATH_TO_FILE</holdframe_download>
|
158
|
-
<thumbnail_download>http://www.moovatom.com/PATH_TO_FILE</thumbnail_download>
|
159
|
-
<holdframe_serve>http://static.moovatom.com/PATH_TO_FILE</holdframe_serve>
|
160
|
-
<thumbnail_serve>http://static.moovatom.com/PATH_TO_FILE</thumbnail_serve>
|
161
|
-
<rtmp_stream>rtmp://media.moovatom.com/PATH_TO_FILE</rtmp_stream>
|
162
|
-
<http_stream>http://media.moovatom.com:1935/PATH_TO_FILE</http_stream>
|
163
|
-
<rtsp_stream>rtsp://media.moovatom.com:1935/PATH_TO_FILE</rtsp_stream>
|
164
|
-
<download>http://www.moovatom.com/PATH_TO_FILE</download>
|
165
|
-
</version>
|
166
|
-
<version>
|
167
|
-
<name>small</name>
|
168
|
-
<type>video/mp4</type>
|
169
|
-
<holdframe_download>http://www.moovatom.com/PATH_TO_FILE</holdframe_download>
|
170
|
-
<thumbnail_download>http://www.moovatom.com/PATH_TO_FILE</thumbnail_download>
|
171
|
-
<holdframe_serve>http://static.moovatom.com/PATH_TO_FILE</holdframe_serve>
|
172
|
-
<thumbnail_serve>http://static.moovatom.com/PATH_TO_FILE</thumbnail_serve>
|
173
|
-
<rtmp_stream>rtmp://media.moovatom.com/PATH_TO_FILE</rtmp_stream>
|
174
|
-
<http_stream>http://media.moovatom.com:1935/PATH_TO_FILE</http_stream>
|
175
|
-
<rtsp_stream>rtsp://media.moovatom.com:1935/PATH_TO_FILE</rtsp_stream>
|
176
|
-
<download>http://www.moovatom.com/PATH_TO_FILE</download>
|
177
|
-
</version>
|
178
|
-
<version>
|
179
|
-
<name>medium</name>
|
180
|
-
<type>video/mp4</type>
|
181
|
-
<holdframe_download>http://www.moovatom.com/PATH_TO_FILE</holdframe_download>
|
182
|
-
<thumbnail_download>http://www.moovatom.com/PATH_TO_FILE</thumbnail_download>
|
183
|
-
<holdframe_serve>http://static.moovatom.com/PATH_TO_FILE</holdframe_serve>
|
184
|
-
<thumbnail_serve>http://static.moovatom.com/PATH_TO_FILE</thumbnail_serve>
|
185
|
-
<rtmp_stream>rtmp://media.moovatom.com/PATH_TO_FILE</rtmp_stream>
|
186
|
-
<http_stream>http://media.moovatom.com:1935/PATH_TO_FILE</http_stream>
|
187
|
-
<rtsp_stream>rtsp://media.moovatom.com:1935/PATH_TO_FILE</rtsp_stream>
|
188
|
-
<download>http://www.moovatom.com/PATH_TO_FILE</download>
|
189
|
-
</version>
|
190
|
-
<version>
|
191
|
-
<name>large</name>
|
192
|
-
<type>video/mp4</type>
|
193
|
-
<holdframe_download>http://www.moovatom.com/PATH_TO_FILE</holdframe_download>
|
194
|
-
<thumbnail_download>http://www.moovatom.com/PATH_TO_FILE</thumbnail_download>
|
195
|
-
<holdframe_serve>http://static.moovatom.com/PATH_TO_FILE</holdframe_serve>
|
196
|
-
<thumbnail_serve>http://static.moovatom.com/PATH_TO_FILE</thumbnail_serve>
|
197
|
-
<rtmp_stream>rtmp://media.moovatom.com/PATH_TO_FILE</rtmp_stream>
|
198
|
-
<http_stream>http://media.moovatom.com:1935/PATH_TO_FILE</http_stream>
|
199
|
-
<rtsp_stream>rtsp://media.moovatom.com:1935/PATH_TO_FILE</rtsp_stream>
|
200
|
-
<download>http://www.moovatom.com/PATH_TO_FILE</download>
|
201
|
-
</version>
|
202
|
-
</versions>
|
203
|
-
</response>
|
204
|
-
```
|
205
|
-
|
206
|
-
Cancel
|
207
|
-
======
|
208
|
-
To cancel an unfinished encoding on Moovatom's servers you need a `MoovAtom::MoovEngine` object populated with the following information:
|
209
|
-
|
210
|
-
```
|
211
|
-
new_conn = MoovAtom::MoovEngine.new
|
212
|
-
|
213
|
-
new_conn.username = "MOOVATOM_USERNAME"
|
214
|
-
new_conn.userkey = "MOOVATOM_USERKEY"
|
215
|
-
new_conn.uuid = "UUID_OF_VIDEO"
|
216
|
-
|
217
|
-
response = new_conn.cancel
|
218
|
-
```
|
219
|
-
|
220
|
-
A successful cancellation results in the following response:
|
221
|
-
|
222
|
-
```
|
223
|
-
<?xml version="1.0"?>
|
224
|
-
<response>
|
225
|
-
<uuid>UUID</uuid>
|
226
|
-
<message>This job was successfully cancelled.</message>
|
227
|
-
</response>
|
228
|
-
```
|
229
|
-
|
230
|
-
For more specific instructions on using the Moovatom API please check the [documentation](http://www.moovatom.com/support/requests.html)
|
231
|
-
|
232
|
-
Testing
|
233
|
-
=======
|
234
|
-
This gem uses [Minitest](https://github.com/seattlerb/minitest), [Turn](https://github.com/TwP/turn) and [Fakeweb](https://github.com/chrisk/fakeweb) to implement specs for each of the above four request methods.
|
390
|
+
The entire test suite is under the spec directory. The `spec_helper.rb` file contains the common testing code and gets required by each `*_spec.rb` file. There is one spec file (`init_spec.rb`) that tests the expected functionality related to initializing a new MoovEngine object. Each of the five action methods also has a single spec file dedicated to testing its expected functionality. All API requests are mocked through [Fakeweb](https://github.com/chrisk/fakeweb) and the responses come from the files in the fixtures directory.
|
391
|
+
|
392
|
+
The Rakefile's default task is 'minitest', which will load and execute all the `*_spec.rb` files in the spec directory. So a simple call to `rake` on the command line from the project's root directory will run the entire test suite.
|
393
|
+
|
394
|
+
This is the first Ruby project in which I started from a TDD/BDD design perspective. If anyone has a problem with the tests or sees areas where I can improve please [open an issue](https://github.com/humanshell/moovatom/issues) here so it can be discussed and everyone can learn a little. I really enjoyed creating tests that helped drive the design of the code. I'm sure there are *PLENTY* of areas in which I can improve.
|
395
|
+
|
396
|
+
# Moovatom
|
397
|
+
|
398
|
+
[MoovAtom](http://moovatom.com/) is an online video conversion and streaming service. The service insulates your videos from competitor's ads or links to inappropriate content. It offers customizable players that support hot linkable watermarks in addition to stream paths to your own player so you can control your videos, and your brand, on your own terms. Streaming is supported to all Apple mobile devices as well as most Android and Blackberry platforms. A unique QR Code is generated for each video for use in advertisements, allowing your viewers to simply "scan and play" your content. Advanced analytics and metrics provide valuable incite into how your viewers are watching your videos. The MoovAtom servers support both FTP access and direct uploads so huge file sizes are easy to handle. MoovAtom makes it easy to protect your copyrights, the streaming servers provide unparalleled protection over other services using progressive downloads to a user's browser cache.
|
235
399
|
|
400
|
+
For more specific information about the Moovatom service please see their [home page](http://moovatom.com/).
|
data/Rakefile
CHANGED
@@ -2,17 +2,26 @@ require 'bundler/gem_tasks'
|
|
2
2
|
require "bundler/version"
|
3
3
|
require 'rake/testtask'
|
4
4
|
|
5
|
+
desc "Run specs"
|
5
6
|
task :default => :minitest
|
6
7
|
|
7
8
|
Rake::TestTask.new(:minitest) do |t|
|
8
9
|
t.libs << 'spec'
|
9
10
|
t.test_files = FileList['spec/*_spec.rb']
|
10
11
|
end
|
12
|
+
|
13
|
+
desc "Generate Documentation"
|
14
|
+
task :doc do
|
15
|
+
system "rm -rf doc/"
|
16
|
+
system "rdoc"
|
17
|
+
end
|
11
18
|
|
19
|
+
desc "Build gem"
|
12
20
|
task :build do
|
13
21
|
system "gem build moovatom.gemspec"
|
14
22
|
end
|
15
23
|
|
24
|
+
desc "Release gem"
|
16
25
|
task :release => :build do
|
17
26
|
system "gem push pkg/moovatom-#{MoovAtom::VERSION}.gem"
|
18
27
|
end
|
data/lib/moovatom/version.rb
CHANGED