Permalink
Browse files

Add serialize capabilities to Response

  • Loading branch information...
1 parent 5399021 commit d09db4c5549e72b42eefbf1ea5c98f95bd1bd3d9 @hanklords committed Nov 20, 2010
Showing with 6 additions and 1 deletion.
  1. +6 −1 lib/flickraw.rb
View
@@ -47,7 +47,9 @@ module FlickRaw
class Response
def self.build(h, type) # :nodoc:
- if type =~ /s$/ and (a = h[$`]).is_a? Array
+ if h.is_a? Response
+ h
+ elsif type =~ /s$/ and (a = h[$`]).is_a? Array
ResponseList.new(h, type, a.collect {|e| Response.build(e, $`)})
elsif h.keys == ["_content"]
h["_content"]
@@ -74,6 +76,8 @@ def [](k); @h[k] end
def to_s; @h["_content"] || super end
def inspect; @h.inspect end
def to_hash; @h end
+ def marshal_dump; [@h, @flickr_type] end
+ def marshal_load(data); initialize(*data) end
end
class ResponseList < Response
@@ -84,6 +88,7 @@ def each; @a.each{|e| yield e} end
def to_a; @a end
def inspect; @a.inspect end
def size; @a.size end
+ def marshal_dump; [@h, @flickr_type, @a] end
end
class FailedResponse < StandardError

0 comments on commit d09db4c

Please sign in to comment.