Deputy.Locations (Deputy v0.5.0)

Copy Markdown View Source

Functions for interacting with locations (companies) in Deputy.

Summary

Functions

Archive a location.

Same as archive/2 but raises on error.

Add a new location.

Same as create/2 but raises on error.

Add a new workplace with areas.

Delete a location.

Same as delete/2 but raises on error.

get(client, id) deprecated

Get location by ID.

get!(client, id) deprecated

Same as get/2 but raises on error.

Get a location's settings.

Same as get_settings/2 but raises on error.

Get all locations.

Same as list/1 but raises on error.

Get a simplified list of locations.

Same as list_simplified/1 but raises on error.

Update a location.

Same as update/3 but raises on error.

Modify settings for all locations.

Modify settings for a single location.

Functions

archive(client, id)

@spec archive(Deputy.t(), integer()) :: {:ok, map()} | {:error, Deputy.Error.t()}

Archive a location.

Parameters

  • client: A Deputy client.
  • id: The ID of the location to archive.

Examples

client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
Deputy.Locations.archive(client, 1)
# => {:ok, %{"success" => true}}

archive!(client, id)

@spec archive!(Deputy.t(), integer()) :: map()

Same as archive/2 but raises on error.

create(client, attrs)

@spec create(Deputy.t(), map()) :: {:ok, map()} | {:error, Deputy.Error.t()}

Add a new location.

Parameters

  • client: A Deputy client.
  • attrs: A map containing the new location details.

Location parameters

  • strWorkplaceName: String naming the workplace.
  • strWorkplaceCode: A string with a length of 3 allowing you to define a short code for the location.
  • strAddress: String of the location's address.
  • strAddressNotes: Optional. Notes about the address.
  • intParentCompany: Optional. Integer ID of parent company.
  • intIsWorkplace: Boolean (1 - True, 0 - False) whether the location is considered a workplace.
  • intIsPayrollEntity: Boolean (1 - True, 0 - False) whether the location has payroll setup.
  • strTimezone: Timezone for the workplace using TZ database naming.
  • strPayrollExportCode: Optional. String naming what to use as a code for payroll exports.

Examples

client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
attrs = %{
  strWorkplaceName: "New Location",
  strWorkplaceCode: "NLC",
  strAddress: "123 Test St",
  intIsWorkplace: 1,
  intIsPayrollEntity: 1,
  strTimezone: "America/New_York"
}
Deputy.Locations.create(client, attrs)
# => {:ok, %{"Id" => 123}}

create!(client, attrs)

@spec create!(Deputy.t(), map()) :: map()

Same as create/2 but raises on error.

create_workplace(client, attrs)

@spec create_workplace(Deputy.t(), map()) :: {:ok, map()} | {:error, Deputy.Error.t()}

Add a new workplace with areas.

Parameters

  • client: A Deputy client.
  • attrs: A map containing the new workplace details.

Workplace parameters

  • strWorkplaceName: String naming the workplace.
  • strWorkplaceTimezone: Timezone for the workplace using TZ database naming.
  • strAddress: String of the location's address.
  • strLat: The latitude of the location using a string.
  • strLon: The longitude of the location using a string.
  • intCountry: An integer which defines which country the location is in.
  • arrAreaNames: An array of the area names to add to the location.
  • strWorkplaceCode: A string with a length of 3 allowing you to define a short code for the location.
  • strPayrollExportCode: Optional. String naming what to use as a code for payroll exports.
  • blnIsWorkplace: Boolean (1 - True, 0 - False) whether the location is considered a workplace.
  • blnIsPayrollEntity: Boolean (1 - True, 0 - False) whether the location has payroll setup.

Examples

client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
attrs = %{
  strWorkplaceName: "New Workplace",
  strWorkplaceTimezone: "America/New_York",
  strAddress: "123 Test St",
  strLat: "40.7128",
  strLon: "-74.0060",
  intCountry: 1,
  arrAreaNames: ["Reception", "Kitchen"],
  strWorkplaceCode: "NWP",
  blnIsWorkplace: 1,
  blnIsPayrollEntity: 1
}
Deputy.Locations.create_workplace(client, attrs)
# => {:ok, %{"Id" => 123}}

create_workplace!(client, attrs)

@spec create_workplace!(Deputy.t(), map()) :: map()

Same as create_workplace/2 but raises on error.

delete(client, id)

@spec delete(Deputy.t(), integer()) :: {:ok, map()} | {:error, Deputy.Error.t()}

Delete a location.

Parameters

  • client: A Deputy client.
  • id: The ID of the location to delete.

Examples

client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
Deputy.Locations.delete(client, 1)
# => {:ok, %{"success" => true}}

delete!(client, id)

@spec delete!(Deputy.t(), integer()) :: map()

Same as delete/2 but raises on error.

get(client, id)

This function is deprecated. Use Deputy.My.location/2 instead..
@spec get(Deputy.t(), integer()) :: {:ok, map()} | {:error, Deputy.Error.t()}

Get location by ID.

This calls the /api/v1/my/location/:id endpoint, scoped to the authenticated user's accessible locations. For that semantic, prefer Deputy.My.location/2.

Parameters

  • client: A Deputy client.
  • id: The ID of the location to retrieve.

Examples

client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
Deputy.Locations.get(client, 1)
# => {:ok, %{"Id" => 1, "CompanyName" => "Test Company"}}

get!(client, id)

This function is deprecated. Use Deputy.My.location!/2 instead..
@spec get!(Deputy.t(), integer()) :: map()

Same as get/2 but raises on error.

get_settings(client, id)

@spec get_settings(Deputy.t(), integer()) :: {:ok, map()} | {:error, Deputy.Error.t()}

Get a location's settings.

Parameters

  • client: A Deputy client.
  • id: The ID of the location to retrieve settings for.

Examples

client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
Deputy.Locations.get_settings(client, 1)
# => {:ok, %{"WEEK_START" => 1}}

get_settings!(client, id)

@spec get_settings!(Deputy.t(), integer()) :: map()

Same as get_settings/2 but raises on error.

list(client)

@spec list(Deputy.t()) :: {:ok, [map()]} | {:error, Deputy.Error.t()}

Get all locations.

Examples

client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
Deputy.Locations.list(client)
# => {:ok, [%{"Id" => 1, "CompanyName" => "Test Company"}]}

list!(client)

@spec list!(Deputy.t()) :: [map()]

Same as list/1 but raises on error.

list_simplified(client)

@spec list_simplified(Deputy.t()) :: {:ok, [map()]} | {:error, Deputy.Error.t()}

Get a simplified list of locations.

Examples

client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
Deputy.Locations.list_simplified(client)
# => {:ok, [%{"Id" => 1, "CompanyName" => "Test Company"}]}

list_simplified!(client)

@spec list_simplified!(Deputy.t()) :: [map()]

Same as list_simplified/1 but raises on error.

update(client, id, attrs)

@spec update(Deputy.t(), integer(), map()) ::
  {:ok, map()} | {:error, Deputy.Error.t()}

Update a location.

Parameters

  • client: A Deputy client.
  • id: The ID of the location to update.
  • attrs: A map containing the fields to update.

Examples

client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
Deputy.Locations.update(client, 1, %{strWorkplaceCode: "UPD"})
# => {:ok, %{"success" => true}}

update!(client, id, attrs)

@spec update!(Deputy.t(), integer(), map()) :: map()

Same as update/3 but raises on error.

update_all_settings(client, settings)

@spec update_all_settings(Deputy.t(), map()) ::
  {:ok, map()} | {:error, Deputy.Error.t()}

Modify settings for all locations.

Parameters

  • client: A Deputy client.
  • settings: A map of settings to update.

Examples

client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
Deputy.Locations.update_all_settings(client, %{"WEEK_START" => 2})
# => {:ok, %{"success" => true}}

update_all_settings!(client, settings)

@spec update_all_settings!(Deputy.t(), map()) :: map()

Same as update_all_settings/2 but raises on error.

update_settings(client, id, settings)

@spec update_settings(Deputy.t(), integer(), map()) ::
  {:ok, map()} | {:error, Deputy.Error.t()}

Modify settings for a single location.

Parameters

  • client: A Deputy client.
  • id: The ID of the location to update settings for.
  • settings: A map of settings to update.

Examples

client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
Deputy.Locations.update_settings(client, 1, %{"WEEK_START" => 2})
# => {:ok, %{"success" => true}}

update_settings!(client, id, settings)

@spec update_settings!(Deputy.t(), integer(), map()) :: map()

Same as update_settings/3 but raises on error.