brightcove-api 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -5,6 +5,7 @@ Ruby gem for interacting with the Brightcove media API. http://docs.brightcove.c
5
5
  == Requirements
6
6
 
7
7
  * HTTParty
8
+ * JSON
8
9
  * FakeWeb (only for testing)
9
10
 
10
11
  == Install
@@ -21,7 +22,9 @@ Ruby gem for interacting with the Brightcove media API. http://docs.brightcove.c
21
22
  => {"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}
22
23
  >> response = brightcove.get('find_all_videos', {:page_size => 5, :sort_by => 'PLAYS_TOTAL'})
23
24
  => {"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}
24
-
25
+ >> response = brightcove.post('delete_video', {:video_id => '595153263001'})
26
+ => {"result"=>{}, "id"=>nil, "error"=>nil}
27
+
25
28
  == Note on Patches/Pull Requests
26
29
 
27
30
  * Fork the project.
data/Rakefile CHANGED
@@ -12,7 +12,6 @@ begin
12
12
  gem.authors = ["David Czarnecki"]
13
13
  gem.add_dependency('httparty', '0.5.2')
14
14
  gem.add_dependency('fakeweb', '1.2.8')
15
- gem.add_dependency('mocha', '0.9.8')
16
15
  gem.add_dependency('json', '1.2.4')
17
16
  end
18
17
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
@@ -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.1"
8
+ s.version = "1.0.2"
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{2010-09-24}
12
+ s.date = %q{2010-09-25}
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 = [
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  "VERSION",
26
26
  "brightcove-api.gemspec",
27
27
  "lib/brightcove-api.rb",
28
+ "test/fakeweb/delete_video_response.json",
28
29
  "test/fakeweb/find_all_videos_response.json",
29
30
  "test/helper.rb",
30
31
  "test/test_brightcove-api.rb"
@@ -46,18 +47,15 @@ Gem::Specification.new do |s|
46
47
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
48
  s.add_runtime_dependency(%q<httparty>, ["= 0.5.2"])
48
49
  s.add_runtime_dependency(%q<fakeweb>, ["= 1.2.8"])
49
- s.add_runtime_dependency(%q<mocha>, ["= 0.9.8"])
50
50
  s.add_runtime_dependency(%q<json>, ["= 1.2.4"])
51
51
  else
52
52
  s.add_dependency(%q<httparty>, ["= 0.5.2"])
53
53
  s.add_dependency(%q<fakeweb>, ["= 1.2.8"])
54
- s.add_dependency(%q<mocha>, ["= 0.9.8"])
55
54
  s.add_dependency(%q<json>, ["= 1.2.4"])
56
55
  end
57
56
  else
58
57
  s.add_dependency(%q<httparty>, ["= 0.5.2"])
59
58
  s.add_dependency(%q<fakeweb>, ["= 1.2.8"])
60
- s.add_dependency(%q<mocha>, ["= 0.9.8"])
61
59
  s.add_dependency(%q<json>, ["= 1.2.4"])
62
60
  end
63
61
  end
@@ -5,7 +5,7 @@ module Brightcove
5
5
  class API
6
6
  include HTTParty
7
7
 
8
- VERSION = '1.0.1'.freeze
8
+ VERSION = '1.0.2'.freeze
9
9
 
10
10
  DEFAULT_HEADERS = {
11
11
  'User-Agent' => "brightcove-api gem #{VERSION}"
@@ -13,18 +13,22 @@ module Brightcove
13
13
 
14
14
  headers(DEFAULT_HEADERS)
15
15
 
16
- API_URL = 'http://api.brightcove.com/services/library'
16
+ READ_API_URL = 'http://api.brightcove.com/services/library'
17
+ WRITE_API_URL = 'http://api.brightcove.com/services/post'
17
18
 
18
- attr_accessor :api_url
19
+ attr_accessor :read_api_url
20
+ attr_accessor :write_api_url
21
+ attr_accessor :token
19
22
 
20
23
  # Brightcove returns text/html as the Content-Type for a response even though the response is JSON.
21
24
  # So, let's just parse the response as JSON
22
25
  format(:json)
23
26
 
24
27
  # Initialize with your API token
25
- def initialize(token, api_url = API_URL)
28
+ def initialize(token, read_api_url = READ_API_URL, write_api_url = WRITE_API_URL)
26
29
  @token = token
27
- @api_url = api_url
30
+ @read_api_url = read_api_url
31
+ @write_api_url = write_api_url
28
32
  end
29
33
 
30
34
  def debug(location = $stderr)
@@ -44,7 +48,18 @@ module Brightcove
44
48
  query = {}
45
49
  query.merge!({:query => options})
46
50
 
47
- self.class.get(@api_url, query)
48
- end
51
+ self.class.get(@read_api_url, query)
52
+ end
53
+
54
+ # 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.
55
+ def post(api_method, parameters = {})
56
+ parameters.merge!({"token" => @token})
57
+
58
+ body = {}
59
+ body.merge!({:method => api_method})
60
+ body.merge!({:params => parameters})
61
+
62
+ self.class.post(@write_api_url, {:body => {:json => JSON.generate(body)}})
63
+ end
49
64
  end
50
65
  end
@@ -0,0 +1 @@
1
+ {"result":{}, "id":nil, "error":nil}
@@ -12,14 +12,33 @@ class TestBrightcoveApi < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def test_api_version
15
- assert_equal '1.0.1', Brightcove::API::VERSION
15
+ assert_equal '1.0.2', Brightcove::API::VERSION
16
16
  end
17
17
 
18
- def test_can_set_api_url
18
+ def test_can_set_read_api_url
19
19
  brightcove = Brightcove::API.new('apikeytoken')
20
- brightcove.api_url = 'http://some.api.com'
21
20
 
22
- assert_equal 'http://some.api.com', brightcove.api_url
21
+ assert_equal Brightcove::API::READ_API_URL, brightcove.read_api_url
22
+
23
+ brightcove.read_api_url = 'http://some.api.com'
24
+
25
+ assert_equal 'http://some.api.com', brightcove.read_api_url
26
+ end
27
+
28
+ def test_can_set_write_api_url
29
+ brightcove = Brightcove::API.new('apikeytoken')
30
+
31
+ assert_equal Brightcove::API::WRITE_API_URL, brightcove.write_api_url
32
+
33
+ brightcove.write_api_url = 'http://some.api.com'
34
+
35
+ assert_equal 'http://some.api.com', brightcove.write_api_url
36
+ end
37
+
38
+ def test_can_set_token
39
+ brightcove = Brightcove::API.new('apikeytoken')
40
+
41
+ assert_equal 'apikeytoken', brightcove.token
23
42
  end
24
43
 
25
44
  def test_can_set_http_headers
@@ -41,4 +60,17 @@ class TestBrightcoveApi < Test::Unit::TestCase
41
60
  assert_equal 5, brightcove_response['items'].size
42
61
  assert_equal 0, brightcove_response['page_number']
43
62
  end
63
+
64
+ def test_delete_video
65
+ FakeWeb.register_uri(:post,
66
+ 'http://api.brightcove.com/services/post',
67
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'delete_video_response.json'),
68
+ :content_type => "application/json")
69
+
70
+ brightcove = Brightcove::API.new('0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.')
71
+ brightcove_response = brightcove.post('delete_video', {:video_id => '595153261337'})
72
+
73
+ assert brightcove_response.has_key?('result')
74
+ assert_equal brightcove_response['error'], 'nil'
75
+ end
44
76
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brightcove-api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 2
10
+ version: 1.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Czarnecki
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-24 00:00:00 -04:00
18
+ date: 2010-09-25 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -50,26 +50,10 @@ dependencies:
50
50
  version: 1.2.8
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: mocha
55
- prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - "="
60
- - !ruby/object:Gem::Version
61
- hash: 43
62
- segments:
63
- - 0
64
- - 9
65
- - 8
66
- version: 0.9.8
67
- type: :runtime
68
- version_requirements: *id003
69
53
  - !ruby/object:Gem::Dependency
70
54
  name: json
71
55
  prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ requirement: &id003 !ruby/object:Gem::Requirement
73
57
  none: false
74
58
  requirements:
75
59
  - - "="
@@ -81,7 +65,7 @@ dependencies:
81
65
  - 4
82
66
  version: 1.2.4
83
67
  type: :runtime
84
- version_requirements: *id004
68
+ version_requirements: *id003
85
69
  description: Ruby gem for interacting with the Brightcove media API. http://docs.brightcove.com/en/media/
86
70
  email: dczarnecki@agoragames.com
87
71
  executables: []
@@ -100,6 +84,7 @@ files:
100
84
  - VERSION
101
85
  - brightcove-api.gemspec
102
86
  - lib/brightcove-api.rb
87
+ - test/fakeweb/delete_video_response.json
103
88
  - test/fakeweb/find_all_videos_response.json
104
89
  - test/helper.rb
105
90
  - test/test_brightcove-api.rb