Permalink
Browse files

Synthetic args prefixed with a dash (-)

  • Loading branch information...
1 parent c2879d3 commit 490f675db1742527112af921a647cd20f06eab19 @semifor committed Sep 23, 2011
Showing with 34 additions and 8 deletions.
  1. +5 −0 lib/Net/Twitter/Core.pm
  2. +10 −1 lib/Net/Twitter/Role/API/Lists.pm
  3. +19 −7 src/net-twitter-pod.tt2
View
@@ -55,6 +55,11 @@ sub _extract_synthetic_args {
$synthetic_args->{$k} = delete $args->{$k} if exists $args->{$k};
}
+ # New strategy - rarther than having to track the names of all synthetic args
+ # centrally, we'll prefix them with a dash (-). 'authenticate' and 'since' are
+ # grandfathered. '-authenticate' and '-since' will work, too.
+ $synthetic_args->{$_} = delete $args->{"-$_"} for grep s/^-//, keys %$args;
+
return $synthetic_args;
}
@@ -384,7 +384,16 @@ for my $method ( qw/
/ )
{
my $legacy_method = "legacy_$method";
- around $method => sub { shift; shift->$legacy_method(@_) };
+ around $method => sub {
+ my $orig = shift;
+ my $self = shift;
+
+ my $args = ref $_[-1] eq 'HASH' ? pop : {};
+ my $legacy = exists $args->{-legacy_lists_api} ? delete $args->{-legacy_lists_api} : 1;
+ return $self->$legacy_method(@_, $args) if $legacy;
+
+ $self->$orig(@_, $args);
+ };
}
1;
View
@@ -370,9 +370,9 @@ To set up Basic Authentication in C<Net::Twitter>, provide the C<username> and
C<password> options to L</new> or call the L</credentials> method.
In addition to the arguments specified for each API method described below, an
-additional C<authenticate> parameter can be passed. To request an
-C<Authorization> header, pass C<< authenticated => 1 >>; to suppress an
-authentication header, pass C<< authentication => 0 >>. Even if requested, an
+additional C<-authenticate> parameter can be passed. To request an
+C<Authorization> header, pass C<< -authenticate => 1 >>; to suppress an
+authentication header, pass C<< -authenticate => 0 >>. Even if requested, an
Authorization header will not be added if there are no user credentials
(username and password for Basic Authentication; access tokens for OAuth).
@@ -491,7 +491,7 @@ each API method, Net::Twitter supports additional I<synthetic> arguments.
=over 4
-=item authenticate
+=item -authenticate
When set to 1, Net::Twitter will provide an Authorization header for the API
call; when set to 0, it will suppress the Authentication header. This argument
@@ -500,13 +500,21 @@ probably only useful for the C<rate_limit_satus> method which returns different
values for authenticated and unauthenticated calls. See L</AUTHENTICATION> for
more details.
-=item since
+=item -since
API methods that accept the C<since_id> argument will also accept the synthetic
-C<since> argument, instead. C<since> may be a C<Date::Time> object, an epoch
+C<-since> argument, instead. C<-since> may be a C<Date::Time> object, an epoch
time (the number of seconds since the system epoch), or a string in the same
format returned by Twitter for the C<created_at> attribute. Only statuses with a
-C<created_at> time greater than C<since> will be returned by the API call.
+C<created_at> time greater than C<-since> will be returned by the API call.
+
+=item -legacy_lists_api
+
+This option is only effective when the legacy C<API::Lists> trait is applied.
+Passing C<-legacy_lists_api> set to 0 for lists methods will use the new lists
+endpoints and semantics. This will facilitate upgrading an application to use
+the new lists api methods. When the C<API::Lists> trait is not applied, this
+option is ignored.
=back
@@ -574,6 +582,10 @@ If you are using the C<API::Lists> trait, you should remove it from your code
and change the arguments in your list API method calls to match those described
above.
+Also, if using the C<API::Lists> trait, you can pass synthectic argument
+C<-legacy_lists_api> set to 0 for individual calls to use the new endpoints
+semantics.
+
=head1 TwitterVision API Methods
These methods are provided when trait C<API::TwitterVision> is included in the

0 comments on commit 490f675

Please sign in to comment.