brightcove-api 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 David Czarnecki
1
+ Copyright (c) 2010 David Czarnecki (Agora Games)
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.rdoc CHANGED
@@ -1,7 +1,27 @@
1
1
  = brightcove-api
2
2
 
3
- Description goes here.
3
+ Ruby gem for interacting with the Brightcove media API. http://docs.brightcove.com/en/media/
4
4
 
5
+ == Requirements
6
+
7
+ * HTTParty
8
+ * FakeWeb (only for testing)
9
+
10
+ == Install
11
+
12
+ * sudo gem install brightcove-api
13
+
14
+ == Example
15
+
16
+ >> require 'brightcove-api'
17
+ => true
18
+ >> brightcove = Brightcove::API.new('0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.')
19
+ => #<Brightcove::API:0x114dbc8 @token="0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.", @api_url="http://api.brightcove.com/services/library">
20
+ >> response = brightcove.get('find_all_videos', {:page_size => 3, :video_fields => 'id,name,linkURL,linkText'})
21
+ => {"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
+ >> response = brightcove.get('find_all_videos', {:page_size => 5, :sort_by => 'PLAYS_TOTAL'})
23
+ => {"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
+
5
25
  == Note on Patches/Pull Requests
6
26
 
7
27
  * Fork the project.
data/Rakefile CHANGED
@@ -12,6 +12,8 @@ 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
+ gem.add_dependency('json', '1.2.4')
15
17
  end
16
18
  Jeweler::GemcutterTasks.new
17
19
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{brightcove-api}
8
+ s.version = "1.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["David Czarnecki"]
12
+ s.date = %q{2010-09-24}
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.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "brightcove-api.gemspec",
27
+ "lib/brightcove-api.rb",
28
+ "test/fakeweb/find_all_videos_response.json",
29
+ "test/helper.rb",
30
+ "test/test_brightcove-api.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/agoragames/brightcove}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.7}
36
+ s.summary = %q{Ruby gem for interacting with the Brightcove media API}
37
+ s.test_files = [
38
+ "test/helper.rb",
39
+ "test/test_brightcove-api.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<httparty>, ["= 0.5.2"])
48
+ s.add_runtime_dependency(%q<fakeweb>, ["= 1.2.8"])
49
+ s.add_runtime_dependency(%q<mocha>, ["= 0.9.8"])
50
+ s.add_runtime_dependency(%q<json>, ["= 1.2.4"])
51
+ else
52
+ s.add_dependency(%q<httparty>, ["= 0.5.2"])
53
+ s.add_dependency(%q<fakeweb>, ["= 1.2.8"])
54
+ s.add_dependency(%q<mocha>, ["= 0.9.8"])
55
+ s.add_dependency(%q<json>, ["= 1.2.4"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<httparty>, ["= 0.5.2"])
59
+ s.add_dependency(%q<fakeweb>, ["= 1.2.8"])
60
+ s.add_dependency(%q<mocha>, ["= 0.9.8"])
61
+ s.add_dependency(%q<json>, ["= 1.2.4"])
62
+ end
63
+ end
64
+
@@ -1,16 +1,21 @@
1
1
  require 'httparty'
2
+ require 'json'
2
3
 
3
4
  module Brightcove
4
5
  class API
5
6
  include HTTParty
6
7
 
7
- VERSION = '1.0.0'.freeze
8
+ VERSION = '1.0.1'.freeze
8
9
 
9
10
  DEFAULT_HEADERS = {
10
11
  'User-Agent' => "brightcove-api gem #{VERSION}"
11
12
  }
13
+
14
+ headers(DEFAULT_HEADERS)
12
15
 
13
16
  API_URL = 'http://api.brightcove.com/services/library'
17
+
18
+ attr_accessor :api_url
14
19
 
15
20
  # Brightcove returns text/html as the Content-Type for a response even though the response is JSON.
16
21
  # So, let's just parse the response as JSON
@@ -25,8 +30,13 @@ module Brightcove
25
30
  def debug(location = $stderr)
26
31
  self.class.debug_output(location)
27
32
  end
33
+
34
+ def set_http_headers(http_headers = {})
35
+ http_headers.merge!(DEFAULT_HEADERS)
36
+ headers(http_headers)
37
+ end
28
38
 
29
- # Call Brightcove using a particular API method. The options hash is where you can add any parameters appropriate for the API call.
39
+ # Call Brightcove using a particular API method, api_method. The options hash is where you can add any parameters appropriate for the API call.
30
40
  def get(api_method, options = {})
31
41
  options.merge!({:command => api_method})
32
42
  options.merge!({:token => @token})
@@ -0,0 +1,108 @@
1
+ { "items" : [ { "adKeys" : null,
2
+ "creationDate" : "1171267200000",
3
+ "economics" : "FREE",
4
+ "id" : 496518762,
5
+ "lastModifiedDate" : "1263581295791",
6
+ "length" : 111077,
7
+ "linkText" : null,
8
+ "linkURL" : null,
9
+ "longDescription" : null,
10
+ "name" : "Documentarian Skydiving",
11
+ "playsTotal" : 906,
12
+ "playsTrailingWeek" : 4,
13
+ "publishedDate" : "1171324433253",
14
+ "referenceId" : "title006",
15
+ "shortDescription" : "Thrill seekers document their adventure, from the door of the plane all the way to the ground.",
16
+ "tags" : [ "adventure",
17
+ "base jumping"
18
+ ],
19
+ "thumbnailURL" : "http://brightcove.vo.llnwd.net/d2/unsecured/media/270881183/270881183_502534822_86408e4e20580f7bf0b41c82be8ca9f4b95fb055.jpg?pubId=270881183",
20
+ "videoStillURL" : "http://brightcove.vo.llnwd.net/d2/unsecured/media/270881183/270881183_502534831_9c1e5fe9c3e95ca5009e7ceb68df2915ff669774.jpg?pubId=270881183"
21
+ },
22
+ { "adKeys" : null,
23
+ "creationDate" : "1171267200000",
24
+ "economics" : "FREE",
25
+ "id" : 496518763,
26
+ "lastModifiedDate" : "1250624757582",
27
+ "length" : 70337,
28
+ "linkText" : null,
29
+ "linkURL" : null,
30
+ "longDescription" : null,
31
+ "name" : "Surface Tricks",
32
+ "playsTotal" : 3253,
33
+ "playsTrailingWeek" : 28,
34
+ "publishedDate" : "1225126643431",
35
+ "referenceId" : "surface",
36
+ "shortDescription" : "Instructions on how to do the most common snowboarding tricks that are performed on the ground.",
37
+ "tags" : [ "adventure",
38
+ "snowboarding"
39
+ ],
40
+ "thumbnailURL" : "http://brightcove.vo.llnwd.net/d5/unsecured/media/270881183/270881183_34465519001_asset-1250624757285.jpg?pubId=270881183",
41
+ "videoStillURL" : "http://brightcove.vo.llnwd.net/d5/unsecured/media/270881183/270881183_34465520001_asset-1250624757522.jpg?pubId=270881183"
42
+ },
43
+ { "adKeys" : null,
44
+ "creationDate" : "1171267200000",
45
+ "economics" : "FREE",
46
+ "id" : 496518765,
47
+ "lastModifiedDate" : "1205689028256",
48
+ "length" : 11611,
49
+ "linkText" : null,
50
+ "linkURL" : null,
51
+ "longDescription" : null,
52
+ "name" : "Free Skiing",
53
+ "playsTotal" : 2471,
54
+ "playsTrailingWeek" : 15,
55
+ "publishedDate" : "1171324434490",
56
+ "referenceId" : "title009",
57
+ "shortDescription" : "Hot dog skiing of the 1970s has begun a new life as Freeskiing. Often referred to as New School, Freeride, Park Skiing or Slopestyle, Freeskiing boasts of innovative young skiers who quest for something more extreme and radical than the norm.",
58
+ "tags" : [ "adventure",
59
+ "snowboarding"
60
+ ],
61
+ "thumbnailURL" : "http://brightcove.vo.llnwd.net/d5/unsecured/media/270881183/270881183_1459169541_b317544d5275ab9df2d3030da2f8cbefde8fbdea.jpg?pubId=270881183",
62
+ "videoStillURL" : "http://brightcove.vo.llnwd.net/d5/unsecured/media/270881183/270881183_1459169542_55bfa4b674d1d31c469b91af71d8e81baad2ab32.jpg?pubId=270881183"
63
+ },
64
+ { "adKeys" : null,
65
+ "creationDate" : "1171267200000",
66
+ "economics" : "FREE",
67
+ "id" : 496518766,
68
+ "lastModifiedDate" : "1171324523307",
69
+ "length" : 51251,
70
+ "linkText" : null,
71
+ "linkURL" : null,
72
+ "longDescription" : null,
73
+ "name" : "Wild Slopes '06",
74
+ "playsTotal" : 4458,
75
+ "playsTrailingWeek" : 35,
76
+ "publishedDate" : "1171324434811",
77
+ "referenceId" : "title010",
78
+ "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.",
79
+ "tags" : [ "adventure",
80
+ "snowboarding"
81
+ ],
82
+ "thumbnailURL" : "http://brightcove.vo.llnwd.net/d2/unsecured/media/270881183/270881183_502534829_94499905676eb7cd04a558da2adcf6a34f437b88.jpg?pubId=270881183",
83
+ "videoStillURL" : "http://brightcove.vo.llnwd.net/d2/unsecured/media/270881183/270881183_502534838_f80fe64f052328cd3b2e158d7234003a23091845.jpg?pubId=270881183"
84
+ },
85
+ { "adKeys" : null,
86
+ "creationDate" : "1161241200000",
87
+ "economics" : "FREE",
88
+ "id" : 276024035,
89
+ "lastModifiedDate" : "1263581295791",
90
+ "length" : 418742,
91
+ "linkText" : "Related Link",
92
+ "linkURL" : "http://www.brightcove.com",
93
+ "longDescription" : "Long Description",
94
+ "name" : "Demo Title 2",
95
+ "playsTotal" : 3876,
96
+ "playsTrailingWeek" : 1,
97
+ "publishedDate" : "1161296014264",
98
+ "referenceId" : null,
99
+ "shortDescription" : "Short Description",
100
+ "tags" : [ ],
101
+ "thumbnailURL" : "http://brightcove.vo.llnwd.net/d2/unsecured/media/270881183/270881183_275925069_d1f97c7f07f2a3f4de7b38eda3761f16f39d2a99.jpg?pubId=270881183",
102
+ "videoStillURL" : "http://brightcove.vo.llnwd.net/d2/unsecured/media/270881183/270881183_275943599_b7e2ca63c0311fa3f0b027304b41d252f12d2d66.jpg?pubId=270881183"
103
+ }
104
+ ],
105
+ "page_number" : 0,
106
+ "page_size" : 5,
107
+ "total_count" : -1
108
+ }
@@ -1,5 +1,6 @@
1
1
  require 'helper'
2
2
  require 'fakeweb'
3
+ require 'mocha'
3
4
 
4
5
  class TestBrightcoveApi < Test::Unit::TestCase
5
6
  def setup
@@ -10,6 +11,24 @@ class TestBrightcoveApi < Test::Unit::TestCase
10
11
  FakeWeb.allow_net_connect = true
11
12
  end
12
13
 
14
+ def test_api_version
15
+ assert_equal '1.0.1', Brightcove::API::VERSION
16
+ end
17
+
18
+ def test_can_set_api_url
19
+ brightcove = Brightcove::API.new('apikeytoken')
20
+ brightcove.api_url = 'http://some.api.com'
21
+
22
+ assert_equal 'http://some.api.com', brightcove.api_url
23
+ end
24
+
25
+ def test_can_set_http_headers
26
+ brightcove = Brightcove::API.new('apikeytoken')
27
+ brightcove.expects(:headers).at_least_once
28
+
29
+ brightcove.set_http_headers({'Accept' => 'application/json'})
30
+ end
31
+
13
32
  def test_find_all_videos
14
33
  FakeWeb.register_uri(:get,
15
34
  'http://api.brightcove.com/services/library?page_size=5&token=0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.&command=find_all_videos',
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brightcove-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ hash: 21
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 1
10
+ version: 1.0.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - David Czarnecki
@@ -9,29 +15,73 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-07-29 00:00:00 -04:00
18
+ date: 2010-09-24 00:00:00 -04:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: httparty
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - "="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 0
32
+ - 5
33
+ - 2
23
34
  version: 0.5.2
24
- version:
35
+ type: :runtime
36
+ version_requirements: *id001
25
37
  - !ruby/object:Gem::Dependency
26
38
  name: fakeweb
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
30
42
  requirements:
31
43
  - - "="
32
44
  - !ruby/object:Gem::Version
45
+ hash: 15
46
+ segments:
47
+ - 1
48
+ - 2
49
+ - 8
33
50
  version: 1.2.8
34
- version:
51
+ type: :runtime
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
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - "="
76
+ - !ruby/object:Gem::Version
77
+ hash: 23
78
+ segments:
79
+ - 1
80
+ - 2
81
+ - 4
82
+ version: 1.2.4
83
+ type: :runtime
84
+ version_requirements: *id004
35
85
  description: Ruby gem for interacting with the Brightcove media API. http://docs.brightcove.com/en/media/
36
86
  email: dczarnecki@agoragames.com
37
87
  executables: []
@@ -48,7 +98,9 @@ files:
48
98
  - README.rdoc
49
99
  - Rakefile
50
100
  - VERSION
101
+ - brightcove-api.gemspec
51
102
  - lib/brightcove-api.rb
103
+ - test/fakeweb/find_all_videos_response.json
52
104
  - test/helper.rb
53
105
  - test/test_brightcove-api.rb
54
106
  has_rdoc: true
@@ -61,21 +113,27 @@ rdoc_options:
61
113
  require_paths:
62
114
  - lib
63
115
  required_ruby_version: !ruby/object:Gem::Requirement
116
+ none: false
64
117
  requirements:
65
118
  - - ">="
66
119
  - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
67
123
  version: "0"
68
- version:
69
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
+ none: false
70
126
  requirements:
71
127
  - - ">="
72
128
  - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
73
132
  version: "0"
74
- version:
75
133
  requirements: []
76
134
 
77
135
  rubyforge_project:
78
- rubygems_version: 1.3.5
136
+ rubygems_version: 1.3.7
79
137
  signing_key:
80
138
  specification_version: 3
81
139
  summary: Ruby gem for interacting with the Brightcove media API