class ZAWS::Sumoapi::SumoClient
Public Class Methods
new(creds)
click to toggle source
@param [SumoClient::Creds] creds
# File lib/zaws/external/sumoapi/sumo_client.rb, line 11 def initialize(creds) @creds = creds end
Public Instance Methods
delete(path, options = {})
click to toggle source
# File lib/zaws/external/sumoapi/sumo_client.rb, line 39 def delete(path, options = {}) options[:idempotent] = true json_request('DELETE', path, options) end
get(path, query = {}, options = {})
click to toggle source
Make a GET request expecting a JSON response.
# File lib/zaws/external/sumoapi/sumo_client.rb, line 20 def get(path, query = {}, options = {}) # Handle nil or empty Array options[:query] = query.to_h if query options[:idempotent] = true json_request('GET', path, options) end
json_request(method, path, options = {})
click to toggle source
# File lib/zaws/external/sumoapi/sumo_client.rb, line 44 def json_request(method, path, options = {}) if options[:body] && !options[:body].instance_of?(String) options[:body] = options[:body].to_json end options[:headers] ||= {} options[:headers]['Content-Type'] = 'application/json' response = request(method, path, options) JSON.parse(response.body) if (response.body.length > 0 && response.headers['content-type'].match(/json/)) end
post(path, body, options = {})
click to toggle source
Make a POST request expecting a JSON response.
# File lib/zaws/external/sumoapi/sumo_client.rb, line 28 def post(path, body, options = {}) options[:body] = body json_request('POST', path, options) end
put(path, body, options = {})
click to toggle source
Make a PUT request expecting a JSON response.
# File lib/zaws/external/sumoapi/sumo_client.rb, line 34 def put(path, body, options = {}) options[:body] = body json_request('PUT', path, options) end
request(method, path, options = {})
click to toggle source
# File lib/zaws/external/sumoapi/sumo_client.rb, line 54 def request(method, path, options = {}) connection = Excon.new(@creds.url, :user => "#{@creds.access_id}", :password => "#{@creds.access_key}") options[:expects] ||= [200] options[:method] = method options[:path] = path connection.request(options) end
url()
click to toggle source
# File lib/zaws/external/sumoapi/sumo_client.rb, line 15 def url @creds.url end