r66835 - in /branches/upstream/libnet-github-perl/current: Changes MANIFEST META.yml Makefile.PL examples/ examples/organizations.pl lib/Net/GitHub.pm lib/Net/GitHub/V2.pm lib/Net/GitHub/V2/NoRepo.pm lib/Net/GitHub/V2/Organizations.pm
carnil at users.alioth.debian.org
carnil at users.alioth.debian.org
Sun Jan 2 13:21:28 UTC 2011
Author: carnil
Date: Sun Jan 2 13:21:17 2011
New Revision: 66835
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=66835
Log:
[svn-upgrade] new version libnet-github-perl (0.24)
Added:
branches/upstream/libnet-github-perl/current/examples/
branches/upstream/libnet-github-perl/current/examples/organizations.pl
branches/upstream/libnet-github-perl/current/lib/Net/GitHub/V2/Organizations.pm
Modified:
branches/upstream/libnet-github-perl/current/Changes
branches/upstream/libnet-github-perl/current/MANIFEST
branches/upstream/libnet-github-perl/current/META.yml
branches/upstream/libnet-github-perl/current/Makefile.PL
branches/upstream/libnet-github-perl/current/lib/Net/GitHub.pm
branches/upstream/libnet-github-perl/current/lib/Net/GitHub/V2.pm
branches/upstream/libnet-github-perl/current/lib/Net/GitHub/V2/NoRepo.pm
Modified: branches/upstream/libnet-github-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-github-perl/current/Changes?rev=66835&op=diff
==============================================================================
--- branches/upstream/libnet-github-perl/current/Changes (original)
+++ branches/upstream/libnet-github-perl/current/Changes Sun Jan 2 13:21:17 2011
@@ -1,4 +1,8 @@
Revision history for Net-GitHub
+
+0.24 2011.01.01
+ Organizations API (fayland)
+ update Auth to 'Basic Auth' (fayland)
0.23 2010.11.04
Moose has deprected 'excludes', '-excludes' is preferred (datamuc)
Modified: branches/upstream/libnet-github-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-github-perl/current/MANIFEST?rev=66835&op=diff
==============================================================================
--- branches/upstream/libnet-github-perl/current/MANIFEST (original)
+++ branches/upstream/libnet-github-perl/current/MANIFEST Sun Jan 2 13:21:17 2011
@@ -1,4 +1,5 @@
Changes
+examples/organizations.pl
inc/Module/AutoInstall.pm
inc/Module/Install.pm
inc/Module/Install/AutoInstall.pm
@@ -28,6 +29,7 @@
lib/Net/GitHub/V2/Network.pm
lib/Net/GitHub/V2/NoRepo.pm
lib/Net/GitHub/V2/Object.pm
+lib/Net/GitHub/V2/Organizations.pm
lib/Net/GitHub/V2/Repositories.pm
lib/Net/GitHub/V2/Users.pm
Makefile.PL
Modified: branches/upstream/libnet-github-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-github-perl/current/META.yml?rev=66835&op=diff
==============================================================================
--- branches/upstream/libnet-github-perl/current/META.yml (original)
+++ branches/upstream/libnet-github-perl/current/META.yml Sun Jan 2 13:21:17 2011
@@ -19,6 +19,7 @@
name: Net-GitHub
no_index:
directory:
+ - examples
- inc
- t
requires:
@@ -26,9 +27,10 @@
Crypt::SSLeay: 0
HTML::TreeBuilder: 0
JSON::Any: 0
+ MIME::Base64: 0
URI::Escape: 0
WWW::Mechanize::GZip: 0
resources:
license: http://dev.perl.org/licenses/
repository: http://github.com/fayland/perl-net-github/tree/master
-version: 0.23
+version: 0.24
Modified: branches/upstream/libnet-github-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-github-perl/current/Makefile.PL?rev=66835&op=diff
==============================================================================
--- branches/upstream/libnet-github-perl/current/Makefile.PL (original)
+++ branches/upstream/libnet-github-perl/current/Makefile.PL Sun Jan 2 13:21:17 2011
@@ -7,6 +7,7 @@
repository 'http://github.com/fayland/perl-net-github/tree/master';
+requires 'MIME::Base64';
requires 'URI::Escape';
requires 'Any::Moose';
requires 'Crypt::SSLeay';
Added: branches/upstream/libnet-github-perl/current/examples/organizations.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-github-perl/current/examples/organizations.pl?rev=66835&op=file
==============================================================================
--- branches/upstream/libnet-github-perl/current/examples/organizations.pl (added)
+++ branches/upstream/libnet-github-perl/current/examples/organizations.pl Sun Jan 2 13:21:17 2011
@@ -1,0 +1,83 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use FindBin qw/$Bin/;
+use lib "$Bin/../lib";
+use Net::GitHub;
+use Data::Dumper;
+
+my $github = Net::GitHub->new(
+ owner => $ENV{github_login}, repo => 'perl-net-github',
+ login => $ENV{github_login}, token => $ENV{github_token}
+);
+
+my $organization = $github->organization;
+my $o;
+
+
+
+# get 'github' organization info
+$o = $organization->organizations('PerlChina');
+print Dumper(\$o);
+
+=pod
+
+# update org
+$o = $organization->update('PerlChina', blog => 'http://planet.perlchina.org/', location => 'China');
+print Dumper(\$o);
+
+$o = $organization->organizations; # my organizations
+print Dumper(\$o);
+
+# get user user_organizations
+$o = $organization->user_organizations('technoweenie');
+print Dumper(\$o);
+
+$o = $organization->public_repositories('github');
+print Dumper(\$o);
+
+$o = $organization->public_members('github');
+print Dumper(\$o);
+
+$o = $organization->teams('PerlChina');
+print Dumper(\$o);
+
+$o = $organization->create_team('PerlChina',
+ name => 'fayland',
+ permission => 'admin',
+ repo_names => ['PerlChina/sandbox']
+);
+print Dumper(\$o);
+
+$o = $organization->team(30544);
+print Dumper(\$o);
+
+$o = $organization->update_team(30544,
+ name => 'test',
+ permission => 'push',
+ repo_names => ['PerlChina/sandbox']
+);
+print Dumper(\$o);
+
+$o = $organization->add_team_member(30544, 'fayland');
+print Dumper(\$o);
+
+$o = $organization->team_members(30544);
+print Dumper(\$o);
+
+$o = $organization->remove_team_member(30544, 'fayland');
+print Dumper(\$o);
+
+$o = $organization->add_team_repositories(30544, 'PerlChina/sandbox');
+print Dumper(\$o);
+
+$o = $organization->team_repositories(30544);
+print Dumper(\$o);
+
+$o = $organization->remove_team_repositories(30544, 'PerlChina/sandbox');
+print Dumper(\$o);
+
+=cut
+
+1;
Modified: branches/upstream/libnet-github-perl/current/lib/Net/GitHub.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-github-perl/current/lib/Net/GitHub.pm?rev=66835&op=diff
==============================================================================
--- branches/upstream/libnet-github-perl/current/lib/Net/GitHub.pm (original)
+++ branches/upstream/libnet-github-perl/current/lib/Net/GitHub.pm Sun Jan 2 13:21:17 2011
@@ -2,7 +2,7 @@
use Any::Moose;
-our $VERSION = '0.23';
+our $VERSION = '0.24';
our $AUTHORITY = 'cpan:FAYLAND';
sub new {
@@ -86,6 +86,10 @@
# L<Net::GitHub::V2::Network>
$github->network_meta;
$github->network_data_chunk( $net_hash );
+
+ # L<Net::GitHub::V2::Organizations>
+ $github->organization->organizations('github');
+ $github->organization->teams('PerlChina');
=head1 Git URL
Modified: branches/upstream/libnet-github-perl/current/lib/Net/GitHub/V2.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-github-perl/current/lib/Net/GitHub/V2.pm?rev=66835&op=diff
==============================================================================
--- branches/upstream/libnet-github-perl/current/lib/Net/GitHub/V2.pm (original)
+++ branches/upstream/libnet-github-perl/current/lib/Net/GitHub/V2.pm Sun Jan 2 13:21:17 2011
@@ -11,6 +11,7 @@
use Net::GitHub::V2::Issues;
use Net::GitHub::V2::Object;
use Net::GitHub::V2::Network;
+use Net::GitHub::V2::Organizations;
with 'Net::GitHub::V2::HasRepo';
@@ -80,6 +81,16 @@
handles => ['network_meta', 'network_data_chunk']
);
+has 'organization' => (
+ is => 'rw',
+ isa => 'Net::GitHub::V2::Organizations',
+ lazy => 1,
+ default => sub {
+ my $self = shift;
+ return Net::GitHub::V2::Organizations->new( $self->args_to_pass );
+ },
+);
+
no Any::Moose;
__PACKAGE__->meta->make_immutable;
@@ -166,6 +177,13 @@
L<Net::GitHub::V2::Network>
+=head2 organization
+
+ my $organization = $github->organization->organizations('github');
+ my $teams = $github->organization->teams('PerlChina');
+
+L<Net::GitHub::V2::Organizations>
+
=head1 SEE ALSO
L<Any::Moose>
Modified: branches/upstream/libnet-github-perl/current/lib/Net/GitHub/V2/NoRepo.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-github-perl/current/lib/Net/GitHub/V2/NoRepo.pm?rev=66835&op=diff
==============================================================================
--- branches/upstream/libnet-github-perl/current/lib/Net/GitHub/V2/NoRepo.pm (original)
+++ branches/upstream/libnet-github-perl/current/lib/Net/GitHub/V2/NoRepo.pm Sun Jan 2 13:21:17 2011
@@ -2,11 +2,13 @@
use Any::Moose 'Role';
-our $VERSION = '0.17';
+our $VERSION = '0.24';
our $AUTHORITY = 'cpan:FAYLAND';
use JSON::Any;
use WWW::Mechanize::GZip;
+use MIME::Base64;
+use HTTP::Request::Common;
use Carp qw/croak/;
# repo stuff
@@ -88,8 +90,25 @@
};
sub get_json_to_obj_authed {
+ push @_, 'POST';
+ _get_json_to_obj_authed(@_);
+}
+
+sub get_json_to_obj_authed_PUT {
+ push @_, 'PUT';
+ _get_json_to_obj_authed(@_);
+}
+
+sub get_json_to_obj_authed_DELETE {
+ push @_, 'DELETE';
+ _get_json_to_obj_authed(@_);
+}
+
+sub _get_json_to_obj_authed {
my $self = shift;
my $pending_url = shift;
+
+ my $request_method = pop @_; # can be DELETE or PUT
croak 'login and token are required' unless ( $self->has_login and $self->has_token );
@@ -102,16 +121,16 @@
$key = pop @_;
}
- require HTTP::Request::Common;
- my $res = $self->ua->request(
- HTTP::Request::Common::POST( $url, [
- 'login' => $self->login,
- 'token' => $self->token,
- @_,
- ] ),
- );
+ my $req = $request_method eq 'DELETE' ? HTTP::Request::Common::DELETE( $url, [ @_ ] ) :
+ $request_method eq 'PUT' ? HTTP::Request::Common::PUT( $url, [ @_ ] ) :
+ HTTP::Request::Common::POST( $url, [ @_ ] );
+
+ # "schacon/token:6ef8395fecf207165f1a82178ae1b984"
+ my $auth_basic = $self->login . '/token:' . $self->token;
+ $req->header('Authorization', 'Basic ' . encode_base64($auth_basic));
+
+ my $res = $self->ua->request($req);
return { error => '404 Not Found' } if $res->code == 404;
- return { error => $res->as_string() } unless ( $res->is_success );
my $json = $res->content();
my $data = $self->json->jsonToObj($json);
Added: branches/upstream/libnet-github-perl/current/lib/Net/GitHub/V2/Organizations.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-github-perl/current/lib/Net/GitHub/V2/Organizations.pm?rev=66835&op=file
==============================================================================
--- branches/upstream/libnet-github-perl/current/lib/Net/GitHub/V2/Organizations.pm (added)
+++ branches/upstream/libnet-github-perl/current/lib/Net/GitHub/V2/Organizations.pm Sun Jan 2 13:21:17 2011
@@ -1,0 +1,278 @@
+package Net::GitHub::V2::Organizations;
+
+use Any::Moose;
+
+our $VERSION = '0.24';
+our $AUTHORITY = 'cpan:FAYLAND';
+
+use URI::Escape;
+
+with 'Net::GitHub::V2::NoRepo';
+
+sub organizations {
+ my ( $self, $org ) = @_;
+
+ if ($org) {
+ return $self->get_json_to_obj( 'organizations/' . uri_escape($org), 'organization' );
+ } else {
+ return $self->get_json_to_obj_authed( 'organizations', 'organizations' );
+ }
+}
+
+sub user_organizations {
+ my ( $self, $owner ) = @_;
+
+ $owner ||= $self->owner;
+
+ return $self->get_json_to_obj( "user/show/$owner/organizations", 'organizations' );
+}
+
+sub update {
+ my ( $self, $org, %up ) = @_;
+
+ # with format organization[key] = value
+ my @values;
+ foreach my $key ( keys %up ) {
+ push @values, ( "organization[$key]", $up{$key} );
+ }
+
+ my $url = $self->api_url_https . 'organizations/' . uri_escape($org);
+ return $self->get_json_to_obj_authed( $url, @values, 'organization' );
+}
+
+sub repositories {
+ my ( $self ) = @_;
+
+ return $self->get_json_to_obj_authed( 'organizations/repositories', 'repositories' );
+}
+
+sub public_repositories {
+ my ( $self, $org ) = @_;
+
+ return $self->get_json_to_obj( "organizations/$org/public_repositories", 'repositories' );
+}
+
+sub public_members {
+ my ( $self, $org ) = @_;
+
+ return $self->get_json_to_obj( "organizations/$org/public_members", 'users' );
+}
+
+### Team API
+
+sub teams {
+ my ( $self, $org ) = @_;
+
+ return $self->get_json_to_obj_authed( "organizations/$org/teams", 'teams' );
+}
+
+sub create_team {
+ my ($self, $org, %teams) = @_;
+
+ # with format team[key] = value
+ my @values;
+ foreach my $key ( keys %teams ) {
+ if ($key eq 'repo_names') {
+ foreach my $v (@{ $teams{$key} }) {
+ push @values, ( "team[$key][]", $v );
+ }
+ } else {
+ push @values, ( "team[$key]", $teams{$key} );
+ }
+ }
+
+ my $url = $self->api_url_https . 'organizations/' . uri_escape($org) . '/teams';
+ return $self->get_json_to_obj_authed( $url, @values, 'teams' );
+}
+
+sub team {
+ my ( $self, $team_id ) = @_;
+
+ return $self->get_json_to_obj_authed( "teams/$team_id", 'team' );
+}
+
+sub update_team {
+ my ( $self, $team_id, %teams ) = @_;
+
+ # with format team[key] = value
+ my @values;
+ foreach my $key ( keys %teams ) {
+ if ($key eq 'repo_names') {
+ foreach my $v (@{ $teams{$key} }) {
+ push @values, ( "team[$key][]", $v );
+ }
+ } else {
+ push @values, ( "team[$key]", $teams{$key} );
+ }
+ }
+
+ my $url = $self->api_url_https . "teams/$team_id";
+ return $self->get_json_to_obj_authed( $url, @values, 'team' );
+}
+
+sub delete_team {
+ my ( $self, $team_id ) = @_;
+
+ return $self->get_json_to_obj_authed_DELETE( "teams/$team_id" );
+}
+
+sub team_members {
+ my ( $self, $team_id ) = @_;
+
+ return $self->get_json_to_obj_authed( "teams/$team_id/members", 'users' );
+}
+
+sub add_team_member {
+ my ( $self, $team_id, $user ) = @_;
+
+ my @values= ('name', $user);
+ my $url = $self->api_url_https . "teams/$team_id/members";
+ return $self->get_json_to_obj_authed( $url, @values, 'users' );
+}
+
+sub remove_team_member {
+ my ( $self, $team_id, $user ) = @_;
+
+ my $url = $self->api_url_https . "teams/$team_id/members?name=" . uri_escape($user);
+ return $self->get_json_to_obj_authed_DELETE( $url, 'users' );
+}
+
+sub team_repositories {
+ my ( $self, $team_id ) = @_;
+
+ return $self->get_json_to_obj_authed( "teams/$team_id/repositories", 'repositories' );
+}
+
+sub add_team_repositories {
+ my ( $self, $team_id, $repo ) = @_;
+
+ my @values= ('name', $repo);
+ my $url = $self->api_url_https . "teams/$team_id/repositories";
+ return $self->get_json_to_obj_authed( $url, @values, 'repositories' );
+}
+
+sub remove_team_repositories {
+ my ( $self, $team_id, $repo ) = @_;
+
+ my $url = $self->api_url_https . "teams/$team_id/repositories?name=" . uri_escape($repo);
+ return $self->get_json_to_obj_authed_DELETE( $url, 'repositories' );
+}
+
+no Any::Moose;
+__PACKAGE__->meta->make_immutable;
+
+1;
+__END__
+
+=head1 NAME
+
+Net::GitHub::V2::Organizations - GitHub Organizations API
+
+=head1 SYNOPSIS
+
+ use Net::GitHub::V2::Organizations;
+
+ my $organization = Net::GitHub::V2::Organizations->new(
+ owner => 'fayland'
+ );
+
+=head1 DESCRIPTION
+
+L<http://develop.github.com/p/orgs.html>
+
+For those B<(authentication required)> below, you must set login and token (in L<https://github.com/account>)
+
+ my $user = Net::GitHub::V2::Organizations->new(
+ owner => 'fayland',
+ login => 'fayland', token => '54b5197d7f92f52abc5c7149b313cf51', # faked
+ );
+
+=head1 METHODS
+
+=over 4
+
+=item organizations
+
+ my $o = $organization->organizations('github');
+ my $o_arrayref = $organization->organizations; # my organizations
+
+=item update
+
+ $organization->update('PerlChina', blog => 'http://planet.perlchina.org/', location => 'China');
+
+=item user_organizations
+
+ my $o_arrayref = $organization->user_organizations('technoweenie');
+
+=item repositories
+
+ my $repositories = $organization->repositories;
+
+=item public_repositories
+
+ my $repositories = $organization->public_repositories('github');
+
+=item public_members
+
+ my $users = $organization->public_members('github');
+
+=item teams
+
+ my $teams = $organization->teams('github');
+
+=item create_team
+
+ $organization->create_team('PerlChina',
+ name => 'test',
+ permission => 'admin',
+ repo_names => ['PerlChina/sandbox']
+ );
+
+=item update_team
+
+ $organization->update_team($team_id,
+ name => 'test',
+ permission => 'push',
+ repo_names => ['PerlChina/sandbox']
+ );
+
+=item delete_team
+
+ $organization->delete_team($team_id);
+
+=item team_members
+
+ my $users = $organization->team_members($team_id);
+
+=item add_team_member
+
+ $organization->add_team_member($team_id, $user);
+
+=item remove_team_member
+
+ $organization->remove_team_member($team_id, $user);
+
+=item team_repositories
+
+ my $team_repositories = $organization->team_repositories($team_id);
+
+=item add_team_repositories
+
+ $organization->add_team_repositories($team_id, "$org/$respo");
+
+=item remove_team_repositories
+
+ $organization->remove_team_repositories($team_id, "$org/$respo");
+
+=back
+
+=head1 AUTHOR
+
+Fayland Lam, C<< <fayland at gmail.com> >>
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2009 Fayland Lam, all rights reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
More information about the Pkg-perl-cvs-commits
mailing list