1. Alan Haggai Alavi
  2. Net-Bitbucket

Commits

Alan Haggai Alavi  committed ab4c4fd

Implemented 'Group' resource

  • Participants
  • Parent commits ecf5e4c
  • Branches default

Comments (0)

Files changed (2)

File lib/Net/Bitbucket.pm

View file
  • Ignore whitespace
     Net::Bitbucket::Email
     Net::Bitbucket::Event
     Net::Bitbucket::Follower
+    Net::Bitbucket::Group
 );
 
 use LWP::UserAgent;

File lib/Net/Bitbucket/Group.pm

View file
  • Ignore whitespace
+use strict;
+use warnings;
+
+package Net::Bitbucket::Group;
+
+sub groups {
+    my $self = shift;
+
+    my $url = '/groups/' . $self->{'username'} . '/';
+    return $self->_fetch_response( { 'url' => $url } );
+}
+
+sub group_add {
+    my ( $self, $name ) = @_;
+
+    my $url = '/groups/' . $self->{'username'} . '/';
+    return $self->_fetch_response(
+        {
+            'url'     => $url,
+            'method'  => 'POST',
+            'content' => "name=$name",
+        }
+    );
+}
+
+sub group_update {
+    my $self = shift;
+
+    my ( $old_name, $new_name, $permission, $auto_add );
+    if ( ref $_[0] eq 'HASH' ) {
+        my $args = shift;
+        $old_name   = $args->{'old_name'};
+        $new_name   = $args->{'new_name'};
+        $permission = $args->{'permission'};
+        $auto_add   = $args->{'auto_add'};
+    }
+    else {
+        ( $old_name, $new_name, $permission, $auto_add ) = @_;
+    }
+
+    my $url = '/groups/' . $self->{'username'} . "/$old_name/";
+    return $self->_fetch_response(
+        {
+            'url'    => $url,
+            'method' => 'PUT',
+            'content' =>
+              "name=$new_name&permission=$permission&auto_add=$auto_add",
+        }
+    );
+}
+
+sub group_delete {
+    my ( $self, $name ) = @_;
+
+    my $url = '/groups/' . $self->{'username'} . "/$name/";
+    return $self->_fetch_response( { 'url' => $url, 'method' => 'DELETE' } );
+}
+
+sub group_members {
+    my ( $self, $name ) = @_;
+
+    my $url = '/groups/' . $self->{'username'} . "/$name/members/";
+    return $self->_fetch_response( { 'url' => $url } );
+}
+
+sub group_add_member {
+    my $self = shift;
+
+    my ( $name, $username );
+    if ( ref $_[0] eq 'HASH' ) {
+        my $args = shift;
+        $name     = $args->{'name'};
+        $username = $args->{'username'};
+    }
+    else {
+        ( $name, $username ) = @_;
+    }
+
+    my $url = '/groups/' . $self->{'username'} . "/$name/members/$username/";
+    return $self->_fetch_response(
+        {
+            'url'    => $url,
+            'method' => 'PUT',
+            'header' => { 'Content-Length' => 0 },
+        }
+    );
+}
+
+sub group_remove_member {
+    my $self = shift;
+
+    my ( $name, $username );
+    if ( ref $_[0] eq 'HASH' ) {
+        my $args = shift;
+        $name     = $args->{'name'};
+        $username = $args->{'username'};
+    }
+    else {
+        ( $name, $username ) = @_;
+    }
+
+    my $url = '/groups/' . $self->{'username'} . "/$name/members/$username/";
+    return $self->_fetch_response( { 'url' => $url, 'method' => 'DELETE' } );
+}
+
+1;