[Bps-public-commit] net-lighthouse branch, master, updated. 6a049f46ecbf745776742ea37f49c7938d132979

sunnavy at bestpractical.com sunnavy at bestpractical.com
Mon Sep 7 04:13:35 EDT 2009


The branch, master has been updated
       via  6a049f46ecbf745776742ea37f49c7938d132979 (commit)
      from  fc4d8485d6853942b38b4bc4ef17d2be87619d31 (commit)

Summary of changes:
 lib/Net/Lighthouse/Base.pm              |   17 ++++++++++-------
 lib/Net/Lighthouse/Project.pm           |    6 +++---
 lib/Net/Lighthouse/Project/Changeset.pm |    2 +-
 lib/Net/Lighthouse/Project/Message.pm   |    2 +-
 lib/Net/Lighthouse/Project/Milestone.pm |    2 +-
 lib/Net/Lighthouse/Project/Ticket.pm    |    2 +-
 lib/Net/Lighthouse/Project/TicketBin.pm |    2 +-
 t/01-base.t                             |   12 ++++++------
 8 files changed, 24 insertions(+), 21 deletions(-)

- Log -----------------------------------------------------------------
commit 6a049f46ecbf745776742ea37f49c7938d132979
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon Sep 7 16:13:31 2009 +0800

    mv email,password and token to auth hash

diff --git a/lib/Net/Lighthouse/Base.pm b/lib/Net/Lighthouse/Base.pm
index 6d877fd..ed93d8f 100644
--- a/lib/Net/Lighthouse/Base.pm
+++ b/lib/Net/Lighthouse/Base.pm
@@ -9,9 +9,11 @@ has 'account' => (
     is  => 'ro',
 );
 
-has [ 'email', 'password', 'token' ] => (
-    isa => 'Str',
-    is  => 'rw',
+has 'auth' => (
+    isa     => 'HashRef',
+    is      => 'rw',
+    default => sub { {} },
+    lazy    => 1,
 );
 
 no Any::Moose;
@@ -30,13 +32,14 @@ sub ua {
         agent => 'net-lighthouse/' . $Net::Lighthouse::VERSION );
     $ua->default_header( 'Content-Type' => 'application/xml' );
     # email and password have high priority
-    if ( $self->email && $self->password ) {
-        my $base64 = encode_base64( $self->email . ':' . $self->password );
+    my $auth = $self->auth;
+    if ( $auth->{email} && $auth->{password} ) {
+        my $base64 = encode_base64( $auth->{email} . ':' . $auth->{password} );
         chomp $base64;
         $ua->default_header( Authorization => 'Basic ' . $base64 );
     }
-    elsif ( $self->token ) {
-        $ua->default_header( 'X-LighthouseToken', $self->token );
+    elsif ( $auth->{token} ) {
+        $ua->default_header( 'X-LighthouseToken', $auth->{token} );
     }
 
     return $ua;
diff --git a/lib/Net/Lighthouse/Project.pm b/lib/Net/Lighthouse/Project.pm
index e7016ac..bf311a6 100644
--- a/lib/Net/Lighthouse/Project.pm
+++ b/lib/Net/Lighthouse/Project.pm
@@ -209,7 +209,7 @@ sub list {
         return map {
             my $p = Net::Lighthouse::Project->new(
                 map { $_ => $self->$_ }
-                  grep { $self->$_ } qw/account email password token/
+                  grep { $self->$_ } qw/account auth/
             );
             $p->load_from_xml($_);
         } @$ps;
@@ -262,7 +262,7 @@ sub _new {
     my $object = $class->new(
         project_id => $self->id,
         map { $_ => $self->$_ }
-          grep { $self->$_ } qw/account email password token/
+          grep { $self->$_ } qw/account auth/
     );
     return $object;
 }
@@ -281,7 +281,7 @@ sub _list {
     my $object = $class->new(
         project_id => $self->id,
         map { $_ => $self->$_ }
-          grep { $self->$_ } qw/account email password token/
+          grep { $self->$_ } qw/account auth/
     );
     return $object->list(@_);
 }
diff --git a/lib/Net/Lighthouse/Project/Changeset.pm b/lib/Net/Lighthouse/Project/Changeset.pm
index 3cf8643..8693b4e 100644
--- a/lib/Net/Lighthouse/Project/Changeset.pm
+++ b/lib/Net/Lighthouse/Project/Changeset.pm
@@ -138,7 +138,7 @@ sub list {
         return map {
             my $t = Net::Lighthouse::Project::Changeset->new(
                 map { $_ => $self->$_ }
-                  grep { $self->$_ } qw/account email password token project_id/
+                  grep { $self->$_ } qw/account auth project_id/
             );
             $t->load_from_xml($_);
         } @$ts;
diff --git a/lib/Net/Lighthouse/Project/Message.pm b/lib/Net/Lighthouse/Project/Message.pm
index cd43ef8..5454b76 100644
--- a/lib/Net/Lighthouse/Project/Message.pm
+++ b/lib/Net/Lighthouse/Project/Message.pm
@@ -245,7 +245,7 @@ sub list {
         return map {
             my $t = Net::Lighthouse::Project::Message->new(
                 map { $_ => $self->$_ }
-                  grep { $self->$_ } qw/account email password token project_id/
+                  grep { $self->$_ } qw/account auth project_id/
             );
             $t->load_from_xml($_);
         } @$ts;
diff --git a/lib/Net/Lighthouse/Project/Milestone.pm b/lib/Net/Lighthouse/Project/Milestone.pm
index cf3189f..95a9bdb 100644
--- a/lib/Net/Lighthouse/Project/Milestone.pm
+++ b/lib/Net/Lighthouse/Project/Milestone.pm
@@ -181,7 +181,7 @@ sub list {
         return map {
             my $t = Net::Lighthouse::Project::Milestone->new(
                 map { $_ => $self->$_ }
-                  grep { $self->$_ } qw/account email password token project_id/
+                  grep { $self->$_ } qw/account auth project_id/
             );
             $t->load_from_xml($_);
         } @$ts;
diff --git a/lib/Net/Lighthouse/Project/Ticket.pm b/lib/Net/Lighthouse/Project/Ticket.pm
index 0ed84a0..6381d4b 100644
--- a/lib/Net/Lighthouse/Project/Ticket.pm
+++ b/lib/Net/Lighthouse/Project/Ticket.pm
@@ -276,7 +276,7 @@ sub list {
         return map {
             my $t = Net::Lighthouse::Project::Ticket->new(
                 map { $_ => $self->$_ }
-                  grep { $self->$_ } qw/account email password token project_id/
+                  grep { $self->$_ } qw/account auth project_id/
             );
             $t->load_from_xml($_);
         } @$ts;
diff --git a/lib/Net/Lighthouse/Project/TicketBin.pm b/lib/Net/Lighthouse/Project/TicketBin.pm
index 8f7104d..eddca1c 100644
--- a/lib/Net/Lighthouse/Project/TicketBin.pm
+++ b/lib/Net/Lighthouse/Project/TicketBin.pm
@@ -195,7 +195,7 @@ sub list {
         return map {
             my $t = Net::Lighthouse::Project::TicketBin->new(
                 map { $_ => $self->$_ }
-                  grep { $self->$_ } qw/account email password token project_id/
+                  grep { $self->$_ } qw/account auth project_id/
             );
             $t->load_from_xml($_);
         } @$ts;
diff --git a/t/01-base.t b/t/01-base.t
index 85e167f..33cafcc 100644
--- a/t/01-base.t
+++ b/t/01-base.t
@@ -1,14 +1,14 @@
 use strict;
 use warnings;
 
-use Test::More tests => 15;
+use Test::More tests => 13;
 use MIME::Base64;
 
 use_ok('Net::Lighthouse');
 can_ok( 'Net::Lighthouse', 'new' );
 my $lh = Net::Lighthouse->new( account => 'sunnavy' );
 isa_ok( $lh, 'Net::Lighthouse' );
-for (qw/account email password token base_url ua/) {
+for (qw/account auth base_url ua/) {
     can_ok( $lh, $_ );
 }
 
@@ -24,12 +24,12 @@ is( $lh->ua->default_header('Content-Type'),
     'application/xml', 'content-type of ua' );
 
 my $token = 'a' x 40;
-$lh->token($token);
+$lh->auth->{token} = $token;
 is( $lh->ua->default_header('X-LighthouseToken'),
     $token, 'X-LighthouseToken of ua' );
-$lh->email('mark at twain.org');
-$lh->password('huckleberry');
-my $auth_base64 = encode_base64( $lh->email . ':' . $lh->password );
+$lh->auth->{email} = 'mark at twain.org';
+$lh->auth->{password} = 'huckleberry';
+my $auth_base64 = encode_base64( $lh->auth->{email} . ':' . $lh->auth->{password} );
 chomp $auth_base64;
 is(
     $lh->ua->default_header('Authorization'),

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



More information about the Bps-public-commit mailing list