Class: HTTParty::Response
Instance Method Summary collapse
- #code ⇒ Object
-
#initialize(response, data, options = {}) ⇒ Response
constructor
A new instance of Response.
- #ok? ⇒ Boolean
- #parsed_response ⇒ Object
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, = {}) @cached_response = NSCachedURLResponse.alloc.initWithResponse response.value, data: data @options = end |
Instance Method Details
#code ⇒ Object
116 117 118 |
# File 'lib/lock-o-motion/mocks/httparty.rb', line 116 def code @cached_response.response.statusCode end |
#ok? ⇒ Boolean
120 121 122 |
# File 'lib/lock-o-motion/mocks/httparty.rb', line 120 def ok? code.to_s.match /^20\d$/ end |
#parsed_response ⇒ Object
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 |