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 via Request
  • decode/1 — map API data item into a struct or map
  • encode/1 — map/struct write attrs into a JSON body (usually WriteAttrs.take/2)
  • list_query_keys/0 — optional filter keys for list_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}/:iddecode/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

Callbacks

@callback decode(map()) :: term()
@callback encode(term()) :: map()
Link to this callback

list_query_keys()

View Source (optional)
@callback list_query_keys() :: [atom()]
@callback path() :: String.t()

Functions

Link to this function

create(resource, client, attrs, opts \\ [])

View Source
@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.

Link to this function

delete(resource, client, id, opts \\ [])

View Source
@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).

Link to this function

get(resource, client, id, opts \\ [])

View Source
@spec get(t(), Tesla.Client.t(), term(), keyword()) ::
  {:ok, term()} | {:error, ExPipedrive.Error.t()}

GET /api/v2/{path}/:iddecode/1 on data.

Link to this function

list_page(resource, client, opts \\ [])

View Source
@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{}}.

Link to this function

stream(resource, client, opts \\ [])

View Source
@spec stream(t(), Tesla.Client.t(), keyword()) :: Enumerable.t()

Lazily streams decoded items across all v2 cursor pages.

Link to this function

update(resource, client, id, attrs, opts \\ [])

View Source
@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.