lib/smile/photo.rb in smile-0.2.0 vs lib/smile/photo.rb in smile-0.2.1

- old
+ new

@@ -7,14 +7,15 @@ # class Smile::Photo < Smile::Base class << self # Convert the given xml into photo objects to play with - def from_xml( xml, session_id ) - hash = Hash.from_xml( xml )["rsp"] + def from_json( json, session_id ) + result = JSON.parse( json ) - hash["images"]["image"].map do |image| + result["Images"].map do |image_upper| + image = upper_hash_to_lower_hash( image_upper ) image.merge!( :image_id => image["id"] ) image.merge!( :album_key => image["album"]["key"] ) image.merge!( :album_id => image["album"]["id"] ) image.delete( 'album' ) @@ -38,12 +39,13 @@ params = default_params.merge( :method => 'smugmug.images.getInfo' ) params.merge!( options ) if( options ) - xml = RestClient.post Smile::Base::BASE, params - image = Hash.from_xml( xml )["rsp"]["image"] + json = RestClient.post Smile::Base::BASE, params + image_upper = JSON.parse( json ) + image = upper_hash_to_lower_hash( image_upper['Image'] ) image.merge!( :image_id => image["id"] ) image.merge!( :album_key => image["album"]["key"] ) image.merge!( :album_id => image["album"]["id"] ) image.delete( 'album' ) @@ -102,16 +104,16 @@ :ImageID => self.image_id, :ImageKey => self.key ) params.merge!( options ) if( options ) - xml = RestClient.post Smile::Base::BASE, params + json = RestClient.post Smile::Base::BASE, params - rsp = Hash.from_xml( xml )["rsp"] - raise rsp["message"] if rsp["stat"] == 'fail' + json = JSON.parse( json ) + raise json["message"] if json["stat"] == 'fail' - image = Hash.from_xml( xml )["rsp"]["image"] + image = upper_hash_to_lower_hash( json['Image'] ) image.merge!( :image_id => image["id"] ) OpenStruct.new( image ) end @@ -161,16 +163,16 @@ :ImageID => self.image_id, :ImageKey => self.key ) params.merge!( options ) if( options ) - xml = RestClient.post Smile::Base::BASE, params + json = RestClient.post Smile::Base::BASE, params - rsp = Hash.from_xml( xml )["rsp"] - raise rsp["message"] if rsp["stat"] == 'fail' + json = JSON.parse( json ) + raise json["message"] if json["stat"] == 'fail' - image = Hash.from_xml( xml )["rsp"]["image"] + image = upper_hash_to_lower_hash( json['Image'] ) image.merge!( :image_id => image["id"] ) OpenStruct.new( image ) end @@ -212,15 +214,15 @@ :ImageID => self.image_id, :ImageKey => self.key ) params.merge!( options ) if( options ) - xml = RestClient.post Smile::Base::BASE, params + json = RestClient.post Smile::Base::BASE, params - rsp = Hash.from_xml( xml )["rsp"] - raise rsp["message"] if rsp["stat"] == 'fail' - - image = Hash.from_xml( xml )["rsp"]["image"] + json = JSON.parse( json ) + raise json["message"] if json["stat"] == 'fail' + + image = upper_hash_to_lower_hash( json['Image'] ) image.merge!( :image_id => image["id"] ) OpenStruct.new( image ) end \ No newline at end of file