Class: Basecamp::Services::TimesheetsService

Inherits:
BaseService
  • Object
show all
Defined in:
lib/basecamp/generated/services/timesheets_service.rb

Overview

Service for Timesheets operations

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Basecamp::Services::BaseService

Instance Method Details

#create(recording_id:, date:, hours:, description: nil, person_id: nil) ⇒ Hash

Create a timesheet entry on a recording

Parameters:

  • recording_id (Integer)

    recording id ID

  • date (String)

    date

  • hours (String)

    hours

  • description (String, nil) (defaults to: nil)

    description

  • person_id (Integer, nil) (defaults to: nil)

    person id

Returns:

  • (Hash)

    response data



47
48
49
50
51
# File 'lib/basecamp/generated/services/timesheets_service.rb', line 47

def create(recording_id:, date:, hours:, description: nil, person_id: nil)
  with_operation(service: "timesheets", operation: "create", is_mutation: true, resource_id: recording_id) do
    http_post("/recordings/#{recording_id}/timesheet/entries.json", body: compact_params(date: date, hours: hours, description: description, person_id: person_id)).json
  end
end

#destroy(entry_id:) ⇒ void

This method returns an undefined value.

Permanently delete a timesheet entry; answers 403 when the caller may not archive or trash it.

Parameters:

  • entry_id (Integer)

    entry id ID



89
90
91
92
93
94
# File 'lib/basecamp/generated/services/timesheets_service.rb', line 89

def destroy(entry_id:)
  with_operation(service: "timesheets", operation: "destroy", is_mutation: true, resource_id: entry_id) do
    http_delete("/timesheet_entries/#{entry_id}")
    nil
  end
end

#for_project(project_id:, from: nil, to: nil, person_id: nil, page: nil, max_items: nil) ⇒ ListEnumerator<Hash>

Get timesheet for a specific project

Parameters:

  • project_id (Integer)

    project id ID

  • from (String, nil) (defaults to: nil)

    from

  • to (String, nil) (defaults to: nil)

    to

  • person_id (Integer, nil) (defaults to: nil)

    person id

  • page (Integer, nil) (defaults to: nil)

    Page number for paginating through results. Defaults to 1. A positive value selects exactly that page, not a starting offset; see SPEC section 8.

  • max_items (Integer, nil) (defaults to: nil)

    cap on items yielded across pages; nil or non-positive means no cap

Returns:

  • (ListEnumerator<Hash>)

    lazily paginated results (#meta carries pagination metadata)



18
19
20
21
22
23
# File 'lib/basecamp/generated/services/timesheets_service.rb', line 18

def for_project(project_id:, from: nil, to: nil, person_id: nil, page: nil, max_items: nil)
  wrap_paginated(service: "timesheets", operation: "for_project", is_mutation: false, project_id: project_id) do
    params = compact_query_params(from: from, to: to, person_id: person_id, page: page)
    paginate("/projects/#{project_id}/timesheet.json", params: params, operation: "GetProjectTimesheet", max_items: max_items)
  end
end

#for_recording(recording_id:, from: nil, to: nil, person_id: nil, page: nil, max_items: nil) ⇒ ListEnumerator<Hash>

Get timesheet for a specific recording

Parameters:

  • recording_id (Integer)

    recording id ID

  • from (String, nil) (defaults to: nil)

    from

  • to (String, nil) (defaults to: nil)

    to

  • person_id (Integer, nil) (defaults to: nil)

    person id

  • page (Integer, nil) (defaults to: nil)

    Page number for paginating through results. Defaults to 1. A positive value selects exactly that page, not a starting offset; see SPEC section 8.

  • max_items (Integer, nil) (defaults to: nil)

    cap on items yielded across pages; nil or non-positive means no cap

Returns:

  • (ListEnumerator<Hash>)

    lazily paginated results (#meta carries pagination metadata)



33
34
35
36
37
38
# File 'lib/basecamp/generated/services/timesheets_service.rb', line 33

def for_recording(recording_id:, from: nil, to: nil, person_id: nil, page: nil, max_items: nil)
  wrap_paginated(service: "timesheets", operation: "for_recording", is_mutation: false, resource_id: recording_id) do
    params = compact_query_params(from: from, to: to, person_id: person_id, page: page)
    paginate("/recordings/#{recording_id}/timesheet.json", params: params, operation: "GetRecordingTimesheet", max_items: max_items)
  end
end

#get(entry_id:) ⇒ Hash

Get a single timesheet entry

Parameters:

  • entry_id (Integer)

    entry id ID

Returns:

  • (Hash)

    response data



67
68
69
70
71
# File 'lib/basecamp/generated/services/timesheets_service.rb', line 67

def get(entry_id:)
  with_operation(service: "timesheets", operation: "get", is_mutation: false, resource_id: entry_id) do
    http_get("/timesheet_entries/#{entry_id}", operation: "GetTimesheetEntry").json
  end
end

#report(from: nil, to: nil, person_id: nil) ⇒ Array<Hash>

Get account-wide timesheet report

Parameters:

  • from (String, nil) (defaults to: nil)

    from

  • to (String, nil) (defaults to: nil)

    to

  • person_id (Integer, nil) (defaults to: nil)

    person id

Returns:

  • (Array<Hash>)

    response data



58
59
60
61
62
# File 'lib/basecamp/generated/services/timesheets_service.rb', line 58

def report(from: nil, to: nil, person_id: nil)
  with_operation(service: "timesheets", operation: "report", is_mutation: false) do
    http_get("/reports/timesheet.json", params: compact_query_params(from: from, to: to, person_id: person_id), operation: "GetTimesheetReport").json
  end
end

#update(entry_id:, date: nil, hours: nil, description: nil, person_id: nil) ⇒ Hash

Update a timesheet entry

Parameters:

  • entry_id (Integer)

    entry id ID

  • date (String, nil) (defaults to: nil)

    date

  • hours (String, nil) (defaults to: nil)

    hours

  • description (String, nil) (defaults to: nil)

    description

  • person_id (Integer, nil) (defaults to: nil)

    person id

Returns:

  • (Hash)

    response data



80
81
82
83
84
# File 'lib/basecamp/generated/services/timesheets_service.rb', line 80

def update(entry_id:, date: nil, hours: nil, description: nil, person_id: nil)
  with_operation(service: "timesheets", operation: "update", is_mutation: true, resource_id: entry_id) do
    http_put("/timesheet_entries/#{entry_id}", body: compact_params(date: date, hours: hours, description: description, person_id: person_id)).json
  end
end