module SendSonar::Client

Public Class Methods

delete(url, payload, headers={}, &block) click to toggle source
# File lib/send_sonar/client.rb, line 8
def self.delete(url, payload, headers={}, &block)
  execute_with_exceptions { RestClient::Request.execute(:method => :delete, :url => url, :payload => payload, :headers => headers, &block) }
end
execute_with_exceptions() { || ... } click to toggle source
# File lib/send_sonar/client.rb, line 16
def self.execute_with_exceptions
  yield

  rescue Errno::ECONNREFUSED => e
    raise ConnectionRefused.new(e)

  rescue RestClient::RequestTimeout => e
    raise RequestTimeout.new(e)

  rescue RestClient::Exception => e
    if e.http_code == 400
      raise BadRequest.new(e)
    else
      response = e.response && JSON.parse(e.response) || {}
      error = response["error"]
      if exception_class = Exceptions::EXCEPTIONS_MAP[error]
        raise exception_class.new(e)
      else
        raise "SONAR ERROR: #{e.response} - #{e.message}"
      end
    end
end
get(url, headers={}, &block) click to toggle source
# File lib/send_sonar/client.rb, line 12
def self.get(url, headers={}, &block)
  execute_with_exceptions { RestClient::Request.execute(:method => :get, :url => url, :headers => headers, &block) }
end
post(url, payload, headers={}, &block) click to toggle source
# File lib/send_sonar/client.rb, line 4
def self.post(url, payload, headers={}, &block)
  execute_with_exceptions { RestClient::Request.execute(:method => :post, :url => url, :payload => payload, :headers => headers, &block) }
end