Class: Codeland::Starter::Integrations::Heroku

Inherits:
Object
  • Object
show all
Defined in:
lib/codeland/starter/integrations/heroku.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHeroku

Returns a new instance of Heroku.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/codeland/starter/integrations/heroku.rb', line 10

def initialize
  token = if Configuration['heroku']
            Configuration['heroku']['oauth_token']
          else
            yaml = Starter.config.yaml
            message = "Missing heroku key in #{yaml}"
            missing_config(message)
          end
  @app = {}
  @success = false
  @api = PlatformAPI.connect_oauth(token)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



8
9
10
# File 'lib/codeland/starter/integrations/heroku.rb', line 8

def app
  @app
end

Instance Method Details

#createObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/codeland/starter/integrations/heroku.rb', line 28

def create
  begin
    @app = create_app(Starter.name)
    @success = true
  rescue Excon::Errors::Unauthorized
    yaml = Starter.config.yaml
    missing_config("Please verify the Heroku oauth key in #{yaml}")
  rescue Excon::Errors::UnprocessableEntity
    @app = create_random_app
    @success = true
  ensure
    if success?
      add_git_remote
      add_collaborators
    end
  end
end

#outputObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/codeland/starter/integrations/heroku.rb', line 46

def output
  if success?
    puts <<-MESSAGE.gsub(/^\s{12}/, '')
    Heroku created with
    URL: #{app['web_url']}
    Git remote: #{app['git_url']}
    MESSAGE
  else
    puts 'heroku failed'
    puts app
  end
end

#performObject



23
24
25
26
# File 'lib/codeland/starter/integrations/heroku.rb', line 23

def perform
  create
  output
end