Class: ZAWS::Sumoapi::SumoClient
- Inherits:
-
Object
- Object
- ZAWS::Sumoapi::SumoClient
- Defined in:
- lib/zaws/external/sumoapi/sumo_client.rb
Instance Method Summary collapse
- #delete(path, options = {}) ⇒ Object
-
#get(path, query = {}, options = {}) ⇒ Object
Make a GET request expecting a JSON response.
-
#initialize(creds) ⇒ SumoClient
constructor
A new instance of SumoClient.
- #json_request(method, path, options = {}) ⇒ Object
-
#post(path, body, options = {}) ⇒ Object
Make a POST request expecting a JSON response.
-
#put(path, body, options = {}) ⇒ Object
Make a PUT request expecting a JSON response.
- #request(method, path, options = {}) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(creds) ⇒ SumoClient
Returns a new instance of SumoClient.
11 12 13 |
# File 'lib/zaws/external/sumoapi/sumo_client.rb', line 11 def initialize(creds) @creds = creds end |
Instance Method Details
#delete(path, options = {}) ⇒ Object
39 40 41 42 |
# File 'lib/zaws/external/sumoapi/sumo_client.rb', line 39 def delete(path, = {}) [:idempotent] = true json_request('DELETE', path, ) end |
#get(path, query = {}, options = {}) ⇒ Object
Make a GET request expecting a JSON response.
20 21 22 23 24 25 |
# File 'lib/zaws/external/sumoapi/sumo_client.rb', line 20 def get(path, query = {}, = {}) # Handle nil or empty Array [:query] = query.to_h if query [:idempotent] = true json_request('GET', path, ) end |
#json_request(method, path, options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/zaws/external/sumoapi/sumo_client.rb', line 44 def json_request(method, path, = {}) if [:body] && ![:body].instance_of?(String) [:body] = [:body].to_json end [:headers] ||= {} [:headers]['Content-Type'] = 'application/json' response = request(method, path, ) JSON.parse(response.body) if (response.body.length > 0 && response.headers['content-type'].match(/json/)) end |
#post(path, body, options = {}) ⇒ Object
Make a POST request expecting a JSON response.
28 29 30 31 |
# File 'lib/zaws/external/sumoapi/sumo_client.rb', line 28 def post(path, body, = {}) [:body] = body json_request('POST', path, ) end |
#put(path, body, options = {}) ⇒ Object
Make a PUT request expecting a JSON response.
34 35 36 37 |
# File 'lib/zaws/external/sumoapi/sumo_client.rb', line 34 def put(path, body, = {}) [:body] = body json_request('PUT', path, ) end |
#request(method, path, options = {}) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/zaws/external/sumoapi/sumo_client.rb', line 54 def request(method, path, = {}) connection = Excon.new(@creds.url, :user => "#{@creds.access_id}", :password => "#{@creds.access_key}") [:expects] ||= [200] [:method] = method [:path] = path connection.request() end |
#url ⇒ Object
15 16 17 |
# File 'lib/zaws/external/sumoapi/sumo_client.rb', line 15 def url @creds.url end |