Sofa (sofa v0.1.3)
View SourceDocumentation for Sofa
, a test-driven idiomatic Apache CouchDB client.
If the only tool you have is CouchDB, then everything looks like
{:ok, :relax}
Examples
iex> Sofa.init() |> Sofa.client() |> Sofa.connect!()
%{
"couchdb" => "Welcome",
"features" => ["access-ready", "partitioned", "pluggable-storage-engines",
"reshard", "scheduler"],
"git_sha" => "ce596c65d",
"uuid" => "59c032d3a6adcd5b44315137a124bf69",
"vendor" => %{"name" => "FreeBSD"},
"version" => "3.1.1"
}
Summary
Functions
Get _active_tasks. Only available to admin users.
List all databases. Only available to admin users.
Returns user & password credentials extracted from a typical %URI{} userinfo field, as a Tesla-compatible authorization header. Currently only supports BasicAuth user:password combination.
Builds Telsa runtime client, with appropriate middleware header credentials, from supplied %Sofa{} struct.
Given an existing %Sofa{} struct, or a prepared URI, attempts to connect to the CouchDB instance, and returns an updated %Sofa{} to use in future connections to this server, using the same HTTP credentials.
Bang! wrapper around Sofa.connect/1; raises exceptions on error.
Takes an optional parameter, the CouchDB uri, and returns a struct containing the usual CouchDB server properties. The URI may be given as a string or as a %URI struct.
Minimal wrapper around native CouchDB HTTP API, allowing an escape hatch for raw functionality, and as the core abstraction layer for Sofa itself.
Bang! wrapper around Sofa.raw/1; raises exceptions on error.
Types
Functions
Get _active_tasks. Only available to admin users.
List all databases. Only available to admin users.
Returns user & password credentials extracted from a typical %URI{} userinfo field, as a Tesla-compatible authorization header. Currently only supports BasicAuth user:password combination.
Examples
iex> Sofa.auth_info("admin:password")
%{username: "admin", password: "password"}
iex> Sofa.auth_info("blank:")
%{username: "blank", password: ""}
iex> Sofa.auth_info("garbage")
%{}
Builds Telsa runtime client, with appropriate middleware header credentials, from supplied %Sofa{} struct.
Given an existing %Sofa{} struct, or a prepared URI, attempts to connect to the CouchDB instance, and returns an updated %Sofa{} to use in future connections to this server, using the same HTTP credentials.
Returns an updated {:ok, %Sofa{}}
on success, or {:error, reason}
, if
for example, the URL is unreachable, times out, supplied credentials are
rejected by CouchDB, or returns unexpected HTTP status codes.
Bang! wrapper around Sofa.connect/1; raises exceptions on error.
Takes an optional parameter, the CouchDB uri, and returns a struct containing the usual CouchDB server properties. The URI may be given as a string or as a %URI struct.
This should be piped into Sofa.client/1
to create the HTTP client,
which is stored inside the struct with correct authentication information.
Examples
iex> Sofa.init("https://very:Secure@foreignho.st:6984/")
%Sofa{
auth: "very:Secure",
features: nil,
uri: %URI{
authority: "very:Secure@foreignho.st:6984",
fragment: nil,
host: "foreignho.st",
path: "/",
port: 6984,
query: nil,
scheme: "https",
userinfo: "very:Secure"
},
uuid: nil,
vendor: nil,
version: nil
}
@spec raw( t(), Tesla.Env.url(), Tesla.Env.method(), Tesla.Env.opts(), Tesla.Env.body(), Tesla.Env.headers() ) :: {:error, any()} | {:ok, t(), Sofa.Response.t()}
Minimal wrapper around native CouchDB HTTP API, allowing an escape hatch for raw functionality, and as the core abstraction layer for Sofa itself.
@spec raw!( t(), Tesla.Env.url(), Tesla.Env.method(), Tesla.Env.opts(), Tesla.Env.body() ) :: Sofa.Response.t()
Bang! wrapper around Sofa.raw/1; raises exceptions on error.