CampaignFlow.Client (CampaignFlow Client v0.1.0)

View Source

Main client module for the Campaign Flow API.

This module provides a convenient interface for interacting with the Campaign Flow API using OAuth2 authentication and the Req HTTP client library.

Configuration

You can configure the client in your config files:

config :campaign_flow,
  base_url: "https://app.campaignflow.com.au/api/v2",
  client_id: "your_client_id",
  client_secret: "your_client_secret"

Or pass configuration directly when creating a client:

client = CampaignFlow.Client.new(
  base_url: "https://app.campaignflow.com.au/api/v2",
  client_id: "your_client_id",
  client_secret: "your_client_secret"
)

Usage

# Create a new client
client = CampaignFlow.Client.new(
  client_id: "your_client_id",
  client_secret: "your_client_secret"
)

# Make API calls using resource modules
{:ok, campaigns} = CampaignFlow.Client.Campaigns.list(client)
{:ok, campaign} = CampaignFlow.Client.Campaigns.get(client, campaign_id)

Summary

Functions

Ensures the client has a valid access token, refreshing if necessary.

Creates a new Campaign Flow API client.

Creates a new client for the test environment.

Checks if the client's current access token is valid.

Types

t()

@type t() :: %CampaignFlow.Client{
  access_token: String.t() | nil,
  base_url: String.t(),
  client_id: String.t(),
  client_secret: String.t(),
  req_options: keyword(),
  token_expires_at: DateTime.t() | nil
}

Functions

authenticate(client)

@spec authenticate(t()) :: {:ok, t()} | {:error, term()}

Ensures the client has a valid access token, refreshing if necessary.

Examples

client = CampaignFlow.Client.new(client_id: "id", client_secret: "secret")
{:ok, authenticated_client} = CampaignFlow.Client.authenticate(client)

new(opts \\ [])

@spec new(keyword()) :: t()

Creates a new Campaign Flow API client.

Options

  • :base_url - The base URL for the API (overrides environment setting)
  • :environment - The environment to use (:prod or :test, defaults to :prod)
  • :client_id - OAuth2 client ID (required)
  • :client_secret - OAuth2 client secret (required)
  • :req_options - Additional options to pass to Req

Examples

client = CampaignFlow.Client.new(client_id: "id", client_secret: "secret")
#=> %CampaignFlow.Client{...}

client = CampaignFlow.Client.new(client_id: "id", client_secret: "secret", environment: :test)
#=> %CampaignFlow.Client{base_url: "https://test.campaignflow.com.au/api/v2", ...}

test(opts \\ [])

@spec test(keyword()) :: t()

Creates a new client for the test environment.

Examples

client = CampaignFlow.Client.test(client_id: "id", client_secret: "secret")
#=> %CampaignFlow.Client{base_url: "https://test.campaignflow.com.au/api/v2", ...}

token_valid?(client)

@spec token_valid?(t()) :: boolean()

Checks if the client's current access token is valid.