Current section
Files
Jump to
Current section
Files
lib/flickrex/oauth/mock.ex
defmodule Flickrex.OAuth.Mock do
@moduledoc false
@behaviour Flickrex.OAuth
@type token :: Flickrex.OAuth.token
@spec request(:get | :post, binary, Keyword.t, token, token, token, token) :: tuple
def request(:get, "https://api.flickr.com/services/oauth/request_token", _, _, _, _, _) do
terms = %{oauth_callback_confirmed: true, oauth_token: "REQUEST_TOKEN",
oauth_token_secret: "REQUEST_TOKEN_SECRET"}
body = terms |> URI.encode_query |> String.to_char_list
{:ok, {nil, nil, body}}
end
def request(:get, "https://api.flickr.com/services/oauth/access_token", _, _, _, _, _) do
terms = %{fullname: "FULLNAME", oauth_token: "ACCESS_TOKEN",
oauth_token_secret: "ACCESS_TOKEN_SECRET",
user_nsid: "USER_NSID", username: "USERNAME"}
body = terms |> URI.encode_query |> String.to_char_list
{:ok, {nil, nil, body}}
end
def request(verb, "https://api.flickr.com/services/rest", params, _, _, _, _) do
method = Keyword.get(params, :method)
format = Keyword.get(params, :format)
no_json = Keyword.get(params, :nojsoncallback)
param =
params
|> Keyword.drop([:method, :format, :nojsoncallback])
|> Enum.map(fn {k,v} -> "#{k}:#{v}" end)
|> Enum.join(",")
body = '{"verb":"#{verb}","param":"#{param}","nojsoncallback":#{no_json},"method":"#{method}","format":"#{format}","stat":"ok"}'
{:ok, {nil, nil, body}}
end
def request(method, url, params, ck, cs, at, ats) do
args = [method: method, url: url, ck: ck, cs: cs, at: at, ats: ats]
query = Keyword.merge(args, params)
body = URI.encode_query(query)
{:ok, {nil, nil, body}}
end
end