Assembla home | Assembla project page
 

Changeset 60

Show
Ignore:
Timestamp:
08/20/08 01:14:40 (3 months ago)
Author:
importantyesterday
Message:

Refactored for updated last.fm APIs:
Updated TopArtistsGatewayStub to use new xml values.
Updated TopArtists to make variable xml type of XML not XMLList.
Updated TopArtists instance methods.
Updated TopArtistsTest to reflect these changes.
Updated TopArtistsGateway not to modify the data.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • AudioScrobbler/branches/Pantsuit/src/net/buckyschwarz/pantsuit/domain/TopArtists.as

    r57 r60  
    2929   public class TopArtists extends EventDispatcher 
    3030   { 
    31       private var _topArtistsXMLListCollection : XMLListCollection 
     31      private var _xmlListCollection : XMLListCollection 
    3232      private var _artistCollection : ArrayCollection; 
    33       private var _xml : XMLList 
     33      private var _xml : XML; 
    3434      private var _user : User; 
    3535 
    3636      public function TopArtists() 
    3737      { 
    38          _topArtistsXMLListCollection = new XMLListCollection(); 
     38         _xmlListCollection = new XMLListCollection(); 
    3939         _artistCollection = new ArrayCollection(); 
    4040         _xml = null; 
     
    4343      public function getTruncatedXMLListCollection(count : int) : XMLListCollection 
    4444      { 
    45          var collection : XMLListCollection
     45         var collection : XMLListCollection = _xmlListCollection
    4646 
    4747         if (count > 0) 
    4848         { 
    49             collection = new XMLListCollection(XMLList(topArtistsXMLListCollection.getItemAt(0))); 
     49            collection = new XMLListCollection(XMLList(xmlListCollection.getItemAt(0))); 
    5050            for(var i : int = 1; i < count; i++) 
    5151            { 
    52                collection.addItem(XMLList(topArtistsXMLListCollection.getItemAt(i))); 
     52               collection.addItem(XMLList(_xmlListCollection.getItemAt(i))); 
    5353            }   
    5454         } 
     
    6262         for(var i : int = 0; i < count; i++) 
    6363         { 
    64             var artist : Artist = new Artist(); 
    65  
    66             artist.name = topArtistsXMLListCollection.getItemAt(i).name; 
    67             artist.mbid = topArtistsXMLListCollection.getItemAt(i).mbid; 
    68             artist.playCount = topArtistsXMLListCollection.getItemAt(i).playcount; 
    69             artist.rank = topArtistsXMLListCollection.getItemAt(i).rank; 
    70             artist.url = topArtistsXMLListCollection.getItemAt(i).url; 
    71             artist.thumbnail = topArtistsXMLListCollection.getItemAt(i).thumbnail; 
    72             artist.image = topArtistsXMLListCollection.getItemAt(i).image; 
    73  
    74             collection.addItem(artist); 
     64            collection.addItemAt(_artistCollection.getItemAt(i), i); 
    7565         } 
    7666         return collection; 
     
    7868 
    7969      /** 
    80       * Calls the methods to populate the topArtistsXMLListCollection and artistCollections 
     70      * Calls the methods to populate the xmlListCollection and artistCollections 
    8171      *  
    8272      * @throws xml is null error 
     
    9080         else 
    9181         { 
    92             _topArtistsXMLListCollection = new XMLListCollection(new XMLList(_xml)); 
    93             _artistCollection = getTruncatedArtistCollection(0); 
     82            buildXMLListCollection(); 
     83            buildArtistCollection(); 
    9484         } 
    9585      } 
    9686 
    97       public function get xml() : XMLList 
     87      private function buildArtistCollection() : void 
     88      { 
     89         var artist : Artist; 
     90         for(var i : int = 0; i < _xmlListCollection.length; i++) 
     91         { 
     92            artist = new Artist(); 
     93            artist.name = _xmlListCollection.getItemAt(i).name; 
     94            artist.mbid = _xmlListCollection.getItemAt(i).mbid; 
     95            artist.playCount = _xmlListCollection.getItemAt(i).playcount; 
     96            artist.rank = _xmlListCollection.getItemAt(i).@rank; 
     97            artist.url = _xmlListCollection.getItemAt(i).url; 
     98            artist.thumbnail = _xmlListCollection.getItemAt(i).image.(@size=="small"); 
     99            artist.image = _xmlListCollection.getItemAt(i).image.(@size=="large"); 
     100 
     101            _artistCollection.addItem(artist); 
     102         } 
     103      } 
     104 
     105      private function buildXMLListCollection() : void 
     106      { 
     107         _xmlListCollection = new XMLListCollection(_xml.topartists.artist); 
     108      } 
     109       
     110 
     111      public function get xml() : XML 
    98112      { 
    99113         return _xml; 
    100114      } 
    101115 
    102       public function set xml(xml : XMLList) : void 
     116      public function set xml(xml : XML) : void 
    103117      { 
    104118         _xml = xml; 
    105119      } 
    106120 
    107       public function get topArtistsXMLListCollection() : XMLListCollection 
     121      public function get xmlListCollection() : XMLListCollection 
    108122      { 
    109          if (null == _topArtistsXMLListCollection) 
     123         if (null == _xmlListCollection) 
    110124         { 
    111             _topArtistsXMLListCollection = new XMLListCollection(_xml); 
     125            buildXMLListCollection(); 
    112126         } 
    113          return _topArtistsXMLListCollection; 
    114       } 
    115  
    116       public function set topArtistsXMLListCollection(topArtistsXMLListCollection : XMLListCollection) : void 
    117       { 
    118          if (null != topArtistsXMLListCollection) 
    119          { 
    120             _topArtistsXMLListCollection = topArtistsXMLListCollection; 
    121          } 
     127         return _xmlListCollection; 
    122128      } 
    123129 
  • AudioScrobbler/branches/Pantsuit/src/net/buckyschwarz/pantsuit/gateway/TopArtistsGateway.as

    r58 r60  
    9696      } 
    9797 
    98       public function get xml() : XMLList 
     98      public function get xml() : XML 
    9999      { 
    100          return _xml.artist
     100         return _xml
    101101      } 
    102102 
  • AudioScrobbler/branches/Pantsuit/src/test/net/buckyschwarz/pantsuit/TopArtistsTest.as

    r57 r60  
    5151      override public function setUp() : void 
    5252      { 
    53          topArtists = new TopArtists(); 
    54          topArtistsGatewayStub = new TopArtistsGatewayStub(); 
    55          artist = new Artist(); 
    56  
    57          xml = <artist> 
     53         xml = <artist rank="1"> 
    5854                  <name>The Beatles</name> 
     55                  <playcount>2019</playcount> 
    5956                  <mbid>b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d</mbid> 
    60                   <playcount>1262</playcount> 
    61                   <rank>1</rank> 
    6257                  <url>http://www.last.fm/music/The+Beatles</url> 
    63                   <thumbnail>http://userserve-ak.last.fm/serve/50/298947.jpg</thumbnail> 
    64                   <image>http://userserve-ak.last.fm/serve/160/298947.jpg</image> 
     58                  <streamable>0</streamable> 
     59                  <image size="small">http://userserve-ak.last.fm/serve/34/67726.jpg</image> 
     60                  <image size="medium">http://userserve-ak.last.fm/serve/64/67726.jpg</image> 
     61                  <image size="large">http://userserve-ak.last.fm/serve/126/67726.jpg</image> 
    6562               </artist>; 
    66          fullxml = <topartists user="buckyhana" type="overall"> 
    67                       <artist> 
    68                          <name>The Beatles</name> 
    69                          <mbid>b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d</mbid> 
    70                          <playcount>1262</playcount> 
    71                          <rank>1</rank> 
    72                          <url>http://www.last.fm/music/The+Beatles</url> 
    73                          <thumbnail>http://userserve-ak.last.fm/serve/50/298947.jpg</thumbnail> 
    74                          <image>http://userserve-ak.last.fm/serve/160/298947.jpg</image> 
    75                       </artist> 
    76                       <artist> 
    77                          <name>Minus the Bear</name> 
    78                          <mbid>c1e98e4a-4628-4c89-a7a6-0e0171600b05</mbid> 
    79                          <playcount>559</playcount> 
    80                          <rank>2</rank> 
    81                          <url>http://www.last.fm/music/Minus+the+Bear</url> 
    82                          <thumbnail>http://userserve-ak.last.fm/serve/50/267884.jpg</thumbnail> 
    83                          <image>http://userserve-ak.last.fm/serve/160/267884.jpg</image> 
    84                       </artist> 
    85                       <artist> 
    86                          <name>Death Cab for Cutie</name> 
    87                          <mbid>0039c7ae-e1a7-4a7d-9b49-0cbc716821a6</mbid> 
    88                          <playcount>374</playcount> 
    89                          <rank>3</rank> 
    90                          <url>http://www.last.fm/music/Death+Cab+for+Cutie</url> 
    91                          <thumbnail>http://userserve-ak.last.fm/serve/50/202695.jpg</thumbnail> 
    92                          <image>http://userserve-ak.last.fm/serve/160/202695.jpg</image> 
    93                       </artist> 
    94                    </topartists>; 
    95          artist.name = "The Beatles"; 
    96          artist.mbid = "b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d"; 
    97          artist.url = "http://www.last.fm/music/The+Beatles"; 
    98          artist.thumbnail = "http://userserve-ak.last.fm/serve/50/298947.jpg"; 
    99          artist.image = "http://userserve-ak.last.fm/serve/160/298947.jpg"; 
    100  
    101          firstArtistXMLListCollection = new XMLListCollection(new XMLList(xml)); 
    102          fullXMLListColleciton = new XMLListCollection(new XMLList(fullxml.artist)); 
    103  
    104          topArtists.xml = new XMLList(fullxml.artist); 
    105          topArtists.buildTopArtists(); 
    10663      } 
    10764 
    10865      public function testBuildTopArtists() : void 
    10966      { 
    110          var topArtistsBuild : TopArtists = new TopArtists(); 
     67         var topArtists : TopArtists = new TopArtists(); 
     68         var topArtistsGatewayStub : TopArtistsGatewayStub = new TopArtistsGatewayStub(); 
    11169         var error : Error = new Error("Xml is null. Try calling the TopArtistsController::fetchTopArtists method first."); 
    11270 
    11371         try 
    11472         { 
    115             topArtistsBuild.buildTopArtists(); 
     73            topArtists.buildTopArtists(); 
    11674         } 
    11775         catch (e : Error) 
     
    12078         } 
    12179 
    122          topArtistsBuild.xml = fullxml.artist; 
    123          topArtistsBuild.buildTopArtists(); 
    124          assertEquals(fullXMLListColleciton.toString(), topArtistsBuild.topArtistsXMLListCollection.toString()); 
     80         topArtistsGatewayStub.fetch(); 
     81         topArtists.xml = topArtistsGatewayStub.xml; 
     82 
     83         var collection : XMLListCollection = new XMLListCollection(new XMLList(topArtistsGatewayStub.xml.topartists.artist)); 
     84 
     85         topArtists.buildTopArtists(); 
     86         assertEquals(collection.toString(), topArtists.xmlListCollection.toString()); 
    12587      } 
    12688 
    12789      public function testGetTruncatedXMLListCollection() : void 
    12890      { 
    129          assertEquals(firstArtistXMLListCollection.toString(), topArtists.getTruncatedXMLListCollection(1).toString()); 
     91         var topArtists : TopArtists = new TopArtists(); 
     92         var gatewayStub : TopArtistsGatewayStub = new TopArtistsGatewayStub(); 
     93 
     94         gatewayStub.fetch(); 
     95         topArtists.xml = gatewayStub.xml; 
     96         topArtists.buildTopArtists(); 
     97 
     98         assertEquals(new XMLListCollection(new XMLList(xml)).toString(), topArtists.getTruncatedXMLListCollection(1).toString()); 
    13099      } 
    131100 
    132101      public function testGetTruncatedArtistCollection() : void 
    133102      { 
     103         var topArtists : TopArtists = new TopArtists(); 
     104         var gatewayStub : TopArtistsGatewayStub = new TopArtistsGatewayStub(); 
     105         var artist : Artist = new Artist(); 
     106 
     107         gatewayStub.fetch(); 
     108         topArtists.xml = gatewayStub.xml; 
     109         topArtists.buildTopArtists(); 
     110          
     111         artist.name = "The Beatles"; 
     112         artist.mbid = "b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d"; 
     113         artist.url = "http://www.last.fm/music/The+Beatles"; 
     114         artist.thumbnail = "http://userserve-ak.last.fm/serve/34/67726.jpg"; 
     115         artist.image = "http://userserve-ak.last.fm/serve/126/67726.jpg"; 
     116         artist.rank = 1; 
     117 
    134118         var truncatedArtist : Artist = topArtists.getTruncatedArtistCollection(1).getItemAt(0) as Artist; 
    135119 
     
    137121         assertEquals(artist.mbid, truncatedArtist.mbid); 
    138122         assertEquals(artist.url, truncatedArtist.url); 
    139          assertEquals(artist.thumbnail, truncatedArtist.thumbnail); 
    140123         assertEquals(artist.image, truncatedArtist.image); 
     124         assertEquals(artist.rank, truncatedArtist.rank); 
    141125      } 
    142126   } 
  • AudioScrobbler/branches/Pantsuit/src/test/net/buckyschwarz/pantsuit/stubs/TopArtistsGatewayStub.as

    r56 r60  
    3636      override public function fetch() : void 
    3737      { 
    38          _xml = <topartists user="buckyhana" type="overall"> 
    39                   <artist> 
    40                      <name>The Beatles</name> 
    41                      <mbid>b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d</mbid> 
    42                      <playcount>1262</playcount> 
    43                      <rank>1</rank> 
    44                      <url>http://www.last.fm/music/The+Beatles</url> 
    45                      <thumbnail>http://userserve-ak.last.fm/serve/50/298947.jpg</thumbnail> 
    46                      <image>http://userserve-ak.last.fm/serve/160/298947.jpg</image> 
    47                   </artist> 
    48                   <artist> 
    49                      <name>Minus the Bear</name> 
    50                      <mbid>c1e98e4a-4628-4c89-a7a6-0e0171600b05</mbid> 
    51                      <playcount>559</playcount> 
    52                      <rank>2</rank> 
    53                      <url>http://www.last.fm/music/Minus+the+Bear</url> 
    54                      <thumbnail>http://userserve-ak.last.fm/serve/50/267884.jpg</thumbnail> 
    55                      <image>http://userserve-ak.last.fm/serve/160/267884.jpg</image> 
    56                   </artist> 
    57                   <artist> 
    58                      <name>Death Cab for Cutie</name> 
    59                      <mbid>0039c7ae-e1a7-4a7d-9b49-0cbc716821a6</mbid> 
    60                      <playcount>374</playcount> 
    61                      <rank>3</rank> 
    62                      <url>http://www.last.fm/music/Death+Cab+for+Cutie</url> 
    63                      <thumbnail>http://userserve-ak.last.fm/serve/50/202695.jpg</thumbnail> 
    64                      <image>http://userserve-ak.last.fm/serve/160/202695.jpg</image> 
    65                   </artist> 
    66                </topartists>; 
     38         _xml = <lfm status="ok"> 
     39                   <topartists user="buckyhana" type="overall"> 
     40                      <artist rank="1"> 
     41                         <name>The Beatles</name> 
     42                         <playcount>2019</playcount> 
     43                         <mbid>b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d</mbid> 
     44                         <url>http://www.last.fm/music/The+Beatles</url> 
     45                         <streamable>0</streamable> 
     46                         <image size="small">http://userserve-ak.last.fm/serve/34/67726.jpg</image> 
     47                         <image size="medium">http://userserve-ak.last.fm/serve/64/67726.jpg</image> 
     48                         <image size="large">http://userserve-ak.last.fm/serve/126/67726.jpg</image> 
     49                      </artist> 
     50                      <artist rank="2"> 
     51                         <name>Minus the Bear</name> 
     52                         <playcount>649</playcount> 
     53                         <mbid>c1e98e4a-4628-4c89-a7a6-0e0171600b05</mbid> 
     54                         <url>http://www.last.fm/music/Minus+the+Bear</url> 
     55                         <streamable>1</streamable> 
     56                         <image size="small">http://userserve-ak.last.fm/serve/34/170922.jpg</image> 
     57                         <image size="medium">http://userserve-ak.last.fm/serve/64/170922.jpg</image> 
     58                         <image size="large">http://userserve-ak.last.fm/serve/126/170922.jpg</image> 
     59                      </artist> 
     60                      <artist rank="3"> 
     61                         <name>Death Cab for Cutie</name> 
     62                         <playcount>488</playcount> 
     63                         <mbid>0039c7ae-e1a7-4a7d-9b49-0cbc716821a6</mbid> 
     64                         <url>http://www.last.fm/music/Death+Cab+for+Cutie</url> 
     65                         <streamable>1</streamable> 
     66                         <image size="small">http://userserve-ak.last.fm/serve/34/74052.jpg</image> 
     67                         <image size="medium">http://userserve-ak.last.fm/serve/64/74052.jpg</image> 
     68                         <image size="large">http://userserve-ak.last.fm/serve/126/74052.jpg</image> 
     69                      </artist> 
     70                   </topartists> 
     71                </lfm>; 
    6772 
    6873         dispatchEvent(new TopArtistsEvent(TopArtistsEvent.RESULT));