class ByeFlickr::ResponseToJson

Public Class Methods

call(r) click to toggle source
# File lib/bye_flickr/response_to_json.rb, line 8
def self.call(r)
  new(r).serialize.to_json
end
new(r) click to toggle source
# File lib/bye_flickr/response_to_json.rb, line 4
def initialize(r)
  @r = r
end

Public Instance Methods

serialize(o = @r) click to toggle source
# File lib/bye_flickr/response_to_json.rb, line 12
def serialize(o = @r)
  case o
  when FlickRaw::Response
    serialize_response o
  when FlickRaw::ResponseList, Enumerable
    serialize_response_list o
  else
    o
  end
end

Private Instance Methods

serialize_response(r) click to toggle source
# File lib/bye_flickr/response_to_json.rb, line 30
def serialize_response(r)
  Hash.new.tap do |hsh|
    r.to_hash.each do |key, value|
      hsh[key] = serialize value
    end
  end
end
serialize_response_list(list) click to toggle source
# File lib/bye_flickr/response_to_json.rb, line 26
def serialize_response_list(list)
  list.to_a.map{|o|serialize(o)}
end