Class: InvisibleCollector::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/invisible_collector/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, content) ⇒ Response

Returns a new instance of Response.



7
8
9
10
# File 'lib/invisible_collector/response.rb', line 7

def initialize(response, content)
  @success = response.success?
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



5
6
7
# File 'lib/invisible_collector/response.rb', line 5

def content
  @content
end

Instance Method Details

#error?Boolean

true if the request failed for some reason

Returns:

  • (Boolean)


15
16
17
# File 'lib/invisible_collector/response.rb', line 15

def error?
  !@success
end

#presenceObject

Returns the content of the response if the request was successful otherwise return nil. response.presence is equivalent to

response.present? ? response.content : nil

Returns:

  • Depends on the actual request made.



26
27
28
# File 'lib/invisible_collector/response.rb', line 26

def presence
  @content if success?
end

#success?Boolean

true if the request was executed successfully

Returns:

  • (Boolean)


33
34
35
# File 'lib/invisible_collector/response.rb', line 33

def success?
  @success
end