45 lines
1015 B
Elixir
45 lines
1015 B
Elixir
defmodule SomethingErlang.Grover do
|
|
use GenServer
|
|
|
|
alias SomethingErlang.AwfulApi
|
|
require Logger
|
|
|
|
def get_thread!(thread_id, page_number) do
|
|
GenServer.call(__MODULE__, {:show_thread, thread_id, page_number})
|
|
end
|
|
|
|
def get_bookmarks!(pid, page_number) do
|
|
GenServer.call(pid, {:show_bookmarks, page_number})
|
|
end
|
|
|
|
def start_link(user) do
|
|
GenServer.start_link(
|
|
__MODULE__,
|
|
[user]
|
|
)
|
|
end
|
|
|
|
@impl true
|
|
def init([user]) do
|
|
%{bbuserid: userid, bbpassword: userhash} = user
|
|
|
|
initial_state = %{
|
|
user: %{id: userid, hash: userhash}
|
|
}
|
|
|
|
{:ok, initial_state} |> dbg()
|
|
end
|
|
|
|
@impl true
|
|
def handle_call({:show_thread, thread_id, page_number}, _from, state) do
|
|
thread = AwfulApi.parsed_thread(thread_id, page_number, state.user)
|
|
{:reply, thread, state}
|
|
end
|
|
|
|
@impl true
|
|
def handle_call({:show_bookmarks, page_number}, _from, state) do
|
|
bookmarks = AwfulApi.bookmarks(page_number, state.user)
|
|
{:reply, bookmarks, state} |> dbg()
|
|
end
|
|
end
|