File Coverage

blib/lib/Catmandu/Importer/Twitter.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Catmandu::Importer::Twitter;
2              
3 1     1   15377 use Catmandu::Sane;
  1         79262  
  1         5  
4 1     1   286 use Moo;
  1         2  
  1         5  
5 1     1   560 use Net::Twitter;
  0            
  0            
6              
7             with 'Catmandu::Importer';
8              
9             our $VERSION = '0.03';
10              
11             has query => ( is => 'ro', required => 1 );
12             has twitter => ( is => 'ro' );
13             has twitter_consumer_key => ( is => 'ro', required => 1 );
14             has twitter_consumer_secret => ( is => 'ro', required => 1 );
15             has twitter_access_token => ( is => 'ro', required => 1 );
16             has twitter_access_token_secret => ( is => 'ro', required => 1 );
17              
18             before generator => sub {
19             my $self = shift;
20             $self->{twitter} = Net::Twitter->new(
21             traits => [qw/API::RESTv1_1/],
22             consumer_key => $self->twitter_consumer_key,
23             consumer_secret => $self->twitter_consumer_secret,
24             access_token => $self->twitter_access_token,
25             access_token_secret => $self->twitter_access_token_secret,
26             ) or die "$!";
27              
28             };
29              
30             sub generator {
31             my ($self) = @_;
32              
33             sub {
34             state $res = $self->{twitter}->search( $self->query );
35              
36             return unless @{ $res->{statuses} };
37             return shift @{ $res->{statuses} };
38             };
39             }
40              
41             =head1 NAME
42              
43             Catmandu::Importer::Twitter - Package that imports Twitter feeds
44              
45             =head1 SYNOPSIS
46              
47             use Catmandu::Importer::Twitter;
48              
49             my $importer = Catmandu::Importer::Twitter->new(
50             consumer_key => '<your key>' ,
51             consumer_secret => '<your secret>' ,
52             access_token => '<your token>' ,
53             access_token_secret => '<your token secret>' ,
54             query => '#elag2013'
55             );
56              
57             my $n = $importer->each(sub {
58             my $hashref = $_[0];
59             # ...
60             });
61              
62             =head1 METHODS
63              
64             =head2 new(query => '...')
65              
66             Create a new Twitter importer using a query as input.
67              
68             =head2 count
69              
70             =head2 each(&callback)
71              
72             =head2 ...
73              
74             Every Catmandu::Importer is a Catmandu::Iterable all its methods are inherited. The
75             Catmandu::Importer::Twitter methods are not idempotent: Twitter feeds can only be read once.
76              
77             =head1 SEE ALSO
78              
79             L<Catmandu::Iterable>
80              
81             =cut
82              
83             1;