2021-05-01 23:26:48 +02:00
|
|
|
require "json"
|
|
|
|
|
|
|
|
class Articles::Show < BrowserAction
|
2021-10-03 22:45:20 +02:00
|
|
|
fallback do
|
2022-02-13 16:08:16 +01:00
|
|
|
post_id = ArticleIdParser.parse(context.request)
|
2021-10-11 17:56:28 +02:00
|
|
|
case post_id
|
2021-10-03 22:45:20 +02:00
|
|
|
in Monads::Just
|
2021-10-11 17:56:28 +02:00
|
|
|
response = client_class.post_data(post_id.value!)
|
2021-10-03 22:45:20 +02:00
|
|
|
page = PageConverter.new.convert(response.data)
|
|
|
|
html ShowPage, page: page
|
|
|
|
in Monads::Nothing, Monads::Maybe
|
|
|
|
html(
|
2022-02-12 23:56:36 +01:00
|
|
|
Errors::ParseErrorPage,
|
2021-09-05 03:31:48 +02:00
|
|
|
message: "Error parsing the URL",
|
2021-12-12 18:01:55 +01:00
|
|
|
status_code: 500,
|
2022-02-12 23:56:36 +01:00
|
|
|
original_path: request.path,
|
2021-09-05 03:31:48 +02:00
|
|
|
)
|
|
|
|
end
|
2021-10-03 22:45:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def client_class
|
2021-12-12 18:01:55 +01:00
|
|
|
if use_local?
|
2021-10-03 22:45:20 +02:00
|
|
|
LocalClient
|
2021-05-01 23:26:48 +02:00
|
|
|
else
|
2021-10-03 22:45:20 +02:00
|
|
|
MediumClient
|
2021-05-01 23:26:48 +02:00
|
|
|
end
|
|
|
|
end
|
2021-12-12 18:01:55 +01:00
|
|
|
|
|
|
|
def use_local?
|
|
|
|
ENV.fetch("USE_LOCAL", "false") == "true"
|
|
|
|
end
|
2021-05-01 23:26:48 +02:00
|
|
|
end
|