sparkpost v0.1.0 SparkPost.Endpoint

Base client for the SparkPost API, able to make requests and interpret responses. This module underpins the SparkPost.* modules.

Summary

Functions

Extract a meaningful structure from a generic endpoint response: response.results[subkey] as struct_type

Functions

marshal_response(response, struct_type, subkey \\ nil)

Extract a meaningful structure from a generic endpoint response: response.results[subkey] as struct_type

request(method, endpoint, body \\ %{}, headers \\ %{}, options \\ [])

Make a request to the SparkPost API.

Parameters

  • method: HTTP 1.1 request method as an atom:

    • :delete
    • :get
    • :head
    • :options
    • :patch
    • :post
    • :put
  • endpoint: SparkPost API endpoint as string (“transmissions”, “templates”, …)
  • body: A Map that will be encoded to JSON to be sent as the body of the request (defaults to empty)
  • headers: A Map of headers of the form %{“Header-Name” => “Value”} to be sent with the request
  • options: A Keyword list of optional elements including:

    • :params: A Keyword list of query parameters

Example

List transmissions for the “ElixirRox” campaign:

  SparkPost.Endpoint.request(:get, "transmissions", [campaign_id: "ElixirRox"])
  #=> %SparkPost.Endpoint.Response{results: [%{"campaign_id" => "",
    "content" => %{"template_id" => "inline"}, "description" => "",
    "id" => "102258558346809186", "name" => "102258558346809186",
    "state" => "Success"}, ...], status_code: 200}