Humaans.TimesheetEntries behaviour (Humaans v0.4.0)

View Source

This module provides functions for managing timesheet entry resources in the Humaans API. Timesheet entries represent individual time records for a person, such as hours worked on a specific date.

Summary

Functions

Creates a new timesheet entry resource.

Deletes a specific timesheet entry by ID.

Lists all timesheet entry resources.

Retrieves a specific timesheet entry by ID.

Updates a specific timesheet entry by ID.

Types

delete_response()

@type delete_response() :: {:ok, %{id: String.t(), deleted: bool()}} | {:error, any()}

list_response()

@type list_response() ::
  {:ok,
   [
     %Humaans.Resources.TimesheetEntry{
       created_at: term(),
       date: term(),
       duration: term(),
       end_time: term(),
       id: term(),
       person_id: term(),
       start_time: term(),
       updated_at: term()
     }
   ]}
  | {:error, any()}

response()

@type response() ::
  {:ok,
   %Humaans.Resources.TimesheetEntry{
     created_at: term(),
     date: term(),
     duration: term(),
     end_time: term(),
     id: term(),
     person_id: term(),
     start_time: term(),
     updated_at: term()
   }}
  | {:error, any()}

Callbacks

create(client, map)

@callback create(client :: map(), map()) :: {:ok, map()} | {:error, any()}

delete(client, t)

@callback delete(client :: map(), String.t()) :: {:ok, map()} | {:error, any()}

list(client, map)

@callback list(client :: map(), map()) :: {:ok, map()} | {:error, any()}

retrieve(client, t)

@callback retrieve(client :: map(), String.t()) :: {:ok, map()} | {:error, any()}

update(client, t, map)

@callback update(client :: map(), String.t(), map()) :: {:ok, map()} | {:error, any()}

Functions

create(client, params)

@spec create(client :: map(), params :: keyword()) :: response()

Creates a new timesheet entry resource.

Parameters

  • client - Client map created with Humaans.new/1
  • params - Map of parameters for the new timesheet entry

Examples

client = Humaans.new(access_token: "your_access_token")

params = %{
  personId: "person_id",
  date: "2023-01-10",
  startTime: "09:00:00",
  endTime: "17:00:00"
}

{:ok, entry} = Humaans.TimesheetEntries.create(client, params)

delete(client, id)

@spec delete(client :: map(), id :: String.t()) :: delete_response()

Deletes a specific timesheet entry by ID.

Parameters

  • client - Client map created with Humaans.new/1
  • id - String ID of the timesheet entry to delete

Examples

client = Humaans.new(access_token: "your_access_token")

{:ok, result} = Humaans.TimesheetEntries.delete(client, "entry_id")
# result contains %{id: "entry_id", deleted: true}

list(client, params \\ %{})

@spec list(client :: map(), params :: keyword()) :: list_response()

Lists all timesheet entry resources.

Returns a list of timesheet entry resources that match the optional filters provided in params.

Parameters

  • client - Client map created with Humaans.new/1
  • params - Optional parameters for filtering the results (default: %{})

Examples

client = Humaans.new(access_token: "your_access_token")

# List all timesheet entries
{:ok, entries} = Humaans.TimesheetEntries.list(client)

# List with filtering parameters
{:ok, entries} = Humaans.TimesheetEntries.list(client, %{personId: "person_id"})

retrieve(client, id)

@spec retrieve(client :: map(), id :: String.t()) :: response()

Retrieves a specific timesheet entry by ID.

Parameters

  • client - Client map created with Humaans.new/1
  • id - String ID of the timesheet entry to retrieve

Examples

client = Humaans.new(access_token: "your_access_token")

{:ok, entry} = Humaans.TimesheetEntries.retrieve(client, "entry_id")

update(client, id, params)

@spec update(client :: map(), id :: String.t(), params :: keyword()) :: response()

Updates a specific timesheet entry by ID.

Parameters

  • client - Client map created with Humaans.new/1
  • id - String ID of the timesheet entry to update
  • params - Map of parameters to update

Examples

client = Humaans.new(access_token: "your_access_token")

params = %{startTime: "10:00:00", endTime: "18:00:00"}

{:ok, updated_entry} = Humaans.TimesheetEntries.update(client, "entry_id", params)