Class: Brightcove::API
- Inherits:
-
Object
- Object
- Brightcove::API
- Includes:
- HTTParty
- Defined in:
- lib/brightcove-api.rb
Constant Summary collapse
- VERSION =
'1.0.2'.freeze
- DEFAULT_HEADERS =
{ 'User-Agent' => "brightcove-api gem #{VERSION}" }
- READ_API_URL =
'http://api.brightcove.com/services/library'
- WRITE_API_URL =
'http://api.brightcove.com/services/post'
Instance Attribute Summary collapse
-
#read_api_url ⇒ Object
Returns the value of attribute read_api_url.
-
#token ⇒ Object
Returns the value of attribute token.
-
#write_api_url ⇒ Object
Returns the value of attribute write_api_url.
Instance Method Summary collapse
- #debug(location = $stderr) ⇒ Object
-
#get(api_method, options = {}) ⇒ Object
Call Brightcove using a particular API method, api_method.
-
#initialize(token, read_api_url = READ_API_URL, write_api_url = WRITE_API_URL) ⇒ API
constructor
Initialize with your API token.
-
#post(api_method, parameters = {}) ⇒ Object
Post to Brightcove using a particular API method, api_method.
- #set_http_headers(http_headers = {}) ⇒ Object
Constructor Details
#initialize(token, read_api_url = READ_API_URL, write_api_url = WRITE_API_URL) ⇒ API
Initialize with your API token
28 29 30 31 32 |
# File 'lib/brightcove-api.rb', line 28 def initialize(token, read_api_url = READ_API_URL, write_api_url = WRITE_API_URL) @token = token @read_api_url = read_api_url @write_api_url = write_api_url end |
Instance Attribute Details
#read_api_url ⇒ Object
Returns the value of attribute read_api_url.
19 20 21 |
# File 'lib/brightcove-api.rb', line 19 def read_api_url @read_api_url end |
#token ⇒ Object
Returns the value of attribute token.
21 22 23 |
# File 'lib/brightcove-api.rb', line 21 def token @token end |
#write_api_url ⇒ Object
Returns the value of attribute write_api_url.
20 21 22 |
# File 'lib/brightcove-api.rb', line 20 def write_api_url @write_api_url end |
Instance Method Details
#debug(location = $stderr) ⇒ Object
34 35 36 |
# File 'lib/brightcove-api.rb', line 34 def debug(location = $stderr) self.class.debug_output(location) end |
#get(api_method, options = {}) ⇒ Object
Call Brightcove using a particular API method, api_method. The options hash is where you can add any parameters appropriate for the API call.
44 45 46 47 48 49 50 51 52 |
# File 'lib/brightcove-api.rb', line 44 def get(api_method, = {}) .merge!({:command => api_method}) .merge!({:token => @token}) query = {} query.merge!({:query => }) self.class.get(@read_api_url, query) end |
#post(api_method, parameters = {}) ⇒ Object
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 56 57 58 59 60 61 62 63 |
# File 'lib/brightcove-api.rb', line 55 def post(api_method, parameters = {}) parameters.merge!({"token" => @token}) body = {} body.merge!({:method => api_method}) body.merge!({:params => parameters}) self.class.post(@write_api_url, {:body => {:json => JSON.generate(body)}}) end |
#set_http_headers(http_headers = {}) ⇒ Object
38 39 40 41 |
# File 'lib/brightcove-api.rb', line 38 def set_http_headers(http_headers = {}) http_headers.merge!(DEFAULT_HEADERS) headers(http_headers) end |