Class: Wrappi::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/wrappi/endpoint.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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 = {}, options = {})
  @input_params = input_params
  @options = options
end

Instance Attribute Details

#input_paramsObject (readonly)

Returns the value of attribute input_params.



18
19
20
# File 'lib/wrappi/endpoint.rb', line 18

def input_params
  @input_params
end

#optionsObject (readonly)

Returns the value of attribute options.



18
19
20
# File 'lib/wrappi/endpoint.rb', line 18

def options
  @options
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_requestObject



60
61
62
# File 'lib/wrappi/endpoint.rb', line 60

def around_request
  self.class.instance_variable_get(:@around_request)
end

#bodyObject



52
# File 'lib/wrappi/endpoint.rb', line 52

def body; response.body end

#cache_keyObject

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_paramsObject

overridable



43
44
45
# File 'lib/wrappi/endpoint.rb', line 43

def consummated_params
  params
end

#loggerObject



78
79
80
# File 'lib/wrappi/endpoint.rb', line 78

def logger
  client.logger
end

#responseObject Also known as: call



47
48
49
# File 'lib/wrappi/endpoint.rb', line 47

def response
  @response ||= Executer.call(self)
end

#retry_ifObject



68
69
70
# File 'lib/wrappi/endpoint.rb', line 68

def retry_if
  self.class.instance_variable_get(:@retry_if)
end

#statusObject



54
# File 'lib/wrappi/endpoint.rb', line 54

def status; response.status end

#success?Boolean

Returns:

  • (Boolean)


53
# File 'lib/wrappi/endpoint.rb', line 53

def success?; response.success? end

#urlObject



28
29
30
# File 'lib/wrappi/endpoint.rb', line 28

def url
  _url.to_s
end

#url_with_paramsObject



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