Class: SmartyStreets::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload, status_code, header = nil, error = nil) ⇒ Response

Returns a new instance of Response.



5
6
7
8
9
10
# File 'lib/smartystreets_ruby_sdk/response.rb', line 5

def initialize(payload, status_code, header = nil, error = nil)
  @payload = payload
  @status_code = status_code
  @header = header
  @error = error
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



3
4
5
# File 'lib/smartystreets_ruby_sdk/response.rb', line 3

def error
  @error
end

#headerObject

Returns the value of attribute header.



3
4
5
# File 'lib/smartystreets_ruby_sdk/response.rb', line 3

def header
  @header
end

#payloadObject

Returns the value of attribute payload.



3
4
5
# File 'lib/smartystreets_ruby_sdk/response.rb', line 3

def payload
  @payload
end

#status_codeObject

Returns the value of attribute status_code.



3
4
5
# File 'lib/smartystreets_ruby_sdk/response.rb', line 3

def status_code
  @status_code
end

Instance Method Details

#find_header(name) ⇒ Object

Case-insensitive lookup that works on both plain Hash (used by mocks) and Net::HTTPResponse (returned by the live HTTP transport, which exposes each_header but not each_pair).



15
16
17
18
19
20
21
22
23
# File 'lib/smartystreets_ruby_sdk/response.rb', line 15

def find_header(name)
  return nil if @header.nil?
  target = name.to_s.downcase
  iterator = @header.respond_to?(:each_header) ? :each_header : :each_pair
  @header.send(iterator) do |k, v|
    return v if k.to_s.downcase == target
  end
  nil
end