brightcove-api 1.0.11 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ .DS_Store
2
+ *.tmproj
3
+ tmtags
4
+ *~
5
+ \#*
6
+ .\#*
7
+ *.swp
8
+ coverage
9
+ rdoc
10
+ pkg
11
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format doc
data/.rvmrc CHANGED
@@ -1,2 +1,3 @@
1
- rvm --create 1.8.7@brightcove-api_gem
2
- rvm --create 1.9.2@brightcove-api_gem
1
+ rvm use --create 1.8.7@brightcove-api_gem
2
+ rvm use --create 1.9.2@brightcove-api_gem
3
+ rvm use --create 1.9.3@brightcove-api_gem
@@ -1,3 +1,7 @@
1
+ # 1.0.12 (2012-06-12)
2
+
3
+ * Allow post streaming when you have an file handle instead of a filename. Thanks @keysolutions
4
+
1
5
  # 1.0.11 (2011-09-13)
2
6
 
3
7
  * Only set `timeout` and `open_timeout` in `post_file(...)` and `post_file_streaming(...)` if they are set
data/Gemfile CHANGED
@@ -1,18 +1,3 @@
1
1
  source :rubygems
2
2
 
3
- group :development do
4
- gem 'bundler', '~> 1.0.0'
5
- gem 'jeweler', '~> 1.5.1'
6
- gem 'rcov', '~> 0.9.9'
7
- end
8
-
9
- group :test do
10
- gem 'fakeweb'
11
- gem 'mocha'
12
- end
13
-
14
- gem 'httparty'
15
- gem 'json'
16
- gem 'rest-client'
17
- gem 'multipart-post'
18
- gem 'orderedhash'
3
+ gemspec
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2011 David Czarnecki
1
+ Copyright (c) 2010-2012 David Czarnecki
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,10 +1,8 @@
1
- brightcove-api
2
- ==============
1
+ # brightcove-api
3
2
 
4
3
  Ruby gem for interacting with the Brightcove media API. http://docs.brightcove.com/en/media/
5
4
 
6
- Requirements
7
- ============
5
+ ## Requirements
8
6
 
9
7
  * HTTParty
10
8
 
@@ -13,41 +11,54 @@ Requirements
13
11
  * multipart-post (for the `post_file_streaming(...) method`)
14
12
  * orderedhash (only if you're using Ruby 1.8.7)
15
13
 
16
- Install
17
- =======
14
+ ## Install
18
15
 
19
- * sudo gem install brightcove-api
16
+ ```
17
+ gem install brightcove-api
18
+ ```
20
19
 
21
- Examples
22
- ========
20
+ ## Examples
23
21
 
24
- >> require 'brightcove-api'
25
- => true
26
- >> brightcove = Brightcove::API.new('0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.')
27
- => #<Brightcove::API:0x114dbc8 @token="0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.", @api_url="http://api.brightcove.com/services/library">
28
- >> response = brightcove.get('find_all_videos', {:page_size => 3, :video_fields => 'id,name,linkURL,linkText'})
29
- => {"items"=>[{"name"=>"Documentarian Skydiving", "id"=>496518762, "linkText"=>nil, "linkURL"=>nil}, {"name"=>"Surface Tricks", "id"=>496518763, "linkText"=>nil, "linkURL"=>nil}, {"name"=>"Free Skiing", "id"=>496518765, "linkText"=>nil, "linkURL"=>nil}], "page_number"=>0, "page_size"=>3, "total_count"=>-1}
30
- >> response = brightcove.get('find_all_videos', {:page_size => 5, :sort_by => 'PLAYS_TOTAL'})
31
- => {"items"=>[{"longDescription"=>nil, "name"=>"Wild Slopes '06", "lastModifiedDate"=>"1171324523307", "thumbnailURL"=>"http://brightcove.vo.llnwd.net/d2/unsecured/media/270881183/270881183_502534829_94499905676eb7cd04a558da2adcf6a34f437b88.jpg?pubId=270881183", "tags"=>["adventure", "snowboarding"], "playsTrailingWeek"=>35, "shortDescription"=>"A ski and snowboard movie that challenges the hype and dares you to see what freeskiing and snowboarding have become. Documenting the very best of this year's riding and culture.", "playsTotal"=>4458, "adKeys"=>nil, "id"=>496518766, "length"=>51251, "videoStillURL"=>"http://brightcove.vo.llnwd.net/d2/unsecured/media/270881183/270881183_502534838_f80fe64f052328cd3b2e158d7234003a23091845.jpg?pubId=270881183", "publishedDate"=>"1171324434811", "creationDate"=>"1171267200000", "linkText"=>nil, "economics"=>"FREE", "referenceId"=>"title010", "linkURL"=>nil}, {"longDescription"=>nil, "name"=>"Jellyfish", "lastModifiedDate"=>"1245181300374", "thumbnailURL"=>"http://brightcove.vo.llnwd.net/d7/unsecured/media/270881183/270881183_26530711001_jellyFish.jpg?pubId=270881183", "tags"=>["sea", "custom skins"], "playsTrailingWeek"=>46, "shortDescription"=>"Jellyfish", "playsTotal"=>4081, "adKeys"=>nil, "id"=>26512561001, "length"=>28400, "videoStillURL"=>"http://brightcove.vo.llnwd.net/d7/unsecured/media/270881183/270881183_26519430001_vs-270881183-vid26513829001-img0000.jpg?pubId=270881183", "publishedDate"=>"1245172164326", "creationDate"=>"1245172164326", "linkText"=>nil, "economics"=>"AD_SUPPORTED", "referenceId"=>nil, "linkURL"=>nil}, {"longDescription"=>"Long Description", "name"=>"Demo Title 2", "lastModifiedDate"=>"1263581295791", "thumbnailURL"=>"http://brightcove.vo.llnwd.net/d2/unsecured/media/270881183/270881183_275925069_d1f97c7f07f2a3f4de7b38eda3761f16f39d2a99.jpg?pubId=270881183", "tags"=>[], "playsTrailingWeek"=>1, "shortDescription"=>"Short Description", "playsTotal"=>3876, "adKeys"=>nil, "id"=>276024035, "length"=>418742, "videoStillURL"=>"http://brightcove.vo.llnwd.net/d2/unsecured/media/270881183/270881183_275943599_b7e2ca63c0311fa3f0b027304b41d252f12d2d66.jpg?pubId=270881183", "publishedDate"=>"1161296014264", "creationDate"=>"1161241200000", "linkText"=>"Related Link", "economics"=>"FREE", "referenceId"=>nil, "linkURL"=>"http://www.brightcove.com"}, {"longDescription"=>nil, "name"=>"Dolphins", "lastModifiedDate"=>"1263581295790", "thumbnailURL"=>"http://brightcove.vo.llnwd.net/d7/unsecured/media/270881183/270881183_26531197001_dolphins.jpg?pubId=270881183", "tags"=>["sea", "custom skins"], "playsTrailingWeek"=>30, "shortDescription"=>"Dolphins", "playsTotal"=>3870, "adKeys"=>nil, "id"=>26511963001, "length"=>12800, "videoStillURL"=>"http://brightcove.vo.llnwd.net/d7/unsecured/media/270881183/270881183_26519372001_vs-270881183-vid26510372001-img0000.jpg?pubId=270881183", "publishedDate"=>"1245171732987", "creationDate"=>"1245171732987", "linkText"=>nil, "economics"=>"AD_SUPPORTED", "referenceId"=>nil, "linkURL"=>nil}, {"longDescription"=>nil, "name"=>"Welcome to Brightcove 3", "lastModifiedDate"=>"1225134261511", "thumbnailURL"=>"http://brightcove.vo.llnwd.net/d6/unsecured/media/270881183/270881183_1858983740_brightcove3-thumb.jpg?pubId=270881183", "tags"=>[], "playsTrailingWeek"=>0, "shortDescription"=>"Tareef Kawaf, Brightcove's SVP of Engineering, welcomes you to Brightcove 3.", "playsTotal"=>3349, "adKeys"=>nil, "id"=>1858922805, "length"=>53820, "videoStillURL"=>"http://brightcove.vo.llnwd.net/d6/unsecured/media/270881183/270881183_1858994782_vid-StudioDashboards.jpg?pubId=270881183", "publishedDate"=>"1225134261508", "creationDate"=>"1224096089173", "linkText"=>nil, "economics"=>"AD_SUPPORTED", "referenceId"=>nil, "linkURL"=>nil}], "page_number"=>0, "page_size"=>5, "total_count"=>-1}
32
- >> response = brightcove.post('delete_video', {:video_id => '595153263001'})
33
- => {"result"=>{}, "id"=>nil, "error"=>nil}
22
+ ```ruby
23
+ require 'brightcove-api'
24
+ => true
25
+
26
+ brightcove = Brightcove::API.new('0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.')
27
+ => #<Brightcove::API:0x114dbc8 @token="0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.", @api_url="http://api.brightcove.com/services/library">
28
+
29
+ response = brightcove.get('find_all_videos', {:page_size => 3, :video_fields => 'id,name,linkURL,linkText'})
30
+ => {"items"=>[{"name"=>"Documentarian Skydiving", "id"=>496518762, "linkText"=>nil, "linkURL"=>nil}, {"name"=>"Surface Tricks", "id"=>496518763, "linkText"=>nil, "linkURL"=>nil}, {"name"=>"Free Skiing", "id"=>496518765, "linkText"=>nil, "linkURL"=>nil}], "page_number"=>0, "page_size"=>3, "total_count"=>-1}
31
+
32
+ response = brightcove.get('find_all_videos', {:page_size => 5, :sort_by => 'PLAYS_TOTAL'})
33
+ => {"items"=>[{"longDescription"=>nil, "name"=>"Wild Slopes '06", "lastModifiedDate"=>"1171324523307", "thumbnailURL"=>"http://brightcove.vo.llnwd.net/d2/unsecured/media/270881183/270881183_502534829_94499905676eb7cd04a558da2adcf6a34f437b88.jpg?pubId=270881183", "tags"=>["adventure", "snowboarding"], "playsTrailingWeek"=>35, "shortDescription"=>"A ski and snowboard movie that challenges the hype and dares you to see what freeskiing and snowboarding have become. Documenting the very best of this year's riding and culture.", "playsTotal"=>4458, "adKeys"=>nil, "id"=>496518766, "length"=>51251, "videoStillURL"=>"http://brightcove.vo.llnwd.net/d2/unsecured/media/270881183/270881183_502534838_f80fe64f052328cd3b2e158d7234003a23091845.jpg?pubId=270881183", "publishedDate"=>"1171324434811", "creationDate"=>"1171267200000", "linkText"=>nil, "economics"=>"FREE", "referenceId"=>"title010", "linkURL"=>nil}, {"longDescription"=>nil, "name"=>"Jellyfish", "lastModifiedDate"=>"1245181300374", "thumbnailURL"=>"http://brightcove.vo.llnwd.net/d7/unsecured/media/270881183/270881183_26530711001_jellyFish.jpg?pubId=270881183", "tags"=>["sea", "custom skins"], "playsTrailingWeek"=>46, "shortDescription"=>"Jellyfish", "playsTotal"=>4081, "adKeys"=>nil, "id"=>26512561001, "length"=>28400, "videoStillURL"=>"http://brightcove.vo.llnwd.net/d7/unsecured/media/270881183/270881183_26519430001_vs-270881183-vid26513829001-img0000.jpg?pubId=270881183", "publishedDate"=>"1245172164326", "creationDate"=>"1245172164326", "linkText"=>nil, "economics"=>"AD_SUPPORTED", "referenceId"=>nil, "linkURL"=>nil}, {"longDescription"=>"Long Description", "name"=>"Demo Title 2", "lastModifiedDate"=>"1263581295791", "thumbnailURL"=>"http://brightcove.vo.llnwd.net/d2/unsecured/media/270881183/270881183_275925069_d1f97c7f07f2a3f4de7b38eda3761f16f39d2a99.jpg?pubId=270881183", "tags"=>[], "playsTrailingWeek"=>1, "shortDescription"=>"Short Description", "playsTotal"=>3876, "adKeys"=>nil, "id"=>276024035, "length"=>418742, "videoStillURL"=>"http://brightcove.vo.llnwd.net/d2/unsecured/media/270881183/270881183_275943599_b7e2ca63c0311fa3f0b027304b41d252f12d2d66.jpg?pubId=270881183", "publishedDate"=>"1161296014264", "creationDate"=>"1161241200000", "linkText"=>"Related Link", "economics"=>"FREE", "referenceId"=>nil, "linkURL"=>"http://www.brightcove.com"}, {"longDescription"=>nil, "name"=>"Dolphins", "lastModifiedDate"=>"1263581295790", "thumbnailURL"=>"http://brightcove.vo.llnwd.net/d7/unsecured/media/270881183/270881183_26531197001_dolphins.jpg?pubId=270881183", "tags"=>["sea", "custom skins"], "playsTrailingWeek"=>30, "shortDescription"=>"Dolphins", "playsTotal"=>3870, "adKeys"=>nil, "id"=>26511963001, "length"=>12800, "videoStillURL"=>"http://brightcove.vo.llnwd.net/d7/unsecured/media/270881183/270881183_26519372001_vs-270881183-vid26510372001-img0000.jpg?pubId=270881183", "publishedDate"=>"1245171732987", "creationDate"=>"1245171732987", "linkText"=>nil, "economics"=>"AD_SUPPORTED", "referenceId"=>nil, "linkURL"=>nil}, {"longDescription"=>nil, "name"=>"Welcome to Brightcove 3", "lastModifiedDate"=>"1225134261511", "thumbnailURL"=>"http://brightcove.vo.llnwd.net/d6/unsecured/media/270881183/270881183_1858983740_brightcove3-thumb.jpg?pubId=270881183", "tags"=>[], "playsTrailingWeek"=>0, "shortDescription"=>"Tareef Kawaf, Brightcove's SVP of Engineering, welcomes you to Brightcove 3.", "playsTotal"=>3349, "adKeys"=>nil, "id"=>1858922805, "length"=>53820, "videoStillURL"=>"http://brightcove.vo.llnwd.net/d6/unsecured/media/270881183/270881183_1858994782_vid-StudioDashboards.jpg?pubId=270881183", "publishedDate"=>"1225134261508", "creationDate"=>"1224096089173", "linkText"=>nil, "economics"=>"AD_SUPPORTED", "referenceId"=>nil, "linkURL"=>nil}], "page_number"=>0, "page_size"=>5, "total_count"=>-1}
34
+
35
+ response = brightcove.post('delete_video', {:video_id => '595153263001'})
36
+ => {"result"=>{}, "id"=>nil, "error"=>nil}
37
+ ```
34
38
 
35
39
  If you want to perform a file upload, for example, to create a video, you can use the __post_file()__ method.
36
40
 
37
- >> response = brightcove.post_file('create_video', '/path/to/video.mov', :video => {:shortDescription => 'Short Description', :name => 'Video name'})
38
- => {"result"=>653155417001, "error=>nil, "id"=>nil}
41
+ ```ruby
42
+ response = brightcove.post_file('create_video', '/path/to/video.mov', :video => {:shortDescription => 'Short Description', :name => 'Video name'})
43
+ => {"result"=>653155417001, "error=>nil, "id"=>nil}
44
+ ```
39
45
 
40
46
  If you want to perform a file upload using HTTP streaming, for example, to create a video, you can use the __post_file_streaming()__ method.
41
47
 
42
- >> response = brightcove.post_file_streaming('create_video', '/path/to/video.mov', 'video/quicktime', :video => {:shortDescription => 'Short Description', :name => 'Video name'})
43
- => {"result"=>653155417001, "error=>nil, "id"=>nil}
48
+ ```ruby
49
+ response = brightcove.post_file_streaming('create_video', '/path/to/video.mov', 'video/quicktime', :video => {:shortDescription => 'Short Description', :name => 'Video name'})
50
+ => {"result"=>653155417001, "error=>nil, "id"=>nil}
51
+ ```
52
+
53
+ You can also use the `post_io_streaming(api_method, file, content_type, parameters)` method which takes an I/O handle instead of a filename.
44
54
 
45
55
  You can now pass `{:output => 'mrss'}` in the __get(...)__ method to return output in Media RSS format. Example:
46
56
 
47
- >> response = brightcove.get('find_all_videos', {:output => 'mrss'})
57
+ ```ruby
58
+ response = brightcove.get('find_all_videos', {:output => 'mrss'})
59
+ ```
48
60
 
49
- Searching
50
- =========
61
+ ## Searching
51
62
 
52
63
  To replicate one of the brightcove search API examples:
53
64
 
@@ -55,14 +66,19 @@ To replicate one of the brightcove search API examples:
55
66
  > description, and which also have the tag "free", and also have either the tag "color" or the
56
67
  > tag "technicolor"
57
68
 
58
- >> brightcove = Brightcove::API.new(...)
59
- >> response = brightcove.get('search_videos', {
60
- :any => [ "tag:color", "tag:technicolor" ],
61
- :all => ["football", "chicago", "tag:free"]
62
- })
69
+ ```ruby
70
+ brightcove = Brightcove::API.new(...)
71
+ response = brightcove.get('search_videos', {
72
+ :any => [ "tag:color", "tag:technicolor" ],
73
+ :all => ["football", "chicago", "tag:free"]
74
+ })
75
+ ```
76
+
77
+ ## Compatibility
63
78
 
64
- Note on Patches/Pull Requests
65
- =============================
79
+ The brightcove-api gem is built and tested under Ruby 1.8.7, 1.9.2 and 1.9.3.
80
+
81
+ ## Note on Patches/Pull Requests
66
82
 
67
83
  * Fork the project.
68
84
  * Make your feature addition or bug fix.
@@ -72,6 +88,6 @@ Note on Patches/Pull Requests
72
88
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
73
89
  * Send me a pull request. Bonus points for topic branches.
74
90
 
75
- Copyright
76
- =========
77
- Copyright (c) 2010-2011 David Czarnecki. See LICENSE for details.
91
+ ## Copyright
92
+
93
+ Copyright (c) 2010-2012 David Czarnecki. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,53 +1,15 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'rake'
11
-
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "brightcove-api"
16
- gem.homepage = "http://github.com/BrightcoveOS/Ruby-MAPI-Wrapper"
17
- gem.license = "MIT"
18
- gem.summary = %Q{Ruby gem for interacting with the Brightcove media API}
19
- gem.description = %Q{Ruby gem for interacting with the Brightcove media API. http://docs.brightcove.com/en/media/}
20
- gem.email = "dczarnecki@agoragames.com"
21
- gem.authors = ["David Czarnecki"]
22
- end
23
- Jeweler::RubygemsDotOrgTasks.new
24
-
25
- require 'rake/testtask'
26
- Rake::TestTask.new(:test) do |test|
27
- test.libs << 'lib' << 'test'
28
- test.pattern = 'test/**/test_*.rb'
29
- test.verbose = true
30
- end
31
-
32
- require 'rcov/rcovtask'
33
- Rcov::RcovTask.new do |test|
34
- test.libs << 'test'
35
- test.pattern = 'test/**/test_*.rb'
36
- test.verbose = true
37
- end
38
-
39
- require 'rake/rdoctask'
40
- Rake::RDocTask.new do |rdoc|
41
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core'
3
+ require 'rspec/core/rake_task'
42
4
 
43
- rdoc.rdoc_dir = 'rdoc'
44
- rdoc.title = "brightcove-api #{version}"
45
- rdoc.rdoc_files.include('README*')
46
- rdoc.rdoc_files.include('lib/**/*.rb')
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = FileList['spec/**/*_spec.rb']
7
+ spec.rspec_opts = ['--backtrace']
8
+ # spec.ruby_opts = ['-w']
47
9
  end
48
10
 
49
- task :default => :test_rubies
11
+ task :default => :spec
50
12
 
51
13
  task :test_rubies do
52
- system "rvm 1.8.7@brightcove-api_gem,1.9.2@brightcove-api_gem rake test"
14
+ system "rvm 1.8.7@brightcove-api_gem,1.9.2@brightcove-api_gem,1.9.3@brightcove-api_gem do rake spec"
53
15
  end
@@ -1,80 +1,33 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
5
3
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{brightcove-api}
8
- s.version = "1.0.11"
4
+ require 'brightcove-api/version'
9
5
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{David Czarnecki}]
12
- s.date = %q{2011-09-13}
6
+ Gem::Specification.new do |s|
7
+ s.name = "brightcove-api"
8
+ s.version = Brightcove::API::VERSION.dup
9
+ s.authors = ["David Czarnecki"]
10
+ s.email = ["dczarnecki@agoragames.com"]
11
+ s.homepage = "http://github.com/BrightcoveOS/Ruby-MAPI-Wrapper"
12
+ s.summary = %q{Ruby gem for interacting with the Brightcove media API}
13
13
  s.description = %q{Ruby gem for interacting with the Brightcove media API. http://docs.brightcove.com/en/media/}
14
- s.email = %q{dczarnecki@agoragames.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.md"
18
- ]
19
- s.files = [
20
- ".rvmrc",
21
- "CHANELOG.markdown",
22
- "Gemfile",
23
- "LICENSE",
24
- "README.md",
25
- "Rakefile",
26
- "VERSION",
27
- "brightcove-api.gemspec",
28
- "lib/brightcove-api.rb",
29
- "test/fakeweb/create_video_response.json",
30
- "test/fakeweb/delete_video_response.json",
31
- "test/fakeweb/find_all_videos_response.json",
32
- "test/fakeweb/find_all_videos_response.xml",
33
- "test/fakeweb/movie.mov",
34
- "test/helper.rb",
35
- "test/test_brightcove-api.rb"
36
- ]
37
- s.homepage = %q{http://github.com/BrightcoveOS/Ruby-MAPI-Wrapper}
38
- s.licenses = [%q{MIT}]
39
- s.require_paths = [%q{lib}]
40
- s.rubygems_version = %q{1.8.8}
41
- s.summary = %q{Ruby gem for interacting with the Brightcove media API}
42
- s.test_files = [
43
- "test/helper.rb",
44
- "test/test_brightcove-api.rb"
45
- ]
46
14
 
47
- if s.respond_to? :specification_version then
48
- s.specification_version = 3
15
+ s.rubyforge_project = "brightcove-api"
49
16
 
50
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
- s.add_runtime_dependency(%q<httparty>, [">= 0"])
52
- s.add_runtime_dependency(%q<json>, [">= 0"])
53
- s.add_runtime_dependency(%q<rest-client>, [">= 0"])
54
- s.add_runtime_dependency(%q<multipart-post>, [">= 0"])
55
- s.add_runtime_dependency(%q<orderedhash>, [">= 0"])
56
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
57
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
58
- s.add_development_dependency(%q<rcov>, ["~> 0.9.9"])
59
- else
60
- s.add_dependency(%q<httparty>, [">= 0"])
61
- s.add_dependency(%q<json>, [">= 0"])
62
- s.add_dependency(%q<rest-client>, [">= 0"])
63
- s.add_dependency(%q<multipart-post>, [">= 0"])
64
- s.add_dependency(%q<orderedhash>, [">= 0"])
65
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
67
- s.add_dependency(%q<rcov>, ["~> 0.9.9"])
68
- end
69
- else
70
- s.add_dependency(%q<httparty>, [">= 0"])
71
- s.add_dependency(%q<json>, [">= 0"])
72
- s.add_dependency(%q<rest-client>, [">= 0"])
73
- s.add_dependency(%q<multipart-post>, [">= 0"])
74
- s.add_dependency(%q<orderedhash>, [">= 0"])
75
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
76
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
77
- s.add_dependency(%q<rcov>, ["~> 0.9.9"])
78
- end
79
- end
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
80
21
 
22
+ s.add_dependency('httparty')
23
+ s.add_dependency('json')
24
+ s.add_dependency('rest-client')
25
+ s.add_dependency('multipart-post')
26
+ s.add_dependency('orderedhash')
27
+
28
+ s.add_development_dependency('fakeweb')
29
+ s.add_development_dependency('mocha')
30
+ s.add_development_dependency('rake')
31
+ s.add_development_dependency('rspec')
32
+ s.add_development_dependency('vcr')
33
+ end
@@ -3,14 +3,13 @@ require 'json'
3
3
  require 'rest-client'
4
4
  require 'orderedhash'
5
5
  require 'net/http/post/multipart'
6
+ require 'brightcove-api/version'
6
7
 
7
8
  module Brightcove
8
9
  class API
9
10
  include HTTParty
10
11
  disable_rails_query_string_format
11
12
 
12
- VERSION = '1.0.11'.freeze
13
-
14
13
  DEFAULT_HEADERS = {
15
14
  'User-Agent' => "brightcove-api gem #{VERSION}"
16
15
  }
@@ -29,7 +28,11 @@ module Brightcove
29
28
  # RestClient POST timeout for opening connection
30
29
  attr_accessor :open_timeout
31
30
 
32
- # Initialize with your API token
31
+ # Initialize a new instance of the +Brightcove::API+ using a Brightcove token.
32
+ #
33
+ # @param token [String] Brightcove token which can be a read-only, write or read-write token.
34
+ # @param read_api_url [String] Read API URL or the default of +Brightcove::API::READ_API_URL+.
35
+ # @param write_api_url [String] Write API URL or the default of +Brightcove::API::WRITE_API_URL+.
33
36
  def initialize(token, read_api_url = READ_API_URL, write_api_url = WRITE_API_URL)
34
37
  @token = token
35
38
  @read_api_url = read_api_url
@@ -38,39 +41,44 @@ module Brightcove
38
41
  @open_timeout = nil
39
42
  end
40
43
 
44
+ # Set a location for debug HTTP output to be written to.
45
+ #
46
+ # @param location [Object] Defaults to +$stderr+.
41
47
  def debug(location = $stderr)
42
48
  self.class.debug_output(location)
43
49
  end
44
50
 
51
+ # Set HTTP headers that should be used in API requests. The
52
+ # +Brightcove::API::DEFAULT_HEADERS+ will be merged into the passed-in
53
+ # hash.
54
+ #
55
+ # @param http_headers [Hash] Updated HTTP headers.
45
56
  def set_http_headers(http_headers = {})
46
57
  http_headers.merge!(DEFAULT_HEADERS)
47
58
  headers(http_headers)
48
59
  end
49
60
 
61
+ # Set a timeout for HTTP requests.
62
+ #
63
+ # @param timeout [int] HTTP timeout value.
50
64
  def set_timeout(timeout)
51
65
  default_timeout(timeout)
52
66
  end
53
67
 
54
- def build_query_from_options(api_method, options = {})
55
- # normalize options to a hash
56
- unless options.respond_to?(:merge!)
57
- options = CGI.parse(options)
58
- end
59
-
60
- options.merge!({:command => api_method, :token => @token})
61
- options.merge!({:format => :xml}) if options.key?(:output) && 'mrss'.eql?(options[:output])
62
- { :query => options }
63
- end
64
-
65
- # Call Brightcove using a particular API method, api_method.
66
- # The options parameter can be either a query string or a hash. In either case, it is where
67
- # you can add any parameters appropriate for the API call. If a query string, it will be
68
- # normalized to a hash via CGI.parse.
68
+ # Make an HTTP GET call to the Brightcove API for a particular API method.
69
+ #
70
+ # @param api_method [String] Brightcove API method.
71
+ # @param options [Hash] Optional hash containing parameter names and values. The options
72
+ # parameter can be either a query string or a hash. If a query string, it will be
73
+ # normalized to a hash via CGI.parse.
69
74
  def get(api_method, options = {})
70
75
  self.class.get(@read_api_url, build_query_from_options(api_method, options))
71
76
  end
72
77
 
73
- # Post to Brightcove using a particular API method, api_method. The parameters hash is where you add all the required parameters appropriate for the API call.
78
+ # Make an HTTP POST call to the Brightcove API for a particular API method.
79
+ #
80
+ # @param api_method [String] Brightcove API method.
81
+ # @param parameters [Hash] Optional hash containing parameter names and values.
74
82
  def post(api_method, parameters = {})
75
83
  parameters.merge!({"token" => @token})
76
84
 
@@ -81,6 +89,11 @@ module Brightcove
81
89
  self.class.post(@write_api_url, {:body => {:json => JSON.generate(body)}})
82
90
  end
83
91
 
92
+ # Post a file to the Brightcove API, e.g. uploading video.
93
+ #
94
+ # @param api_method [String] Brightcove API method.
95
+ # @param file [String] Full path of file to be uploaded.
96
+ # @param parameters [Hash] Optional hash containing parameter names and values.
84
97
  def post_file(api_method, file, parameters = {})
85
98
  parameters.merge!({"token" => @token})
86
99
 
@@ -116,7 +129,21 @@ module Brightcove
116
129
  JSON.parse(response)
117
130
  end
118
131
 
132
+ # Post a file via HTTP streaming to the Brightcove API, e.g. uploading video.
133
+ #
134
+ # @param api_method [String] Brightcove API method.
135
+ # @param upload_file [String] Full path of file to be uploaded.
136
+ # @param parameters [Hash] Optional hash containing parameter names and values.
119
137
  def post_file_streaming(api_method, upload_file, content_type, parameters)
138
+ File.open(upload_file) { |file| post_io_streaming(api_method, file, content_type, parameters) }
139
+ end
140
+
141
+ # Post a file IO object via HTTP streaming to the Brightcove API, e.g. uploading video.
142
+ #
143
+ # @param api_method [String] Brightcove API method.
144
+ # @param file [File handle] File handle of file to be uploaded.
145
+ # @param parameters [Hash] Optional hash containing parameter names and values.
146
+ def post_io_streaming(api_method, file, content_type, parameters)
120
147
  parameters.merge!({"token" => @token})
121
148
 
122
149
  body = {}
@@ -133,20 +160,38 @@ module Brightcove
133
160
 
134
161
  url = URI.parse(@write_api_url)
135
162
  response = nil
136
- File.open(upload_file) do |file|
137
- payload[:json] = body.to_json
138
- payload[:file] = UploadIO.new(file, content_type)
139
-
140
- request = Net::HTTP::Post::Multipart.new(url.path, payload)
141
-
142
- response = Net::HTTP.start(url.host, url.port) do |http|
143
- http.read_timeout = @timeout if @timeout
144
- http.open_timeout = @open_timeout if @open_timeout
145
- http.request(request)
146
- end
163
+
164
+ payload[:json] = body.to_json
165
+ payload[:file] = UploadIO.new(file, content_type)
166
+
167
+ request = Net::HTTP::Post::Multipart.new(url.path, payload)
168
+
169
+ response = Net::HTTP.start(url.host, url.port) do |http|
170
+ http.read_timeout = @timeout if @timeout
171
+ http.open_timeout = @open_timeout if @open_timeout
172
+ http.request(request)
147
173
  end
148
174
 
149
175
  JSON.parse(response.body)
150
176
  end
177
+
178
+ private
179
+
180
+ # Build an appropriate query for the Brightcove API given an +api_method+ and +options+.
181
+ # This will also merge in your API token and set the +format+ to XML if +mrss+ has been
182
+ # requested for the +:output+.
183
+ #
184
+ # @param api_method [String] Brightcove API method.
185
+ # @param options [Hash] Optional hash containing parameter names and values.
186
+ def build_query_from_options(api_method, options = {})
187
+ # normalize options to a hash
188
+ unless options.respond_to?(:merge!)
189
+ options = CGI.parse(options)
190
+ end
191
+
192
+ options.merge!({:command => api_method, :token => @token})
193
+ options.merge!({:format => :xml}) if options.key?(:output) && 'mrss'.eql?(options[:output])
194
+ { :query => options }
195
+ end
151
196
  end
152
197
  end