limelight_video 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/limelight_video.rb +18 -11
- data/limelight_video.gemspec +1 -1
- data/test/integration/limelight_test.rb +2 -1
- metadata +1 -1
data/lib/limelight_video.rb
CHANGED
@@ -2,6 +2,7 @@ require 'faraday'
|
|
2
2
|
require 'json'
|
3
3
|
require 'base64'
|
4
4
|
require 'openssl'
|
5
|
+
require 'tempfile'
|
5
6
|
require 'mime/types'
|
6
7
|
|
7
8
|
class Limelight
|
@@ -21,19 +22,25 @@ class Limelight
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def upload(filename_or_io, attributes = {})
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
case filename_or_io
|
26
|
+
when String
|
27
|
+
file = File.open(filename_or_io)
|
28
|
+
filename = filename_or_io
|
29
|
+
mime = MIME::Types.of(filename_or_io)
|
30
|
+
when Tempfile, StringIO
|
31
|
+
file = filename_or_io
|
32
|
+
filename = attributes.fetch(:filename)
|
33
|
+
mime = attributes[:type] || MIME::Types.of(filename)
|
34
|
+
else
|
35
|
+
raise Errno::ENOENT
|
36
|
+
end
|
32
37
|
|
33
38
|
url = generate_signature('post', @base_url)
|
34
|
-
|
35
|
-
|
36
|
-
response = @client.post(url,
|
39
|
+
media_file = Faraday::UploadIO.new(file, mime, filename)
|
40
|
+
options = { title: attributes.fetch(:title, 'Unnamed'), media_file: media_file}
|
41
|
+
response = @client.post(url, options) do |req|
|
42
|
+
req.options[:open_timeout] = 60*60
|
43
|
+
end
|
37
44
|
JSON.parse response.body
|
38
45
|
end
|
39
46
|
|
data/limelight_video.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'test_fixtures'
|
3
|
+
require 'stringio'
|
3
4
|
|
4
5
|
describe Limelight do
|
5
6
|
before do
|
@@ -19,7 +20,7 @@ describe Limelight do
|
|
19
20
|
|
20
21
|
it 'should upload an io stream' do
|
21
22
|
VCR.use_cassette("limelight upload io", match_requests_on: [:host, :path]) do
|
22
|
-
io = File.
|
23
|
+
io = StringIO.new << File.read(sample_mp4_file)
|
23
24
|
video = @limelight.upload(io, title: 'test', filename: sample_mp4_file)
|
24
25
|
video["media_id"].size.must_equal 32
|
25
26
|
end
|