limelight_video 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/limelight_video.rb +50 -4
- data/limelight_video.gemspec +1 -1
- data/test/fixtures/cassettes/create_and_list_metadata.yml +134 -0
- data/test/fixtures/cassettes/limelight_upload_with_metadata.yml +132 -0
- data/test/integration/limelight_test.rb +20 -2
- data/test/test_helper.rb +4 -0
- metadata +6 -2
data/lib/limelight_video.rb
CHANGED
@@ -21,6 +21,11 @@ class Limelight
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
def media_info(media_id)
|
25
|
+
response = @client.get("#{@base_url}/#{media_id}/properties.json")
|
26
|
+
JSON.parse response.body
|
27
|
+
end
|
28
|
+
|
24
29
|
def upload(filename_or_io, attributes = {})
|
25
30
|
case filename_or_io
|
26
31
|
when String
|
@@ -35,18 +40,59 @@ class Limelight
|
|
35
40
|
raise Errno::ENOENT
|
36
41
|
end
|
37
42
|
|
38
|
-
url = generate_signature('post', @base_url)
|
39
43
|
media_file = Faraday::UploadIO.new(file, mime, filename)
|
40
|
-
options = {
|
41
|
-
|
44
|
+
options = {
|
45
|
+
title: attributes.fetch(:title, 'Unnamed'),
|
46
|
+
media_file: media_file
|
47
|
+
}
|
48
|
+
if attributes[:metadata]
|
49
|
+
custom_properties = attributes[:metadata]
|
50
|
+
properties_to_create = custom_properties.keys.map(&:to_s) - list_metadata
|
51
|
+
create_metadata(properties_to_create)
|
52
|
+
end
|
53
|
+
|
54
|
+
options[:custom_property] = attributes.fetch(:metadata, {})
|
55
|
+
response = @client.post(upload_path, options) do |req|
|
42
56
|
req.options[:open_timeout] = 60*60
|
43
57
|
end
|
58
|
+
|
44
59
|
JSON.parse response.body
|
45
60
|
end
|
46
61
|
|
62
|
+
def upload_url
|
63
|
+
@host + upload_path
|
64
|
+
end
|
65
|
+
|
66
|
+
def upload_path
|
67
|
+
generate_encoded_path('post', @base_url)
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_metadata(names)
|
71
|
+
# http://api.videoplatform.limelight.com/rest/organizations/<org id>/media/properties/custom/<property name>
|
72
|
+
Array(names).each do |name|
|
73
|
+
path = generate_encoded_path('put', "#{@base_url}/properties/custom/#{name}")
|
74
|
+
@client.put(path)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def list_metadata
|
79
|
+
# http://api.videoplatform.limelight.com/rest/organizations/<orgid>/media/properties/custom.{XML,JSON}
|
80
|
+
response = @client.get("#{@base_url}/properties/custom.json")
|
81
|
+
metadata = JSON.parse response.body
|
82
|
+
metadata["custom_property_types"].map { |meta| meta["type_name"] }
|
83
|
+
end
|
84
|
+
|
85
|
+
def remove_metadata(names)
|
86
|
+
# http://api.videoplatform.limelight.com/rest/organizations/<org id>/media/properties/custom/<property name>
|
87
|
+
Array(names).each do |name|
|
88
|
+
path = generate_encoded_path('delete', "#{@base_url}/properties/custom/#{name}")
|
89
|
+
@client.delete(path)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
47
93
|
private
|
48
94
|
|
49
|
-
def
|
95
|
+
def generate_encoded_path(method = 'get', path = @base_url)
|
50
96
|
authorized_action
|
51
97
|
|
52
98
|
params = { access_key: @access_key, expires: Time.now.to_i + 300 }
|
data/limelight_video.gemspec
CHANGED
@@ -0,0 +1,134 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: put
|
5
|
+
uri: http://api.videoplatform.limelight.com/rest/organizations/889457f434f14057bdcc9a1f39bd9614/media/properties/custom/test?access_key=5CIILY3Sw1P%2FqF2VHikRPXMEPdA%3D&expires=1340937602&signature=of8f8C1BctNLdy0oF%2FXUjW2f0y9Co6%2BGxFQq1TIkNw4%3D
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ""
|
9
|
+
headers:
|
10
|
+
content-length:
|
11
|
+
- "0"
|
12
|
+
accept:
|
13
|
+
- "*/*"
|
14
|
+
user-agent:
|
15
|
+
- Ruby
|
16
|
+
connection:
|
17
|
+
- close
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 400
|
21
|
+
message: Bad Request
|
22
|
+
headers:
|
23
|
+
server:
|
24
|
+
- nginx/0.8.54
|
25
|
+
date:
|
26
|
+
- Fri, 29 Jun 2012 02:35:05 GMT
|
27
|
+
content-type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
connection:
|
30
|
+
- close
|
31
|
+
cache-control:
|
32
|
+
- no-cache
|
33
|
+
status:
|
34
|
+
- 400 Bad Request
|
35
|
+
content-length:
|
36
|
+
- "118"
|
37
|
+
via:
|
38
|
+
- 1.0 vps-095.iad.llnw.net
|
39
|
+
body:
|
40
|
+
encoding: US-ASCII
|
41
|
+
string: "{\"errors\": [\"The property you are trying to set to the given name already exists. Please specify a different name.\"]}"
|
42
|
+
http_version: "1.1"
|
43
|
+
recorded_at: Fri, 29 Jun 2012 02:35:05 GMT
|
44
|
+
- request:
|
45
|
+
method: get
|
46
|
+
uri: http://api.videoplatform.limelight.com/rest/organizations/889457f434f14057bdcc9a1f39bd9614/media/properties/custom.json
|
47
|
+
body:
|
48
|
+
encoding: US-ASCII
|
49
|
+
string: ""
|
50
|
+
headers:
|
51
|
+
accept-encoding:
|
52
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
53
|
+
accept:
|
54
|
+
- "*/*"
|
55
|
+
user-agent:
|
56
|
+
- Ruby
|
57
|
+
connection:
|
58
|
+
- close
|
59
|
+
response:
|
60
|
+
status:
|
61
|
+
code: 200
|
62
|
+
message: OK
|
63
|
+
headers:
|
64
|
+
server:
|
65
|
+
- nginx/0.8.54
|
66
|
+
date:
|
67
|
+
- Fri, 29 Jun 2012 02:35:06 GMT
|
68
|
+
content-type:
|
69
|
+
- application/json; charset=utf-8
|
70
|
+
connection:
|
71
|
+
- close
|
72
|
+
cache-control:
|
73
|
+
- max-age=300, max-stale=18000, public
|
74
|
+
status:
|
75
|
+
- 200 OK
|
76
|
+
x-runtime:
|
77
|
+
- 721ms
|
78
|
+
etag:
|
79
|
+
- "\"1a607f813179a110bf2906752175d144\""
|
80
|
+
content-length:
|
81
|
+
- "50"
|
82
|
+
via:
|
83
|
+
- 1.0 vps-099.iad.llnw.net
|
84
|
+
body:
|
85
|
+
encoding: US-ASCII
|
86
|
+
string: "{\"custom_property_types\": [{\"type_name\": \"test\"}]}"
|
87
|
+
http_version: "1.1"
|
88
|
+
recorded_at: Fri, 29 Jun 2012 02:35:06 GMT
|
89
|
+
- request:
|
90
|
+
method: get
|
91
|
+
uri: http://api.videoplatform.limelight.com/rest/organizations/889457f434f14057bdcc9a1f39bd9614/media/properties/custom.json
|
92
|
+
body:
|
93
|
+
encoding: US-ASCII
|
94
|
+
string: ""
|
95
|
+
headers:
|
96
|
+
accept-encoding:
|
97
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
98
|
+
accept:
|
99
|
+
- "*/*"
|
100
|
+
user-agent:
|
101
|
+
- Ruby
|
102
|
+
connection:
|
103
|
+
- close
|
104
|
+
response:
|
105
|
+
status:
|
106
|
+
code: 200
|
107
|
+
message: OK
|
108
|
+
headers:
|
109
|
+
server:
|
110
|
+
- nginx/0.8.54
|
111
|
+
date:
|
112
|
+
- Fri, 29 Jun 2012 02:35:08 GMT
|
113
|
+
content-type:
|
114
|
+
- application/json; charset=utf-8
|
115
|
+
connection:
|
116
|
+
- close
|
117
|
+
cache-control:
|
118
|
+
- max-age=300, max-stale=18000, public
|
119
|
+
status:
|
120
|
+
- 200 OK
|
121
|
+
x-runtime:
|
122
|
+
- 700ms
|
123
|
+
etag:
|
124
|
+
- "\"1a607f813179a110bf2906752175d144\""
|
125
|
+
content-length:
|
126
|
+
- "50"
|
127
|
+
via:
|
128
|
+
- 1.0 vps-095.iad.llnw.net
|
129
|
+
body:
|
130
|
+
encoding: US-ASCII
|
131
|
+
string: "{\"custom_property_types\": [{\"type_name\": \"test\"}]}"
|
132
|
+
http_version: "1.1"
|
133
|
+
recorded_at: Fri, 29 Jun 2012 02:35:08 GMT
|
134
|
+
recorded_with: VCR 2.1.1
|
@@ -0,0 +1,132 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api.videoplatform.limelight.com/rest/organizations/889457f434f14057bdcc9a1f39bd9614/media/properties/custom.json
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ""
|
9
|
+
headers:
|
10
|
+
accept-encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
accept:
|
13
|
+
- "*/*"
|
14
|
+
user-agent:
|
15
|
+
- Ruby
|
16
|
+
connection:
|
17
|
+
- close
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
server:
|
24
|
+
- nginx/0.8.54
|
25
|
+
date:
|
26
|
+
- Fri, 29 Jun 2012 03:10:45 GMT
|
27
|
+
content-type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
connection:
|
30
|
+
- close
|
31
|
+
cache-control:
|
32
|
+
- max-age=300, max-stale=18000, public
|
33
|
+
status:
|
34
|
+
- 200 OK
|
35
|
+
x-runtime:
|
36
|
+
- 688ms
|
37
|
+
etag:
|
38
|
+
- "\"85294995f52af4df68503ed27ec74b98\""
|
39
|
+
content-length:
|
40
|
+
- "80"
|
41
|
+
via:
|
42
|
+
- 1.0 vps-099.iad.llnw.net
|
43
|
+
body:
|
44
|
+
encoding: US-ASCII
|
45
|
+
string: "{\"custom_property_types\": [{\"type_name\": \"test\"}, {\"type_name\": \"internal_id\"}]}"
|
46
|
+
http_version: "1.1"
|
47
|
+
recorded_at: Fri, 29 Jun 2012 03:10:45 GMT
|
48
|
+
- request:
|
49
|
+
method: post
|
50
|
+
uri: http://api.videoplatform.limelight.com/rest/organizations/889457f434f14057bdcc9a1f39bd9614/media?access_key=5CIILY3Sw1P%2FqF2VHikRPXMEPdA%3D&expires=1340939745&signature=Ak7a9gBxw48axbGteF83objpZ%2FjuTK5PwRBVu9NWZ3E%3D
|
51
|
+
body:
|
52
|
+
encoding: US-ASCII
|
53
|
+
string: ""
|
54
|
+
headers:
|
55
|
+
content-type:
|
56
|
+
- multipart/form-data;boundary=-----------RubyMultipartPost
|
57
|
+
content-length:
|
58
|
+
- "246264"
|
59
|
+
accept:
|
60
|
+
- "*/*"
|
61
|
+
user-agent:
|
62
|
+
- Ruby
|
63
|
+
connection:
|
64
|
+
- close
|
65
|
+
response:
|
66
|
+
status:
|
67
|
+
code: 201
|
68
|
+
message: Created
|
69
|
+
headers:
|
70
|
+
server:
|
71
|
+
- nginx/0.8.54
|
72
|
+
date:
|
73
|
+
- Fri, 29 Jun 2012 03:10:55 GMT
|
74
|
+
content-type:
|
75
|
+
- application/json; charset=utf-8
|
76
|
+
connection:
|
77
|
+
- close
|
78
|
+
cache-control:
|
79
|
+
- no-cache
|
80
|
+
status:
|
81
|
+
- 201 Created
|
82
|
+
x-runtime:
|
83
|
+
- 4061ms
|
84
|
+
content-length:
|
85
|
+
- "754"
|
86
|
+
via:
|
87
|
+
- 1.0 vps-098.iad.llnw.net
|
88
|
+
body:
|
89
|
+
encoding: US-ASCII
|
90
|
+
string: "{\"publish_date\": null, \"category\": null, \"description\": null, \"sched_end_date\": null, \"tags\": [], \"title\": \"test metadata\", \"media_id\": \"19a0c0ff2fe44120a7c4e95eb7a6064d\", \"media_type\": \"Video\", \"original_filename\": \"sample-mp4\", \"sched_start_date\": null, \"restrictionrule_id\": null, \"create_date\": 1340939452, \"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\": 1340939452, \"custom_property\": {}, \"duration_in_milliseconds\": 0}"
|
91
|
+
http_version: "1.1"
|
92
|
+
recorded_at: Fri, 29 Jun 2012 03:10:55 GMT
|
93
|
+
- request:
|
94
|
+
method: get
|
95
|
+
uri: http://api.videoplatform.limelight.com/rest/organizations/889457f434f14057bdcc9a1f39bd9614/media/19a0c0ff2fe44120a7c4e95eb7a6064d/properties.json
|
96
|
+
body:
|
97
|
+
encoding: US-ASCII
|
98
|
+
string: ""
|
99
|
+
headers:
|
100
|
+
accept-encoding:
|
101
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
102
|
+
accept:
|
103
|
+
- "*/*"
|
104
|
+
user-agent:
|
105
|
+
- Ruby
|
106
|
+
connection:
|
107
|
+
- close
|
108
|
+
response:
|
109
|
+
status:
|
110
|
+
code: 200
|
111
|
+
message: OK
|
112
|
+
headers:
|
113
|
+
server:
|
114
|
+
- nginx/0.8.54
|
115
|
+
date:
|
116
|
+
- Fri, 29 Jun 2012 03:10:56 GMT
|
117
|
+
content-type:
|
118
|
+
- application/json;charset=UTF-8
|
119
|
+
connection:
|
120
|
+
- close
|
121
|
+
cache-control:
|
122
|
+
- max-age=300,max-stale=18000, public
|
123
|
+
etag:
|
124
|
+
- "\"e6eb64b879c345e598d7d4825c028797\""
|
125
|
+
content-length:
|
126
|
+
- "751"
|
127
|
+
body:
|
128
|
+
encoding: US-ASCII
|
129
|
+
string: "{\"publish_date\":null,\"category\":null,\"description\":null,\"sched_end_date\":null,\"tags\":[],\"title\":\"test metadata\",\"media_id\":\"19a0c0ff2fe44120a7c4e95eb7a6064d\",\"media_type\":\"Video\",\"original_filename\":\"sample-mp4\",\"sched_start_date\":null,\"restrictionrule_id\":null,\"create_date\":1340939452,\"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\":1340939452,\"custom_property\":{\"internal_id\":\"10\"},\"duration_in_milliseconds\":0,\"closed_captions_url\":null}"
|
130
|
+
http_version: "1.1"
|
131
|
+
recorded_at: Fri, 29 Jun 2012 03:10:56 GMT
|
132
|
+
recorded_with: VCR 2.1.1
|
@@ -12,17 +12,35 @@ describe Limelight do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'should upload a video' do
|
15
|
-
|
15
|
+
with_a_cassette("limelight upload media") do
|
16
16
|
video = @limelight.upload(sample_mp4_file, title: 'test')
|
17
17
|
video["media_id"].size.must_equal 32
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should upload an io stream' do
|
22
|
-
|
22
|
+
with_a_cassette("limelight upload io") do
|
23
23
|
io = StringIO.new << File.read(sample_mp4_file)
|
24
24
|
video = @limelight.upload(io, title: 'test', filename: sample_mp4_file)
|
25
25
|
video["media_id"].size.must_equal 32
|
26
26
|
end
|
27
27
|
end
|
28
|
+
|
29
|
+
it 'should create and list all the metadata' do
|
30
|
+
with_a_cassette('create and list metadata') do
|
31
|
+
@limelight.create_metadata("test")
|
32
|
+
assert @limelight.list_metadata.include?("test")
|
33
|
+
assert !@limelight.list_metadata.include?("none")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should upload a video with metadata' do
|
38
|
+
with_a_cassette("limelight upload with metadata") do
|
39
|
+
video = @limelight.upload(sample_mp4_file, title: 'test metadata', metadata: { internal_id: 10 })
|
40
|
+
video["media_id"].size.must_equal 32
|
41
|
+
|
42
|
+
media_info = @limelight.media_info(video["media_id"])
|
43
|
+
assert media_info["custom_property"], "This media should have a custom property"
|
44
|
+
end
|
45
|
+
end
|
28
46
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: limelight_video
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -104,8 +104,10 @@ files:
|
|
104
104
|
- Rakefile
|
105
105
|
- lib/limelight_video.rb
|
106
106
|
- limelight_video.gemspec
|
107
|
+
- test/fixtures/cassettes/create_and_list_metadata.yml
|
107
108
|
- test/fixtures/cassettes/limelight_upload_io.yml
|
108
109
|
- test/fixtures/cassettes/limelight_upload_media.yml
|
110
|
+
- test/fixtures/cassettes/limelight_upload_with_metadata.yml
|
109
111
|
- test/fixtures/files/sample.mp4
|
110
112
|
- test/integration/limelight_test.rb
|
111
113
|
- test/test_fixtures.rb
|
@@ -136,8 +138,10 @@ signing_key:
|
|
136
138
|
specification_version: 3
|
137
139
|
summary: Limelight video client
|
138
140
|
test_files:
|
141
|
+
- test/fixtures/cassettes/create_and_list_metadata.yml
|
139
142
|
- test/fixtures/cassettes/limelight_upload_io.yml
|
140
143
|
- test/fixtures/cassettes/limelight_upload_media.yml
|
144
|
+
- test/fixtures/cassettes/limelight_upload_with_metadata.yml
|
141
145
|
- test/fixtures/files/sample.mp4
|
142
146
|
- test/integration/limelight_test.rb
|
143
147
|
- test/test_fixtures.rb
|