The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
Changes 015
MANIFEST 03
META.yml 11
examples/create_utf8_repo.pl 025
examples/proxy.pl 020
examples/search.pl 025
lib/Net/GitHub/V3/Query.pm 105
lib/Net/GitHub/V3/Search.pm 2088
lib/Net/GitHub/V3.pm 210
lib/Net/GitHub.pm 11
xt/v3/200-repos.t 03
xt/v3/900-search.t 108
12 files changed (This is a version diff) 44204
@@ -1,5 +1,20 @@
 Revision history for Net-GitHub
 
+0.69    2014-09-11
+        pass ua as the args so we can set up proxies for all
+
+0.68    2014-08-30
+        Fixed URI encoding issue #52 (sillymoose)
+
+0.67_01 2014-08-22
+        rewrite Net::GitHub::V3::Search (legacy methods is removed)
+
+0.66    2014-07-31
+         "Unrecognized LWP::UserAgent options" warning (RT #97639)
+
+0.65    2014-06-29
+        fix glob ref issue for perl < 5.14 (Alex Vandiver)
+
 0.64    2014-06-27
         use decoded_content on res in upload_asset (Alex Vandiver)
 
@@ -1,4 +1,7 @@
 Changes
+examples/create_utf8_repo.pl
+examples/proxy.pl
+examples/search.pl
 examples/upload_asset.pl
 inc/Module/AutoInstall.pm
 inc/Module/Install.pm
@@ -35,4 +35,4 @@ requires:
 resources:
   license: http://dev.perl.org/licenses/
   repository: https://github.com/fayland/perl-net-github
-version: 0.64
+version: 0.69
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use FindBin qw/$Bin/;
+use lib "$Bin/../lib";
+use Net::GitHub::V3;
+use Data::Dumper;
+
+die unless ( ($ENV{GITHUB_USER} and $ENV{GITHUB_PASS}) or $ENV{GITHUB_ACCESS_TOKEN} );
+
+# either user+pass or token
+my $gh = Net::GitHub::V3->new( login => $ENV{GITHUB_USER}, pass => $ENV{GITHUB_PASS});
+# my $gh = Net::GitHub->new( access_token => $ENV{GITHUB_ACCESS_TOKEN});
+
+use utf8;
+use Encode;
+
+my $x = $gh->repos->create({
+    name => "Foo-Bar-Baz",
+    description => encode_utf8("Testing ünicode descriptions"),
+});
+print Dumper(\$x);
+
+1;
\ No newline at end of file
@@ -0,0 +1,20 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use FindBin qw/$Bin/;
+use lib "$Bin/../lib";
+use Net::GitHub::V3;
+use Data::Dumper;
+
+my $gh = Net::GitHub::V3->new();
+my $search = $gh->search;
+$gh->ua->proxy('https', 'socks://127.0.0.1:9050');
+
+my %data = $search->repositories({
+    q => 'perl',
+    per_page => 100,
+});
+map { print $_->{url} . "\n" } @{$data{items}};
+
+1;
\ No newline at end of file
@@ -0,0 +1,25 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use FindBin qw/$Bin/;
+use lib "$Bin/../lib";
+use Net::GitHub::V3;
+use Data::Dumper;
+
+my $gh = Net::GitHub::V3->new();
+my $search = $gh->search;
+
+my %data = $search->repositories({
+    q => 'perl',
+    per_page => 100,
+});
+map { print $_->{url} . "\n" } @{$data{items}};
+
+while ($search->has_next_page) {
+    sleep 12; # 5 queries max per minute
+    %data = $search->next_page;
+    map { print $_->{url} . "\n" } @{$data{items}};
+}
+
+1;
\ No newline at end of file
@@ -1,6 +1,6 @@
 package Net::GitHub::V3::Query;
 
-our $VERSION = '0.60';
+our $VERSION = '0.69';
 our $AUTHORITY = 'cpan:FAYLAND';
 
 use URI;
@@ -72,7 +72,7 @@ sub set_default_user_repo {
 sub args_to_pass {
     my $self = shift;
     my $ret;
-    foreach my $col ('login', 'pass', 'access_token', 'raw_string', 'raw_response', 'api_url', 'api_throttle', 'u', 'repo') {
+    foreach my $col ('login', 'pass', 'access_token', 'raw_string', 'raw_response', 'api_url', 'api_throttle', 'u', 'repo', 'next_url', 'last_url', 'first_url', 'prev_url', 'ua') {
         my $v = $self->$col;
         $ret->{$col} = $v if defined $v;
     }
@@ -87,8 +87,6 @@ has 'ua' => (
         LWP::UserAgent->new(
             agent       => "perl-net-github $VERSION",
             cookie_jar  => {},
-            stack_depth => 1,
-            autocheck   => 0,
             keep_alive  => 4,
             timeout     => 60,
         );
@@ -232,12 +230,9 @@ sub __build_methods {
         my $check_status = $v->{check_status};
         my $is_u_repo = $v->{is_u_repo}; # need auto shift u/repo
 
-        my $glob = do {
-          no strict 'refs';
-          no warnings 'once';
-          *{"${package}::${m}"};
-        };
-        *$glob = sub {
+        no strict 'refs';
+        no warnings 'once';
+        *{"${package}::${m}"} = sub {
             my $self = shift;
 
             # count how much %s inside u
@@ -2,23 +2,77 @@ package Net::GitHub::V3::Search;
 
 use Moo;
 
-our $VERSION = '0.60';
+our $VERSION = '0.68';
 our $AUTHORITY = 'cpan:FAYLAND';
 
 use URI::Escape;
 
 with 'Net::GitHub::V3::Query';
 
-## build methods on fly
-my %__methods = (
+sub repositories {
+    my ( $self, $args ) = @_;
 
-    issues => { url => '/legacy/issues/search/%s/%s/%s/%s', is_u_repo => 1 },
-    repos  => { url => '/legacy/repos/search/%s' },
-    user   => { url => '/legacy/user/search/%s' },
-    email  => { url => '/legacy/user/email/%s' },
+    # for old
+    unless (ref($args) eq 'HASH') {
+        $args = { q => $args };
+    }
 
-);
-__build_methods(__PACKAGE__, %__methods);
+    my $uri = URI->new('/search/repositories');
+    $uri->query_form($args);
+
+    my $url = $uri->as_string;
+    $url =~ s/%3A/:/g;
+    $url =~ s/%2B/+/g;
+
+    return $self->query($url);
+}
+
+sub code {
+    my ( $self, $args ) = @_;
+
+    # for old
+    unless (ref($args) eq 'HASH') {
+        $args = { q => $args };
+    }
+
+    my $uri = URI->new('/search/code');
+    $uri->query_form($args);
+    return $self->query($uri->as_string);
+}
+
+sub issues {
+    my ( $self, $args ) = @_;
+
+    # for old
+    unless (ref($args) eq 'HASH') {
+        $args = { q => $args };
+    }
+
+    my $uri = URI->new('/search/issues');
+    $uri->query_form($args);
+    return $self->query($uri->as_string);
+}
+
+sub users {
+    my ( $self, $args ) = @_;
+
+    # for old
+    unless (ref($args) eq 'HASH') {
+        $args = { q => $args };
+    }
+
+    my $uri = URI->new('/search/users');
+    $uri->query_form($args);
+    return $self->query($uri->as_string);
+}
+
+## DEPERCATED
+sub repos {
+    (shift)->repositories(@_);
+}
+sub user {
+    (shift)->repositories(@_);
+}
 
 no Moo;
 
@@ -48,23 +102,37 @@ L<http://developer.github.com/v3/search/>
 
 =item issues
 
-    my %data = $search->issues('fayland', 'perl-net-github', 'closed', 'milestone');
-    print Dumper(\$data{issues});
+    my %data = $search->issues({
+        q => 'state:open repo:fayland/perl-net-github',
+        sort  => 'created',
+        order => 'asc',
+    });
+    print Dumper(\$data{items});
 
-=item repos
+=item repositories
 
-    my %data = $search->repos('perl-net-github');
-    print Dumper(\$data{repositories});
+    my %data = $search->repositories({
+        q => 'perl',
+        sort  => 'stars',
+        order => 'desc',
+    });
+    print Dumper(\$data{items});
 
-=item user
+=item code
 
-    my %data = $search->user('fayland');
-    print Dumper(\$data{users});
+    my %data = $search->code({
+        q => 'addClass in:file language:js repo:jquery/jquery'
+    });
+    print Dumper(\$data{items});
 
-=item email
+=item users
 
-    my %data = $search->email('fayland@gmail.com');
-    print Dumper(\$data{user});
+    my %data = $search->users({
+        q => 'perl',
+        sort  => 'followers',
+        order => 'desc',
+    });
+    print Dumper(\$data{users});
 
 =back
 
@@ -3,7 +3,7 @@ package Net::GitHub::V3;
 use Moo;
 use Types::Standard qw(InstanceOf);
 
-our $VERSION = '0.60';
+our $VERSION = '0.69';
 our $AUTHORITY = 'cpan:FAYLAND';
 
 with 'Net::GitHub::V3::Query';
@@ -228,9 +228,17 @@ The C<per_page> parameter mentioned in their docs is B<NOT> supported by this mo
   while ($gh->issue->has_next_page) {
       push @issues, $gh->issue->query($gh->issue->next_url);
       ## OR ##
-      push @issues, $gh->issue->next_page);
+      push @issues, $gh->issue->next_page;
   }
 
+=head3 ua
+
+To set the proxy for ua, you can do something like following
+
+    $gh->ua->proxy('https', 'socks://127.0.0.1:9050');
+
+$gh->ua is an instance of L<LWP::UserAgent>
+
 =head2 METHODS
 
 =head3 query($method, $url, $data)
@@ -2,7 +2,7 @@ package Net::GitHub;
 
 use Net::GitHub::V3;
 
-our $VERSION = '0.64';
+our $VERSION = '0.69';
 our $AUTHORITY = 'cpan:FAYLAND';
 
 sub new {
@@ -19,6 +19,9 @@ ok( $repos );
 my @p = $repos->list;
 ok(@p > 3, 'more than 3 repos');
 
+my $rp = $repos->get('fayland', 'perl-net-github');
+diag(Dumper(\$rp)); use Data::Dumper;
+
 
 =pod
 
@@ -12,18 +12,16 @@ my $search = $gh->search;
 ok( $gh );
 ok( $search );
 
-my %data = $search->issues('fayland', 'perl-net-github', 'closed', 'milestone');
-diag Dumper(\$data{issues});
+my %data = $search->issues({
+    q => 'state:open repo:fayland/perl-net-github',
+});
+diag Dumper(\$data{items});
 
-#%data = $search->repos('perl-net-github');
-#diag Dumper(\$data{repositories});
-
-#%data = $search->user('fayland');
-#diag Dumper(\$data{users});
-
-%data = $search->email('fayland@gmail.com');
-diag Dumper(\$data{user});
+#%data = $search->repositories('perl-net-github');
+#diag Dumper(\$data{items});
 
+#%data = $search->users('fayland');
+#diag Dumper(\$data{items});
 
 done_testing;