Sha256: 744f73a0c349e3817a3f50a502ccdeb2be402b8cd601fd1255494dccbf13fd87
Contents?: true
Size: 970 Bytes
Versions: 4
Compression:
Stored size: 970 Bytes
Contents
require 'hashie' require 'json' module Coop class APIObject < Hashie::Mash # 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 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 end %w(agenda group status user).each{ |o| require "coop/api_object/#{o}" } end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
coop-1.1.1 | lib/coop/api_object.rb |
coop-1.1.0 | lib/coop/api_object.rb |
coop-1.0.1 | lib/coop/api_object.rb |
coop-1.0.0 | lib/coop/api_object.rb |