Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Net-Twitter CPAN distribution.

Report information
The Basics
Id: 41824
Status: resolved
Priority: 0/
Queue: Net-Twitter

People
Owner: cthom [...] cpan.org
Requestors: jtpdgd [...] aol.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.21
Fixed in: (no value)



Subject: Detailed return value
I think it is more comfortable for a Net::Twitter user that if it return more detailed information. As you know, create_friend method returns JSON objects if successfully making friends with or undef if not. But in some situation, users wants to know reasons for failure. And, original Twitter API returns the reasons via JSON objects. The same may be said for other methods. So, it might be better to return JSON object directly if is_success is true or not, and leave an error judgement up to a user-implemented-error-parser. Thank you for reading.
Other than the "relationship_exists" and "test" methods, every Net::Twitter method takes whatever twitter returns and tries to convert the JSON into a hashref, which it returns. If twitter does not return anything, the JSON::Any module will convert "nothing" into undef, which Net::Twitter returns to the caller. There's no point at which Net::Twitter is NOT returning the maximum information as returned by twitter. It does not detect and error and discard that information and choose to return undef on its own. Basically, if you get undef returned, it's because twitter didn't return anything. If twitter returned something, you'd have gotten it back in a hashref. In the event you get an undef, the only extra information available to you is the HTTP code and the message that was returned. You can see these with the http_code and http_message methods.
CC: jtpdgd [...] aim.com
Subject: Re: [rt.cpan.org #41824] Resolved: Detailed return value
Date: Sat, 20 Dec 2008 12:38:32 +0900
To: bug-Net-Twitter [...] rt.cpan.org
From: "AYANOKOUZI, Ryuunosuke" <jtpdgd [...] aim.com>
とりあえずてすとでもしてみるかな。
CC: jtpdgd [...] aim.com
Subject: Re: [rt.cpan.org #41824] Resolved: Detailed return value
Date: Sat, 20 Dec 2008 14:38:11 +0900
To: bug-Net-Twitter [...] rt.cpan.org
From: "AYANOKOUZI, Ryuunosuke" <jtpdgd [...] aim.com>
Thank you for your suggestion. It is true that referring not only $twit->create_friend() but also $twit->http_code and $twit->http_messages methods is also enough to judge that $twit->create_friend operation is success or failure. But, don't you think some of the users want to know the reason why 2xx code is not responded(blocked, 2000 over, etc.). For now, users never get an information of http header and body, unless 2xx code is responded. And, in some situations of failure, http body contains more detailed information of failure than http response codes. For example, it seems to be 5 error cases responding "403 Forbidden". 1. You have been blocked from following this account at the request of the user. 2. You are unable to follow more people. Please read about our following limits 3. You've already requested to follow user. 4. User not found. 5. User is already on your list. If these errors are responded, users can recognize $twit->create_friend() is faild but never know the reason of failure. Because $twit->create_friend() and $twit never contain information of http body; I have ran bellow test code, and sniffed packets. For each 5 error cases, request and response http packets are also shown bellow. Dumped $twit->create_friend() is always undef. And unfortunately, $twit have not contain any information the reason of failure. I think for some users, at least for me, the reason of failure is important information. I would appreciate if you could take my opinion into consideration. Thank you for reading. TEST CODE #!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; use Net::Twitter; my $twit = Net::Twitter->new( username => '********', password => '********', ); my $args = { id => '********', follow => 1, }; my $res = $twit->create_friend($args); print &Dumper($res); print &Dumper($twit); exit; 1. You have been blocked from following this account at the request of the user. REQUEST POST /friendships/create/********.json HTTP/1.1. TE: deflate,gzip;q=0.3. Connection: TE, close. Authorization: Basic ************************. Host: twitter.com. User-Agent: Net::Twitter/1.21 (PERL). Content-Length: 11. Content-Type: application/x-www-form-urlencoded. X-Twitter-Client-URL:: http://x4.net/twitter/meta.xml. X-Twitter-Client-Version:: 1.21. X-Twitter-Client:: Perl Net::Twitter. . follow=true RESPONSE HTTP/1.1 403 Forbidden. Date: Fri, 19 Dec 2008 22:29:34 GMT. Server: hi. Last-Modified: Fri, 19 Dec 2008 22:29:34 GMT. Status: 403 Forbidden. Pragma: no-cache. Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0. Content-Type: application/json; charset=utf-8. Content-Length: 161. Expires: Tue, 31 Mar 1981 05:00:00 GMT. Set-Cookie: _twitter_sess=****************************************************************************************************************************************************************************************; domain=.twitter.com; path=/. Vary: Accept-Encoding. Connection: close. . {"request":"\/friendships\/create\/********.json","error":"Could not follow user: You have been blocked from following this account at the request of the user."} 2. You are unable to follow more people. Please read about our following limits REQUEST POST /friendships/create/*******.json HTTP/1.1. TE: deflate,gzip;q=0.3. Connection: TE, close. Authorization: Basic ************************. Host: twitter.com. User-Agent: Net::Twitter/1.21 (PERL). Content-Length: 11. Content-Type: application/x-www-form-urlencoded. X-Twitter-Client-URL:: http://x4.net/twitter/meta.xml. X-Twitter-Client-Version:: 1.21. X-Twitter-Client:: Perl Net::Twitter. . follow=true RESPONSE HTTP/1.1 403 Forbidden. Date: Fri, 19 Dec 2008 22:39:40 GMT. Server: hi. Last-Modified: Fri, 19 Dec 2008 22:39:40 GMT. Status: 403 Forbidden. Pragma: no-cache. Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0. Content-Type: application/json; charset=utf-8. Content-Length: 232. Expires: Tue, 31 Mar 1981 05:00:00 GMT. Set-Cookie: _twitter_sess=****************************************************************************************************************************************************************************************; domain=.twitter.com; path=/. Vary: Accept-Encoding. Connection: close. . {"request":"\/friendships\/create\/*******.json","error":"Could not follow user: You are unable to follow more people. Please read about our <a href=\"http:\/\/help.twitter.com\/index.php?pg=kb.page&id=242\">following limits<\/a>."} 3. You've already requested to follow user. REQUEST POST /friendships/create/*******.json HTTP/1.1. TE: deflate,gzip;q=0.3. Connection: TE, close. Authorization: Basic ************************. Host: twitter.com. User-Agent: Net::Twitter/1.21 (PERL). Content-Length: 11. Content-Type: application/x-www-form-urlencoded. X-Twitter-Client-URL:: http://x4.net/twitter/meta.xml. X-Twitter-Client-Version:: 1.21. X-Twitter-Client:: Perl Net::Twitter. . follow=true RESPONSE HTTP/1.1 403 Forbidden. Date: Fri, 19 Dec 2008 22:26:17 GMT. Server: hi. Last-Modified: Fri, 19 Dec 2008 22:26:17 GMT. Status: 403 Forbidden. Pragma: no-cache. Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0. Content-Type: application/json; charset=utf-8. Content-Length: 126. Expires: Tue, 31 Mar 1981 05:00:00 GMT. Set-Cookie: _twitter_sess=****************************************************************************************************************************************************************************************; domain=.twitter.com; path=/. Vary: Accept-Encoding. Connection: close. . {"request":"\/friendships\/create\/*******.json","error":"Could not follow user: You've already requested to follow *******."} 4. User not found. REQUEST POST /friendships/create/********.json HTTP/1.1. TE: deflate,gzip;q=0.3. Connection: TE, close. Authorization: Basic ************************. Host: twitter.com. User-Agent: Net::Twitter/1.21 (PERL). Content-Length: 11. Content-Type: application/x-www-form-urlencoded. X-Twitter-Client-URL:: http://x4.net/twitter/meta.xml. X-Twitter-Client-Version:: 1.21. X-Twitter-Client:: Perl Net::Twitter. . follow=true RESPONSE HTTP/1.1 403 Forbidden. Date: Fri, 19 Dec 2008 22:21:20 GMT. Server: hi. Last-Modified: Fri, 19 Dec 2008 22:21:20 GMT. Status: 403 Forbidden. Pragma: no-cache. Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0. Content-Type: application/json; charset=utf-8. Content-Length: 99. Expires: Tue, 31 Mar 1981 05:00:00 GMT. Set-Cookie: _twitter_sess=****************************************************************************************************************************************************************************************; domain=.twitter.com; path=/. Vary: Accept-Encoding. Connection: close. . {"request":"\/friendships\/create\/********.json","error":"Could not follow user: User not found."} 5. User is already on your list. REQUEST POST /friendships/create/********.json HTTP/1.1. TE: deflate,gzip;q=0.3. Connection: TE, close. Authorization: Basic ************************. Host: twitter.com. User-Agent: Net::Twitter/1.21 (PERL). Content-Length: 11. Content-Type: application/x-www-form-urlencoded. X-Twitter-Client-URL:: http://x4.net/twitter/meta.xml. X-Twitter-Client-Version:: 1.21. X-Twitter-Client:: Perl Net::Twitter. . follow=true RESPONSE HTTP/1.1 403 Forbidden. Date: Fri, 19 Dec 2008 22:11:39 GMT. Server: hi. Last-Modified: Fri, 19 Dec 2008 22:11:39 GMT. Status: 403 Forbidden. Pragma: no-cache. Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0. Content-Type: application/json; charset=utf-8. Content-Length: 117. Expires: Tue, 31 Mar 1981 05:00:00 GMT. Set-Cookie: _twitter_sess=****************************************************************************************************************************************************************************************; domain=.twitter.com; path=/. Vary: Accept-Encoding. Connection: close. . {"request":"\/friendships\/create\/********.json","error":"Could not follow user: ******** is already on your list."}
I was all set to tell you that you were wrong, and then looked at my code and realized that each method was, in fact, discarding the error JSON. My fault entirely, I hadn't really looked at it in a long time. I've made a change in HEAD: http://github.com/ct/net-twitter/commit/43b7c86b622584a6272f5ba75e2451ad592e6ab5 It'll be in 1.22. I need to do some more cleanup, so it should be released shortly.