Class: Wrappi::Endpoint
- Inherits:
-
Object
- Object
- Wrappi::Endpoint
- Defined in:
- lib/wrappi/endpoint.rb
Instance Attribute Summary collapse
-
#input_params ⇒ Object
readonly
Returns the value of attribute input_params.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.around_request(&block) ⇒ Object
AROUND REQUEST.
- .call(*args) ⇒ Object
-
.retry_if(&block) ⇒ Object
RETRY.
Instance Method Summary collapse
- #around_request ⇒ Object
- #body ⇒ Object
-
#cache_key ⇒ Object
Cache.
-
#consummated_params ⇒ Object
overridable.
-
#initialize(input_params = {}, options = {}) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #logger ⇒ Object
- #response ⇒ Object (also: #call)
- #retry_if ⇒ Object
- #status ⇒ Object
- #success? ⇒ Boolean
- #url ⇒ Object
- #url_with_params ⇒ Object
Constructor Details
#initialize(input_params = {}, options = {}) ⇒ Endpoint
Returns a new instance of Endpoint.
19 20 21 22 |
# File 'lib/wrappi/endpoint.rb', line 19 def initialize(input_params = {}, = {}) @input_params = input_params = end |
Instance Attribute Details
#input_params ⇒ Object (readonly)
Returns the value of attribute input_params.
18 19 20 |
# File 'lib/wrappi/endpoint.rb', line 18 def input_params @input_params end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
18 19 20 |
# File 'lib/wrappi/endpoint.rb', line 18 def end |
Class Method Details
.around_request(&block) ⇒ Object
AROUND REQUEST
57 58 59 |
# File 'lib/wrappi/endpoint.rb', line 57 def self.around_request(&block) @around_request = block end |
.call(*args) ⇒ Object
24 25 26 |
# File 'lib/wrappi/endpoint.rb', line 24 def self.call(*args) new(*args).call end |
.retry_if(&block) ⇒ Object
RETRY
65 66 67 |
# File 'lib/wrappi/endpoint.rb', line 65 def self.retry_if(&block) @retry_if = block end |
Instance Method Details
#around_request ⇒ Object
60 61 62 |
# File 'lib/wrappi/endpoint.rb', line 60 def around_request self.class.instance_variable_get(:@around_request) end |
#body ⇒ Object
52 |
# File 'lib/wrappi/endpoint.rb', line 52 def body; response.body end |
#cache_key ⇒ Object
Cache
73 74 75 76 |
# File 'lib/wrappi/endpoint.rb', line 73 def cache_key # TODO: think headers have to be in the key as well @cache_key ||= "[#{verb.to_s.upcase}]##{url}#{params_cache_key}" end |
#consummated_params ⇒ Object
overridable
43 44 45 |
# File 'lib/wrappi/endpoint.rb', line 43 def consummated_params params end |
#logger ⇒ Object
78 79 80 |
# File 'lib/wrappi/endpoint.rb', line 78 def logger client.logger end |
#response ⇒ Object Also known as: call
47 48 49 |
# File 'lib/wrappi/endpoint.rb', line 47 def response @response ||= Executer.call(self) end |
#retry_if ⇒ Object
68 69 70 |
# File 'lib/wrappi/endpoint.rb', line 68 def retry_if self.class.instance_variable_get(:@retry_if) end |
#status ⇒ Object
54 |
# File 'lib/wrappi/endpoint.rb', line 54 def status; response.status end |
#success? ⇒ Boolean
53 |
# File 'lib/wrappi/endpoint.rb', line 53 def success?; response.success? end |
#url ⇒ Object
28 29 30 |
# File 'lib/wrappi/endpoint.rb', line 28 def url _url.to_s end |
#url_with_params ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/wrappi/endpoint.rb', line 32 def url_with_params if verb == :get _url.tap do |u| u.query = URI.encode_www_form(consummated_params) if consummated_params.any? end.to_s else url end end |