plunk/contacts

Types

pub type Action =
  definitions.Action
pub type ActionResult {
  GetContactResult(ExtendedContact)
  ListContactsResult(List(Contact))
  CountContactsResult(Count)
  CreateContactResult(CreatedContact)
  SubscriptionResult(Subscription)
  DeleteContactResult(DeletedContact)
}

Constructors

  • GetContactResult(ExtendedContact)
  • ListContactsResult(List(Contact))
  • CountContactsResult(Count)
  • CreateContactResult(CreatedContact)
  • SubscriptionResult(Subscription)
  • DeleteContactResult(DeletedContact)
pub type Contact =
  definitions.Contact
pub type Count =
  definitions.Count
pub type CreateContactData {
  CreateContactData(
    email: String,
    subscribed: Bool,
    data: Option(List(#(String, String))),
  )
}

Constructors

  • CreateContactData(
      email: String,
      subscribed: Bool,
      data: Option(List(#(String, String))),
    )
pub type CreatedContact =
  definitions.CreatedContact
pub type DeletedContact =
  definitions.DeletedContact
pub type Email =
  definitions.Email
pub type Event =
  definitions.Event
pub type ExtendedContact =
  definitions.ExtendedContact
pub type For {
  GetContact
  ListContacts
  CountContacts
  CreateContact
  Subscribe
  Unsubscribe
  DeleteContact
}

Constructors

  • GetContact
  • ListContacts
  • CountContacts
  • CreateContact
  • Subscribe
  • Unsubscribe
  • DeleteContact
pub type Subscription =
  definitions.Subscription
pub type SubscriptionData {
  Subscription(id: String)
}

Constructors

  • Subscription(id: String)
pub type Trigger =
  definitions.Trigger

Functions

pub fn count(instance: Instance) -> Request(String)

Get count of all contacts

pub fn create(
  instance: Instance,
  contact: CreateContactData,
) -> Request(String)

Create a contact

pub fn decode(
  res: Response(String),
  for for: For,
) -> Result(ActionResult, PlunkError)

This function decodes all the responses related to this resource albeit a bit differently from the other decode functions (but, still type-safe)

Example

import gleam/io
import gleam/hackney
import plunk
import plunk/contacts.{GetContact, GetContactResult}

fn main() {
  let instance = plunk.new("API_KEY")
  let req = contacts.get(instance, "some-uuid-for-your-contact")
  let assert Ok(resp) = hackney.send(req)
  let assert Ok(data) = contacts.decode(resp, for: GetContact)
  let assert GetContactResult(contact) = data
  io.println(contact.id)
}
pub fn delete(instance: Instance, id: String) -> Request(String)

Delete a contact

pub fn get(
  instance: Instance,
  id contact_id: String,
) -> Request(String)

Get a contact by ID

pub fn list(instance: Instance) -> Request(String)

Get all contacts

pub fn subscribe(
  instance: Instance,
  id: String,
) -> Request(String)

Subscribe a contact

pub fn unsubscribe(
  instance: Instance,
  id: String,
) -> Request(String)

Unsubscribe a contact

Search Document