Sha256: 87f906d5e1e83b8fcfdba24cb87662339071002d0a6eafc505ba06eaf54ff1cb

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

require 'httparty'
require 'json'

module Brightcove
  class API
    include HTTParty
    
    VERSION = '1.0.1'.freeze
    
    DEFAULT_HEADERS = {
      'User-Agent' => "brightcove-api gem #{VERSION}"
    }
    
    headers(DEFAULT_HEADERS)
        
    API_URL = 'http://api.brightcove.com/services/library'
    
    attr_accessor :api_url
        
    # Brightcove returns text/html as the Content-Type for a response even though the response is JSON.
    # So, let's just parse the response as JSON
    format(:json)
    
    # Initialize with your API token  
    def initialize(token, api_url = API_URL)
      @token = token
      @api_url = api_url
    end
    
    def debug(location = $stderr)
      self.class.debug_output(location)
    end
        
    def set_http_headers(http_headers = {})
      http_headers.merge!(DEFAULT_HEADERS)
      headers(http_headers)
    end
    
    # Call Brightcove using a particular API method, api_method. The options hash is where you can add any parameters appropriate for the API call.
    def get(api_method, options = {})
      options.merge!({:command => api_method})
      options.merge!({:token => @token})

      query = {}
      query.merge!({:query => options})
            
      self.class.get(@api_url, query)
    end    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
brightcove-api-1.0.1 lib/brightcove-api.rb