File: 13_search.t

package info (click to toggle)
libnet-twitter-perl 3.13008-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 656 kB
  • ctags: 235
  • sloc: perl: 5,408; makefile: 4
file content (42 lines) | stat: -rw-r--r-- 974 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!perl
use warnings;
use strict;
use Test::More;
use lib qw(t/lib);

eval 'use TestUA';
plan skip_all => 'LWP::UserAgent 5.819 required' if $@;

plan tests => 5;

use Net::Twitter;

my $nt = Net::Twitter->new(traits => [qw/API::Search/]);

my $request;
my %args;
my $response = HTTP::Response->new(200, 'OK');
$response->content('{"test":"success"}');

$nt->ua->add_handler(request_send => sub {
    $request = shift;

    $response->request($request);
    %args = $request->uri->query_form;

    return $response;
});

my $search_term = "intelligent life";
my $r = $nt->search($search_term);
isa_ok $r,       'HASH',       "result is expected type";
is     $args{q}, $search_term, "param q has search term";

# additional args in a HASH ref
$r = $nt->search($search_term, { page => 2 });
is $args{page}, 2, "page parameter set";

like $request->uri, qr(/search.twitter.com/), 'search endpoint';

$nt->trends;
like $request->uri, qr(/api.twitter.com/1/), 'trends endpoint';