plunk/contacts
Types
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 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 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)
Functions
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 get(
instance: Instance,
id contact_id: String,
) -> Request(String)
Get a contact by ID
pub fn subscribe(
instance: Instance,
id: String,
) -> Request(String)
Subscribe a contact
pub fn unsubscribe(
instance: Instance,
id: String,
) -> Request(String)
Unsubscribe a contact