module Fortnox::API::Repository::Loaders
Public Instance Methods
all()
click to toggle source
# File lib/fortnox/api/repositories/base/loaders.rb, line 9 def all response_hash = get(self.class::URI) instantiate_collection_response(response_hash) end
escape(key, value)
click to toggle source
# File lib/fortnox/api/repositories/base/loaders.rb, line 49 def escape(key, value) "#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}" end
find(id_or_hash)
click to toggle source
# File lib/fortnox/api/repositories/base/loaders.rb, line 27 def find(id_or_hash) return find_all_by(id_or_hash) if id_or_hash.is_a? Hash find_one_by(id_or_hash) end
find_all_by(hash)
click to toggle source
# File lib/fortnox/api/repositories/base/loaders.rb, line 38 def find_all_by(hash) response_hash = get("#{self.class::URI}?#{to_query(hash)}") instantiate_collection_response(response_hash) end
find_one_by(id)
click to toggle source
# File lib/fortnox/api/repositories/base/loaders.rb, line 33 def find_one_by(id) response_hash = get("#{self.class::URI}#{id}") instantiate(@mapper.wrapped_json_hash_to_entity_hash(response_hash)) end
only(filter)
click to toggle source
# File lib/fortnox/api/repositories/base/loaders.rb, line 14 def only(filter) response_hash = get("#{self.class::URI}?filter=#{filter}") instantiate_collection_response(response_hash) end
search(hash)
click to toggle source
# File lib/fortnox/api/repositories/base/loaders.rb, line 19 def search(hash) attribute, value = hash.first uri_encoded_value = CGI.escape(value) uri = "#{self.class::URI}?#{attribute}=#{uri_encoded_value}" response_hash = get(uri) instantiate_collection_response(response_hash) end
to_query(hash)
click to toggle source
# File lib/fortnox/api/repositories/base/loaders.rb, line 43 def to_query(hash) hash.collect do |key, value| escape(key, value) end.sort * '&' end
Private Instance Methods
instantiate_collection_response(response_hash)
click to toggle source
# File lib/fortnox/api/repositories/base/loaders.rb, line 55 def instantiate_collection_response(response_hash) entities_hash = @mapper.wrapped_json_collection_to_entities_hash(response_hash) entities_hash.map do |entity_hash| instantiate(entity_hash) end end