Class Heroku::Client
In: lib/heroku/client.rb
Parent: Object

A Ruby class to call the Heroku REST API. You might use this if you want to manage your Heroku apps from within a Ruby program, such as Capistrano.

Example:

  require 'heroku'
  heroku = Heroku::Client.new('me@example.com', 'mypass')
  heroku.create('myapp')

Methods

Attributes

host  [R] 
password  [R] 
user  [R] 

Public Class methods

[Source]

    # File lib/heroku/client.rb, line 18
18:         def initialize(user, password, host='heroku.com')
19:                 @user = user
20:                 @password = password
21:                 @host = host
22:         end

Public Instance methods

Invite a person by email address to collaborate on the app. Optional third parameter can be edit or view.

[Source]

    # File lib/heroku/client.rb, line 70
70:         def add_collaborator(app_name, email, access='view')
71:                 xml(post("/apps/#{app_name}/collaborators", { 'collaborator[email]' => email, 'collaborator[access]' => access }))
72:         end

Add an ssh public key to the current user.

[Source]

    # File lib/heroku/client.rb, line 93
93:         def add_key(key)
94:                 post("/user/keys", key, { 'Content-Type' => 'text/ssh-authkey' })
95:         end

Create a new app, with an optional name.

[Source]

    # File lib/heroku/client.rb, line 40
40:         def create(name=nil, options={})
41:                 params = {}
42:                 params['app[name]'] = name if name
43:                 xml(post('/apps', params)).elements["//app/name"].text
44:         end

Destroy the app permanently.

[Source]

    # File lib/heroku/client.rb, line 55
55:         def destroy(name)
56:                 delete("/apps/#{name}")
57:         end

Show info such as mode, custom domain, and collaborators on an app.

[Source]

    # File lib/heroku/client.rb, line 31
31:         def info(name)
32:                 doc = xml(get("/apps/#{name}"))
33:                 attrs = { :collaborators => list_collaborators(name) }
34:                 doc.elements.to_a('//app/*').inject(attrs) do |hash, element|
35:                         hash[element.name.to_sym] = element.text; hash
36:                 end
37:         end

Get the list of ssh public keys for the current user.

[Source]

    # File lib/heroku/client.rb, line 85
85:         def keys
86:                 doc = xml get('/user/keys')
87:                 doc.elements.to_a('//keys/key').map do |key|
88:                         key.elements['contents'].text
89:                 end
90:         end

Show a list of apps which you are a collaborator on.

[Source]

    # File lib/heroku/client.rb, line 25
25:         def list
26:                 doc = xml(get('/apps'))
27:                 doc.elements.to_a("//apps/app/name").map { |a| a.text }
28:         end

Get a list of collaborators on the app, returns an array of hashes each of which contain :email and :access (=> edit | view) elements.

[Source]

    # File lib/heroku/client.rb, line 61
61:         def list_collaborators(app_name)
62:                 doc = xml(get("/apps/#{app_name}/collaborators"))
63:                 doc.elements.to_a("//collaborators/collaborator").map do |a|
64:                         { :email => a.elements['email'].text, :access => a.elements['access'].text }
65:                 end
66:         end

Run a rake command on the Heroku app.

[Source]

     # File lib/heroku/client.rb, line 108
108:         def rake(app_name, cmd)
109:                 post("/apps/#{app_name}/rake", cmd)
110:         end

Clear all keys on the current user.

[Source]

     # File lib/heroku/client.rb, line 103
103:         def remove_all_keys
104:                 delete("/user/keys")
105:         end

Remove a collaborator.

[Source]

    # File lib/heroku/client.rb, line 80
80:         def remove_collaborator(app_name, email)
81:                 delete("/apps/#{app_name}/collaborators/#{escape(email)}")
82:         end

Remove an existing ssh public key from the current user.

[Source]

     # File lib/heroku/client.rb, line 98
 98:         def remove_key(key)
 99:                 delete("/user/keys/#{escape(key)}")
100:         end

[Source]

     # File lib/heroku/client.rb, line 114
114:         def resource(uri)
115:                 RestClient::Resource.new("http://#{host}", user, password)[uri]
116:         end

Update an app. Available attributes:

  :name => rename the app (changes http and git urls)
  :public => true | false
  :mode => production | development

[Source]

    # File lib/heroku/client.rb, line 50
50:         def update(name, attributes)
51:                 put("/apps/#{name}", :app => attributes)
52:         end

Change an existing collaborator.

[Source]

    # File lib/heroku/client.rb, line 75
75:         def update_collaborator(app_name, email, access)
76:                 put("/apps/#{app_name}/collaborators/#{escape(email)}", { 'collaborator[access]' => access })
77:         end

[Validate]