Module: Client
Instance Method Summary collapse
- #create_deploy ⇒ Object
- #create_project ⇒ Object
- #deploy_opts ⇒ Object
- #fetch_projects ⇒ Object
- #options ⇒ Object
- #print_project_response(response) ⇒ Object
- #print_projects ⇒ Object
Instance Method Details
#create_deploy ⇒ Object
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' => .api_key }.merge!(deploy_opts) request.set_form_data(opts) response = http.request(request) puts response. if response.respond_to?(:message) end |
#create_project ⇒ Object
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://#{.account}.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]' => .name,'auth_token' => .auth_token) response = http.request(request) response.body print_project_response(response.body) end |
#deploy_opts ⇒ Object
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}]" => .send(attr)) end opts end |
#fetch_projects ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/airbrake/cli/client.rb', line 10 def fetch_projects uri = URI.parse "http://#{.account}.airbrake.io"\ "/data_api/v1/projects.xml?auth_token=#{.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 |
#options ⇒ Object
6 7 8 |
# File 'lib/airbrake/cli/client.rb', line 6 def Runner. end |
#print_project_response(response) ⇒ Object
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 |
#print_projects ⇒ Object
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 |