[Bps-public-commit] net-lighthouse branch, master, updated. 95db0b5f2749dfaa199e22b22b68d24be43ebcff

sunnavy at bestpractical.com sunnavy at bestpractical.com
Tue Sep 8 02:55:55 EDT 2009


The branch, master has been updated
       via  95db0b5f2749dfaa199e22b22b68d24be43ebcff (commit)
      from  11909ab8ca2f1eab12602b6b181fa2eb67acedb4 (commit)

Summary of changes:
 lib/Net/Lighthouse/User.pm |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

- Log -----------------------------------------------------------------
commit 95db0b5f2749dfaa199e22b22b68d24be43ebcff
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Sep 8 14:55:50 2009 +0800

    implement user->memberships

diff --git a/lib/Net/Lighthouse/User.pm b/lib/Net/Lighthouse/User.pm
index 5a3d36b..650095f 100644
--- a/lib/Net/Lighthouse/User.pm
+++ b/lib/Net/Lighthouse/User.pm
@@ -93,6 +93,23 @@ sub update {
 
 sub memberships {
     my $self = shift;
+    my $ua   = $self->ua;
+    my $url  = $self->base_url . '/users/' . $self->id . '/memberships.xml';
+    my $res  = $ua->get($url);
+    require Net::Lighthouse::User::Membership;
+    if ( $res->is_success ) {
+        my $ms = XMLin( $res->content, KeyAttr => [] )->{membership};
+        my @list = map {
+            my $m = Net::Lighthouse::User::Membership->new;
+            $m->load_from_xml($_);
+        } ref $ms eq 'ARRAY' ? @$ms : $ms;
+        return wantarray ? @list : \@list;
+    }
+    else {
+        die "try to get $url failed: "
+          . $res->status_line . "\n"
+          . $res->content;
+    }
 }
 
 1;

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list