Class: HTTParty::Response

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Response.



108
109
110
111
# File 'lib/motion-bundler/mocks/httparty.rb', line 108

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

Instance Method Details

#codeObject



124
125
126
# File 'lib/motion-bundler/mocks/httparty.rb', line 124

def code
  @cached_response.response.statusCode
end

#ok?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/motion-bundler/mocks/httparty.rb', line 128

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

#parsed_responseObject



113
114
115
116
117
118
119
120
121
122
# File 'lib/motion-bundler/mocks/httparty.rb', line 113

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