Class: FreeAgent::ProjectsResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/free_agent/resources/projects.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(contact:, name:, status:, currency:, budget_units:, **params) ⇒ Object



18
19
20
21
22
23
# File 'lib/free_agent/resources/projects.rb', line 18

def create(contact:, name:, status:, currency:, budget_units:, **params)
  attributes = { contact: contact, name: name, status: status, currency: currency, budget_units: budget_units }

  response = post_request("projects", body: attributes.merge(params))
  Project.new(response.body["project"]) if response.success?
end

#delete(id:) ⇒ Object



30
31
32
33
# File 'lib/free_agent/resources/projects.rb', line 30

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

#list(**params) ⇒ Object



3
4
5
6
# File 'lib/free_agent/resources/projects.rb', line 3

def list(**params)
  response = get_request("projects", params: params)
  Collection.from_response(response, type: Project)
end

#list_for_contact(contact:, **params) ⇒ Object



8
9
10
11
# File 'lib/free_agent/resources/projects.rb', line 8

def list_for_contact(contact:, **params)
  response = get_request("projects?contact=#{contact}", params: params)
  Collection.from_response(response, type: Project)
end

#retrieve(id:) ⇒ Object



13
14
15
16
# File 'lib/free_agent/resources/projects.rb', line 13

def retrieve(id:)
  response = get_request("projects/#{id}")
  Project.new(response.body["project"])
end

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



25
26
27
28
# File 'lib/free_agent/resources/projects.rb', line 25

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