BusyBird

 view release on metacpan or  search on metacpan

lib/BusyBird/Config.pm  view on Meta::CPAN

use Encode ();
use Tie::IxHash;
use BusyBird::StatusStorage::SQLite;
use File::ShareDir ();

my %_DEFAULTS = ();

$_DEFAULTS{timeline} = {
    time_zone => sub { "local" },
    time_format => sub { '%x (%a) %X %Z' },
    time_locale => sub { $ENV{LC_TIME} or "C" },
    post_button_url => sub { "https://twitter.com/intent/tweet" },

    status_permalink_builder => sub { return sub {
        my ($status) = @_;
        my $ss = safed($status);
        my $permalink_in_status = $ss->val(qw(busybird status_permalink));
        return $permalink_in_status if defined $permalink_in_status;
        my $id =   $ss->val(qw(busybird original id))
                || $ss->val(qw(busybird original id_str))
                || $ss->val("id")

lib/BusyBird/Main/PSGI/View.pm  view on Meta::CPAN

    my ($self, $timeline_name) = @_;
    weaken $self;  ## in case the functions are kept by $self
    return {
        bb_timestamp => sub {
            my ($timestamp_string) = @_;
            return "" if !$timestamp_string;
            my $timezone = $self->_get_timezone($self->{main_obj}->get_timeline_config($timeline_name, "time_zone"));
            my $dt = BusyBird::DateTime::Format->parse_datetime($timestamp_string);
            return "" if !defined($dt);
            $dt->set_time_zone($timezone);
            $dt->set_locale($self->{main_obj}->get_timeline_config($timeline_name, "time_locale"));
            return $dt->strftime($self->{main_obj}->get_timeline_config($timeline_name, "time_format"));
        },
        bb_status_permalink => sub {
            my ($status) = @_;
            my $builder = $self->{main_obj}->get_timeline_config($timeline_name, "status_permalink_builder");
            my $url = try {
                $builder->($status);
            }catch {
                my ($e) = @_;
                bblog("error", "Error in status_permalink_builder: $e");

lib/BusyBird/Manual/Config.pod  view on Meta::CPAN


=head1 SYNOPSIS

In your ~/.busybird/config.psgi

    use BusyBird;
    
    busybird->set_config(
        timeline_list_per_page => 100,
        time_zone => "UTC",
        time_locale => "en_US",
    );
    
    timeline("home")->set_config(
        time_zone => "+0900"
    );

    end;

=head1 DESCRIPTION

lib/BusyBird/Manual/Config.pod  view on Meta::CPAN

You can set special value C<"local"> to C<TIMEZONE_STR>.
This means the timezone of the local environment is used.

=head2 C<time_format> => STRFTIME_FORMAT_STR

B<Default:> C<"%x (%a) %X %Z">

Format used to render status timestamps.
The format string conforms to the C<strftime(3)> specification.

=head2 C<time_locale> => LOCALE_STR

B<Default:> C<LC_TIME> environment variable or C<"C">

Locale used to render status timestamps.

C<LOCALE_STR> is a valid locale string such as C<"en_US">, C<"ja_JP"> etc.

=head2 C<post_button_url> => URL_STR

B<Default:> C<"https://twitter.com/intent/tweet">

Link URL attached to the "Post" button in the navigation bar.

=head2 C<status_permalink_builder> => CODEREF($status)

B<Default:> return C<< $status->{busybird}{status_permalink} >>, or build permalink to the status page of twitter.com, or return C<undef>

lib/BusyBird/Manual/Config.pod  view on Meta::CPAN

=head2 C<default_level_threshold> => INT

B<Default:> C<0>

The default level threshold for the timeline.

=head1 EXAMPLES

=head2 Customize Timestamps

Status timestamps are rendered using C<time_zone>, C<time_format>, C<time_locale> parameters.
By default L<BusyBird> guesses the "correct" config for your system.

    busybird->set_config(
        time_zone => 'America/Los_Angeles',
        time_format => '%Y-%m-%d %A %H:%M:%S %Z',
        time_locale => 'en_US',
    );

=head2 Expand URLs for Links in Statuses

By default L<BusyBird> renders Twitter Entities in status objects just like Twitter does,
but you can customize this behavior by changing C<*_entity_url_builder> and C<*_entity_text_builder> parameters.

For example, Twitter truncates the displayed text for C<urls> and C<media> entites.
If you want to see fully expanded URLs in statuses, do the following.

lib/BusyBird/Manual/Status.pod  view on Meta::CPAN

If set, this string is used for the permalink URL for the user.


=head2 C<created_at>

The timestamp string at which the status is created.

The timestamp string must be parsable by L<BusyBird::DateTime::Format>.

To customize the way L<BusyBird> renders this timestamp,
see C<time_zone>, C<time_format>, C<time_locale> of L<BusyBird::Manual::Config>.

=head2 C<entities>

Object containing L<Twitter Entities|https://dev.twitter.com/docs/platform-objects/entities>.

Twitter Entities are objects annotating the status text.
Currently L<BusyBird> reads the following fields to create hyperlinks in the text.

=over

lib/BusyBird/Manual/Tutorial.pod  view on Meta::CPAN


    busybird->set_config(time_zone => "UTC");

A global config parameter affects all timelines and the overall behavior of the L<BusyBird> instance.
In the above example, status timestamps in all timelines are rendered in UTC time zone.

C<set_config()> method accepts more than one key-value pairs.

    busybird->set_config(
        time_zone   => "+0900",
        time_locale => "ja_JP"
    );

Some parameters are B<< per-timeline config parameters, >>
which can be set to individual timelines.

To set a per-timeline parameter, use C<< timeline(...)->set_config(...) >>.

    busybird->set_config(time_zone => "UTC");
    
    timeline("foobar")->set_config(time_zone => "+0900");

t/Config.t  view on Meta::CPAN

    is($main->get_timeline_config("__no_timeline", "_some_item"), "hoge", "timeline_config for non-existent timeline gives main's config");
    is($main->get_timeline_config("test", "no_item"), undef, "timeline_config for item not existing in either timeline or main gives undef");
}

{
    note("--- default config (_item_for_test)");
    my ($main, $timeline) = create_main_and_timeline();
    foreach my $case (
        {key => "time_zone", exp => "local"},
        {key => "time_format", exp => '%x (%a) %X %Z'},
        {key => "time_locale", exp => $ENV{LC_TIME} || "C"},
        {key => "post_button_url", exp => "https://twitter.com/intent/tweet"},
        {key => "timeline_web_notifications", exp => "simple"},
        {key => "hidden", exp => 0},
        {key => "attached_image_max_height", exp => 360},
        {key => "attached_image_show_default", exp => "hidden"},
        {key => "acked_statuses_load_count", exp => 20},
        {key => "default_level_threshold", exp => 0},
    ) {
        is($main->get_config($case->{key}), $case->{exp}, "$case->{key} get_config OK");
        is($main->get_timeline_config("test", $case->{key}), $case->{exp}, "$case->{key} get_timeline_config OK");

t/Main_PSGI_View.t  view on Meta::CPAN

}

{
    note("--- template_functions_for_timeline");
    my $main = create_main();
    my $view = BusyBird::Main::PSGI::View->new(main_obj => $main, script_name => "");
    my $funcs = $view->template_functions_for_timeline('test');
    $main->set_config(
        time_zone => "UTC",
        time_format => '%Y-%m-%d %H:%M:%S',
        time_locale => 'en_US',
    );

    note("--- -- bb_timestamp");
    foreach my $case (
        {label => 'normal', args => ['Tue May 28 20:10:13 +0900 2013'], exp => '2013-05-28 11:10:13'},
        {label => 'undef', args => [undef], exp => ''},
        {label => 'empty string', args => [''], exp => ''},
    ) {
        is($funcs->{bb_timestamp}->(@{$case->{args}}), $case->{exp}, "$case->{label}: OK");
    }

t/WebAPI_html.t  view on Meta::CPAN

            is($statuses_html[0]->id, $case->{exp_id}, "$case->{label}: ID OK");
        };
    }
}

{
    note("--- retweet rendering");
    my $main = create_main();
    $main->set_config(
        time_zone => "+0000",
        time_locale => 'en_US',
        time_format => '%Y-%m-%d %H:%M:%S',
        status_permalink_builder => sub { "" },
    );
    my $timeline = $main->timeline('test');
    $timeline->add([{
        id => "retweet_id",
        created_at => "Fri Jun 07 13:50:13 +0900 2013",
        user => { screen_name => "retweeter" },
        busybird => { level => 5 },
        text => 'RT @speaker: I say something!',



( run in 1.219 second using v1.01-cache-2.11-cpan-ceb78f64989 )