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



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

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



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

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

#list(**params) ⇒ Object



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

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

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



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

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

#retrieve(id:) ⇒ Object



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

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

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



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

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