module PlatformAPI

Ruby HTTP client for the Heroku API.

Constants

SCHEMA
VERSION

Public Class Methods

connect(api_key, options=nil) click to toggle source

Get a Client configured to use HTTP Basic or header-based authentication.

@param api_key [String] The API key to use when connecting. @param options [Hash<Symbol,String>] Optionally, custom settings

to use with the client.  Allowed options are `default_headers`,
`cache`, `user` and `url`.

@return [Client] A client configured to use the API with HTTP Basic

or header-based authentication.
# File lib/platform-api/client.rb, line 23
def self.connect(api_key, options=nil)
  options = custom_options(options)
  uri = URI.parse(options[:url])

  if options[:user]
    uri.user = URI.encode_www_form_component options[:user]
  end

  if api_key
    uri.user ||= 'user'
    uri.password = api_key
  end

  client = Heroics.client_from_schema(SCHEMA, uri.to_s, options)
  Client.new(client)
end
connect_oauth(oauth_token, options=nil) click to toggle source

Get a Client configured to use OAuth authentication.

@param oauth_token [String] The OAuth token to use with the API. @param options [Hash<Symbol,String>] Optionally, custom settings

to use with the client.  Allowed options are `default_headers`,
`cache` and `url`.

@return [Client] A client configured to use the API with OAuth

authentication.
# File lib/platform-api/client.rb, line 48
def self.connect_oauth(oauth_token, options=nil)
  options = custom_options(options)
  url = options[:url]
  client = Heroics.oauth_client_from_schema(oauth_token, SCHEMA, url, options)
  Client.new(client)
end
connect_token(token, options=nil) click to toggle source

Get a Client configured to use Token authentication.

@param token [String] The token to use with the API. @param options [Hash<Symbol,String>] Optionally, custom settings

to use with the client.  Allowed options are `default_headers`,
`cache` and `url`.

@return [Client] A client configured to use the API with OAuth

authentication.
# File lib/platform-api/client.rb, line 63
def self.connect_token(token, options=nil)
  options = custom_options(options)
  url = options[:url]
  client = Heroics.token_client_from_schema(token, SCHEMA, url, options)
  Client.new(client)
end
rate_throttle() click to toggle source

Get access to the rate throttling class object for configuration.

# File lib/platform-api.rb, line 15
def self.rate_throttle
  @rate_throttle
end
rate_throttle=(rate_throttle) click to toggle source
# File lib/platform-api.rb, line 7
def self.rate_throttle=(rate_throttle)
  @rate_throttle = rate_throttle
  Heroics.default_configuration do |config|
    config.rate_throttle = @rate_throttle
  end
end

Private Class Methods

custom_options(options) click to toggle source

Get customized options.

# File lib/platform-api/client.rb, line 71
def self.custom_options(options)
  return default_options if options.nil?

  final_options = default_options
  if options[:default_headers]
    final_options[:default_headers].merge!(options[:default_headers])
  end
  final_options[:cache] = options[:cache] || Moneta.new(:File, dir: "#{Dir.home}/.heroics/platform-api")
  final_options[:url] = options[:url] if options[:url]
  final_options[:user] = options[:user] if options[:user]
  final_options
end
default_options() click to toggle source

Get the default options.

# File lib/platform-api/client.rb, line 85
def self.default_options
  default_headers = {"Accept"=>"application/vnd.heroku+json; version=3", "User-Agent"=>"platform-api/3.3.0"}
  {
    default_headers: default_headers,
    url:             "https://api.heroku.com"
  }
end