Module: HoptoadTasks

Defined in:
lib/hoptoad_tasks.rb

Overview

Capistrano tasks for notifying Hoptoad of deploys

Class Method Summary collapse

Class Method Details

.deploy(opts = {}) ⇒ Object

Alerts Hoptoad of a deploy.

Parameters:

  • opts (Hash) (defaults to: {})

    Data about the deploy that is set to Hoptoad

Options Hash (opts):

  • :rails_env (String)

    Environment of the deploy (production, staging)

  • :scm_revision (String)

    The given revision/sha that is being deployed

  • :scm_repository (String)

    Address of your repository to help with code lookups

  • :local_username (String)

    Who is deploying



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/hoptoad_tasks.rb', line 16

def self.deploy(opts = {})
  if HoptoadNotifier.configuration.api_key.blank?
    puts "I don't seem to be configured with an API key.  Please check your configuration."
    return false
  end

  if opts[:rails_env].blank?
    puts "I don't know to which Rails environment you are deploying (use the TO=production option)."
    return false
  end

  params = {'api_key' => opts.delete(:api_key) ||
                           HoptoadNotifier.configuration.api_key}
  opts.each {|k,v| params["deploy[#{k}]"] = v }

  url = URI.parse("http://#{HoptoadNotifier.configuration.host || 'hoptoadapp.com'}/deploys.txt")

  proxy = Net::HTTP.Proxy(HoptoadNotifier.configuration.proxy_host,
                          HoptoadNotifier.configuration.proxy_port,
                          HoptoadNotifier.configuration.proxy_user,
                          HoptoadNotifier.configuration.proxy_pass)

  response = proxy.post_form(url, params)

  puts response.body
  return Net::HTTPSuccess === response
end