View Source ExPipedrive.Resource behaviour (ex_pipedrive v0.1.0)
Behaviour and HTTP helpers for Pipedrive resource modules.
Core v2 modules (ExPipedrive.Products, ExPipedrive.Stages, …) implement
this behaviour and delegate CRUD / list / stream to the helpers below. Host
apps can do the same for endpoints without a first-class module. Prefer
ExPipedrive.Raw for one-off untyped calls.
Callbacks
path/0— collection segment (e.g."products"); versioned viaRequestdecode/1— map APIdataitem into a struct or mapencode/1— map/struct write attrs into a JSON body (usuallyWriteAttrs.take/2)list_query_keys/0— optional filter keys forlist_page/3/stream/3
Custom resource example
defmodule MyApp.Pipedrive.LeadLabels do
@behaviour ExPipedrive.Resource
alias ExPipedrive.Resource
alias ExPipedrive.WriteAttrs
@impl true
def path, do: "leadLabels"
@impl true
def decode(data) when is_map(data), do: data
@impl true
def encode(attrs), do: WriteAttrs.take(attrs, ~w(name color))
@impl true
def list_query_keys, do: [:ids]
def get(client, id), do: Resource.get(__MODULE__, client, id)
def create(client, attrs), do: Resource.create(__MODULE__, client, attrs)
def update(client, id, attrs), do: Resource.update(__MODULE__, client, id, attrs)
def delete(client, id), do: Resource.delete(__MODULE__, client, id)
def list_page(client, opts \ []), do: Resource.list_page(__MODULE__, client, opts)
def stream(client, opts \ []), do: Resource.stream(__MODULE__, client, opts)
end
Summary
Functions
POST /api/v2/{path} with encode/1 body → decode/1 on data.
DELETE /api/v2/{path}/:id. Returns the decoded response body (not decode/1).
GET /api/v2/{path}/:id → decode/1 on data.
Lists one cursor page via GET /api/v2/{path}.
Lazily streams decoded items across all v2 cursor pages.
PATCH /api/v2/{path}/:id with encode/1 body → decode/1 on data.
Types
@type t() :: module()
Callbacks
Functions
@spec create(t(), Tesla.Client.t(), term(), keyword()) :: {:ok, term()} | {:error, ExPipedrive.Error.t()}
POST /api/v2/{path} with encode/1 body → decode/1 on data.
Success statuses default to [200, 201] (Pipedrive varies by resource).
Override with :success_statuses.
@spec delete(t(), Tesla.Client.t(), term(), keyword()) :: {:ok, term()} | {:error, ExPipedrive.Error.t()}
DELETE /api/v2/{path}/:id. Returns the decoded response body (not decode/1).
@spec get(t(), Tesla.Client.t(), term(), keyword()) :: {:ok, term()} | {:error, ExPipedrive.Error.t()}
GET /api/v2/{path}/:id → decode/1 on data.
@spec list_page(t(), Tesla.Client.t(), keyword()) :: {:ok, ExPipedrive.Page.t()} | {:error, ExPipedrive.Error.t()}
Lists one cursor page via GET /api/v2/{path}.
Builds the query from :cursor, :limit (clamped), and keys from
list_query_keys/0 when implemented. Returns {:ok, %ExPipedrive.Page{}}.
@spec stream(t(), Tesla.Client.t(), keyword()) :: Enumerable.t()
Lazily streams decoded items across all v2 cursor pages.
@spec update(t(), Tesla.Client.t(), term(), term(), keyword()) :: {:ok, term()} | {:error, ExPipedrive.Error.t()}
PATCH /api/v2/{path}/:id with encode/1 body → decode/1 on data.