Class: FreeAgent::ContactsResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/free_agent/resources/contacts.rb

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from FreeAgent::Resource

Instance Method Details

#create(**params) ⇒ Object



14
15
16
17
18
19
# File 'lib/free_agent/resources/contacts.rb', line 14

def create(**params)
  raise "first_name and last_name or organisation_name is required" unless !params[:first_name].nil? || !params[:organisation_name].nil?

  response = post_request("contacts", body: params)
  Contact.new(response.body["contact"]) if response.success?
end

#delete(id:) ⇒ Object



26
27
28
29
# File 'lib/free_agent/resources/contacts.rb', line 26

def delete(id:)
  response = delete_request("contacts/#{id}")
  response.success?
end

#list(**params) ⇒ Object



4
5
6
7
# File 'lib/free_agent/resources/contacts.rb', line 4

def list(**params)
  response = get_request("contacts", params: params)
  Collection.from_response(response, type: Contact, key: "contacts")
end

#retrieve(id:) ⇒ Object



9
10
11
12
# File 'lib/free_agent/resources/contacts.rb', line 9

def retrieve(id:)
  response = get_request("contacts/#{id}")
  Contact.new(response.body["contact"])
end

#update(id:, **params) ⇒ Object



21
22
23
24
# File 'lib/free_agent/resources/contacts.rb', line 21

def update(id:, **params)
  response = put_request("contacts/#{id}", body: params)
  Contact.new(response.body["contact"]) if response.success?
end