2017-04-21 14:56:24 +00:00
|
|
|
# vim: set foldmarker={,}:
|
|
|
|
use strict;
|
2017-04-23 18:51:48 +00:00
|
|
|
use RSSTootalizer::Base;
|
2017-04-21 14:56:24 +00:00
|
|
|
|
2017-04-23 18:51:48 +00:00
|
|
|
package RSSTootalizer::App;
|
|
|
|
@RSSTootalizer::App::ISA = qw(RSSTootalizer::Base);
|
2017-04-21 14:56:24 +00:00
|
|
|
use JSON;
|
|
|
|
use Data::Dumper;
|
|
|
|
|
|
|
|
sub dbTable :lvalue { "apps"; }
|
|
|
|
sub orderBy :lvalue { "instance ASC"; }
|
|
|
|
|
|
|
|
# Class functions
|
|
|
|
sub get_or_create_by_instance {
|
|
|
|
my $class = shift;
|
|
|
|
my $instance = shift;
|
|
|
|
|
2017-04-23 18:51:48 +00:00
|
|
|
my $app = RSSTootalizer::DB->doSELECT("SELECT * FROM apps WHERE instance = ?", $instance);
|
2017-04-21 14:56:24 +00:00
|
|
|
$app = $$app[0];
|
|
|
|
unless (defined($app)){
|
|
|
|
open(DATA, "./register_app.bash '$main::config->{app}->{client_name}' '$main::config->{app}->{redirect_uris}' '$main::config->{app}->{website}' '$instance'|");
|
|
|
|
my $reply = "";
|
|
|
|
{
|
2017-04-23 19:24:03 +00:00
|
|
|
local $/ = undef;
|
2017-04-21 14:56:24 +00:00
|
|
|
$reply = <DATA>;
|
|
|
|
}
|
|
|
|
close DATA;
|
|
|
|
|
|
|
|
$reply = decode_json($reply);
|
2017-04-23 18:51:48 +00:00
|
|
|
RSSTootalizer::DB->doINSERT("INSERT INTO apps (instance, instance_id, instance_client_id, instance_client_secret) VALUES (?, ?, ?, ?)", $instance, $reply->{id}, $reply->{client_id}, $reply->{client_secret});
|
2017-04-21 14:56:24 +00:00
|
|
|
|
2017-04-23 18:51:48 +00:00
|
|
|
$app = RSSTootalizer::DB->doSELECT("SELECT * FROM apps WHERE instance = ?", $instance);
|
2017-04-21 14:56:24 +00:00
|
|
|
$app = $$app[0];
|
|
|
|
}
|
|
|
|
$class->new($app)
|
|
|
|
}
|
|
|
|
|
|
|
|
# Object methods
|
|
|
|
|
|
|
|
sub app {
|
|
|
|
my $self = shift;
|
2017-04-23 18:51:48 +00:00
|
|
|
my $retVal = RSSTootalizer::Application->get_by("id", $self->{"data"}->{"app_id"});
|
2017-04-21 14:56:24 +00:00
|
|
|
return $retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|