Class: Coop::APIObject
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- Coop::APIObject
- Defined in:
- lib/coop/api_object.rb
Class Method Summary collapse
-
.parse_response(response) ⇒ Object
Public: Parse an HTTParty Response into a single APIObject or an Array of such.
Class Method Details
.parse_response(response) ⇒ Object
Public: Parse an HTTParty Response into a single APIObject or an Array of such
response - The HTTParty Response object that will be parsed
Examples
APIObject.parse_response(HTTParty.get("http://coopapp.com/groups"))
# => [{"type" => "Note", "users" => ...}]
Returns a singular or array of APIObjects, depending on what it’s fed
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/coop/api_object.rb', line 16 def self.parse_response(response) response = response.parsed_response.class == String ? JSON.parse(response.parsed_response) : response.parsed_response if response.class == Array output = Array.new response.each do |item| output << self.new(item) end elsif response.class == Hash output = self.new(response) end output end |