Packages
The Elixir SDK for the Thinkific Admin API
Current section
Files
Jump to
Current section
Files
lib/thinkific_admin_api/connection.ex
# NOTE: This class is auto generated by the swagger code generator program.
# https://github.com/swagger-api/swagger-codegen.git
# Do not edit the class manually.
defmodule ThinkificAdminAPI.Connection do
@moduledoc """
Handle Tesla connections for ThinkificAdminAPI.
"""
use Tesla
# Add any middleware here (authentication)
plug Tesla.Middleware.BaseUrl, "https://api.thinkific.com/api/public/v1"
plug Tesla.Middleware.Headers, [{"User-Agent", "elixir-sdk"}]
@doc """
Configure an authless client connection
# Returns
Tesla.Env.client
"""
@spec new() :: Tesla.Env.client
def new do
middleware = [
{Tesla.Middleware.BaseUrl, "https://api.thinkific.com/api/public/v1"},
{Tesla.Middleware.Headers, [{"User-Agent", "elixir-sdk"}]},
]
Tesla.client(middleware)
end
@doc """
Configure a client connection with subdomain and Authentication header
Ie.:
ThinkificAdminAPI.Connection.new("my-subdomain, "%{"Authorization" => "Bearer 1360ddc6-4029-47ec-a027-e5f1e60f4c38"})
ThinkificAdminAPI.Connection.new("my-subdomain, "%{"X-Auth-API-Key" => "9icu13c55130879ef301b1975a21f27c"})
## Parameters
- subdomain (String): Thinkific's site subdomain
- header (Map): Request headers(specific for the Authorization or X-Auth-API-Key)
# Returns
Tesla.Env.client
"""
@spec new(String, Map) :: Tesla.Env.client
def new(subdomain, %{"Authorization" => token}) do
middleware = [
{Tesla.Middleware.BaseUrl, "https://" <> subdomain <> ".thinkific.com/api/public/v1"},
{Tesla.Middleware.Headers, [{"User-Agent", "elixir-sdk"}, {"Authorization", token}]}
]
Tesla.client(middleware)
end
def new(subdomain, %{"X-Auth-API-Key" => api_key}) do
middleware = [
{Tesla.Middleware.BaseUrl, "https://" <> subdomain <> ".thinkific.com/api/public/v1"},
{Tesla.Middleware.Headers, [{"User-Agent", "elixir-sdk"}, {"X-Auth-API-Key", api_key}, {"X-Auth-Subdomain", subdomain}]}
]
Tesla.client(middleware)
end
end