Exact.Resource (exact_online v0.1.0)

Copy Markdown View Source

Generates the CRUD functions for one Exact Online resource.

Exact Online exposes around 600 resources. This library ships modules for a handful of them and gives you this macro for the rest, because a resource module is five lines:

defmodule MyApp.Exact.Item do
  @moduledoc "See [Items](https://start.exactonline.nl/docs/HlpRestAPIResourcesDetails.aspx?name=LogisticsItems)."
  use Exact.Resource, service: "logistics", resource: "Items"
end

MyApp.Exact.Item.list(client, select: ["ID", "Code", "Description"], top: 25)

Options

  • :resource - required, the resource name as it appears in the URL
  • :service - the service segment, omit for a resource that has none
  • :key - the primary key field, defaults to "ID"
  • :key_type - :guid (default), :integer or :string. Decides how the key predicate in the URL is formatted
  • :only - restrict the generated functions, for example only: [:list, :stream, :get] for a read-only resource

Generated functions

list/2, stream/2, get/3, create/2, update/3, delete/2 and path/0, each delegating to the matching Exact.Client function. Records are plain maps keyed by the field names Exact Online uses; nothing is renamed, so the reference documentation applies as written.

Summary

Functions

Formats a key predicate value.

Functions

key(id, atom)

@spec key(term(), :guid | :integer | :string) :: String.t()

Formats a key predicate value.

iex> Exact.Resource.key("11111111-2222-3333-4444-555555555555", :guid)
"guid'11111111-2222-3333-4444-555555555555'"

iex> Exact.Resource.key(123_456, :integer)
"123456"