limelight_video 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+ gem "rake"
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ limelight (0.0.1)
5
+ faraday (~> 0.8.0)
6
+ mime-types (~> 1.18)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ fakeweb (1.3.0)
12
+ faraday (0.8.0)
13
+ multipart-post (~> 1.1)
14
+ mime-types (1.18)
15
+ minitest (3.0.0)
16
+ multipart-post (1.1.5)
17
+ rake (0.9.2.2)
18
+ vcr (2.1.1)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ fakeweb (~> 1.3.0)
25
+ limelight!
26
+ minitest (~> 3.0.0)
27
+ rake
28
+ vcr (~> 2.1.0)
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # Limelight Video
2
+
3
+ API interaction with the Limelight CDN
4
+
5
+ ```ruby
6
+ require 'limelight_video'
7
+
8
+ limelight = Limelight.new(
9
+ organization: 'your organization key',
10
+ access_key: 'your access key',
11
+ secret: 'your secret key',
12
+ )
13
+
14
+ limelight.upload('my cool file', '~/Downloads/sample.mp4')
15
+ ```
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'rake/testtask'
2
+
3
+ namespace :test do
4
+ Rake::TestTask.new :unit do |t|
5
+ t.pattern = "test/unit/**/*_test.rb"
6
+ t.libs = ["lib", "test"]
7
+ end
8
+
9
+ Rake::TestTask.new :integration do |t|
10
+ t.pattern = "test/integration/**/*_test.rb"
11
+ t.libs = ["lib", "test"]
12
+ end
13
+ end
14
+
15
+ task :test => ["test:unit", "test:integration"]
16
+ task default: :test
@@ -0,0 +1,57 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require 'base64'
4
+ require 'openssl'
5
+ require 'mime/types'
6
+
7
+ class Limelight
8
+ def initialize(options = {})
9
+ @organization = options.fetch(:organization, ENV['LIMELIGHT_ORGANIZATION'])
10
+ raise KeyError.new("organization") if !@organization
11
+
12
+ @access_key = options.fetch(:access_key, ENV['LIMELIGHT_ACCESS_KEY'])
13
+ @secret = options.fetch(:secret, ENV['LIMELIGHT_SECRET'])
14
+
15
+ @host = 'http://api.videoplatform.limelight.com'
16
+ @base_url = "/rest/organizations/#{@organization}/media"
17
+ @client = Faraday.new(@host) do |builder|
18
+ builder.request :multipart
19
+ builder.adapter :net_http
20
+ end
21
+ end
22
+
23
+ def upload(title, filename)
24
+ raise Errno::ENOENT if !File.exists?(filename)
25
+
26
+ url = generate_signature('post', @base_url)
27
+ mime = MIME::Types.type_for(filename)
28
+ file = Faraday::UploadIO.new(filename, mime)
29
+ response = @client.post(url, title: title, media_file: file)
30
+ JSON.parse response.body
31
+ end
32
+
33
+ private
34
+
35
+ def generate_signature(method = 'get', path = @base_url)
36
+ authorized_action
37
+
38
+ params = { access_key: @access_key, expires: Time.now.to_i + 300 }
39
+ signed = payload(params, method, path)
40
+ signature = Base64.encode64(OpenSSL::HMAC.digest('sha256', @secret, signed))
41
+ params[:signature] = signature.chomp
42
+
43
+ "#{path}?#{Faraday::Utils.build_query(params)}"
44
+ end
45
+
46
+ def authorized_action
47
+ raise KeyError.new("secret") if !@secret
48
+ raise KeyError.new("access_key") if !@access_key
49
+ end
50
+
51
+ def payload(params, method = 'get', path = @base_url)
52
+ [
53
+ method.downcase, URI.parse(@host).host, path,
54
+ params.sort.map{ |arr| arr.join('=') }.join('&')
55
+ ].join('|')
56
+ end
57
+ end
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "limelight_video"
3
+ s.version = "0.0.1"
4
+ s.summary = "Limelight video client"
5
+ s.description = "Interact with the Limelight CDN platform"
6
+ s.authors = ["elcuervo"]
7
+ s.email = ["yo@brunoaguirre.com"]
8
+ s.homepage = "http://github.com/elcuervo/limelight_video"
9
+ s.files = `git ls-files`.split("\n")
10
+ s.test_files = `git ls-files test`.split("\n")
11
+
12
+ s.add_dependency("faraday", "~> 0.8.0")
13
+ s.add_dependency("mime-types", "~> 1.18")
14
+
15
+ s.add_development_dependency("minitest", "~> 3.0.0")
16
+ s.add_development_dependency("fakeweb", "~> 1.3.0")
17
+ s.add_development_dependency("vcr", "~> 2.1.0")
18
+ end
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://api.videoplatform.limelight.com/rest/organizations/889457f434f14057bdcc9a1f39bd9614/media?access_key=5CIILY3Sw1P%2FqF2VHikRPXMEPdA%3D&expires=1337863294&signature=YkR%2BoskXW3HPpBBb9A9vft9wY5aA7QZ%2F1LnlGqklZFs%3D
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ""
9
+ headers:
10
+ content-type:
11
+ - multipart/form-data;boundary=-----------RubyMultipartPost
12
+ content-length:
13
+ - "246148"
14
+ accept:
15
+ - "*/*"
16
+ user-agent:
17
+ - Ruby
18
+ connection:
19
+ - close
20
+ response:
21
+ status:
22
+ code: 201
23
+ message: Created
24
+ headers:
25
+ server:
26
+ - nginx/0.8.54
27
+ date:
28
+ - Thu, 24 May 2012 12:36:43 GMT
29
+ content-type:
30
+ - application/json; charset=utf-8
31
+ connection:
32
+ - close
33
+ cache-control:
34
+ - no-cache
35
+ status:
36
+ - 201 Created
37
+ x-runtime:
38
+ - 1577ms
39
+ content-length:
40
+ - "747"
41
+ via:
42
+ - 1.0 vps-099.iad.llnw.net
43
+ body:
44
+ encoding: US-ASCII
45
+ string: "{\"publish_date\": null, \"category\": null, \"description\": null, \"sched_end_date\": null, \"tags\": [], \"title\": \"test\", \"media_id\": \"5b9db4b56210492eb0a4bae1b5f9e3ec\", \"media_type\": \"Video\", \"original_filename\": \"sample-mp4\", \"sched_start_date\": null, \"restrictionrule_id\": null, \"create_date\": 1337863002, \"state\": \"New\", \"total_storage_in_bytes\": 0, \"thumbnails\": [{\"url\": \"http://img.delvenetworks.com/0000000000000000000000/0000000000000000000000/defaultVideoPreviewImage.swf\", \"width\": \"\", \"height\": \"\"}, {\"url\": \"http://img.delvenetworks.com/0000000000000000000000/0000000000000000000000/defaultVideoPreviewImage.swf\", \"width\": \"\", \"height\": \"\"}], \"ref_id\": null, \"update_date\": 1337863003, \"custom_property\": null, \"duration_in_milliseconds\": 0}"
46
+ http_version: "1.1"
47
+ recorded_at: Thu, 24 May 2012 12:36:43 GMT
48
+ recorded_with: VCR 2.1.1
Binary file
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+ require 'test_fixtures'
3
+
4
+ describe Limelight do
5
+ it 'should upload a video' do
6
+ limelight = Limelight.new(
7
+ organization: '889457f434f14057bdcc9a1f39bd9614',
8
+ access_key: '5CIILY3Sw1P/qF2VHikRPXMEPdA=',
9
+ secret: 'Frpgy2kz/xDAnrO3IBAWDRkNJ3s='
10
+ )
11
+ VCR.use_cassette("limelight upload media", match_requests_on: [:host, :path]) do
12
+ video = limelight.upload('test', sample_mp4_file)
13
+ video["media_id"].size.must_equal 32
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ def sample_mp4_file
2
+ File.join(File.dirname(__FILE__), 'fixtures/files', 'sample.mp4')
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'vcr'
2
+ require "minitest/autorun"
3
+ require 'limelight_video'
4
+
5
+ VCR.configure do |c|
6
+ c.cassette_library_dir = 'test/fixtures/cassettes'
7
+ c.hook_into :fakeweb
8
+ end
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+ require 'test_fixtures'
3
+
4
+ describe Limelight do
5
+ it 'should validate minimal initializer' do
6
+ assert_raises KeyError do
7
+ Limelight.new
8
+ end
9
+ end
10
+
11
+ it 'should validate tokens for authorized actions' do
12
+ limelight = Limelight.new(organization: 'something', access_key: 'another')
13
+ assert_raises KeyError do
14
+ limelight.upload('test', sample_mp4_file)
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: limelight_video
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - elcuervo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.8.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: mime-types
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.18'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.18'
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 3.0.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: fakeweb
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.3.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.3.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: vcr
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 2.1.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 2.1.0
94
+ description: Interact with the Limelight CDN platform
95
+ email:
96
+ - yo@brunoaguirre.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - Gemfile
102
+ - Gemfile.lock
103
+ - README.md
104
+ - Rakefile
105
+ - lib/limelight_video.rb
106
+ - limelight_video.gemspec
107
+ - test/fixtures/cassettes/limelight_upload_media.yml
108
+ - test/fixtures/files/sample.mp4
109
+ - test/integration/limelight_test.rb
110
+ - test/test_fixtures.rb
111
+ - test/test_helper.rb
112
+ - test/unit/limelight_test.rb
113
+ homepage: http://github.com/elcuervo/limelight_video
114
+ licenses: []
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 1.8.22
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: Limelight video client
137
+ test_files:
138
+ - test/fixtures/cassettes/limelight_upload_media.yml
139
+ - test/fixtures/files/sample.mp4
140
+ - test/integration/limelight_test.rb
141
+ - test/test_fixtures.rb
142
+ - test/test_helper.rb
143
+ - test/unit/limelight_test.rb