everybit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in everybit.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2013- Everybit Media Services, Inc. (https://everybit.co)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,281 @@
1
+ ![Everybit Logo](http://dev.everybit.co/wp-content/themes/everybit/img/everybit-logo.png)
2
+
3
+ This gem encapsulates the functionality needed to access the [Everybit](http://dev.everybit.co) Streaming Media API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'everybit'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself with the usual gem install command:
16
+
17
+ $ gem install everybit
18
+
19
+ ## Requirements
20
+
21
+ * Ruby 1.9.3
22
+ * rest-client, multi_json
23
+
24
+ ## Usage
25
+
26
+ Detailed documentation for communicating with the Everybit Streaming Media API is available [here](http://docs.everybit.co). The information in this readme is only a brief introduction. If you have a specific problem with this gem you can [open an issue](https://github.com/everybit/everybit-ruby/issues) or, for more specific help with using the API in general, you can visit our dedicated [support site](https://everybit.zendesk.com/home).
27
+
28
+ ### Preparation
29
+
30
+ All communication with the Everybit Streaming Media API must be accompanied by your Everybit API key. This key is available in the My Account section of our Dashboard Media Management Portal and is randomly generated upon successful registration.
31
+
32
+ To setup the `everybit` gem with your API key, simply set it in the global `Everybit` object:
33
+
34
+ ```ruby
35
+ Everybit.api_key = '1a2b3c4d5e6f7g8h9i'
36
+ ```
37
+
38
+ You can also view and change the base URL to which the gem will submit your media's details:
39
+
40
+ ```ruby
41
+ Everybit.api_base
42
+ # => 'https://api.everybit.co'
43
+
44
+ Everybit.api_base = 'http://api.example.com'
45
+ # => 'https://api.example.com'
46
+ ```
47
+
48
+ ### Accounts
49
+
50
+ The library allows you to retrieve the details for the account attached to the API key provided:
51
+
52
+ ```ruby
53
+ Everybit.api_key = 'YOUR_API_KEY'
54
+ acct = Everybit::Account.retrieve
55
+
56
+ acct.code
57
+ # => 200
58
+
59
+ acct.status # this is the status of the request, not the account itself
60
+ # => true
61
+
62
+ acct[:uuid] # => '787c8956-1857-4771-9d4e-b99b4dedfeae'
63
+ acct[:email] # => 'jsmith@example.com'
64
+ acct[:username] # => 'jsmith'
65
+ acct[:first_name] # => 'John'
66
+ acct[:last_name] # => 'Smith'
67
+ ```
68
+
69
+ ### Videos
70
+
71
+ #### Status
72
+
73
+ To check the status of a video that's been uploaded for encoding and conversion:
74
+
75
+ ```ruby
76
+ Everybit.api_key = 'YOUR_API_KEY'
77
+ video = Everybit::Video.status('UUID_OF_VIDEO')
78
+
79
+ video.code
80
+ # => 200
81
+
82
+ video.status # this is the status of the request, not the video itself
83
+ # => true
84
+
85
+ video[:uuid] # => 'UUID_OF_VIDEO'
86
+ video[:processing] # => true
87
+ video[:progress] # => 50
88
+ video[:completed] # => false
89
+ video[:completed_date] # => ''
90
+ ```
91
+
92
+ #### Details
93
+
94
+ To request the details of a video that's completed encoding and conversion:
95
+
96
+ ```ruby
97
+ Everybit.api_key = 'YOUR_API_KEY'
98
+ video = Everybit::Video.details('UUID_OF_VIDEO')
99
+
100
+ video.code
101
+ # => 200
102
+
103
+ video.status # this is the status of the request, not the video itself
104
+ # => true
105
+
106
+ video[:created_date] # => 1362636380 (milliseconds since epoch)
107
+ video[:external_callback] # => the callback url provided during create request
108
+ video[:lat] # => 40.714353
109
+ video[:lon] # => -74.005973
110
+ video[:owner_uuid] # => uuid of the user that created the video
111
+ video[:source_url] # => the source url provided during create request
112
+ video[:summary] # => 'A short description about the video.'
113
+ video[:title] # => 'Video Title'
114
+ video[:play_count] # => number of times this video has been played
115
+ video[:data_consumed] # => amount of data streamed for this video
116
+ video[:tags] # => [array of tags]
117
+ video[:visibility] # => 'public|protected|private'
118
+ video[:last_updated] # => 1362636380 (milliseconds since epoch)
119
+ video[:uuid] # => UUID_OF_VIDEO
120
+ video[:thumbnail] # => path to a thumbnail of the video's full size hold frame image
121
+ video[:original_file] # => path to original file uploaded during create request
122
+ video[:player_url] # => url to the video's player
123
+ video[:media_info] # => {HASH OF DETAILED MEDIA INFO}
124
+ video[:player_attributes] # => {HASH OF CUSTOMIZABLE PLAYER ATTRIBUTES}
125
+ video[:versions] # => [ARRAY OF HASHES FOR EACH VERSION CREATED DURING ENCODING]
126
+ ```
127
+
128
+ #### Create
129
+
130
+ When you need to upload a new video for encoding and conversion, use the create method. Besides your api key, there are eight additional pieces of information that can be sent in a create request:
131
+
132
+ 1. title (required)
133
+ 2. summary
134
+ 3. tags
135
+ 4. lat
136
+ 5. lon
137
+ 6. visibility (required)
138
+ 7. source_file (required)
139
+ 8. callback_url (required)
140
+
141
+ ```ruby
142
+ Everybit.api_key = 'YOUR_API_KEY'
143
+
144
+ video_details = {
145
+ title: 'Dolphin Training',
146
+ summary: 'How to train your dolphin like a pro.',
147
+ tags: ['dolphin', 'training'],
148
+ lat: 40.714353,
149
+ lon: -74.005973,
150
+ visibility: 'public',
151
+ source_file: 'http://example.com/dolphin.mp4',
152
+ callback_url: 'http://example.com/everybit_callback'
153
+ }
154
+
155
+ video = Everybit::Video.create(video_details)
156
+ ```
157
+
158
+ The request will return one of two responses. A success response if the video has successfully started encoding and conversion, or an error response if something prevented the video from being created:
159
+
160
+ Success response:
161
+ {
162
+ "code": 200,
163
+ "status": true,
164
+ "data": {
165
+ "uuid": UUID
166
+ }
167
+ }
168
+
169
+ Error response:
170
+ {
171
+ "code": 400,
172
+ "status": false,
173
+ "data": {
174
+ "error" "specific error message here"
175
+ }
176
+ }
177
+
178
+ #### Update
179
+
180
+ When you need to change the attributes for a video that's completed encoding, use the update method.
181
+
182
+ ```ruby
183
+ Everybit.api_key = 'YOUR_API_KEY'
184
+
185
+ video_updates = {
186
+ lat: 39.737567,
187
+ lon: -104.984718,
188
+ summary: 'updated summary',
189
+ title: 'updated title',
190
+ tags: ['updated', 'tags'],
191
+ visibility: 'public|protected|private',
192
+ player_attributes: {
193
+ template_name: "default",
194
+ width: 640,
195
+ height: 360,
196
+ hold_frame: "http://example.com/custom_hold_frame",
197
+ show_hold_frame: true,
198
+ sharing_enabled: true,
199
+ show_email_share: true,
200
+ show_embed_share: true,
201
+ show_social_share: true,
202
+ auto_play: false,
203
+ scaling: "fit",
204
+ fade_in_speed: 0,
205
+ fade_out_speed: 0,
206
+ start_time: 0.000,
207
+ duration: 0.000,
208
+ show_controls: true,
209
+ auto_hide_controls: true,
210
+ auto_hide_controls_fullscreen_only: false,
211
+ auto_hide_controls_delay: 10000,
212
+ hardware_accelerated: false,
213
+ background_color: "#000000",
214
+ background_gradient: "low",
215
+ time_color: "#01DAFF",
216
+ duration_color: "#FFFFFF",
217
+ progress_color: "#015B7A",
218
+ progress_gradient: "medium",
219
+ buffer_color: "#6C9CBC",
220
+ buffer_gradient: "none",
221
+ slider_color: "#000000",
222
+ slider_gradient: "none",
223
+ button_color: "#889AA4",
224
+ button_over_color: "#92B2BD",
225
+ volume_slider_color: "#000000",
226
+ volume_color: "#000000",
227
+ volume_slider_gradient: "none",
228
+ time_background_color: "#555555",
229
+ time_border_color: "#FFFFFF"
230
+ }
231
+ }
232
+
233
+ video = Everybit::Video.update(video_updated)
234
+ ```
235
+
236
+ The response from an update request is the same as a details response, except it will contain your updated details.
237
+
238
+ #### Delete
239
+
240
+ To delete a video that's completed encoding and conversion:
241
+
242
+ ```ruby
243
+ Everybit.api_key = 'YOUR_API_KEY'
244
+ video = Everybit::Video.delete('UUID_OF_VIDEO')
245
+ ```
246
+
247
+ The request will return one of two responses. A success response if the video was successfully deleted, or an error response if something prevented the video from being deleted:
248
+
249
+ Success response:
250
+ {
251
+ "code": 200,
252
+ "status": true,
253
+ "data": {
254
+ "message": "your video was deleted successfully"
255
+ }
256
+ }
257
+
258
+ Error response:
259
+ {
260
+ "code": 400,
261
+ "status": false,
262
+ "data": {
263
+ "error": "specific error message here"
264
+ }
265
+ }
266
+
267
+ ## Tests
268
+
269
+ All tests are located in the `spec` directory and are written using [Minitest's](http://docs.seattlerb.org/minitest/) spec (expectation) syntax. They've been divided into test files according to the resource under test. So, for example, all the tests for the Account class can be found in `spec/account_spec.rb`. You can run all tests with the usual `rake` command with no arguments. If you'd like to run only one set of tests, you can specify them using the minitest namespace for that resource. e.g. `rake minitest:account`.
270
+
271
+ A list of available rake tasks can be output with the usual `rake -T` command.
272
+
273
+ ## Contributing
274
+
275
+ 1. Fork it
276
+ 2. Create your feature branch `git checkout -b my-new-feature`
277
+ 3. Commit your changes `git commit -am 'Add some feature'`
278
+ 4. Push to the branch `git push origin my-new-feature`
279
+ 5. Create new Pull Request
280
+
281
+ If you're developing locally, the gem's Rakefile includes Bundler's gem tasks. So calling `rake build` will build the gem and `rake install` will first build and then install the gem locally. A gem binary called `everybit-console` has been included to make local testing a little easier. It will launch an irb session with the `everybit` gem already required.
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ desc 'Generate gem documentation'
5
+ task :doc do
6
+ system 'rm -rf doc/'
7
+ system 'rdoc --exclude=/spec/'
8
+ end
9
+
10
+ namespace :minitest do
11
+ Rake::TestTask.new(:all) do |t|
12
+ t.libs << 'spec'
13
+ t.test_files = FileList['spec/*_spec.rb']
14
+ end
15
+
16
+ Rake::TestTask.new(:misc) do |t|
17
+ t.libs << 'spec'
18
+ t.test_files = ['spec/misc_spec.rb']
19
+ end
20
+
21
+ Rake::TestTask.new(:account) do |t|
22
+ t.libs << 'spec'
23
+ t.test_files = ['spec/account_spec.rb']
24
+ end
25
+
26
+ Rake::TestTask.new(:video) do |t|
27
+ t.libs << 'spec'
28
+ t.test_files = ['spec/video_spec.rb']
29
+ end
30
+ end
31
+
32
+ task :default => 'minitest:all'
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
3
+
4
+ libs = ' -r irb/completion'
5
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/everybit'}"
6
+ puts 'Loading everybit gem'
7
+ exec "#{irb} #{libs} --simple-prompt"
data/everybit.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'everybit/version'
6
+
7
+ Gem::Specification.new do |gem|
8
+
9
+ #-- author info
10
+ gem.authors = ['Dominic Giglio']
11
+ gem.email = ['humanshell@gmail.com']
12
+ gem.homepage = 'http://dev.everybit.co'
13
+
14
+ #-- gem info
15
+ gem.name = 'everybit'
16
+ gem.version = Everybit::VERSION
17
+ gem.summary = %q{Access Everybit API}
18
+ gem.description = %q{This gem defines methods for controlling your media through Everybit's API.}
19
+ gem.files = `git ls-files`.split($/)
20
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
+ gem.require_paths = ['lib']
23
+ gem.rubyforge_project = 'everybit'
24
+
25
+ #-- release dependencies
26
+ gem.add_dependency 'rest-client', '~> 1.6'
27
+ gem.add_dependency 'multi_json', '~> 1.5'
28
+
29
+ #-- development dependencies
30
+ gem.add_development_dependency('minitest')
31
+ gem.add_development_dependency('turn')
32
+
33
+ end
@@ -0,0 +1,8 @@
1
+ module Everybit
2
+ class Account < Resource
3
+ def self.retrieve(params={})
4
+ res = Everybit.request(:get, '/v1/account', params)
5
+ self.new(res[:code], res[:status], res[:data])
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ module Everybit
2
+ class Collection
3
+
4
+ attr_reader :code, :status, :data
5
+
6
+ def initialize(code, status, data)
7
+ @code = code
8
+ @status = status
9
+ @data = data
10
+ end
11
+
12
+ def inspect()
13
+ "#<#{self.class}> DATA: #{@data}"
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ module Everybit
2
+ class AuthenticationError < EverybitError
3
+ end
4
+ end
@@ -0,0 +1,20 @@
1
+ module Everybit
2
+ class EverybitError < StandardError
3
+ attr_reader :message
4
+ attr_reader :http_status
5
+ attr_reader :http_body
6
+ attr_reader :json_body
7
+
8
+ def initialize(message=nil, http_status=nil, http_body=nil, json_body=nil)
9
+ @message = message
10
+ @http_status = http_status
11
+ @http_body = http_body
12
+ @json_body = json_body
13
+ end
14
+
15
+ def to_s
16
+ status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
17
+ "#{status_string}#{@message}"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,32 @@
1
+ module Everybit
2
+ class EverybitObject
3
+
4
+ attr_reader :code, :status
5
+
6
+ def initialize(code, status, data)
7
+ @code = code
8
+ @status = status
9
+ @data = data
10
+ end
11
+
12
+ def [](k)
13
+ @data[k]
14
+ end
15
+
16
+ def []=(k, v)
17
+ @data[k] = v
18
+ end
19
+
20
+ def to_s
21
+ MultiJson.dump(@data)
22
+ end
23
+
24
+ def to_json(*a)
25
+ @data
26
+ end
27
+
28
+ def inspect()
29
+ "#<#{self.class}:#{@data[:uuid]}> JSON: #{@data}"
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,13 @@
1
+ module Everybit
2
+ module Createable
3
+ module ClassMethods
4
+ def create(params={})
5
+ retrieve(:post, url, params)
6
+ end
7
+ end
8
+
9
+ def self.included(base)
10
+ base.extend(ClassMethods)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module Everybit
2
+ module Deleteable
3
+ module ClassMethods
4
+ def delete(uuid, params={})
5
+ raise ArgumentError, 'A uuid was not provided.' unless uuid
6
+ retrieve(:delete, delete_url(uuid), params)
7
+ end
8
+ end
9
+
10
+ def self.included(base)
11
+ base.extend(ClassMethods)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module Everybit
2
+ module Listable
3
+ module ClassMethods
4
+ def all(params={})
5
+ res = Everybit.request(:get, url, params)
6
+ res[:data].map! { |elem| self.new(res[:code], res[:status], elem) }
7
+ Collection.new(res[:code], res[:status], res[:data])
8
+ end
9
+ end
10
+
11
+ def self.included(base)
12
+ base.extend(ClassMethods)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ module Everybit
2
+ module Updateable
3
+ module InstanceMethods
4
+ def save(params={})
5
+ @data.merge! params
6
+ res = Everybit.request(:put, update_url(@data[:uuid]), @data)
7
+ @code = res[:code]
8
+ @status = res[:status]
9
+
10
+ if res[:status]
11
+ @data[:message] = res[:data][:message]
12
+ else
13
+ @data[:error] = res[:data][:error]
14
+ end
15
+
16
+ self
17
+ end
18
+
19
+ def update_url(uuid)
20
+ "#{self.class.url}/#{uuid}"
21
+ end
22
+ end
23
+
24
+ def self.included(receiver)
25
+ receiver.send :include, InstanceMethods
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ module Everybit
2
+ class Resource < EverybitObject
3
+
4
+ def self.class_name
5
+ self.name.split('::')[-1]
6
+ end
7
+
8
+ def self.url()
9
+ if self == Resource
10
+ raise NotImplementedError.new('Resource is an abstract class. You should perform actions on its subclasses.')
11
+ end
12
+ "/v1/#{CGI.escape(class_name.downcase)}s"
13
+ end
14
+
15
+ def self.retrieve(method, url, params={}, headers={})
16
+ res = Everybit.request(method, url, params, headers)
17
+ self.new(res[:code], res[:status], res[:data])
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Everybit
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,33 @@
1
+ module Everybit
2
+ class Video < Resource
3
+ include Everybit::Listable
4
+ include Everybit::Deleteable
5
+ include Everybit::Createable
6
+ include Everybit::Updateable
7
+
8
+ def self.status(uuid, params={})
9
+ raise ArgumentError, 'A uuid was not provided.' unless uuid
10
+ retrieve(:get, status_url(uuid), params)
11
+ end
12
+
13
+ def self.details(uuid, params={})
14
+ raise ArgumentError, 'A uuid was not provided.' unless uuid
15
+ retrieve(:get, details_url(uuid), params)
16
+ end
17
+
18
+ private
19
+
20
+ def self.status_url(uuid)
21
+ url + "/#{uuid}/status"
22
+ end
23
+
24
+ def self.details_url(uuid)
25
+ url + "/#{uuid}"
26
+ end
27
+
28
+ def self.delete_url(uuid)
29
+ url + "/#{uuid}"
30
+ end
31
+
32
+ end
33
+ end