Skip to content

surgeapi/surge-elixir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Surge SDK for Elixir

Surge is the easiest SMS API for developers. We write all of our code in Elixir, and we're proud to maintain a first party client for Elixir.

Installation

Add surge to your list of dependencies in mix.exs:

def deps do
  [
    {:surge_api, "~> 0.1.0"}
  ]
end

Then run:

mix deps.get

Configuration

Configure your Surge API credentials in your application configuration:

# config/config.exs
config :surge_api,
  api_key: System.get_env("SURGE_API_KEY"),
  base_url: System.get_env("SURGE_API_URL", "https://api.surge.app")

Quick Start

Using the Default Client

The SDK will automatically use your configured API key:

# Send a message
{:ok, message} = Surge.Messages.create(account.id, %{
  from: "+15551234567",
  to: "+15559876543",
  body: "Hello from Surge!"
})

Using a Custom Client

You can create a client to use specific credentials, base URL, or other options:

client = Surge.Client.new("sk_test_your_api_key")

# Use the client for API calls
{:ok, account} = Surge.Accounts.create(client, %{name: "Test Account"})

Error Handling

All API calls return either {:ok, result} or {:error, error}:

case Surge.Messages.create("acct_123", params) do
  {:ok, message} ->
    IO.puts("Message sent: #{message.id}")
  
  {:error, %Surge.Error{} = error} ->
    IO.puts("Error: #{error.message}")
    IO.puts("Error type: #{error.type}")
    IO.puts("Error details: #{inspect(error.detail)}")
end

Advanced Configuration

Custom Request Options

You can pass custom options to the underlying HTTP client:

client = Surge.Client.new("api_key", 
  req_options: [
    timeout: 30_000,
    retry: :transient
  ]
)

Using a Different Base URL

For testing or using a different Surge environment:

client = Surge.Client.new("api_key", base_url: "https://staging.surge.app")

Documentation

Generate the documentation locally:

mix docs
open doc/index.html

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This SDK is distributed under the MIT license. See LICENSE for more information.

Support

For questions and support:

About

An Elixir SDK for the Surge API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages