Class: Hawkei::APIResource
- Inherits:
-
HawkeiObject
- Object
- HawkeiObject
- Hawkei::APIResource
- Defined in:
- lib/hawkei/api_resource.rb
Overview
Hawkei API Resource
Define the API requests methods
Instance Attribute Summary
Attributes inherited from HawkeiObject
#data, #errors, #raw, #successful
Class Method Summary collapse
-
.class_name ⇒ String
The class name.
-
.request(method, path, payload = {}, options = {}) ⇒ Hash
Send a request to the API.
-
.resource_name ⇒ String
Resource name.
-
.resource_path(path = nil) ⇒ String
Resource path.
Instance Method Summary collapse
-
#request(method, resource_path, payload = {}, options = {}) ⇒ Hash
Send a request to the API.
-
#resource_name ⇒ String
Resource name.
-
#resource_path(path = nil) ⇒ String
Resource path.
Methods inherited from HawkeiObject
#[], #[]=, #add_data, #initialize, initialize_from, #inspect, #keys, #load_response_api, #method_missing, #to_hash, #to_json, #type_from_string_object, #update_attributes, #update_from
Constructor Details
This class inherits a constructor from Hawkei::HawkeiObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Hawkei::HawkeiObject
Class Method Details
.class_name ⇒ String
Returns the class name.
49 50 51 |
# File 'lib/hawkei/api_resource.rb', line 49 def class_name name.split('::')[-1] end |
.request(method, path, payload = {}, options = {}) ⇒ Hash
Send a request to the API
rubocop:disable Metrics/AbcSize
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/hawkei/api_resource.rb', line 64 def request(method, path, payload = {}, = {}) payload[:sent_at] = Time.now.utc.iso8601(3) payload = Util.deep_obfuscate_value(payload, configurations.) url_params = Util.encode_parameters(payload) if method == :get uri = build_endpoint_url(path, url_params) = Util.compact( method: method, url: uri.to_s, payload: payload.to_json, proxy: configurations.proxy_url, use_ssl: configurations.http_secure ).merge(headers()).merge() Request.execute().body rescue Hawkei::RequestError => error return error.http_body if error.http_status == 422 raise end |
.resource_name ⇒ String
Returns resource name.
43 44 45 |
# File 'lib/hawkei/api_resource.rb', line 43 def resource_name Util.underscore("#{class_name}s") end |
.resource_path(path = nil) ⇒ String
Returns resource path.
37 38 39 |
# File 'lib/hawkei/api_resource.rb', line 37 def resource_path(path = nil) "/api/#{configurations.api_version}/#{path || @resource_name || CGI.escape(resource_name)}" end |
Instance Method Details
#request(method, resource_path, payload = {}, options = {}) ⇒ Hash
Send a request to the API
29 30 31 |
# File 'lib/hawkei/api_resource.rb', line 29 def request(method, resource_path, payload = {}, = {}) self.class.request(method, resource_path, payload, ) end |
#resource_name ⇒ String
Returns resource name.
9 10 11 |
# File 'lib/hawkei/api_resource.rb', line 9 def resource_name self.class.resource_name end |
#resource_path(path = nil) ⇒ String
Returns resource path.
15 16 17 |
# File 'lib/hawkei/api_resource.rb', line 15 def resource_path(path = nil) self.class.resource_path(path) end |