Skip to content

Commit

Permalink
Merge pull request #136 from parroty/revert-133-fix-baaad-error-handling
Browse files Browse the repository at this point in the history
Revert "Covering all patterns and preventing errors"
  • Loading branch information
parroty authored Nov 11, 2020
2 parents c6d1aca + fc3e014 commit 9bd5ba3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 109 deletions.
22 changes: 8 additions & 14 deletions lib/extwitter/api/auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,14 @@ defmodule ExTwitter.API.Auth do
def request_token(redirect_url \\ nil) do
oauth = ExTwitter.Config.get_tuples |> verify_params
params = if redirect_url, do: [{"oauth_callback", redirect_url}], else: []
response =
{:ok, {{_, 200, _}, _headers, body}} =
ExTwitter.OAuth.request(:post, request_url("oauth/request_token"),
params, oauth[:consumer_key], oauth[:consumer_secret], "", "")

case response do
{:ok, {{_, 200, _}, _headers, body}} ->
token =
Elixir.URI.decode_query(to_string body)
|> Enum.map(fn {k,v} -> {String.to_atom(k), v} end)
|> Enum.into(%{})
|> ExTwitter.Parser.parse_request_token
{:ok, token}
_ -> {:error, :unknown}
end
Elixir.URI.decode_query(to_string body)
|> Enum.map(fn {k,v} -> {String.to_atom(k), v} end)
|> Enum.into(%{})
|> ExTwitter.Parser.parse_request_token
end

def authorize_url(oauth_token, options \\ %{}) do
Expand All @@ -38,16 +32,16 @@ defmodule ExTwitter.API.Auth do
def access_token(verifier, request_token) do
oauth = ExTwitter.Config.get_tuples |> verify_params
response = ExTwitter.OAuth.request(:post, request_url("oauth/access_token"),
[{"oauth_verifier", verifier}], oauth[:consumer_key], oauth[:consumer_secret], request_token, nil)
[oauth_verifier: verifier], oauth[:consumer_key], oauth[:consumer_secret], request_token, nil)
case response do
{:ok, {{_, 200, _}, _headers, body}} ->
access_token = Elixir.URI.decode_query(to_string body)
|> Enum.map(fn {k,v} -> {String.to_atom(k), v} end)
|> Enum.into(%{})
|> ExTwitter.Parser.parse_access_token
{:ok, access_token}
_ -> {:error, :unknown}
{:ok, {{_, code, _}, _, _}} ->
{:error, code}
end
end
end

6 changes: 3 additions & 3 deletions lib/extwitter/behaviour.ex
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ defmodule ExTwitter.Behaviour do
@callback rate_limit_status(Keyword.t()) :: map()
@callback lookup_status(String.t()) :: [ExTwitter.Model.Tweet.t()]
@callback lookup_status(String.t(), Keyword.t()) :: [ExTwitter.Model.Tweet.t()]
@callback request_token(String.t()) :: {:ok, ExTwitter.Model.RequestToken.t()} | {:error, atom()}
@callback request_token() :: {:ok, ExTwitter.Model.RequestToken.t()} | {:error, atom()}
@callback request_token(String.t()) :: ExTwitter.Model.RequestToken.t()
@callback request_token :: ExTwitter.Model.RequestToken.t()
@callback authorize_url(String.t()) :: {:ok, String.t()} | {:error, String.t()}
@callback authorize_url(String.t(), map()) :: {:ok, String.t()} | {:error, String.t()}
@callback authenticate_url(String.t(), map()) :: {:ok, String.t()} | {:error, String.t()}
@callback authenticate_url(String.t()) :: {:ok, String.t()} | {:error, String.t()}
@callback access_token(String.t(), String.t()) :: {:ok, ExTwitter.Model.AccessToken.t()} | {:error, atom()}
@callback access_token(String.t(), String.t()) :: {:ok, ExTwitter.Model.AccessToken.t()} | {:error, String.t()}
end
Loading

0 comments on commit 9bd5ba3

Please sign in to comment.