[Bps-public-commit] net-lighthouse branch, master, updated. 04101dc2e302ea8ad487922c405f3e06350c32ce

sunnavy at bestpractical.com sunnavy at bestpractical.com
Thu Sep 3 08:27:48 EDT 2009


The branch, master has been updated
       via  04101dc2e302ea8ad487922c405f3e06350c32ce (commit)
      from  d2d15600b1317726d97740fdbddc5efbee6dbed6 (commit)

Summary of changes:
 lib/Net/Lighthouse/Project/Ticket.pm |   22 +++++++++++++++++-----
 t/03-ticket.t                        |    8 +++++---
 t/data/ticket_1.xml                  |   16 ++++++++++++++--
 3 files changed, 36 insertions(+), 10 deletions(-)

- Log -----------------------------------------------------------------
commit 04101dc2e302ea8ad487922c405f3e06350c32ce
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Sep 3 20:27:43 2009 +0800

    update attachments parse: xml structure is more complex

diff --git a/lib/Net/Lighthouse/Project/Ticket.pm b/lib/Net/Lighthouse/Project/Ticket.pm
index 6ff4808..4fc0d1c 100644
--- a/lib/Net/Lighthouse/Project/Ticket.pm
+++ b/lib/Net/Lighthouse/Project/Ticket.pm
@@ -104,15 +104,27 @@ sub _translate_from_xml {
             ];
         }
         elsif ( $k eq 'attachments' ) {
-            my $attachments = $ref->{attachments}{attachment};
-            next unless $attachments;
-            $attachments = [ $attachments ] unless ref $attachments eq 'ARRAY';
+            my @attachments;
+            for ( keys %{$ref->{attachments}} ) {
+                my $att = $ref->{attachments}{$_};
+                next unless ref $att;
+                if ( ref $att eq 'ARRAY' ) {
+                    push @attachments, @{$att};
+                }
+                else {
+                    push @attachments, $att;
+                }
+            }
+            next unless @attachments;
+
             require Net::Lighthouse::Project::Ticket::Attachment;
             $ref->{attachments} = [
                 map {
-                    my $v = Net::Lighthouse::Project::Ticket::Attachment->new;
+                    my $v =
+                      Net::Lighthouse::Project::Ticket::Attachment->new(
+                        ua => $self->ua );
                     $v->load_from_xml($_)
-                  } @$attachments
+                  } @attachments
             ];
         }
     }
diff --git a/t/03-ticket.t b/t/03-ticket.t
index a0b9602..0b7584d 100644
--- a/t/03-ticket.t
+++ b/t/03-ticket.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 71;
+use Test::More tests => 72;
 use Test::Mock::LWP;
 use DateTime;
 use_ok('Net::Lighthouse::Project');
@@ -69,7 +69,7 @@ my %hash = (
         second => 50,
     ),
     'assigned_user_id'  => 67166,
-    'attachments_count' => 1,
+    'attachments_count' => 2,
     'url'        => 'http://sunnavy.lighthouseapp.com/projects/35918/tickets/1',
     'tag'        => 'first',
     'creator_id' => 67166,
@@ -101,9 +101,11 @@ for my $k ( keys %hash ) {
 is( @{$n1->versions}, 1, 'version number' );
 isa_ok( $n1->versions->[0], 'Net::Lighthouse::Project::Ticket::Version' );
 is( $n1->versions->[0]->creator_id, 67166, 'version creator_id' );
-is( @{$n1->attachments}, 1, 'attachment number' );
+is( @{$n1->attachments}, 2, 'attachment number' );
 isa_ok( $n1->attachments->[0], 'Net::Lighthouse::Project::Ticket::Attachment' );
 is( $n1->attachments->[0]->filename, 'first', 'attachment filename' );
+is( $n1->attachments->[1]->content_type,
+    'image/jpeg', 'attachment content type' );
 
 $Mock_response->mock(
     content => sub {
diff --git a/t/data/ticket_1.xml b/t/data/ticket_1.xml
index fe9734f..976105f 100644
--- a/t/data/ticket_1.xml
+++ b/t/data/ticket_1.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <ticket>
   <assigned-user-id type="integer">67166</assigned-user-id>
-  <attachments-count type="integer">1</attachments-count>
+  <attachments-count type="integer">2</attachments-count>
   <closed type="boolean">false</closed>
   <created-at type="datetime">2009-08-21T11:15:50Z</created-at>
   <creator-id type="integer">67166</creator-id>
@@ -62,5 +62,17 @@
       <width type="integer" nil="true"/>
       <url>http://sunnavy.lighthouseapp.com/attachments/249828/first</url>
     </attachment>
+    <attachment-image type="Attachment">
+      <code>b5ed989a941beda06d677f23f59e15888765904b</code>
+      <content-type>image/jpeg</content-type>
+      <created-at type="datetime">2009-08-31T14:03:20+08:00</created-at>
+      <filename>simpsons_nelson_haha.jpg</filename>
+      <height type="integer">326</height>
+      <id type="integer">256710</id>
+      <size type="integer">65411</size>
+      <uploader-id type="integer">67166</uploader-id>
+      <width type="integer">350</width>
+      <url>http://sunnavy.lighthouseapp.com/attachments/256710/simpsons_nelson_haha.jpg</url>
+    </attachment-image>
   </attachments>
-</ticket>
\ No newline at end of file
+</ticket>

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



More information about the Bps-public-commit mailing list