Packages
extwitter
0.13.0
0.14.0
0.13.1
0.13.0
0.12.5
0.12.4
0.12.3
0.12.2
0.12.1
0.12.0
0.11.0
0.10.0
0.9.6
0.9.5
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.6
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.3
0.7.2
0.7.1
0.7.0
0.6.3
0.6.2
0.6.1
0.6.0
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.0
0.2.1
0.2.0
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Twitter client library for Elixir.
Current section
Files
Jump to
Current section
Files
lib/extwitter/api/auth.ex
defmodule ExTwitter.API.Auth do
@moduledoc """
Provides Authorization and Authentication API interfaces.
"""
import ExTwitter.API.Base
def request_token(redirect_url \\ nil) do
oauth = ExTwitter.Config.get_tuples |> verify_params
params = if redirect_url, do: [{"oauth_callback", redirect_url}], else: []
{:ok, {{_, 200, _}, _headers, body}} =
ExTwitter.OAuth.request(:post, request_url("oauth/request_token"),
params, oauth[:consumer_key], oauth[:consumer_secret], "", "")
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
args = Map.merge(%{oauth_token: oauth_token}, options)
{:ok, request_url("oauth/authorize?" <> Elixir.URI.encode_query(args)) |> to_string}
end
def authenticate_url(oauth_token, options \\ %{}) do
args = Map.merge(%{oauth_token: oauth_token}, options)
{:ok, request_url("oauth/authenticate?" <> Elixir.URI.encode_query(args)) |> to_string}
end
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)
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}
{:ok, {{_, code, _}, _, _}} ->
{:error, code}
end
end
end