Codebase list libnet-twitter-perl / 7d27cf8
[svn-upgrade] Integrating new upstream version, libnet-twitter-perl (3.11008) Jonathan Yu 14 years ago
14 changed file(s) with 429 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
0 3.11008 2010-03-02
1 - Added support for new api methods: reverse_geocode, geo_id
2 - Updated method "update" with new parameters: place_id, display_coordinates
3
04 3.11007 2010-02-27
15 - xAuth implemented and tested
26
5959 t/99-pod_coverage.t
6060 t/99-pod_spelling.t
6161 t/99-pod_syntax.t
62 t/geo.t
6263 t/lib/TestUA.pm
6364 t/unicode.t
4949 homepage: http://github.com/semifor/Net-Twitter
5050 license: http://dev.perl.org/licenses/
5151 repository: git://github.com/semifor/Net-Twitter.git
52 version: 3.11007
52 version: 3.11008
11 Net::Twitter - A perl interface to the Twitter API
22
33 VERSION
4 This document describes Net::Twitter version 3.11007
4 This document describes Net::Twitter version 3.11008
55
66 SYNOPSIS
77 use Net::Twitter;
784784
785785 Returns: Bool
786786
787 geo_id
788 geo_id(id)
789
790 Parameters: id
791 Required: id
792
793 Returns details of a place returned from the "reverse_geocode"
794 method.
795
796 Returns: HashRef
797
787798 home_timeline
788799
789800 Parameters: since_id, max_id, count, page
908919 Returns: Arrayref[Status]
909920
910921 retweets_of_me
911 alias: rewtweeted_of_me
922 alias: retweeted_of_me
912923
913924 Parameters: since_id, max_id, count, page
914925 Required: *none*
917928 have been retweeted by others.
918929
919930 Returns: ArrayRef[Status]
931
932 reverse_geocode
933 reverse_geocode(lat, long)
934
935 Parameters: lat, long, accuracy, granularity, max_results
936 Required: lat, long
937
938 Search for places (cities and neighborhoods) that can be attached to
939 a statuses/update. Given a latitude and a longitude, return a list
940 of all the valid places that can be used as a place_id when updating
941 a status. Conceptually, a query can be made from the user's
942 location, retrieve a list of places, have the user validate the
943 location he or she is at, and then send the ID of this location up
944 with a call to statuses/update.
945
946 There are multiple granularities of places that can be returned --
947 "neighborhoods", "cities", etc. At this time, only United States
948 data is available through this method.
949
950 lat Required. The latitude to query about. Valid ranges are -90.0 to
951 +90.0 (North is positive) inclusive.
952
953 long
954 Required. The longitude to query about. Valid ranges are -180.0
955 to +180.0 (East is positive) inclusive.
956
957 accuracy
958 Optional. A hint on the "region" in which to search. If a
959 number, then this is a radius in meters, but it can also take a
960 string that is suffixed with ft to specify feet. If this is not
961 passed in, then it is assumed to be 0m. If coming from a device,
962 in practice, this value is whatever accuracy the device has
963 measuring its location (whether it be coming from a GPS, WiFi
964 triangulation, etc.).
965
966 granularity
967 Optional. The minimal granularity of data to return. If this is
968 not passed in, then "neighborhood" is assumed. "city" can also
969 be passed.
970
971 max_results
972 Optional. A hint as to the number of results to return. This
973 does not guarantee that the number of results returned will
974 equal max_results, but instead informs how many "nearby" results
975 to return. Ideally, only pass in the number of places you intend
976 to display to the user here.
977
978 Returns: HashRef
920979
921980 saved_searches
922981
10361095 update
10371096 update(status)
10381097
1039 Parameters: status, lat, long, in_reply_to_status_id
1098 Parameters: status, lat, long, place_id, display_coordinates,
1099 in_reply_to_status_id
10401100 Required: status
10411101
10421102 Updates the authenticating user's status. Requires the status
10431103 parameter specified. A status update with text identical to the
10441104 authenticating user's current status will be ignored.
10451105
1046 The optional "lat" and "long" parameters add location data to the
1047 status for a geo enabled account. They expect values in the ranges
1048 -90.0 to +90.0 and -180.0 to +180.0 respectively. They are ignored
1049 unless the user's "geo_enabled" field is true.
1106 status
1107 Required. The text of your status update. URL encode as
1108 necessary. Statuses over 140 characters will cause a 403 error
1109 to be returned from the API.
1110
1111 in_reply_to_status_id
1112 Optional. The ID of an existing status that the update is in
1113 reply to. o Note: This parameter will be ignored unless the
1114 author of the tweet this parameter references is mentioned
1115 within the status text. Therefore, you must include @username,
1116 where username is the author of the referenced tweet, within the
1117 update.
1118
1119 lat Optional. The location's latitude that this tweet refers to. The
1120 valid ranges for latitude is -90.0 to +90.0 (North is positive)
1121 inclusive. This parameter will be ignored if outside that range,
1122 if it is not a number, if geo_enabled is disabled, or if there
1123 not a corresponding long parameter with this tweet.
1124
1125 long
1126 Optional. The location's longitude that this tweet refers to.
1127 The valid ranges for longitude is -180.0 to +180.0 (East is
1128 positive) inclusive. This parameter will be ignored if outside
1129 that range, if it is not a number, if geo_enabled is disabled,
1130 or if there not a corresponding lat parameter with this tweet.
1131
1132 place_id
1133 Optional. The place to attach to this status update. Valid
1134 place_ids can be found by querying "reverse_geocode".
1135
1136 display_coordinates
1137 Optional. By default, geo-tweets will have their coordinates
1138 exposed in the status object (to remain backwards compatible
1139 with existing API applications). To turn off the display of the
1140 precise latitude and longitude (but keep the contextual location
1141 information), pass "display_coordinates =" 0> on the status
1142 update.
10501143
10511144 Returns: Status
10521145
11 use Moose;
22
33 # use *all* digits for fBSD ports
4 our $VERSION = '3.11007';
4 our $VERSION = '3.11008';
55 $VERSION = eval $VERSION; # numify for warning-free dev releases
66
77 extends 'Net::Twitter::Core';
6767 ? $synthetic_args->{authenticate}
6868 : $options{authenticate}
6969 ;
70 # promote boolean parameters
71 for my $boolean_arg ( @{ $options{booleans} } ) {
72 if ( exists $args->{$boolean_arg} ) {
73 next if $args->{$boolean_arg} =~ /^true|false$/;
74 $args->{$boolean_arg} = $args->{$boolean_arg} ? 'true' : 'false';
75 }
76 }
7077
7178 my $local_path = $modify_path->($path, $args);
7279
108115 has required => ( isa => 'ArrayRef[Str]', is => 'ro', default => sub { [] } );
109116 has returns => ( isa => 'Str', is => 'ro', predicate => 'has_returns' );
110117 has deprecated => ( isa => 'Bool', is => 'ro', default => 0 );
118 has booleans => ( isa => 'ArrayRef[Str]', is => 'ro', default => sub { [] } );
111119 has authenticate => ( isa => 'Bool', is => 'ro', required => 1 );
112120 has datetime_parser => ( is => 'ro', required => 1 );
113121
1616 use namespace::autoclean;
1717
1818 # use *all* digits for fBSD ports
19 our $VERSION = '3.11007';
19 our $VERSION = '3.11008';
2020
2121 $VERSION = eval $VERSION; # numify for warning-free dev releases
2222
11 use Moose;
22
33 # use *all* digits for fBSD ports
4 our $VERSION = '3.11007';
4 our $VERSION = '3.11008';
55 $VERSION = eval $VERSION; # numify for warning-free dev releases
66
77 extends 'Net::Twitter::Core';
130130 Returns the 20 most recent tweets of the authenticated user that have been
131131 retweeted by others.
132132
133 aliases => [qw/rewtweeted_of_me/],
133 aliases => [qw/retweeted_of_me/],
134134 path => 'statuses/retweets_of_me',
135135 method => 'GET',
136136 params => [qw/since_id max_id count page/],
195195 );
196196
197197 twitter_api_method update => (
198 description => <<EOT,
198 path => 'statuses/update',
199 method => 'POST',
200 params => [qw/status lat long place_id display_coordinates in_reply_to_status_id/],
201 required => [qw/status/],
202 booleans => [qw/display_coordinates/],
203 add_source => 1,
204 returns => 'Status',
205 description => <<'EOT',
206
199207 Updates the authenticating user's status. Requires the status parameter
200208 specified. A status update with text identical to the authenticating
201209 user's current status will be ignored.
202210
203 The optional C<lat> and C<long> parameters add location data to the status for
204 a geo enabled account. They expect values in the ranges -90.0 to +90.0 and
205 -180.0 to +180.0 respectively. They are ignored unless the user's
206 C<geo_enabled> field is true.
211 =over 4
212
213 =item status
214
215 Required. The text of your status update. URL encode as necessary. Statuses
216 over 140 characters will cause a 403 error to be returned from the API.
217
218 =item in_reply_to_status_id
219
220 Optional. The ID of an existing status that the update is in reply to. o Note:
221 This parameter will be ignored unless the author of the tweet this parameter
222 references is mentioned within the status text. Therefore, you must include
223 @username, where username is the author of the referenced tweet, within the
224 update.
225
226 =item lat
227
228 Optional. The location's latitude that this tweet refers to. The valid ranges
229 for latitude is -90.0 to +90.0 (North is positive) inclusive. This parameter
230 will be ignored if outside that range, if it is not a number, if geo_enabled is
231 disabled, or if there not a corresponding long parameter with this tweet.
232
233 =item long
234
235 Optional. The location's longitude that this tweet refers to. The valid ranges
236 for longitude is -180.0 to +180.0 (East is positive) inclusive. This parameter
237 will be ignored if outside that range, if it is not a number, if geo_enabled is
238 disabled, or if there not a corresponding lat parameter with this tweet.
239
240 =item place_id
241
242 Optional. The place to attach to this status update. Valid place_ids can be
243 found by querying C<reverse_geocode>.
244
245 =item display_coordinates
246
247 Optional. By default, geo-tweets will have their coordinates exposed in the
248 status object (to remain backwards compatible with existing API applications).
249 To turn off the display of the precise latitude and longitude (but keep the
250 contextual location information), pass C<display_coordinates => 0> on the
251 status update.
252
253 =back
254
207255 EOT
208256
209 path => 'statuses/update',
210 method => 'POST',
211 params => [qw/status lat long in_reply_to_status_id/],
212 required => [qw/status/],
213 add_source => 1,
214 returns => 'Status',
215257 );
216258
217259 twitter_api_method destroy_status => (
855897
856898 );
857899
900 twitter_api_method reverse_geocode => (
901 path => 'geo/reverse_geocode',
902 method => 'GET',
903 params => [qw/lat long accuracy granularity max_results/],
904 required => [qw/lat long/],
905 returns => 'HashRef',
906 description => <<'EOT',
907
908 Search for places (cities and neighborhoods) that can be attached to a
909 statuses/update. Given a latitude and a longitude, return a list of all the
910 valid places that can be used as a place_id when updating a status.
911 Conceptually, a query can be made from the user's location, retrieve a list of
912 places, have the user validate the location he or she is at, and then send the
913 ID of this location up with a call to statuses/update.
914
915 There are multiple granularities of places that can be returned --
916 "neighborhoods", "cities", etc. At this time, only United States data is
917 available through this method.
918
919 =over 4
920
921 =item lat
922
923 Required. The latitude to query about. Valid ranges are -90.0 to +90.0 (North
924 is positive) inclusive.
925
926 =item long
927
928 Required. The longitude to query about. Valid ranges are -180.0 to +180.0
929 (East is positive) inclusive.
930
931 =item accuracy
932
933 Optional. A hint on the "region" in which to search. If a number, then this is
934 a radius in meters, but it can also take a string that is suffixed with ft to
935 specify feet. If this is not passed in, then it is assumed to be 0m. If
936 coming from a device, in practice, this value is whatever accuracy the device
937 has measuring its location (whether it be coming from a GPS, WiFi
938 triangulation, etc.).
939
940 =item granularity
941
942 Optional. The minimal granularity of data to return. If this is not passed
943 in, then C<neighborhood> is assumed. C<city> can also be passed.
944
945 =item max_results
946
947 Optional. A hint as to the number of results to return. This does not
948 guarantee that the number of results returned will equal max_results, but
949 instead informs how many "nearby" results to return. Ideally, only pass in the
950 number of places you intend to display to the user here.
951
952 =back
953
954 EOT
955 );
956
957 twitter_api_method geo_id => (
958 path => 'geo/id/id',
959 method => 'GET',
960 params => [qw/id/],
961 required => [qw/id/],
962 returns => 'HashRef',
963 description => <<'EOT',
964 Returns details of a place returned from the C<reverse_geocode> method.
965 EOT
966 );
967
858968 1;
859969
860970 __END__
11 use Moose;
22
33 # use *all* digits for fBSD ports
4 our $VERSION = '3.11007';
4 our $VERSION = '3.11008';
55 $VERSION = eval $VERSION; # numify for warning-free dev releases
66
77 extends 'Net::Twitter::Core';
1010 );
1111
1212 # use *all* digits for fBSD ports
13 our $VERSION = '3.11007';
13 our $VERSION = '3.11008';
1414
1515 $VERSION = eval $VERSION; # numify for warning-free dev releases
1616
33
44 =head1 VERSION
55
6 This document describes Net::Twitter version 3.11007
6 This document describes Net::Twitter version 3.11008
77
88 =head1 SYNOPSIS
99
10331033
10341034 Returns: Bool
10351035
1036 =item B<geo_id>
1037
1038 =item B<geo_id(id)>
1039
1040
1041
1042 =over 4
1043
1044 =item Parameters: id
1045
1046 =item Required: id
1047
1048 =back
1049
1050 Returns details of a place returned from the C<reverse_geocode> method.
1051
1052
1053 Returns: HashRef
1054
10361055 =item B<home_timeline>
10371056
10381057
12371256 =item B<retweets_of_me>
12381257
12391258
1240 =item alias: rewtweeted_of_me
1259 =item alias: retweeted_of_me
12411260
12421261
12431262 =over 4
12531272
12541273
12551274 Returns: ArrayRef[Status]
1275
1276 =item B<reverse_geocode>
1277
1278 =item B<reverse_geocode(lat, long)>
1279
1280
1281
1282 =over 4
1283
1284 =item Parameters: lat, long, accuracy, granularity, max_results
1285
1286 =item Required: lat, long
1287
1288 =back
1289
1290
1291 Search for places (cities and neighborhoods) that can be attached to a
1292 statuses/update. Given a latitude and a longitude, return a list of all the
1293 valid places that can be used as a place_id when updating a status.
1294 Conceptually, a query can be made from the user's location, retrieve a list of
1295 places, have the user validate the location he or she is at, and then send the
1296 ID of this location up with a call to statuses/update.
1297
1298 There are multiple granularities of places that can be returned --
1299 "neighborhoods", "cities", etc. At this time, only United States data is
1300 available through this method.
1301
1302 =over 4
1303
1304 =item lat
1305
1306 Required. The latitude to query about. Valid ranges are -90.0 to +90.0 (North
1307 is positive) inclusive.
1308
1309 =item long
1310
1311 Required. The longitude to query about. Valid ranges are -180.0 to +180.0
1312 (East is positive) inclusive.
1313
1314 =item accuracy
1315
1316 Optional. A hint on the "region" in which to search. If a number, then this is
1317 a radius in meters, but it can also take a string that is suffixed with ft to
1318 specify feet. If this is not passed in, then it is assumed to be 0m. If
1319 coming from a device, in practice, this value is whatever accuracy the device
1320 has measuring its location (whether it be coming from a GPS, WiFi
1321 triangulation, etc.).
1322
1323 =item granularity
1324
1325 Optional. The minimal granularity of data to return. If this is not passed
1326 in, then C<neighborhood> is assumed. C<city> can also be passed.
1327
1328 =item max_results
1329
1330 Optional. A hint as to the number of results to return. This does not
1331 guarantee that the number of results returned will equal max_results, but
1332 instead informs how many "nearby" results to return. Ideally, only pass in the
1333 number of places you intend to display to the user here.
1334
1335 =back
1336
1337
1338
1339 Returns: HashRef
12561340
12571341 =item B<saved_searches>
12581342
14481532
14491533 =over 4
14501534
1451 =item Parameters: status, lat, long, in_reply_to_status_id
1535 =item Parameters: status, lat, long, place_id, display_coordinates, in_reply_to_status_id
14521536
14531537 =item Required: status
14541538
14551539 =back
1540
14561541
14571542 Updates the authenticating user's status. Requires the status parameter
14581543 specified. A status update with text identical to the authenticating
14591544 user's current status will be ignored.
14601545
1461 The optional C<lat> and C<long> parameters add location data to the status for
1462 a geo enabled account. They expect values in the ranges -90.0 to +90.0 and
1463 -180.0 to +180.0 respectively. They are ignored unless the user's
1464 C<geo_enabled> field is true.
1546 =over 4
1547
1548 =item status
1549
1550 Required. The text of your status update. URL encode as necessary. Statuses
1551 over 140 characters will cause a 403 error to be returned from the API.
1552
1553 =item in_reply_to_status_id
1554
1555 Optional. The ID of an existing status that the update is in reply to. o Note:
1556 This parameter will be ignored unless the author of the tweet this parameter
1557 references is mentioned within the status text. Therefore, you must include
1558 @username, where username is the author of the referenced tweet, within the
1559 update.
1560
1561 =item lat
1562
1563 Optional. The location's latitude that this tweet refers to. The valid ranges
1564 for latitude is -90.0 to +90.0 (North is positive) inclusive. This parameter
1565 will be ignored if outside that range, if it is not a number, if geo_enabled is
1566 disabled, or if there not a corresponding long parameter with this tweet.
1567
1568 =item long
1569
1570 Optional. The location's longitude that this tweet refers to. The valid ranges
1571 for longitude is -180.0 to +180.0 (East is positive) inclusive. This parameter
1572 will be ignored if outside that range, if it is not a number, if geo_enabled is
1573 disabled, or if there not a corresponding lat parameter with this tweet.
1574
1575 =item place_id
1576
1577 Optional. The place to attach to this status update. Valid place_ids can be
1578 found by querying C<reverse_geocode>.
1579
1580 =item display_coordinates
1581
1582 Optional. By default, geo-tweets will have their coordinates exposed in the
1583 status object (to remain backwards compatible with existing API applications).
1584 To turn off the display of the precise latitude and longitude (but keep the
1585 contextual location information), pass C<display_coordinates => 0> on the
1586 status update.
1587
1588 =back
1589
14651590
14661591
14671592 Returns: Status
2222 CPAN
2323 DateTime
2424 DirectMessage
25 EOT
2526 Etcheverry
2627 ExtendedUser
2728 geo
29 GPS
30 granularities
2831 Grennan
2932 IM
3033 IP
9699 url
97100 useragent
98101 username
102 WiFi
99103 WOEID
100104 woeid
101105 xAuth
0 #!perl
1 use warnings;
2 use strict;
3 use Try::Tiny;
4 use Test::More tests => 2;
5 use Net::Twitter;
6
7 eval "use LWP::UserAgent 5.819";
8 plan skip_all => 'LWP::UserAgent >= 5.819 required' if $@;
9
10 my $req;
11 my $ua = LWP::UserAgent->new;
12 $ua->add_handler(request_send => sub {
13 $req = shift;
14 my $res = HTTP::Response->new(200);
15 $res->content('{"test":"OK"}');
16 return $res;
17 });
18
19 sub params {
20 my $uri = URI->new;
21 $uri->query($req->content);
22 my %params = $uri->query_form;
23 return \%params;
24 }
25
26 my $nt = Net::Twitter->new(
27 traits => [qw/API::REST/],
28 username => 'fred',
29 password => 'secret',
30 ua => $ua,
31 );
32
33 my $r = $nt->update({
34 status => 'Hello, world!',
35 lat => 37.78215,
36 long => -122.40060,
37 display_coordinates => 1,
38 });
39
40 my $params = params();
41 is params()->{display_coordinates}, 'true', "1 promoted to true";
42
43 $r = $nt->update({
44 status => 'Hello, world!',
45 lat => 37.78215,
46 long => -122.40060,
47 display_coordinates => 0,
48 });
49
50 $params = params();
51 is params()->{display_coordinates}, 'false', "0 promoted to false";