Permalink
Browse files

Adding support for partitioned resource indexing.

  • Loading branch information...
1 parent 33b7236 commit 158eb7b291cbb819166782cc57e6e852a817b59a Thor Kell committed Jun 22, 2010
Showing with 25 additions and 11 deletions.
  1. +0 −5 lib/soundcloud/extended_array.rb
  2. +11 −1 lib/soundcloud/partitioned_resource.rb
  3. +14 −5 lib/soundcloud/sc_xml_format.rb
@@ -1,5 +0,0 @@
-class PartitionedResource < Array
-
- attr_accessor :next_partition
-
-end
@@ -2,4 +2,14 @@ class PartitionedResource < Array
attr_accessor :next_partition
-end
+ def get_next_partition(soundcloud_method)
+ if next_partition != nil
+ path = next_partition[/\/[a-z]+\?.*/]
+
+ soundcloud_method.find(:all,:from => path)
+ else
+
+ nil
+ end
+ end
+end
@@ -17,15 +17,24 @@ def encode(hash, options={})
def decode(xml)
# Extract the link to the next collection, if present.
- r1 = %r[next-partition-href=\".+\"]
+ r1 = %r[ next-partition-href=\".+\"]
r2 = %r[http://.+"]
if xml[r1] !=nil
- resource_data = PartitionedResource.new(from_xml_data(Hash.from_xml(xml)))
- resource_data.next_partition = xml[r1][r2].chop
- resource_data
+ next_partition_url = xml[r1][r2].chop
+ xml[r1] = ''
else
- from_xml_data(Hash.from_xml(xml))
+ next_partition_url = nil
end
+
+ response = from_xml_data(Hash.from_xml(xml))
+ if response.class == Array
+ resource_data = PartitionedResource.new(response)
+ resource_data.next_partition = next_partition_url
+ else
+ resource_data = response
+ end
+
+ resource_data
end
private

0 comments on commit 158eb7b

Please sign in to comment.