Module: AlertLogic::RestMethods
- Included in:
- Client
- Defined in:
- lib/alert_logic/client/rest_methods.rb
Overview
RestMethods mixin for Client class
Instance Method Summary collapse
- #create(resource_type, payload) ⇒ Object
-
#delete(resource_type, resource_id) ⇒ Object
Standard REST methods.
- #get(resource_type, resource_id, params = {}) ⇒ Object (also: #retrieve)
- #list(resource_type, params = {}) ⇒ Object
- #post(resource_type, resource_id, payload) ⇒ Object (also: #edit)
- #put(resource_type, resource_id, payload) ⇒ Object (also: #replace)
Instance Method Details
#create(resource_type, payload) ⇒ Object
54 55 56 |
# File 'lib/alert_logic/client/rest_methods.rb', line 54 def create(resource_type, payload) post(resource_type, nil, payload) end |
#delete(resource_type, resource_id) ⇒ Object
Standard REST methods
5 6 7 8 9 10 11 |
# File 'lib/alert_logic/client/rest_methods.rb', line 5 def delete(resource_type, resource_id) parse_response_for(resource_type) do @connection.delete do |request| request.url "#{pluralize(resource_type)}/#{resource_id}" end end end |
#get(resource_type, resource_id, params = {}) ⇒ Object Also known as: retrieve
13 14 15 16 17 18 19 20 21 |
# File 'lib/alert_logic/client/rest_methods.rb', line 13 def get(resource_type, resource_id, params = {}) parse_response_for(resource_type) do base_url = pluralize(resource_type) @connection.get do |request| request.url resource_id ? "#{base_url}/#{resource_id}" : base_url params.each { |k, v| request.params[k] = v } end end end |
#list(resource_type, params = {}) ⇒ Object
50 51 52 |
# File 'lib/alert_logic/client/rest_methods.rb', line 50 def list(resource_type, params = {}) get(resource_type, nil, params) end |
#post(resource_type, resource_id, payload) ⇒ Object Also known as: edit
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/alert_logic/client/rest_methods.rb', line 23 def post(resource_type, resource_id, payload) parse_response_for(resource_type) do base_url = pluralize(resource_type) @connection.post do |request| request.url resource_id ? "#{base_url}/#{resource_id}" : base_url request.body = payload.to_json request.headers['Content-Type'] = 'application/json' end end end |
#put(resource_type, resource_id, payload) ⇒ Object Also known as: replace
34 35 36 37 38 39 40 41 42 |
# File 'lib/alert_logic/client/rest_methods.rb', line 34 def put(resource_type, resource_id, payload) parse_response_for(resource_type) do @connection.put do |request| request.url "#{pluralize(resource_type)}/#{resource_id}" request.body = payload.to_json request.headers['Content-Type'] = 'application/json' end end end |