class VimeoApi::Client

Public Class Methods

new(options = {}) click to toggle source
# File lib/vimeo_api/client.rb, line 4
def initialize(options = {})
  @consumer_key = options[:consumer_key]
  @consumer_secret = options[:consumer_secret]
  @token = options[:token]
  @secret = options[:secret]
  @debug = options[:debug]
  @api_version = options[:api_version] || '3.2'
  @api_host = options[:api_host] || 'api.vimeo.com'
  @redirect_uri = options[:redirect_uri]
end

Public Instance Methods

authorize_url(options={}) click to toggle source
# File lib/vimeo_api/client.rb, line 15
def authorize_url(options={})
  consumer.auth_code.authorize_url(options)
end
get_token(code) click to toggle source
# File lib/vimeo_api/client.rb, line 19
def get_token(code)
  consumer.auth_code.get_token(code, redirect_uri: @redirect_uri)
end

Private Instance Methods

access_token(options={}) click to toggle source
# File lib/vimeo_api/client.rb, line 44
def access_token(options={})
  @access_token ||= OAuth2::AccessToken.new(consumer, @token, options)
end
auth_header() click to toggle source
# File lib/vimeo_api/client.rb, line 25
def auth_header
  if @token.nil? || @token == ''
    auth_header = Base64.strict_encode64("#{@consumer_key}:#{@consumer_secret}")
    "basic #{auth_header}"
  else
    "Bearer #{@token}"
  end
end
consumer(options={}) click to toggle source
# File lib/vimeo_api/client.rb, line 34
def consumer(options={})
  @consumer ||= OAuth2::Client.new(
    @consumer_key,
    @consumer_secret,
    { site: "https://#{@api_host}",
      token_url: "/oauth/access_token"
    }
  )
end
get(path, headers={}) click to toggle source
# File lib/vimeo_api/client.rb, line 48
def get(path, headers={})
  puts "[Client] GET #{path}" if @debug
  headers.merge!(
    "User-Agent" => "vimeo_api gem v#{VimeoApi::VERSION}",
    "Accept" => "application/vnd.vimeo.*+json; version=#{@api_version}",
    'Authorization' => auth_header
  )
  oauth_response = access_token.get("/#{path}", headers)
  parse(oauth_response.body)
end
parse(response_body) click to toggle source

def post(path, body='', headers={})

puts "[Client] POST #{path}" if @debug
headers.merge!("User-Agent" => "twitter_oauth gem v#{VimeoApi::VERSION}")
headers.merge!("Content-Type" => "application/x-www-form-urlencoded\r\n")
oauth_response = access_token.post("/#{@api_version}#{path}", body, headers)
parse(oauth_response.body)

end

def delete(path, headers={})

puts "[Client] DELETE #{path}" if @debug
headers.merge!("User-Agent" => "twitter_oauth gem v#{TwitterOAuth::VERSION}")
oauth_response = access_token.delete("/#{@api_version}#{path}", headers)
parse(oauth_response.body)

end

# File lib/vimeo_api/client.rb, line 74
def parse(response_body)
  begin
    JSON.parse(response_body)
  rescue JSON::ParserError
    {:response => response_body}.to_json
  end
end