Skip to content

Commit

Permalink
Version 1.1:
Browse files Browse the repository at this point in the history
- Switch http clients from httpotion -> httpoison (ibrowse -> hackney)
- Cleanup README
- Add attachment to card
- Bump version
  • Loading branch information
Christopher Yammine authored Mar 22, 2017
1 parent 143637c commit 5ff5ddc
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: elixir
elixir:
- 1.3.2
- 1.4.0
otp_release:
- 19.0
env:
Expand Down
24 changes: 2 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ end
def deps do
[
...,
{:ex_trello, "~> 1.0.1"}
{:ex_trello, "~> 1.1.0"}
]
end
```
Expand Down Expand Up @@ -153,29 +153,9 @@ ExTrello.configure(
{:ok, member} = ExTrello.member() # Fetches the authenticated member record from Trello
```


## TODO:
- [x] ~~Fetch Boards~~
- [x] ~~Create & Edit Boards~~
- [x] ~~Support nested resources~~
- [x] ~~Fetch Cards~~
- [x] ~~Comment on Cards~~
- [x] ~~Create & Edit Cards~~
- [x] ~~Implement own OAuth 1.0 library to remove dependency on `erlang-oauth` (or investigate existing solutions)~~
- [x] ~~Usage tutorial.~~
- [x] ~~Tests (IN PROGRESS)~~
- [ ] Add models for ~~label~~, ~~checklist~~, ~~member~~, notification, ~~organization~~, session, token, ~~action~~
- [ ] Pagination
- [ ] Code Cleanup! (Perhaps remove `defapicall` macro and use the `with` keyword instead? Have to evaluate.)
- [ ] Example Application
- [ ] Investigate handling storage of request_token.oauth_token_secret instead of leaving that up to the dev.


## LICENSE
The MIT License (MIT)
Copyright (c) 2016 Christopher Yammine

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 changes: 6 additions & 6 deletions lib/ex_trello/api/auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ defmodule ExTrello.API.Auth do
params = if redirect_url, do: [{"oauth_callback", redirect_url}], else: []

case OAuth.request(:get, request_url("OAuthGetRequestToken"), params, credentials) do
%HTTPotion.Response{body: body, status_code: code} when code in 200..300 ->
%HTTPoison.Response{body: body, status_code: code} when code in 200..300 ->
URI.decode_query(body)
|> Utils.snake_case_keys
|> Parser.parse_request_token
%HTTPotion.Response{body: body, status_code: code} ->
%HTTPoison.Response{body: body, status_code: code} ->
throw(%ExTrello.Error{code: code, message: body})
%HTTPotion.ErrorResponse{message: message} ->
%HTTPoison.Error{reason: message} ->
throw(%ExTrello.ConnectionError{reason: message})
end
end
Expand All @@ -38,13 +38,13 @@ defmodule ExTrello.API.Auth do
credentials = [{:token, request_token}, {:token_secret, request_token_secret} | consumer] |> OAuther.credentials

case OAuth.request(:get, request_url("OAuthGetAccessToken"), [oauth_verifier: verifier], credentials) do
%HTTPotion.Response{body: body, status_code: 200} ->
%HTTPoison.Response{body: body, status_code: 200} ->
URI.decode_query(body)
|> Utils.snake_case_keys
|> Parser.parse_access_token
%HTTPotion.Response{body: body, status_code: code} ->
%HTTPoison.Response{body: body, status_code: code} ->
throw(%ExTrello.Error{code: code, message: body})
%HTTPotion.ErrorResponse{message: message} ->
%HTTPoison.Error{reason: message} ->
throw(%ExTrello.ConnectionError{reason: message})
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/ex_trello/api/base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ defmodule ExTrello.API.Base do
credentials = ExTrello.Config.get |> verify_params |> OAuther.credentials

case ExTrello.OAuth.request(method, url, params, credentials) do
%HTTPotion.Response{body: body, status_code: code} when code >= 200 and code < 300 ->
%HTTPoison.Response{body: body, status_code: code} when code >= 200 and code < 300 ->
Poison.decode!(body)
|> Utils.snake_case_keys

%HTTPotion.Response{body: body, status_code: code} ->
%HTTPoison.Response{body: body, status_code: code} ->
throw(%ExTrello.Error{code: code, message: body})

%HTTPotion.ErrorResponse{message: message} ->
%HTTPoison.Error{reason: message} ->
throw(%ExTrello.ConnectionError{reason: message})
end
end
Expand Down
9 changes: 9 additions & 0 deletions lib/ex_trello/api/cards.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@ defmodule ExTrello.API.Cards do
request(:post, "cards/#{id_or_shortlink}/actions/comments", [text: text])
|> Parser.parse_action
end

def add_attachment(card, file_path) when is_binary(file_path), do: add_attachment(card, [])
def add_attachment(%Card{id: id}, file_path, options) when is_binary(file_path) and is_list(options) do
add_attachment(id, file_path, options)
end
defapicall add_attachment(id, file_path, options) when is_binary(id) and is_binary(file_path) and is_list(options) do
opts = [{:file, file_path}|options]
request(:file, "cards/#{id}/attachments", opts)
end
end
4 changes: 2 additions & 2 deletions lib/ex_trello/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule ExTrello.Config do
@doc """
Get OAuth configuration values.
"""
def get, do: get(current_scope)
def get, do: get(current_scope())
def get(:global) do
Application.get_env(:ex_trello, :oauth, nil)
end
Expand All @@ -15,7 +15,7 @@ defmodule ExTrello.Config do
@doc """
Set OAuth configuration values.
"""
def set(value), do: set(current_scope, value)
def set(value), do: set(current_scope(), value)
def set(:global, value), do: Application.put_env(:ex_trello, :oauth, value)
def set(:process, value) do
Process.put(:_ex_trello_oauth, value)
Expand Down
22 changes: 15 additions & 7 deletions lib/ex_trello/oauth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,27 @@ defmodule ExTrello.OAuth do

case method do
:get ->
HTTPotion.request(method, url <> "?#{URI.encode_query(request_params)}", headers: to_keyword([authorization_header]))
HTTPoison.get(url <> "?#{URI.encode_query(request_params)}", [authorization_header])
:file ->
HTTPoison.post(url, {:multipart, prep_file_upload(request_params)}, [authorization_header])
_ ->
HTTPotion.request(
# https://hexdocs.pm/httpoison/HTTPoison.html#request/5
HTTPoison.request(
method,
url,
headers: to_keyword([authorization_header, {"Content-Type", "application/x-www-form-urlencoded"}]),
body: URI.encode_query(request_params)
{:form, request_params},
[authorization_header]
)
end
end |> elem(1)
end

defp to_keyword(list) when is_list(list) do
list |> Enum.map(fn ({k, v}) -> {:"#{k}", v} end)
defp prep_file_upload(params) do
params |> Enum.map(fn
{"file", value} ->
{:file, value}
any ->
any
end)
end

defp stringify_params(params) when is_list(params) do
Expand Down
2 changes: 0 additions & 2 deletions lib/ex_trello/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ defmodule ExTrello.Parser do
# TODO: Maybe look into writing a macro to define these functions from the `@nested_resources` word list
defp preprocess(%{board: board} = object, :board), do: Map.put(object, :board, board |> parse_board)
defp preprocess(%{boards: boards} = object, :boards), do: Map.put(object, :boards, Enum.map(boards, &parse_board/1))

defp preprocess(%{labels: labels} = object, :labels), do: Map.put(object, :labels, Enum.map(labels, &parse_label/1))

defp preprocess(%{card: card} = object, :card), do: Map.put(object, :card, card |> parse_card)
defp preprocess(%{cards: cards} = object, :cards), do: Map.put(object, :cards, Enum.map(cards, &parse_card/1))
defp preprocess(%{list: list} = object, :list), do: Map.put(object, :list, list |> parse_list)
Expand Down
8 changes: 4 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ defmodule ExTrello.Mixfile do

def project do
[app: :ex_trello,
version: "1.0.1",
elixir: "~> 1.3",
version: "1.1.0",
elixir: "~> 1.0",
description: "An Elixir package to interface with the Trello API",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
Expand All @@ -18,14 +18,14 @@ defmodule ExTrello.Mixfile do
#
# Type "mix help compile.app" for more information
def application do
[applications: [:logger, :inets, :ssl, :crypto, :httpotion]]
[applications: [:logger, :inets, :ssl, :crypto, :httpoison]]
end

defp deps do
[
{:oauther, "~> 1.0.1"},
{:poison, "~> 2.2"},
{:httpotion, "~> 3.0.0"},
{:httpoison, "~> 0.11.0"},
{:ex_doc, ">= 0.0.0", only: :dev},
{:exvcr, "~> 0.7", only: :test},
{:excoveralls, "~> 0.5", only: :test},
Expand Down
28 changes: 13 additions & 15 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
%{"certifi": {:hex, :certifi, "0.4.0", "a7966efb868b179023618d29a407548f70c52466bf1849b9e8ebd0e34b7ea11f", [:rebar3], []},
"dialyxir": {:hex, :dialyxir, "0.3.5", "eaba092549e044c76f83165978979f60110dc58dd5b92fd952bf2312f64e9b14", [:mix], []},
"earmark": {:hex, :earmark, "1.0.1", "2c2cd903bfdc3de3f189bd9a8d4569a075b88a8981ded9a0d95672f6e2b63141", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.13.0", "aa2f8fe4c6136a2f7cfc0a7e06805f82530e91df00e2bff4b4362002b43ada65", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
"exactor": {:hex, :exactor, "2.2.1", "89bc6798f7ed5b5a090f8e4a0b6997478a3266e831d2ff31677ac764ffa75973", [:mix], []},
"excoveralls": {:hex, :excoveralls, "0.5.5", "d97b6fc7aa59c5f04f2fa7ec40fc0b7555ceea2a5f7e7c442aad98ddd7f79002", [:mix], [{:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}]},
"exjsx": {:hex, :exjsx, "3.2.0", "7136cc739ace295fc74c378f33699e5145bead4fdc1b4799822d0287489136fb", [:mix], [{:jsx, "~> 2.6.2", [hex: :jsx, optional: false]}]},
"exvcr": {:hex, :exvcr, "0.8.2", "8ad46e077995e1ff1278b44001844fcd1e9c172bd1d9f6303e6c8f9ba8bbb679", [:mix], [{:exactor, "~> 2.2", [hex: :exactor, optional: false]}, {:exjsx, "~> 3.2", [hex: :exjsx, optional: false]}, {:httpoison, "~> 0.8", [hex: :httpoison, optional: true]}, {:httpotion, "~> 3.0", [hex: :httpotion, optional: true]}, {:ibrowse, "~> 4.2.2", [hex: :ibrowse, optional: true]}, {:meck, "~> 0.8.3", [hex: :meck, optional: false]}]},
"hackney": {:hex, :hackney, "1.6.1", "ddd22d42db2b50e6a155439c8811b8f6df61a4395de10509714ad2751c6da817", [:rebar3], [{:certifi, "0.4.0", [hex: :certifi, optional: false]}, {:idna, "1.2.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.0", [hex: :ssl_verify_fun, optional: false]}]},
"httpotion": {:hex, :httpotion, "3.0.1", "6165e7fe4052dfeadd4b480e4ed6619975242ac91d577e4868af92613f9e99df", [:mix], [{:ibrowse, "~> 4.2", [hex: :ibrowse, optional: false]}]},
"ibrowse": {:hex, :ibrowse, "4.2.2", "b32b5bafcc77b7277eff030ed32e1acc3f610c64e9f6aea19822abcadf681b4b", [:rebar3], []},
%{"certifi": {:hex, :certifi, "0.7.0", "861a57f3808f7eb0c2d1802afeaae0fa5de813b0df0979153cbafcd853ababaf", [:rebar3], []},
"dialyxir": {:hex, :dialyxir, "0.4.3", "a4daeebd0107de10d3bbae2ccb6b8905e69544db1ed5fe9148ad27cd4cb2c0cd", [:mix], []},
"earmark": {:hex, :earmark, "1.1.0", "8c2bf85d725050a92042bc1edf362621004d43ca6241c756f39612084e95487f", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.14.5", "c0433c8117e948404d93ca69411dd575ec6be39b47802e81ca8d91017a0cf83c", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
"exactor": {:hex, :exactor, "2.2.3", "a6972f43bb6160afeb73e1d8ab45ba604cd0ac8b5244c557093f6e92ce582786", [:mix], []},
"excoveralls": {:hex, :excoveralls, "0.6.1", "9e946b6db84dba592f47632157ecd135a46384b98a430fd16007dc910c70348b", [:mix], [{:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}]},
"exjsx": {:hex, :exjsx, "3.2.1", "1bc5bf1e4fd249104178f0885030bcd75a4526f4d2a1e976f4b428d347614f0f", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, optional: false]}]},
"exvcr": {:hex, :exvcr, "0.8.5", "95d8f28de82d27f057f855048a5a661f00bf46204f594db662057522ecf3acb1", [:mix], [{:exactor, "~> 2.2", [hex: :exactor, optional: false]}, {:exjsx, "~> 3.2", [hex: :exjsx, optional: false]}, {:httpoison, "~> 0.8", [hex: :httpoison, optional: true]}, {:httpotion, "~> 3.0", [hex: :httpotion, optional: true]}, {:ibrowse, "~> 4.2.2", [hex: :ibrowse, optional: true]}, {:meck, "~> 0.8.3", [hex: :meck, optional: false]}]},
"hackney": {:hex, :hackney, "1.6.5", "8c025ee397ac94a184b0743c73b33b96465e85f90a02e210e86df6cbafaa5065", [:rebar3], [{:certifi, "0.7.0", [hex: :certifi, optional: false]}, {:idna, "1.2.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]},
"httpoison": {:hex, :httpoison, "0.11.0", "b9240a9c44fc46fcd8618d17898859ba09a3c1b47210b74316c0ffef10735e76", [:mix], [{:hackney, "~> 1.6.3", [hex: :hackney, optional: false]}]},
"idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [:rebar3], []},
"inch_ex": {:hex, :inch_ex, "0.5.3", "39f11e96181ab7edc9c508a836b33b5d9a8ec0859f56886852db3d5708889ae7", [:mix], [{:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: false]}]},
"jsx": {:hex, :jsx, "2.6.2", "213721e058da0587a4bce3cc8a00ff6684ced229c8f9223245c6ff2c88fbaa5a", [:mix, :rebar], []},
"inch_ex": {:hex, :inch_ex, "0.5.5", "b63f57e281467bd3456461525fdbc9e158c8edbe603da6e3e4671befde796a3d", [:mix], [{:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, optional: false]}]},
"jsx": {:hex, :jsx, "2.8.1", "1453b4eb3615acb3e2cd0a105d27e6761e2ed2e501ac0b390f5bbec497669846", [:mix, :rebar3], []},
"meck": {:hex, :meck, "0.8.4", "59ca1cd971372aa223138efcf9b29475bde299e1953046a0c727184790ab1520", [:make, :rebar], []},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []},
"oauth": {:git, "https://github.com/tim/erlang-oauth.git", "fca8163e8f7af867015e2413c4b03a4f8f4df0c9", []},
"oauther": {:hex, :oauther, "1.0.2", "c2a8476649f3def353db4d38aa498d1313a21e2dd36958ac74f6ee80ef374620", [:mix], []},
"poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [:mix], []},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.0", "edee20847c42e379bf91261db474ffbe373f8acb56e9079acb6038d4e0bf414f", [:make, :rebar], []}}
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []}}
8 changes: 4 additions & 4 deletions test/auth_test.exs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule ExTrello.AuthTest do
use ExUnit.Case, async: false
use ExVCR.Mock
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney

setup_all do
HTTPotion.start # Ensure :httpotion is started.
HTTPoison.start # Ensure :httpoison is started.

ExVCR.Config.filter_request_headers("Authorization")
ExVCR.Config.filter_sensitive_data("oauth_signature=[^\"]+", "<REMOVED>")
Expand Down Expand Up @@ -34,7 +34,7 @@ defmodule ExTrello.AuthTest do
use_cassette "failed_connection", custom: true do
response = ExTrello.request_token("something")

assert match?({:connection_error, %ExTrello.ConnectionError{reason: "nxdomain", message: "Connection error."}}, response)
assert match?({:connection_error, %ExTrello.ConnectionError{reason: ["conn_failed", ["error", "nxdomain"]], message: "Connection error."}}, response)
end
end

Expand Down Expand Up @@ -81,7 +81,7 @@ defmodule ExTrello.AuthTest do
use_cassette "failed_connection", custom: true do
response = ExTrello.access_token("something", "strange", "in the neighborhood")

assert match?({:connection_error, %ExTrello.ConnectionError{reason: "nxdomain", message: "Connection error."}}, response)
assert match?({:connection_error, %ExTrello.ConnectionError{reason: ["conn_failed", ["error", "nxdomain"]], message: "Connection error."}}, response)
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/ex_trello_test.exs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
defmodule ExTrelloTest do
use ExUnit.Case, async: false
use ExVCR.Mock
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
doctest ExTrello

alias ExTrello.Model.{Action, Board, Card, Label, Member, Organization, Checklist, Notification}
alias ExTrello.Model.List, as: TrelloList # Necessary because Elixit.List module is being used in these tests

setup_all do
HTTPotion.start # Ensure :httpotion is started.
HTTPoison.start # Ensure :httpoison is started.

ExVCR.Config.filter_request_headers("Authorization")
ExVCR.Config.filter_sensitive_data("oauth_signature=[^\"]+", "<REMOVED>")
Expand Down Expand Up @@ -37,7 +37,7 @@ defmodule ExTrelloTest do
use_cassette "failed_connection", custom: true do
response = ExTrello.boards()

assert match?({:connection_error, %ExTrello.ConnectionError{reason: "nxdomain", message: "Connection error."}}, response)
assert match?({:connection_error, %ExTrello.ConnectionError{reason: ["conn_failed", ["error", "nxdomain"]], message: "Connection error."}}, response)
end
end

Expand Down

0 comments on commit 5ff5ddc

Please sign in to comment.