Permalink
Browse files

added update_with_media API method

  • Loading branch information...
1 parent 4876214 commit eaa8a1c325fb9e17339566976c495b6d0cc36902 @semifor committed Sep 21, 2011
Showing with 164 additions and 0 deletions.
  1. +1 −0 Changes
  2. +69 −0 README
  3. +2 −0 lib/Net/Twitter/Role/API/REST.pm
  4. +89 −0 lib/Net/Twitter/Role/API/Upload.pm
  5. +2 −0 src/net-twitter-pod.tt2
  6. +1 −0 t/99-pod_spelling.t
View
@@ -1,3 +1,4 @@
+ - added update_with_media (Allen Haim)
- added get_privacy_policy and get_tos API methods
- added get_languages and get_settings API methods
- added contributors and contributees API methods
View
69 README
@@ -1801,6 +1801,40 @@ REST API Methods
Returns: ExtendedUser
+ update_with_media
+ update_with_media(status, media)
+
+ Parameters: status, media[], possibly_sensitive,
+ in_reply_to_status_id, lat, long, place_id, display_coordinates
+ Required: status, media
+
+ Updates the authenticating user's status and attaches media for
+ upload.
+
+ The "media[]" parameter is an arrayref with the following
+ interpretation:
+
+ [ $file ]
+ [ $file, $filename ]
+ [ $file, $filename, Content_Type => $mime_type ]
+ [ undef, $filename, Content_Type => $mime_type, Content => $raw_image_data ]
+
+ The first value of the array ($file) is the name of a file to open.
+ The second value ($filename) is the name given to Twitter for the
+ file. If $filename is not provided, the basename portion of $file is
+ used. If $mime_type is not provided, it will be provided
+ automatically using LWP::MediaTypes::guess_media_type().
+
+ $raw_image_data can be provided, rather than opening a file, by
+ passing "undef" as the first array value.
+
+ The Tweet text will be rewritten to include the media URL(s), which
+ will reduce the number of characters allowed in the Tweet text. If
+ the URL(s) cannot be appended without text truncation, the tweet
+ will be rejected and this method will return an HTTP 403 error.
+
+ Returns: Status
+
user_suggestions
user_suggestions(category)
alias: follow_suggestions
@@ -1857,6 +1891,40 @@ REST API Methods
Returns: ExtendedUser
+ update_with_media
+ update_with_media(status, media)
+
+ Parameters: status, media[], possibly_sensitive,
+ in_reply_to_status_id, lat, long, place_id, display_coordinates
+ Required: status, media
+
+ Updates the authenticating user's status and attaches media for
+ upload.
+
+ The "media[]" parameter is an arrayref with the following
+ interpretation:
+
+ [ $file ]
+ [ $file, $filename ]
+ [ $file, $filename, Content_Type => $mime_type ]
+ [ undef, $filename, Content_Type => $mime_type, Content => $raw_image_data ]
+
+ The first value of the array ($file) is the name of a file to open.
+ The second value ($filename) is the name given to Twitter for the
+ file. If $filename is not provided, the basename portion of $file is
+ used. If $mime_type is not provided, it will be provided
+ automatically using LWP::MediaTypes::guess_media_type().
+
+ $raw_image_data can be provided, rather than opening a file, by
+ passing "undef" as the first array value.
+
+ The Tweet text will be rewritten to include the media URL(s), which
+ will reduce the number of characters allowed in the Tweet text. If
+ the URL(s) cannot be appended without text truncation, the tweet
+ will be rejected and this method will return an HTTP 403 error.
+
+ Returns: Status
+
Search API Methods
These methods are provided when trait "API::Search" is included in the
"traits" option to "new".
@@ -2073,6 +2141,7 @@ AUTHOR
CONTRIBUTORS
Roberto Etcheverry <retcheverry@gmail.com> (@retcheverry on Twitter)
+ Allen Haim
KATOU Akira
@@ -6,6 +6,8 @@ use URI;
requires qw/ua username password credentials/;
+with 'Net::Twitter::Role::API::Upload';
+
has apiurl => ( isa => 'Str', is => 'ro', default => 'http://api.twitter.com/1' );
has apihost => ( isa => 'Str', is => 'ro', lazy => 1, builder => '_build_apihost' );
has apirealm => ( isa => 'Str', is => 'ro', default => 'Twitter API' );
@@ -0,0 +1,89 @@
+package Net::Twitter::Role::API::Upload;
+use Moose::Role;
+use Net::Twitter::API;
+use DateTime::Format::Strptime;
+use URI;
+
+has upload_url => isa => 'Str', is => 'ro', default => 'http://upload.twitter.com/1';
+
+after BUILD => sub {
+ my $self = shift;
+
+ $self->{upload_url} =~ s/^http:/https:/ if $self->ssl;
+};
+
+base_url 'upload_url';
+authenticate 1;
+
+our $DATETIME_PARSER = DateTime::Format::Strptime->new(pattern => '%a %b %d %T %z %Y');
+datetime_parser $DATETIME_PARSER;
+
+twitter_api_method update_with_media => (
+ path => 'statuses/update_with_media',
+ method => 'POST',
+ params => [qw/
+ status media[] possibly_sensitive in_reply_to_status_id lat long place_id display_coordinates
+ /],
+ required => [qw/status media/],
+ booleans => [qw/possibly_sensitive display_coordinates/],
+ returns => 'Status',
+ description => <<'EOT',
+Updates the authenticating user's status and attaches media for upload.
+
+The C<media[]> parameter is an arrayref with the following interpretation:
+
+ [ $file ]
+ [ $file, $filename ]
+ [ $file, $filename, Content_Type => $mime_type ]
+ [ undef, $filename, Content_Type => $mime_type, Content => $raw_image_data ]
+
+The first value of the array (C<$file>) is the name of a file to open. The
+second value (C<$filename>) is the name given to Twitter for the file. If
+C<$filename> is not provided, the basename portion of C<$file> is used. If
+C<$mime_type> is not provided, it will be provided automatically using
+L<LWP::MediaTypes::guess_media_type()>.
+
+C<$raw_image_data> can be provided, rather than opening a file, by passing
+C<undef> as the first array value.
+
+The Tweet text will be rewritten to include the media URL(s), which will reduce
+the number of characters allowed in the Tweet text. If the URL(s) cannot be
+appended without text truncation, the tweet will be rejected and this method
+will return an HTTP 403 error.
+EOT
+
+);
+
+1;
+
+__END__
+
+=head1 NAME
+
+Net::Twitter::Role::API::Upload - A definition of the Twitter Upload API as a Moose role
+
+=head1 SYNOPSIS
+
+ package My::Twitter;
+ use Moose;
+ with 'Net::Twitter::API::Upload';
+
+=head1 DESCRIPTION
+
+This module provides definitions the Twitter Upload API methods.
+
+=head1 AUTHOR
+
+Allen Haim
+
+Marc Mims <marc@questright.com>
+
+=head1 LICENSE
+
+Copyright (c) 2011 Marc Mims
+
+The Twitter API itself, and the description text used in this module is:
+
+Copyright (c) 2011 Twitter
+
+This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
View
@@ -554,6 +554,7 @@ to indicate the numerical ID of the Twitter user that sent the status.
=head2 Methods
[% INCLUDE APIDOC class='API::REST' %]
+[% INCLUDE APIDOC class='API::Upload' %]
=head1 Search API Methods
@@ -754,6 +755,7 @@ Marc Mims <marc@questright.com> (@semifor on Twitter)
=head1 CONTRIBUTORS
Roberto Etcheverry <retcheverry@gmail.com> (@retcheverry on Twitter)
+Allen Haim
KATOU Akira
View
@@ -43,6 +43,7 @@ geocode
GPS
granularities
Grennan
+Haim
Identi
identi
identica

0 comments on commit eaa8a1c

Please sign in to comment.