Class: FreeAgent::TimeslipsResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/free_agent/resources/timeslips.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(task:, user:, project:, dated_on:, hours:, **params) ⇒ Object



29
30
31
32
33
34
# File 'lib/free_agent/resources/timeslips.rb', line 29

def create(task:, user:, project:, dated_on:, hours:,  **params)
  attributes = {task: task, user: user, project: project, dated_on: dated_on, hours: hours}

  response = post_request("timeslips", body: attributes.merge(params))
  Timeslip.new(response.body["timeslip"]) if response.success?
end

#delete(id:) ⇒ Object



41
42
43
44
# File 'lib/free_agent/resources/timeslips.rb', line 41

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

#list(**params) ⇒ Object



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

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

#list_for_project(project:, **params) ⇒ Object



19
20
21
22
# File 'lib/free_agent/resources/timeslips.rb', line 19

def list_for_project(project:, **params)
  response = get_request("timeslips?project=#{project}", params: params)
  Collection.from_response(response, type: Timeslip, key: "timeslips")
end

#list_for_task(task:, **params) ⇒ Object



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

def list_for_task(task:, **params)
  response = get_request("timeslips?task=#{task}", params: params)
  Collection.from_response(response, type: Timeslip, key: "timeslips")
end

#list_for_user(user:, **params) ⇒ Object



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

def list_for_user(user:, **params)
  response = get_request("timeslips?user=#{user}", params: params)
  Collection.from_response(response, type: Timeslip, key: "timeslips")
end

#retrieve(id:) ⇒ Object



24
25
26
27
# File 'lib/free_agent/resources/timeslips.rb', line 24

def retrieve(id:)
  response = get_request("timeslips/#{id}")
  Timeslip.new(response.body["timeslip"])
end

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



36
37
38
39
# File 'lib/free_agent/resources/timeslips.rb', line 36

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