Class: HTTParty::Response

Inherits:
Object show all
Defined in:
lib/lock-o-motion/mocks/httparty.rb

Instance Method Summary collapse

Constructor Details

#initialize(response, data, options = {}) ⇒ Response

Returns a new instance of Response.



100
101
102
103
# File 'lib/lock-o-motion/mocks/httparty.rb', line 100

def initialize(response, data, options = {})
  @cached_response = NSCachedURLResponse.alloc.initWithResponse response.value, data: data
  @options = options
end

Instance Method Details

#codeObject



116
117
118
# File 'lib/lock-o-motion/mocks/httparty.rb', line 116

def code
  @cached_response.response.statusCode
end

#ok?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/lock-o-motion/mocks/httparty.rb', line 120

def ok?
  code.to_s.match /^20\d$/
end

#parsed_responseObject



105
106
107
108
109
110
111
112
113
114
# File 'lib/lock-o-motion/mocks/httparty.rb', line 105

def parsed_response
  @parsed_response ||= begin
    case @options[:format]
    when :json
      NSJSONSerialization.JSONObjectWithData @cached_response.data, options: NSJSONReadingMutableContainers, error: nil
    else
      NSString.alloc.initWithData @cached_response.data, encoding: NSUTF8StringEncoding
    end
  end
end