Adding json api to see all offers.
This commit is contained in:
parent
8326233d99
commit
098bff90b3
@ -49,6 +49,7 @@ sub startup ($self) {
|
||||
|
||||
# Normal route to controller
|
||||
$r->get('/')->to('Page#index');
|
||||
$r->get('/offers.json')->to('Page#active_offers_json');
|
||||
$r->get('/all.rss')->to('Page#all_rss');
|
||||
$r->get('/shiny.rss')->to('Page#shiny_rss');
|
||||
$r->get('/pokerus.rss')->to('Page#pokerus_rss');
|
||||
|
@ -7,11 +7,11 @@ use warnings;
|
||||
use DateTime::Format::Pg;
|
||||
use DateTime::Format::Mail;
|
||||
use Mojo::DOM;
|
||||
use Mojo::JSON qw/to_json/;
|
||||
|
||||
use Mojo::Base 'Mojolicious::Controller', -signatures;
|
||||
use GTSRSSApi::DB;
|
||||
|
||||
|
||||
# This action will render a template
|
||||
sub index ($self) {
|
||||
|
||||
@ -19,8 +19,19 @@ sub index ($self) {
|
||||
$self->render;
|
||||
}
|
||||
|
||||
sub active_offers_json($self) {
|
||||
my $db = GTSRSSApi::DB->connect;
|
||||
my @offers = $db->selectall_array( <<'EOF', { Slice => {} } );
|
||||
SELECT * FROM offers WHERE is_available ORDER BY date DESC LIMIT 100;
|
||||
EOF
|
||||
@offers =
|
||||
map { $_->{date} = DateTime::Format::Pg->parse_datetime( $_->{date} ); $_ }
|
||||
@offers;
|
||||
return $self->render( json => \@offers );
|
||||
}
|
||||
|
||||
sub all_rss ($self) {
|
||||
my $db = GTSRSSApi::DB->connect;
|
||||
my $db = GTSRSSApi::DB->connect;
|
||||
my @news = $db->selectall_array( <<'EOF', { Slice => {} } );
|
||||
SELECT species, news_text, date FROM news ORDER BY date DESC LIMIT 100;
|
||||
EOF
|
||||
@ -36,7 +47,7 @@ EOF
|
||||
}
|
||||
|
||||
sub computer_all_rss ($self) {
|
||||
my $db = GTSRSSApi::DB->connect;
|
||||
my $db = GTSRSSApi::DB->connect;
|
||||
my @news = $db->selectall_array( <<'EOF', { Slice => {} } );
|
||||
SELECT species, news_text, date FROM news_computer ORDER BY date DESC LIMIT 100;
|
||||
EOF
|
||||
@ -52,7 +63,7 @@ EOF
|
||||
}
|
||||
|
||||
sub computer_shiny_rss ($self) {
|
||||
my $db = GTSRSSApi::DB->connect;
|
||||
my $db = GTSRSSApi::DB->connect;
|
||||
my @news = $db->selectall_array( <<'EOF', { Slice => {} } );
|
||||
SELECT species, news_text, date FROM news_computer WHERE is_shiny ORDER BY date DESC LIMIT 100;
|
||||
EOF
|
||||
@ -68,7 +79,7 @@ EOF
|
||||
}
|
||||
|
||||
sub shiny_rss ($self) {
|
||||
my $db = GTSRSSApi::DB->connect;
|
||||
my $db = GTSRSSApi::DB->connect;
|
||||
my @news = $db->selectall_array( <<'EOF', { Slice => {} } );
|
||||
SELECT species, news_text, date FROM news WHERE is_shiny ORDER BY date DESC LIMIT 100;
|
||||
EOF
|
||||
@ -84,7 +95,7 @@ EOF
|
||||
}
|
||||
|
||||
sub computer_pokerus_rss($self) {
|
||||
my $db = GTSRSSApi::DB->connect;
|
||||
my $db = GTSRSSApi::DB->connect;
|
||||
my @news = $db->selectall_array( <<'EOF', { Slice => {} } );
|
||||
SELECT species, news_text, date FROM news_computer WHERE has_pokerus ORDER BY date DESC LIMIT 100;
|
||||
EOF
|
||||
@ -100,7 +111,7 @@ EOF
|
||||
}
|
||||
|
||||
sub pokerus_rss($self) {
|
||||
my $db = GTSRSSApi::DB->connect;
|
||||
my $db = GTSRSSApi::DB->connect;
|
||||
my @news = $db->selectall_array( <<'EOF', { Slice => {} } );
|
||||
SELECT species, news_text, date FROM news WHERE has_pokerus ORDER BY date DESC LIMIT 100;
|
||||
EOF
|
||||
@ -125,8 +136,9 @@ sub _feed_from_news_list ( $self, $news, $title, $link ) {
|
||||
$channel_tag->child_nodes->first->append_content($link_tag);
|
||||
$channel_tag->child_nodes->first->append_content($description_tag);
|
||||
|
||||
for my $new ( @$news ) {
|
||||
$channel_tag->child_nodes->first->append_content( $self->_new_to_rss($new) );
|
||||
for my $new (@$news) {
|
||||
$channel_tag->child_nodes->first->append_content(
|
||||
$self->_new_to_rss($new) );
|
||||
}
|
||||
$dom->child_nodes->first->append_content($channel_tag);
|
||||
return $dom;
|
||||
@ -136,10 +148,9 @@ sub _new_to_rss ( $self, $new ) {
|
||||
my $item_tag = Mojo::DOM->new_tag('item');
|
||||
my $title_tag = Mojo::DOM->new_tag( 'title', $new->{species} );
|
||||
my $link = Mojo::DOM->new_tag( 'link', 'https://pkmnclassic.net/gts/' );
|
||||
my $description = Mojo::DOM->new_tag( 'description',
|
||||
$new->{news_text});
|
||||
my $guid = Mojo::DOM->new_tag( 'guid', $new->{uuid} );
|
||||
my $date = Mojo::DOM->new_tag(
|
||||
my $description = Mojo::DOM->new_tag( 'description', $new->{news_text} );
|
||||
my $guid = Mojo::DOM->new_tag( 'guid', $new->{uuid} );
|
||||
my $date = Mojo::DOM->new_tag(
|
||||
'pubDate',
|
||||
''
|
||||
. DateTime::Format::Mail->format_datetime(
|
||||
|
@ -4,12 +4,13 @@
|
||||
<body>
|
||||
<h1>List of RSS Feeds for different kinds of GTS trades in pkmn-classic network.</h1>
|
||||
<ul>
|
||||
<li><a href="/all.rss">All trades.</a></li>
|
||||
<li><a href="/shiny.rss">Only shiny trades.</a></li>
|
||||
<li><a href="/pokerus.rss">Only pokerus trades.</a></li>
|
||||
<li><a href="/computer-all.rss">All trades. (JSON)</a></li>
|
||||
<li><a href="/computer-shiny.rss">Only shiny trades. (JSON)</a></li>
|
||||
<li><a href="/computer-pokerus.rss">Only pokerus trades. (JSON)</a></li>
|
||||
<li><a href="/all.rss">All trades updates limited to 100.</a></li>
|
||||
<li><a href="/shiny.rss">Only shiny trades updates limited to 100.</a></li>
|
||||
<li><a href="/pokerus.rss">Only pokerus trades updates limited to 100.</a></li>
|
||||
<li><a href="/offers.json">All available offers in JSON format for computer processing limited to 100.</a></li>
|
||||
<li><a href="/computer-all.rss">All trades updates limited to 100. (JSON)</a></li>
|
||||
<li><a href="/computer-shiny.rss">Only shiny trades updates limited to 100. (JSON)</a></li>
|
||||
<li><a href="/computer-pokerus.rss">Only pokerus trades updates limited to 100. (JSON)</a></li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user