Class: Morpheus::SecondaryRestInterface
- Inherits:
-
APIClient
- Object
- APIClient
- Morpheus::SecondaryRestInterface
show all
- Defined in:
- lib/morpheus/api/secondary_rest_interface.rb
Overview
Interface class to be subclassed by interfaces that provide CRUD endpoints
for objects underneath another resource
Subclasses must override the base_path(parent_id) method
Instance Method Summary
collapse
-
#base_path(parent_id) ⇒ Object
subclasses should override in your interface Example: "/api/things/#parent_id/widgets".
-
#create(parent_id, payload, params = {}, headers = {}) ⇒ Object
-
#destroy(parent_id, id, params = {}, headers = {}) ⇒ Object
-
#get(parent_id, id, params = {}, headers = {}) ⇒ Object
-
#list(parent_id, params = {}, headers = {}) ⇒ Object
-
#update(parent_id, id, payload, params = {}, headers = {}) ⇒ Object
Instance Method Details
#base_path(parent_id) ⇒ Object
subclasses should override in your interface
Example: "/api/things/#parent_id/widgets"
10
11
12
|
# File 'lib/morpheus/api/secondary_rest_interface.rb', line 10
def base_path(parent_id)
raise "#{self.class} has not defined base_path(parent_id)!"
end
|
#create(parent_id, payload, params = {}, headers = {}) ⇒ Object
25
26
27
28
|
# File 'lib/morpheus/api/secondary_rest_interface.rb', line 25
def create(parent_id, payload, params={}, ={})
validate_id!(parent_id)
execute(method: :post, url: "#{base_path(parent_id)}", params: params, payload: payload, headers: )
end
|
#destroy(parent_id, id, params = {}, headers = {}) ⇒ Object
36
37
38
39
40
|
# File 'lib/morpheus/api/secondary_rest_interface.rb', line 36
def destroy(parent_id, id, params = {}, ={})
validate_id!(parent_id)
validate_id!(id)
execute(method: :delete, url: "#{base_path(parent_id)}/#{CGI::escape(id.to_s)}", params: params, headers: )
end
|
#get(parent_id, id, params = {}, headers = {}) ⇒ Object
19
20
21
22
23
|
# File 'lib/morpheus/api/secondary_rest_interface.rb', line 19
def get(parent_id, id, params={}, ={})
validate_id!(parent_id)
validate_id!(id)
execute(method: :get, url: "#{base_path(parent_id)}/#{CGI::escape(id.to_s)}", params: params, headers: )
end
|
#list(parent_id, params = {}, headers = {}) ⇒ Object
14
15
16
17
|
# File 'lib/morpheus/api/secondary_rest_interface.rb', line 14
def list(parent_id, params={}, ={})
validate_id!(parent_id)
execute(method: :get, url: "#{base_path(parent_id)}", params: params, headers: )
end
|
#update(parent_id, id, payload, params = {}, headers = {}) ⇒ Object
30
31
32
33
34
|
# File 'lib/morpheus/api/secondary_rest_interface.rb', line 30
def update(parent_id, id, payload, params={}, ={})
validate_id!(parent_id)
validate_id!(id)
execute(method: :put, url: "#{base_path(parent_id)}/#{CGI::escape(id.to_s)}", params: params, payload: payload, headers: )
end
|