YourImageShare.Client (YourImageShare v1.0.0)

Copy Markdown View Source

Client for the YourImageShare upload API (https://yourimageshare.com/about/api). Mirrors the existing JS, Python, PHP, Go, Rust, and Ruby SDKs - same method names, same result shapes, same error type - just idiomatic Elixir on top ({:ok, result} | {:error, %YourImageShare.APIError{}} tagged tuples, the direct equivalent of Go's (result, error) return; bang variants that raise are also provided).

Built on Req (https://hex.pm/packages/req) for HTTP + native streaming multipart support.

Summary

Functions

Removes one of your uploads by id. Returns {:error, %APIError{}} on a 404/401.

Same as delete/2, but raises instead of returning {:error, _}.

Returns your uploads, newest first, 50 per page. opts[:page] < 2 fetches the first page.

Same as list/2, but raises instead of returning {:error, _}.

Builds a client. api_key is required - get one from the API tab at https://yourimageshare.com/my-account.

Uploads a local file by path. Streams from disk via File.stream!/1 - doesn't buffer the whole file in memory. opts[:expires_in] auto-deletes the upload after that many seconds (60 to 2,592,000 = 30 days).

Same as upload/3, but raises YourImageShare.APIError instead of returning {:error, _}.

Uploads from any Enumerable/File.Stream (an open file, a network stream, an in-memory list of binaries) - useful when the data isn't already a file on disk. filename should include a real extension so the server can infer the content type correctly.

Same as upload_stream/4, but raises instead of returning {:error, _}.

Types

t()

@type t() :: %YourImageShare.Client{
  api_key: String.t(),
  base_url: String.t(),
  req_options: keyword()
}

Functions

delete(client, id)

@spec delete(t(), String.t()) :: :ok | {:error, YourImageShare.APIError.t()}

Removes one of your uploads by id. Returns {:error, %APIError{}} on a 404/401.

delete!(client, id)

@spec delete!(t(), String.t()) :: :ok

Same as delete/2, but raises instead of returning {:error, _}.

list(client, opts \\ [])

@spec list(
  t(),
  keyword()
) ::
  {:ok, YourImageShare.ListResult.t()} | {:error, YourImageShare.APIError.t()}

Returns your uploads, newest first, 50 per page. opts[:page] < 2 fetches the first page.

list!(client, opts \\ [])

@spec list!(
  t(),
  keyword()
) :: YourImageShare.ListResult.t()

Same as list/2, but raises instead of returning {:error, _}.

new(api_key, opts \\ [])

@spec new(
  String.t(),
  keyword()
) :: t()

Builds a client. api_key is required - get one from the API tab at https://yourimageshare.com/my-account.

Options:

  • :base_url - overrides the API base URL (mainly for testing).
  • :req_options - extra options merged into every Req.new/1 call, e.g. receive_timeout: or a custom :finch pool.

upload(client, file_path, opts \\ [])

@spec upload(t(), Path.t(), keyword()) ::
  {:ok, YourImageShare.UploadResult.t()} | {:error, YourImageShare.APIError.t()}

Uploads a local file by path. Streams from disk via File.stream!/1 - doesn't buffer the whole file in memory. opts[:expires_in] auto-deletes the upload after that many seconds (60 to 2,592,000 = 30 days).

upload!(client, file_path, opts \\ [])

@spec upload!(t(), Path.t(), keyword()) :: YourImageShare.UploadResult.t()

Same as upload/3, but raises YourImageShare.APIError instead of returning {:error, _}.

upload_stream(client, stream, filename, opts \\ [])

@spec upload_stream(t(), Enumerable.t(), String.t(), keyword()) ::
  {:ok, YourImageShare.UploadResult.t()} | {:error, YourImageShare.APIError.t()}

Uploads from any Enumerable/File.Stream (an open file, a network stream, an in-memory list of binaries) - useful when the data isn't already a file on disk. filename should include a real extension so the server can infer the content type correctly.

upload_stream!(client, stream, filename, opts \\ [])

@spec upload_stream!(t(), Enumerable.t(), String.t(), keyword()) ::
  YourImageShare.UploadResult.t()

Same as upload_stream/4, but raises instead of returning {:error, _}.