brightcove-api 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ rvm --create 1.8.7@brightcove-api_gem
2
+ rvm --create 1.9.2@brightcove-api_gem
data/CHANELOG.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.0.9 (2011-06-22)
2
+
3
+ * Added `post_file_streaming` method
4
+
1
5
  # 1.0.7 (2011-03-21)
2
6
 
3
7
  * Allow for hash to be ordered when using the create_video call under Ruby 1.8.7
data/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
1
  source :rubygems
2
2
 
3
3
  group :development do
4
- gem "bundler", "~> 1.0.0"
5
- gem "jeweler", "~> 1.5.1"
6
- gem "rcov", "~> 0.9.9"
4
+ gem 'bundler', '~> 1.0.0'
5
+ gem 'jeweler', '~> 1.5.1'
6
+ gem 'rcov', '~> 0.9.9'
7
7
  end
8
8
 
9
9
  group :test do
@@ -11,7 +11,8 @@ group :test do
11
11
  gem 'mocha'
12
12
  end
13
13
 
14
- gem 'httparty', "~> 0.7.7"
15
- gem 'json', "~> 1.4.6"
16
- gem 'rest-client', "~> 1.6.1"
17
- gem 'orderedhash', "~> 0.0.6"
14
+ gem 'httparty', '~> 0.7.7'
15
+ gem 'json', '~> 1.4.6'
16
+ gem 'rest-client', '~> 1.6.1'
17
+ gem 'multipart-post', '~> 1.1.2'
18
+ gem 'orderedhash', '~> 0.0.6'
data/Rakefile CHANGED
@@ -36,8 +36,6 @@ Rcov::RcovTask.new do |test|
36
36
  test.verbose = true
37
37
  end
38
38
 
39
- task :default => :test
40
-
41
39
  require 'rake/rdoctask'
42
40
  Rake::RDocTask.new do |rdoc|
43
41
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
@@ -48,6 +46,8 @@ Rake::RDocTask.new do |rdoc|
48
46
  rdoc.rdoc_files.include('lib/**/*.rb')
49
47
  end
50
48
 
49
+ task :default => :test_rubies
50
+
51
51
  task :test_rubies do
52
- system "rvm 1.8.7,1.9.2 rake test"
52
+ system "rvm 1.8.7@brightcove-api_gem,1.9.2@brightcove-api_gem rake test"
53
53
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.8
1
+ 1.0.9
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{brightcove-api}
8
- s.version = "1.0.8"
8
+ s.version = "1.0.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Czarnecki"]
12
- s.date = %q{2011-05-10}
12
+ s.date = %q{2011-06-22}
13
13
  s.description = %q{Ruby gem for interacting with the Brightcove media API. http://docs.brightcove.com/en/media/}
14
14
  s.email = %q{dczarnecki@agoragames.com}
15
15
  s.extra_rdoc_files = [
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  "README.md"
18
18
  ]
19
19
  s.files = [
20
+ ".rvmrc",
20
21
  "CHANELOG.markdown",
21
22
  "Gemfile",
22
23
  "LICENSE",
@@ -35,7 +36,7 @@ Gem::Specification.new do |s|
35
36
  s.homepage = %q{http://github.com/BrightcoveOS/Ruby-MAPI-Wrapper}
36
37
  s.licenses = ["MIT"]
37
38
  s.require_paths = ["lib"]
38
- s.rubygems_version = %q{1.7.2}
39
+ s.rubygems_version = %q{1.5.3}
39
40
  s.summary = %q{Ruby gem for interacting with the Brightcove media API}
40
41
  s.test_files = [
41
42
  "test/helper.rb",
@@ -49,6 +50,7 @@ Gem::Specification.new do |s|
49
50
  s.add_runtime_dependency(%q<httparty>, ["~> 0.7.7"])
50
51
  s.add_runtime_dependency(%q<json>, ["~> 1.4.6"])
51
52
  s.add_runtime_dependency(%q<rest-client>, ["~> 1.6.1"])
53
+ s.add_runtime_dependency(%q<multipart-post>, ["~> 1.1.2"])
52
54
  s.add_runtime_dependency(%q<orderedhash>, ["~> 0.0.6"])
53
55
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
54
56
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
@@ -57,6 +59,7 @@ Gem::Specification.new do |s|
57
59
  s.add_dependency(%q<httparty>, ["~> 0.7.7"])
58
60
  s.add_dependency(%q<json>, ["~> 1.4.6"])
59
61
  s.add_dependency(%q<rest-client>, ["~> 1.6.1"])
62
+ s.add_dependency(%q<multipart-post>, ["~> 1.1.2"])
60
63
  s.add_dependency(%q<orderedhash>, ["~> 0.0.6"])
61
64
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
62
65
  s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
@@ -66,6 +69,7 @@ Gem::Specification.new do |s|
66
69
  s.add_dependency(%q<httparty>, ["~> 0.7.7"])
67
70
  s.add_dependency(%q<json>, ["~> 1.4.6"])
68
71
  s.add_dependency(%q<rest-client>, ["~> 1.6.1"])
72
+ s.add_dependency(%q<multipart-post>, ["~> 1.1.2"])
69
73
  s.add_dependency(%q<orderedhash>, ["~> 0.0.6"])
70
74
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
71
75
  s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
@@ -2,13 +2,14 @@ require 'httparty'
2
2
  require 'json'
3
3
  require 'rest-client'
4
4
  require 'orderedhash'
5
+ require 'net/http/post/multipart'
5
6
 
6
7
  module Brightcove
7
8
  class API
8
9
  include HTTParty
9
10
  disable_rails_query_string_format
10
11
 
11
- VERSION = '1.0.8'.freeze
12
+ VERSION = '1.0.9'.freeze
12
13
 
13
14
  DEFAULT_HEADERS = {
14
15
  'User-Agent' => "brightcove-api gem #{VERSION}"
@@ -22,6 +23,11 @@ module Brightcove
22
23
  attr_accessor :read_api_url
23
24
  attr_accessor :write_api_url
24
25
  attr_accessor :token
26
+
27
+ # RestClient POST timeout for reading conection
28
+ attr_accessor :timeout
29
+ # RestClient POST timeout for opening connection
30
+ attr_accessor :open_timeout
25
31
 
26
32
  # Brightcove returns text/html as the Content-Type for a response even though the response is JSON.
27
33
  # So, let's just parse the response as JSON
@@ -93,9 +99,43 @@ module Brightcove
93
99
  payload[:json] = body.to_json
94
100
  payload[:file] = File.new(file, 'rb')
95
101
 
96
- response = RestClient.post(@write_api_url, payload, :content_type => :json, :accept => :json, :multipart => true)
102
+ response = RestClient::Request.execute(
103
+ :method => :post,
104
+ :url => @write_api_url,
105
+ :payload => payload,
106
+ :content_type => :json,
107
+ :accept => :json,
108
+ :multipart => true,
109
+ :timeout => @timeout,
110
+ :open_timeout => @open_timeout
111
+ )
97
112
 
98
113
  JSON.parse(response)
99
114
  end
115
+
116
+ def post_file_streaming(api_method, upload_file, content_type, parameters)
117
+ parameters.merge!({"token" => @token})
118
+
119
+ body = {}
120
+ body.merge!({:method => api_method})
121
+ body.merge!({:params => parameters})
122
+
123
+ url = URI.parse(@write_api_url)
124
+ response = nil
125
+ File.open(upload_file) do |file|
126
+ request = Net::HTTP::Post::Multipart.new(
127
+ url.path,
128
+ {
129
+ :json => body.to_json,
130
+ :file => UploadIO.new(file, content_type)
131
+ })
132
+
133
+ response = Net::HTTP.start(url.host, url.port) do |http|
134
+ http.request(request)
135
+ end
136
+ end
137
+
138
+ JSON.parse(response.body)
139
+ end
100
140
  end
101
141
  end
@@ -1 +1 @@
1
- {"result":{}, "id":nil, "error":nil}
1
+ {"result":{}, "id":null, "error":null}
@@ -12,7 +12,7 @@ class TestBrightcoveApi < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def test_api_version
15
- assert_equal '1.0.8', Brightcove::API::VERSION
15
+ assert_equal '1.0.9', Brightcove::API::VERSION
16
16
  end
17
17
 
18
18
  def test_can_set_read_api_url
@@ -124,7 +124,7 @@ class TestBrightcoveApi < Test::Unit::TestCase
124
124
  brightcove_response = brightcove.post('delete_video', {:video_id => '595153261337'})
125
125
 
126
126
  assert brightcove_response.has_key?('result')
127
- assert_equal brightcove_response['error'], 'nil'
127
+ assert_equal brightcove_response['error'], nil
128
128
  end
129
129
 
130
130
  def test_create_video_using_post_file
@@ -142,4 +142,20 @@ class TestBrightcoveApi < Test::Unit::TestCase
142
142
  assert_equal '653155417001', brightcove_response['result'].to_s
143
143
  assert_equal brightcove_response['error'], nil
144
144
  end
145
+
146
+ def test_create_video_using_post_file_streaming
147
+ FakeWeb.register_uri(:post,
148
+ 'http://api.brightcove.com/services/post',
149
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'create_video_response.json'),
150
+ :content_type => "application/json")
151
+
152
+ brightcove = Brightcove::API.new('0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.')
153
+ brightcove_response = brightcove.post_file_streaming('create_video',
154
+ File.join(File.dirname(__FILE__), 'fakeweb', 'movie.mov'), 'video/quicktime',
155
+ :video => {:shortDescription => "Short Description", :name => "Video"})
156
+
157
+ assert brightcove_response.has_key?('result')
158
+ assert_equal '653155417001', brightcove_response['result'].to_s
159
+ assert_equal brightcove_response['error'], nil
160
+ end
145
161
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: brightcove-api
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.8
5
+ version: 1.0.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - David Czarnecki
@@ -10,7 +10,8 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-10 00:00:00 Z
13
+ date: 2011-06-22 00:00:00 -04:00
14
+ default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: httparty
@@ -46,19 +47,30 @@ dependencies:
46
47
  prerelease: false
47
48
  version_requirements: *id003
48
49
  - !ruby/object:Gem::Dependency
49
- name: orderedhash
50
+ name: multipart-post
50
51
  requirement: &id004 !ruby/object:Gem::Requirement
51
52
  none: false
52
53
  requirements:
53
54
  - - ~>
54
55
  - !ruby/object:Gem::Version
55
- version: 0.0.6
56
+ version: 1.1.2
56
57
  type: :runtime
57
58
  prerelease: false
58
59
  version_requirements: *id004
59
60
  - !ruby/object:Gem::Dependency
60
- name: bundler
61
+ name: orderedhash
61
62
  requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 0.0.6
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: bundler
73
+ requirement: &id006 !ruby/object:Gem::Requirement
62
74
  none: false
63
75
  requirements:
64
76
  - - ~>
@@ -66,10 +78,10 @@ dependencies:
66
78
  version: 1.0.0
67
79
  type: :development
68
80
  prerelease: false
69
- version_requirements: *id005
81
+ version_requirements: *id006
70
82
  - !ruby/object:Gem::Dependency
71
83
  name: jeweler
72
- requirement: &id006 !ruby/object:Gem::Requirement
84
+ requirement: &id007 !ruby/object:Gem::Requirement
73
85
  none: false
74
86
  requirements:
75
87
  - - ~>
@@ -77,10 +89,10 @@ dependencies:
77
89
  version: 1.5.1
78
90
  type: :development
79
91
  prerelease: false
80
- version_requirements: *id006
92
+ version_requirements: *id007
81
93
  - !ruby/object:Gem::Dependency
82
94
  name: rcov
83
- requirement: &id007 !ruby/object:Gem::Requirement
95
+ requirement: &id008 !ruby/object:Gem::Requirement
84
96
  none: false
85
97
  requirements:
86
98
  - - ~>
@@ -88,7 +100,7 @@ dependencies:
88
100
  version: 0.9.9
89
101
  type: :development
90
102
  prerelease: false
91
- version_requirements: *id007
103
+ version_requirements: *id008
92
104
  description: Ruby gem for interacting with the Brightcove media API. http://docs.brightcove.com/en/media/
93
105
  email: dczarnecki@agoragames.com
94
106
  executables: []
@@ -99,6 +111,7 @@ extra_rdoc_files:
99
111
  - LICENSE
100
112
  - README.md
101
113
  files:
114
+ - .rvmrc
102
115
  - CHANELOG.markdown
103
116
  - Gemfile
104
117
  - LICENSE
@@ -113,6 +126,7 @@ files:
113
126
  - test/fakeweb/movie.mov
114
127
  - test/helper.rb
115
128
  - test/test_brightcove-api.rb
129
+ has_rdoc: true
116
130
  homepage: http://github.com/BrightcoveOS/Ruby-MAPI-Wrapper
117
131
  licenses:
118
132
  - MIT
@@ -126,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
140
  requirements:
127
141
  - - ">="
128
142
  - !ruby/object:Gem::Version
129
- hash: 4201101218495079525
143
+ hash: 1985167017172697863
130
144
  segments:
131
145
  - 0
132
146
  version: "0"
@@ -139,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
153
  requirements: []
140
154
 
141
155
  rubyforge_project:
142
- rubygems_version: 1.7.2
156
+ rubygems_version: 1.5.3
143
157
  signing_key:
144
158
  specification_version: 3
145
159
  summary: Ruby gem for interacting with the Brightcove media API