Module: PlatformAPI

Defined in:
lib/platform-api.rb,
lib/platform-api/client.rb,
lib/platform-api/version.rb

Overview

Ruby HTTP client for the Heroku API.

Defined Under Namespace

Classes: Account, AccountFeature, Addon, AddonService, App, AppFeature, AppTransfer, Build, BuildResult, Client, Collaborator, ConfigVar, Domain, Dyno, Formation, Key, LogDrain, LogSession, OauthAuthorization, OauthClient, OauthGrant, OauthToken, Organization, OrganizationApp, OrganizationAppCollaborator, OrganizationMember, Plan, RateLimit, Region, Release, SSLEndpoint, Slug, Stack

Constant Summary collapse

VERSION =
'0.0.9'

Class Method Summary collapse

Class Method Details

.connect(username, password, headers = nil) ⇒ Client

Get a Client configured to use HTTP Basic authentication.

Parameters:

  • username (String)

    The username to use with the API.

  • password (String)

    The password to use with the API.

  • headers (Hash<String,String>) (defaults to: nil)

    Optionally, custom to headers to include with every response.

Returns:

  • (Client)

    A client configured to use the API with HTTP Basic authentication.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/platform-api/client.rb', line 20

def self.connect(username, password, headers=nil)
  url = URI.parse("https://api.heroku.com")
  url.user = username
  url.password = password
  default_headers = {"Accept"=>"application/vnd.heroku+json; version=3"}
  unless headers.nil?
    default_headers.merge!(headers)
  end
  cache = Moneta.new(:File, dir: "#{Dir.home}/.heroics/platform-api")
  options = {
    default_headers: default_headers,
              cache: cache
  }
  client = Heroics.client_from_schema(SCHEMA, url.to_s, options)
  Client.new(client)
end

.connect_oauth(oauth_token, headers = nil) ⇒ Client

Get a Client configured to use OAuth authentication.

Parameters:

  • oauth_token (String)

    The OAuth token to use with the API.

  • headers (Hash<String,String>) (defaults to: nil)

    Optionally, custom to headers to include with every response.

Returns:

  • (Client)

    A client configured to use the API with OAuth authentication.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/platform-api/client.rb', line 44

def self.connect_oauth(oauth_token, headers=nil)
  url = "https://api.heroku.com"
  default_headers = {"Accept"=>"application/vnd.heroku+json; version=3"}
  unless headers.nil?
    default_headers.merge!(headers)
  end
  cache = Moneta.new(:File, dir: "#{Dir.home}/.heroics/platform-api")
  options = {
    default_headers: default_headers,
              cache: cache
  }
  client = Heroics.oauth_client_from_schema(oauth_token, SCHEMA, url, options)
  Client.new(client)
end

.connect_token(token, headers = nil) ⇒ Client

Get a Client configured to use Token authentication.

Parameters:

  • token (String)

    The token to use with the API.

  • headers (Hash<String,String>) (defaults to: nil)

    Optionally, custom to headers to include with every response.

Returns:

  • (Client)

    A client configured to use the API with OAuth authentication.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/platform-api/client.rb', line 66

def self.connect_token(token, headers=nil)
  url = "https://api.heroku.com"
  default_headers = {"Accept"=>"application/vnd.heroku+json; version=3"}
  unless headers.nil?
    default_headers.merge!(headers)
  end
  cache = Moneta.new(:File, dir: "#{Dir.home}/.heroics/platform-api")
  options = {
    default_headers: default_headers,
              cache: cache
  }
  client = Heroics.token_client_from_schema(token, SCHEMA, url, options)
  Client.new(client)
end