Permalink
Browse files

Start implementing search api.

  • Loading branch information...
1 parent 1ddb1a7 commit 5ea992da9af86834a1dd457b1d8e9185ee89d3b2 @plu committed Sep 23, 2012
Showing with 102 additions and 0 deletions.
  1. +11 −0 lib/Pithub.pm
  2. +57 −0 lib/Pithub/Search.pm
  3. +5 −0 t/basic.t
  4. +29 −0 t/search.t
View
@@ -10,6 +10,7 @@ use Pithub::Issues;
use Pithub::Orgs;
use Pithub::PullRequests;
use Pithub::Repos;
+use Pithub::Search;
use Pithub::Users;
extends 'Pithub::Base';
@@ -542,6 +543,16 @@ sub repos {
return shift->_create_instance('Pithub::Repos');
}
+=method search
+
+Provides access to L<Pithub::Search>.
+
+=cut
+
+sub search {
+ return shift->_create_instance('Pithub::Search');
+}
+
=method users
Provides access to L<Pithub::Users>.
View
@@ -0,0 +1,57 @@
+package Pithub::Search;
+
+# ABSTRACT: Github v3 Search API
+
+use Moo;
+use Carp qw(croak);
+extends 'Pithub::Base';
+
+sub emails {
+ my ( $self, %args ) = @_;
+}
+
+=method issues
+
+=over
+
+=item *
+
+Find issues by state and keyword.
+
+ GET /legacy/issues/search/:owner/:repository/:state/:keyword
+
+Examples:
+
+ my $search = Pithub::Search->new;
+ my $result = $search->issues(
+ user => 'plu',
+ repo => 'Pithub',
+ state => 'open',
+ keyword => 'some keyword',
+ );
+
+=back
+
+=cut
+
+sub issues {
+ my ( $self, %args ) = @_;
+ $self->_validate_user_repo_args( \%args );
+ croak 'Missing key in parameters: state' unless $args{state};
+ croak 'Missing key in parameters: keyword' unless $args{keyword};
+ return $self->request(
+ method => 'GET',
+ path => sprintf( '/legacy/issues/search/%s/%s/%s/%s', delete $args{user}, delete $args{repo}, delete $args{state}, delete $args{keyword} ),
+ %args,
+ );
+}
+
+sub repos {
+ my ( $self, %args ) = @_;
+}
+
+sub users {
+ my ( $self, %args ) = @_;
+}
+
+1;
View
@@ -194,6 +194,11 @@ my @tree = (
},
],
},
+ {
+ accessor => 'search',
+ isa => 'Pithub::Search',
+ methods => [qw(emails issues repos users)],
+ },
);
sub validate_tree {
View
@@ -0,0 +1,29 @@
+use FindBin;
+use lib "$FindBin::Bin/lib";
+use Pithub::Test;
+use Test::Most;
+
+BEGIN {
+ use_ok('Pithub::Search');
+}
+
+# Pithub::Search->issues
+{
+ my $obj = Pithub::Test->create( 'Pithub::Search', user => 'foo', repo => 'bar' );
+
+ isa_ok $obj, 'Pithub::Search';
+
+ throws_ok { $obj->issues } qr{Missing key in parameters: state}, 'Missing state parameter';
+ throws_ok { $obj->issues( state => 'open' ) } qr{Missing key in parameters: keyword}, 'Missing keyword parameter';
+
+ {
+ my $result = $obj->issues(
+ state => 'open',
+ keyword => 'term',
+ );
+ is $result->request->method, 'GET', 'HTTP method';
+ is $result->request->uri->path, '/legacy/issues/search/foo/bar/open/term', 'HTTP path';
+ }
+}
+
+done_testing;

0 comments on commit 5ea992d

Please sign in to comment.