class Ubr::API

Public Class Methods

authorize(client_id:, code:, secret:, redirect_uri:) click to toggle source
# File lib/ubr/api.rb, line 28
def self.authorize(client_id:, code:, secret:, redirect_uri:)
  client = RestClient::Resource.new('https://login.uber.com/oauth/token')
  parse_response client.post(
    client_secret: secret,
    client_id: client_id,
    grant_type: 'authorization_code',
    redirect_uri: redirect_uri,
    code: code,
  )
end
new() click to toggle source
# File lib/ubr/api.rb, line 7
def initialize
  token = File.read(API.token_path).strip
  @client = RestClient::Resource.new('https://api.uber.com/v1',
    headers: {
      authorization: "Bearer #{token}",
      content_type: 'application/json'
    }
  )
end
parse_response(response) click to toggle source
# File lib/ubr/api.rb, line 25
def self.parse_response(response)
  JSON.parse response, symbolize_names: true
end
token_path() click to toggle source
# File lib/ubr/api.rb, line 38
def self.token_path
  File.expand_path('~/.ubr')
end

Public Instance Methods

get(path, params={}) click to toggle source
# File lib/ubr/api.rb, line 16
def get(path, params={})
  parse_response @client[path].get(params: params)
end
parse_response(response) click to toggle source
# File lib/ubr/api.rb, line 22
def parse_response(response)
  API.parse_response(response)
end
post(path, params={}) click to toggle source
# File lib/ubr/api.rb, line 19
def post(path, params={})
  parse_response @client[path].post(params.to_json)
end