PDFShift.API (PDFShift v0.1.0)

View Source

Module implementing the PDFShift API endpoints.

Summary

Functions

convert(client, config, source, options \\ %{}, client_opts \\ [])

@spec convert(
  module(),
  PDFShift.Config.t(),
  String.t(),
  PDFShift.Types.convert_options(),
  keyword()
) ::
  {:ok, map()} | {:error, any()}

Converts a HTML document or URL to PDF.

Parameters

  • client - The HTTP client module
  • config - The configuration struct
  • source - URL or HTML content to convert to PDF
  • options - Additional options for the conversion

Returns

  • {:ok, response} - On successful conversion
  • {:error, reason} - On failure

Examples

iex> PDFShift.API.convert(PDFShift.Client, config, "https://example.com")
{:ok, %{body: <<PDF binary data>>, status: 200, headers: [...]}}

credits_usage(client, config, client_opts \\ [])

@spec credits_usage(module(), PDFShift.Config.t(), keyword()) ::
  {:ok, map()} | {:error, any()}

Gets the current credits usage.

Parameters

  • client - The HTTP client module
  • config - The configuration struct

Returns

  • {:ok, response} - On successful request
  • {:error, reason} - On failure

Examples

iex> PDFShift.API.credits_usage(PDFShift.Client, config)
{:ok, %{
  body: %{
    "credits" => %{
      "base" => 50000,
      "remaining" => 49881,
      "total" => 50000,
      "used" => 119
    },
    "success" => true
  },
  status: 200,
  headers: [...]
}}