Class: Heroku::Command::Periscope

Inherits:
BaseWithApp
  • Object
show all
Defined in:
lib/heroku-periscope/version.rb,
lib/heroku/command/periscope.rb

Constant Summary collapse

VERSION =
"0.0.3"
DEFAULT_PERISCOPE_HOST =
"https://www.periscope.io"

Instance Method Summary collapse

Instance Method Details

#indexObject



54
55
56
# File 'lib/heroku/command/periscope.rb', line 54

def index
  puts "Welcome to Periscope! Usage: heroku periscope:set_password my_password"
end

#set_passwordObject



8
9
10
11
12
13
14
15
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
43
44
45
46
47
48
49
50
51
52
# File 'lib/heroku/command/periscope.rb', line 8

def set_password
  db_url = api.get_config_vars(app).body['DATABASE_URL']
  
  password, host, verbose = parse_args(args)
  periscope_host = host || DEFAULT_PERISCOPE_HOST

  if password.nil?
    puts " !    Error: Periscope needs a Password. Usage: heroku periscope:set_password my_password"
  else
    begin
      begin
        uri_scheme = URI.split(periscope_host)[0]
      rescue Exception => e
        uri_scheme = ''
      end
      periscope_host = "http://#{periscope_host}" unless uri_scheme == 'http' or uri_scheme == 'https'
      uri = URI.join(periscope_host, "/welcome/heroku_direct_setup")
      
      http = Net::HTTP.new(uri.host, uri.port)
      http.use_ssl = true if uri.scheme == 'https'
      
      if periscope_host != DEFAULT_PERISCOPE_HOST and http.use_ssl?
        puts " !    Warning: Using HTTPS with a custom Periscope host is insecure."
      end
      
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE if periscope_host != DEFAULT_PERISCOPE_HOST
      request = Net::HTTP::Post.new(uri.request_uri)
      request.set_form_data({
        'site_url'     => "#{app}.herokuapp.com",
        'password'     => password,
        'database_url' => db_url
      })
      http.request(request)
      puts "Success! Login at #{periscope_host} with site #{app}.herokuapp.com to use Periscope."
    rescue Exception => e
      puts " !    Error: Could not connect to Periscope. Please ensure that you are connected " +
        "to the internet and that you've banished all gremlins from your workstation."
      if verbose
        puts "Error details:"
        puts "#{e}"
        puts e.backtrace.join("\n")
      end
    end
  end
end