Class: EML::UK::APIResource
- Inherits:
-
Object
- Object
- EML::UK::APIResource
- Extended by:
- T::Sig
- Defined in:
- lib/eml/uk/api_resource.rb
Instance Method Summary collapse
-
#initialize(id: nil) ⇒ APIResource
constructor
A new instance of APIResource.
- #request(action, endpoint = "", payload: {}, params: {}) ⇒ Object
Constructor Details
#initialize(id: nil) ⇒ APIResource
Returns a new instance of APIResource.
15 16 17 18 19 |
# File 'lib/eml/uk/api_resource.rb', line 15 def initialize(id: nil) @id = T.let(id, T.nilable(String)) @headers = T.let(nil, T.nilable(T::Hash[String, String])) @credentials = T.let(nil, T.nilable(T::Hash[Symbol, String])) end |
Instance Method Details
#request(action, endpoint = "", payload: {}, params: {}) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/eml/uk/api_resource.rb', line 29 def request(action, endpoint = "", payload: {}, params: {}) payload = EML::UK::Payload.convert(self.class, endpoint, payload) params = EML::UK::Parameters.convert(self.class, endpoint, params) url = resource_url(endpoint) response = HTTP.headers(headers). public_send(action, url, json: payload.to_h, params: params.to_h) response_class(endpoint).new(response, id: @id) end |