Current section

Files

Jump to
ex_trello lib ex_trello.ex
Raw

lib/ex_trello.ex

defmodule ExTrello do
@moduledoc """
Provides access interface to the Trello API.
"""
use Application
@doc """
false
"""
def start(_type, _args) do
ExTrello.Supervisor.start_link
end
# -------------- ExTrello Settings -------------
@doc """
Provides OAuth configuration settings for accessing trello server.
The specified configuration applies globally. Use `ExTrello.configure/2`
for setting different configurations on each processes.
## Examples
ExTrello.configure(
app_key: System.get_env("TRELLO_APP_KEY"),
app_secret: System.get_env("TRELLO_APP_SECRET"),
access_token: System.get_env("TRELLO_ACCESS_TOKEN"),
access_token_secret: System.get_env("TRELLO_ACCESS_SECRET")
)
"""
@spec configure(Keyword.t) :: :ok
defdelegate configure(oauth), to: ExTrello.Config, as: :set
@doc """
Provides OAuth configuration settings for accessing trello server.
## Options
The `scope` can have one of the following values.
* `:global` - configuration is shared for all processes.
* `:process` - configuration is isolated for each process.
## Examples
ExTrello.configure(
:process,
app_key: System.get_env("TRELLO_APP_KEY"),
app_secret: System.get_env("TRELLO_APP_SECRET"),
access_token: System.get_env("TRELLO_ACCESS_TOKEN"),
access_token_secret: System.get_env("TRELLO_ACCESS_SECRET")
)
"""
@spec configure(:global | :process, Keyword.t) :: :ok
defdelegate configure(scope, oauth), to: ExTrello.Config, as: :set
@doc """
Fetch all boards of authenticated user.
## Examples
ExTrello.boards()
"""
@spec boards() :: [ExTrello.Model.Board] | []
defdelegate boards, to: ExTrello.API.Boards
@doc """
Fetch all boards of authenticated user.
## Examples
ExTrello.boards([filter: "pinned,public", fields: "shortLink,subscribed"])
## Reference
https://developers.trello.com/advanced-reference/member#get-1-members-idmember-or-username-boards
"""
@spec boards(Keyword.t) :: [ExTrello.Model.Board] | []
defdelegate boards(options), to: ExTrello.API.Boards
@doc """
Fetch all boards of given username or Trello User ID.
## Examples
ExTrello.boards("trello")
## Reference
https://developers.trello.com/advanced-reference/member#get-1-members-idmember-or-username-boards
"""
@spec boards(String.t, Keyword.t) :: [ExTrello.Model.Board] | []
defdelegate boards(user, options), to: ExTrello.API.Boards
@doc """
Fetch board with board_id.
## Examples
ExTrello.board("57663306e4b15193fcc97483")
## Reference
https://developers.trello.com/advanced-reference/board#get-1-boards-board-id
"""
@spec board(String.t) :: ExTrello.Model.Board.t | nil
defdelegate board(id), to: ExTrello.API.Boards
@doc """
Fetch board with board_id. See reference for list of options.
## Examples
ExTrello.board("57663306e4b15193fcc97483", [actions_display: true])
## Reference
https://developers.trello.com/advanced-reference/board#get-1-boards-board-id
"""
@spec board(String.t, Keyword.t) :: ExTrello.Model.Board.t | nil
defdelegate board(id, options), to: ExTrello.API.Boards
@doc """
Create board with supplied `name`.
## Examples
# Bad
ExTrello.create_board(123) #=> %ExTrello.Error{code: 422, message: "You must provide a name with a length between 1 and 16384 to create a board."}
# Good
ExTrello.create_board("TrelloHub")
## Reference
https://developers.trello.com/advanced-reference/board#post-1-boards
"""
@spec create_board(String.t) :: ExTrello.Model.Board.t | nil
defdelegate create_board(name), to: ExTrello.API.Boards
@doc """
Create board with supplied `name` & options.
## Examples
# Bad
ExTrello.create_board(123) #=> %ExTrello.Error{code: 422, message: "You must provide a name with a length between 1 and 16384 to create a board."}
# Good
ExTrello.create_board("TrelloHub", desc: "An application to synchronize your Trello boards with your GitHub activity.", powerups: "all")
## Reference
https://developers.trello.com/advanced-reference/board#post-1-boards
"""
@spec create_board(String.t, Keyword.t) :: ExTrello.Model.Board.t | nil
defdelegate create_board(name, options), to: ExTrello.API.Boards
@doc """
Edit board with supplied field values.
## Examples
# Capture the id of our newly created board.
%ExTrello.Model.Board{id: id} = ExTrello.create_board("Some name")
# Let's edit the name of our new board.
ExTrello.edit_board(id, name: "Another name entirely.")
## Reference
https://developers.trello.com/advanced-reference/board#put-1-boards-board-id
"""
@spec edit_board(String.t, Keyword.t) :: ExTrello.Model.Board.t | nil
defdelegate edit_board(id, options), to: ExTrello.API.Boards
@doc """
GET OAuthGetRequestToken
## Examples
ExTrello.request_token("http://localhost:4000/auth/trello/callback/1234")
## Reference
https://trello.com/app-key
"""
@spec request_token(String.t) :: [ExTrello.Model.RequestToken.t]
defdelegate request_token(return_url), to: ExTrello.API.Auth
@doc """
GET OAuthAuthorizeToken
## Examples
token = ExTrello.request_token("http://localhost:4000/auth/trello/callback/1234")
ExTrello.authorize_url(token.oauth_token, %{return_url: "http://localhost:4000/auth/trello/callback/1234", scope: "read,write", expiration: "never", name: "Example Authentication"})
Returns the URL you should redirect the user to for authorization
"""
@spec authorize_url(String.t, Map.t) :: {:ok, String.t} | {:error, String.t}
defdelegate authorize_url(oauth_token, options), to: ExTrello.API.Auth
@doc """
GET OAuthAuthorizeToken
## Examples
token = ExTrello.request_token
ExTrello.authorize_url(token.oauth_token)
Returns the URL you should redirect the user to for authorization
"""
@spec authorize_url(String.t) :: {:ok, String.t} | {:error, String.t}
defdelegate authorize_url(oauth_token), to: ExTrello.API.Auth
@doc """
GET OAuthGetAccessToken
## Examples
ExTrello.access_token("OAUTH_VERIFIER", "OAUTH_TOKEN", "OAUTH_TOKEN_SECRET")
"""
@spec access_token(String.t, String.t, String.t) :: {:ok, String.t} | {:error, String.t}
defdelegate access_token(verifier, request_token, request_token_secret), to: ExTrello.API.Auth
end