Current section

Files

Jump to
mpx lib mpx.ex
Raw

lib/mpx.ex

defmodule Mpx do
@moduledoc """
Wrapper for the [Ministry Platform](https://www.thinkministry.com/ministryplatform/) api.
For a complete reference to the MP API browse to `https://yourhost/ministryplatformapi/swagger`
## Usage
Currently only a few endpoints are supported:
* `/tables` (get and delete)
* `/tables/:id` (get)
Set configuration options to authenticate with MP in your config.exs. You can use `{:system, "ENV_NAME"}` for runtime configuration.
```
config :mpx,
mp_base_url: {:system, "MP_HOST"},
mp_username: System.get_env("MP_USERNAME"),
mp_password: {:system, "MP_PASSWORD"},
mp_client_id: {:system, "MP_CLIENT_ID"},
mp_client_secret: {:system, "MP_CLIENT_SECRET"}
```
Now call
```
{:ok, token} = Mpx.Authentication.authenticate()
```
to get a reuseable authentication token.
If you prefer not to use elixir configuration to setup you user credentials:
```
{:ok, token} = Mpx.Authentication.authenticate(
username: "username",
password: "password",
client_id: "clientid",
client_secret: "clientsecret")
```
## Querying Table Data
see `Mpx.Tables`
"""
use Application
@doc false
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
worker(Mpx.Authentication, [[name: Mpx.Authentication]])
]
opts = [strategy: :one_for_one]
Supervisor.start_link(children, opts)
end
@doc """
DEPRECATED
Instead please use `Mpx.Authentication.authenticate/1`
"""
@deprecated
@spec authenticate(Mpx.Authentication.authentication_opts | nil) :: {:ok, String.t} | {:error, String.t}
def authenticate(opts \\ []) do
Mpx.Authentication.authenticate(opts)
end
end