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.
@@ -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
- if filename_or_io.is_a?(String) && File.exists?(filename_or_io)
25
- filename = filename_or_io
26
- elsif filename_or_io.respond_to?(:read)
27
- filename = attributes.fetch(:filename)
28
- raise KeyError.new("filename") if !filename
29
- else
30
- raise Errno::ENOENT
31
- end
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
- mime = MIME::Types.type_for(filename)
35
- file = Faraday::UploadIO.new(filename_or_io, mime)
36
- response = @client.post(url, title: attributes.fetch(:title, 'Unnamed'), media_file: file)
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
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "limelight_video"
3
- s.version = "0.0.2"
3
+ s.version = "0.0.3"
4
4
  s.summary = "Limelight video client"
5
5
  s.description = "Interact with the Limelight CDN platform"
6
6
  s.authors = ["elcuervo"]
@@ -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.open(sample_mp4_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
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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: