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.



114
115
116
117
# File 'lib/motion-bundler/mocks/httparty.rb', line 114

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

Instance Method Details

#codeObject



130
131
132
# File 'lib/motion-bundler/mocks/httparty.rb', line 130

def code
  @cached_response.response.statusCode
end

#ok?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/motion-bundler/mocks/httparty.rb', line 134

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

#parsed_responseObject



119
120
121
122
123
124
125
126
127
128
# File 'lib/motion-bundler/mocks/httparty.rb', line 119

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