Sha256: 816b9f204f12ee4c94b728767e7cd20af7e8a1e5cc83f99a86232fa9794c45c2
Contents?: true
Size: 1.39 KB
Versions: 2
Compression:
Stored size: 1.39 KB
Contents
module Pina class Contact class << self def new(params = nil) Pina::Models::Contact.new(params) end def find_by(hash) response = where(hash) return response.items.first if response.is_a? Pina::Models::ContactList response end def where(hash, page = nil) response = Pina::RestAdapter.get(:contacts, hash) return Pina::Models::ContactList.new(attributes(response)) if response.ok? response end def find(id) response = Pina::RestAdapter.get(:contacts, id) return Pina::Models::Contact.new(attributes(response)) if response.ok? response end def all(page = nil) response = Pina::RestAdapter.get(:contacts, page) return Pina::Models::ContactList.new(attributes(response)) if response.ok? response end def create(contact) response = Pina::RestAdapter.post(:contacts, contact) return Pina::Models::Contact.new(attributes(response)) if response.ok? response end def update(id, contact) response = Pina::RestAdapter.patch(:contacts, id, contact) return Pina::Models::Contact.new(attributes(response)) if response.ok? response end private def attributes(response) response.to_hash.merge(response: response) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pina-0.3.1 | lib/pina/contact.rb |
pina-0.2.0 | lib/pina/contact.rb |