Class: Brightcove::API

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_urlObject

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

#tokenObject

Returns the value of attribute token.



21
22
23
# File 'lib/brightcove-api.rb', line 21

def token
  @token
end

#write_api_urlObject

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, options = {})
  options.merge!({:command => api_method})
  options.merge!({:token => @token})

  query = {}
  query.merge!({:query => options})
        
  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