Class: Heroku::Postgres::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/heroku/postgres/client.rb

Overview

Client for interacting with Heroku & Heroku’s Postgres API.

Constant Summary collapse

DEFAULT_HEADERS =
{ 'User-Agent' => 'Heroku-Postgres/v' \
"#{Heroku::Postgres::VERSION}" }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
# File 'lib/heroku/postgres/client.rb', line 10

def initialize(opts = {})
  @url = opts.fetch(:url, 'https://api.heroku.com')
  @username = opts.fetch(:username, {})
  @password = opts.fetch(:password, {})
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/heroku/postgres/client.rb', line 8

def password
  @password
end

#tokenObject

Returns the value of attribute token.



8
9
10
# File 'lib/heroku/postgres/client.rb', line 8

def token
  @token
end

#urlObject

Returns the value of attribute url.



8
9
10
# File 'lib/heroku/postgres/client.rb', line 8

def url
  @url
end

#usernameObject

Returns the value of attribute username.



8
9
10
# File 'lib/heroku/postgres/client.rb', line 8

def username
  @username
end

Instance Method Details

#loginString

Login on behalf of the user.

This is necessary to setup the class correctly so that the API key can be used.

Returns:

  • (String)

    the Heroku API key



22
23
24
25
26
27
# File 'lib/heroku/postgres/client.rb', line 22

def 
  response = (username, password)

  hash = JSON.parse(response.body)
  @token = hash['api_key']
end