Class: Pina::Contact

Inherits:
Object
  • Object
show all
Defined in:
lib/pina/contact.rb

Class Method Summary collapse

Class Method Details

.all(page = nil) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/pina/contact.rb', line 37

def all(page = nil)
  response = Pina::RestAdapter.get(:contacts, page)

  return Pina::Collections::Contact.new(attributes(response)) if
    response.ok?

  response
end

.create(contact) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/pina/contact.rb', line 46

def create(contact)
  response = Pina::RestAdapter.post(:contacts, contact)

  return Pina::Models::Contact.new(attributes(response)) if response.ok?

  response
end

.find(id) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/pina/contact.rb', line 29

def find(id)
  response = Pina::RestAdapter.get(:contacts, id)

  return Pina::Models::Contact.new(attributes(response)) if response.ok?

  response
end

.find_by(hash) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/pina/contact.rb', line 12

def find_by(hash)
  response = where(hash)

  return response.items.first if response.is_a? Pina::Collections::Contact

  response
end

.new(params = nil) ⇒ Object



8
9
10
# File 'lib/pina/contact.rb', line 8

def new(params = nil)
  Pina::Models::Contact.new(params)
end

.update(id, contact) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/pina/contact.rb', line 54

def update(id, contact)
  response = Pina::RestAdapter.patch(:contacts, id, contact)

  return Pina::Models::Contact.new(attributes(response)) if response.ok?

  response
end

.where(hash, page = nil) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/pina/contact.rb', line 20

def where(hash, page = nil)
  response = Pina::RestAdapter.get(:contacts, hash)

  return Pina::Collections::Contact.new(attributes(response)) if
    response.ok?

  response
end