new parser
This commit is contained in:
25
lib/something_erlang/awful_api/client.ex
Normal file
25
lib/something_erlang/awful_api/client.ex
Normal file
@ -0,0 +1,25 @@
|
||||
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
|
Reference in New Issue
Block a user