26 lines
683 B
Elixir
26 lines
683 B
Elixir
|
defmodule SomethingErlang.AwfulApi.Client do
|
||
|
@base_url "https://forums.somethingawful.com/"
|
||
|
|
||
|
def thread_doc(id, page, user) do
|
||
|
resp = new_request(user) |> get_thread(id, page)
|
||
|
:unicode.characters_to_binary(resp.body, :latin1)
|
||
|
end
|
||
|
|
||
|
defp cookies(args) when is_map(args) do
|
||
|
Enum.map_join(args, "; ", fn {k, v} -> "#{k}=#{v}" end)
|
||
|
end
|
||
|
|
||
|
defp get_thread(req, id, page \\ 1) do
|
||
|
url = "showthread.php"
|
||
|
params = [threadid: id, pagenumber: page]
|
||
|
Req.get!(req, url: url, params: params)
|
||
|
end
|
||
|
|
||
|
defp new_request(user) do
|
||
|
Req.new(
|
||
|
base_url: @base_url,
|
||
|
headers: [cookie: [cookies(%{bbuserid: user.id, bbpassword: user.hash})]]
|
||
|
)
|
||
|
end
|
||
|
end
|