Module: Client

Extended by:
Client
Included in:
Client
Defined in:
lib/airbrake/cli/client.rb

Instance Method Summary collapse

Instance Method Details

#create_deployObject



31
32
33
34
35
36
37
38
39
# File 'lib/airbrake/cli/client.rb', line 31

def create_deploy
  uri = URI.parse "http://airbrake.io/deploys.txt"
  http = Net::HTTP.new(uri.host,uri.port)
  request = Net::HTTP::Post.new(uri.request_uri)
  opts = { 'api_key' => options.api_key }.merge!(deploy_opts)
  request.set_form_data(opts)
  response = http.request(request)
  puts response.message if response.respond_to?(:message)
end

#create_projectObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/airbrake/cli/client.rb', line 19

def create_project
  uri = URI.parse "http://#{options.}.airbrake.io"\
  "/data_api/v1/projects.xml"
  http = Net::HTTP.new(uri.host,uri.port)
  request = Net::HTTP::Post.new(uri.request_uri)
  request.set_form_data('project[name]' => options.name,'auth_token' => options.auth_token)
  response = http.request(request)
  response.body

  print_project_response(response.body)
end

#deploy_optsObject



41
42
43
44
45
46
47
# File 'lib/airbrake/cli/client.rb', line 41

def deploy_opts
  opts = {}
  ['rails_env', 'scm_revision', 'scm_repository', 'local_username'].each do |attr|
    opts.merge!("deploy[#{attr}]" => options.send(attr))
  end
  opts
end

#fetch_projectsObject



10
11
12
13
14
15
16
17
# File 'lib/airbrake/cli/client.rb', line 10

def fetch_projects
  uri = URI.parse "http://#{options.}.airbrake.io"\
  "/data_api/v1/projects.xml?auth_token=#{options.auth_token}"
  http = Net::HTTP.new(uri.host,uri.port)
  request = Net::HTTP::Get.new(uri.request_uri)
  response = http.request(request)
  response.body
end

#optionsObject



6
7
8
# File 'lib/airbrake/cli/client.rb', line 6

def options
  Runner.options
end


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/airbrake/cli/client.rb', line 61

def print_project_response(response)
  case response
  when /errors/
    puts "Error creating project: #{response.gsub("\n","").scan(/.*<error[^>]*>(.*?)<\/error>.*/).last.first.gsub(/\s{1,}/," ")}"
  when /project/
    project = Project.new(:id => response[/<id[^>]*>(.*?)<\/id>/,1],
                          :name => response[/<name[^>]*>(.*?)<\/name>/,1],
                          :api_key => response[/<api-key[^>]*>(.*?)<\/api-key>/,1])
    puts "\nProject details\n" + "".rjust(63,"#")
    puts project
  else
    puts "Unexpected error. Please try again!\n"
    puts response
  end
end


49
50
51
52
53
54
55
56
57
58
59
# File 'lib/airbrake/cli/client.rb', line 49

def print_projects
  factory = ProjectFactory.new
  projects = fetch_projects
  factory.create_projects_from_xml(projects)
  abort "No projects were fetched. Did you provide the correct auth token?" if projects.match(/error/m)
  puts "\nProjects\n" + "".rjust(63,"#")
  factory.projects.each do |project|
    puts project
  end
  puts
end