lib/amee/session.rb in hookercookerman-amee-0.1.9 vs lib/amee/session.rb in hookercookerman-amee-0.2.0

- old
+ new

@@ -1,15 +1,16 @@ module Amee class Session - class Expired < StandardError; end - class UnAuthorized < StandardError; end - class NotAuthenticated < StandardError; end - class PermissionDenied < StandardError; end - class NotFound < StandardError; end - class ServerNotFound < StandardError; end - class UnknownError < StandardError; end + class AmeeError < StandardError ;end + class Expired < AmeeError; end + class UnAuthorized < AmeeError; end + class NotAuthenticated < AmeeError; end + class PermissionDenied < AmeeError; end + class NotFound < AmeeError; end + class ServerNotFound < AmeeError; end + class UnknownError < AmeeError; end attr_accessor :auth_token, :cache, :service def self.create(username = nil, password = nil) username ||= Amee::Config[:username] password ||= Amee::Config[:password] @@ -145,24 +146,34 @@ api_call(:get, "get.profile", "/profiles/#{uid}") do |response| Amee::ProfileApi::Profile.from_hash(response, self) end end + # @note representation FULL is not working on AMEE VERSION 2.0 + # ticket has been raised + # # @return [Amee::ProfileApi::ProfileItem] def update_profile_item(path, options = {}) @cache.clear - api_call(:put, "profile_item", path, :query => {:representation => options[:representation] || true}.merge(options[:fields])) do |response| + api_call(:put, options[:representation] ? "profile_item" : "ok", path, + :body => {:representation => options[:representation] ? "full" : ""}.merge(options[:query])) do |response| + return response if (options[:raw_response] || !response.is_a?(Hash)) Amee::ProfileApi::ProfileItem.from_hash(response, self) end end + + # If you want a full representation; which is the profile category by the way + # then pass :representation => true in the options hash + # # @return [Amee::ProfileApi::ProfileCategory] + # @return [String] the location of the new resource if representation is passed in options def create_profile_item(path, uid, options = {}) @cache.clear - api_call(:post, "create.profile_item", path, - :query => {:dataItemUid => uid, :representation => "full"}.merge(options[:fields])) do |response| - return response if options[:hash_response] + api_call(:post, options[:representation] ? "create.profile_item" : "profile_item.location", path, + :query => {:dataItemUid => uid, :representation => options[:representation] ? "full" : ""}.merge(options[:query])) do |response| + return response if (options[:raw_response] || !response.is_a?(Hash)) Amee::ProfileApi::ProfileCategory.from_hash(response, self) do |profile_category| profile_category.lazy_loaded = true end end end @@ -231,11 +242,12 @@ cache_options = options[:cache] || {} @cache.store(key, result, :expires_in => cache_options[:expires_in] || Amee::Config[:expires_in]) end protected + require 'digest/md5' def cache_key(path, params = {}) - path + params.map { |key,value| "#{key}=#{value}" }.join('/') + Digest::MD5.hexdigest(path + params.map { |key,value| "#{key}=#{value}" }.join('/')) end end end \ No newline at end of file