class Dogapi::Service
DEPRECATED: Going forward, use the newer APIService
.
Public Class Methods
new(api_key, api_host=Dogapi.find_datadog_host)
click to toggle source
DEPRECATED: Going forward, use the newer APIService
.
# File lib/dogapi/common.rb 40 def initialize(api_key, api_host=Dogapi.find_datadog_host) 41 @api_key = api_key 42 @host = api_host 43 end
Public Instance Methods
connect() { |conn| ... }
click to toggle source
DEPRECATED: Going forward, use the newer APIService
.
# File lib/dogapi/common.rb 46 def connect 47 warn '[DEPRECATION] Dogapi::Service has been deprecated in favor of the newer V1 services' 48 uri = URI.parse(@host) 49 session = Net::HTTP.new(uri.host, uri.port) 50 if 'https' == uri.scheme 51 session.use_ssl = true 52 end 53 session.start do |conn| 54 yield(conn) 55 end 56 end
request(method, url, params)
click to toggle source
DEPRECATED: Going forward, use the newer APIService
.
# File lib/dogapi/common.rb 59 def request(method, url, params) 60 warn '[DEPRECATION] Dogapi::Service has been deprecated in favor of the newer V1 services' 61 if !params.has_key? :api_key 62 params[:api_key] = @api_key 63 end 64 65 resp_obj = nil 66 connect do |conn| 67 req = method.new(url) 68 req.set_form_data params 69 resp = conn.request(req) 70 begin 71 resp_obj = MultiJson.load(resp.body) 72 rescue 73 raise 'Invalid JSON Response: ' + resp.body 74 end 75 76 if resp_obj.has_key? 'error' 77 request_string = params.pretty_inspect 78 error_string = resp_obj['error'] 79 raise "Failed request\n#{request_string}#{error_string}" 80 end 81 end 82 resp_obj 83 end