class DogapiDemo::Service

DEPRECATED: Going forward, use the newer APIService.

Public Class Methods

new(api_key, api_host=DogapiDemo.find_datadog_host) click to toggle source

DEPRECATED: Going forward, use the newer APIService.

   # File lib/dogapi-demo/common.rb
24 def initialize(api_key, api_host=DogapiDemo.find_datadog_host)
25   @api_key = api_key
26   @host = api_host
27 end

Public Instance Methods

connect() { |conn| ... } click to toggle source

DEPRECATED: Going forward, use the newer APIService.

   # File lib/dogapi-demo/common.rb
30 def connect
31   warn "[DEPRECATION] DogapiDemo::Service has been deprecated in favor of the newer V1 services"
32   uri = URI.parse(@host)
33   session = Net::HTTP.new(uri.host, uri.port)
34   if 'https' == uri.scheme
35     session.use_ssl = true
36   end
37   session.start do |conn|
38     yield(conn)
39   end
40 end
request(method, url, params) click to toggle source

DEPRECATED: Going forward, use the newer APIService.

   # File lib/dogapi-demo/common.rb
43 def request(method, url, params)
44   warn "[DEPRECATION] DogapiDemo::Service has been deprecated in favor of the newer V1 services"
45   if !params.has_key? :api_key
46     params[:api_key] = @api_key
47   end
48 
49   resp_obj = nil
50   connect do |conn|
51     req = method.new(url)
52     req.set_form_data params
53     resp = conn.request(req)
54     begin
55       resp_obj = MultiJson.load(resp.body)
56     rescue
57       raise 'Invalid JSON Response: ' + resp.body
58     end
59 
60     if resp_obj.has_key? 'error'
61       request_string = params.pretty_inspect
62       error_string = resp_obj['error']
63       raise "Failed request\n#{request_string}#{error_string}"
64     end
65   end
66   resp_obj
67 end