lib/smile/photo.rb in smile-0.3.1 vs lib/smile/photo.rb in smile-0.4.0
- old
+ new
@@ -5,23 +5,19 @@
# Created by Zac Kleinpeter on 2009-04-28.
class Smile::Photo < Smile::Base
class << self
# Convert the given xml into photo objects to play with
- def from_json( json, session_id )
- result = JSON.parse( json )
-
- result["Images"].map do |image_upper|
+ def from_json( json )
+ json["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' )
-
- p = Smile::Photo.new( image )
- p.session_id = session_id
- p
+
+ Smile::Photo.new( image )
end
end
# This will pull a single image from the smugmug
#
@@ -29,30 +25,21 @@
# @option options [int] :image_id The id of the image you want to find
# @option options [optional, String] :password The id of the image you want to find
# @option options [optional, String] :site_password password word for the site
# @option options [optional, String] :image_key image key maybe?
def find( options={} )
- set_session if( session_id.nil? )
- options = Smile::ParamConverter.clean_hash_keys( options )
-
- params = default_params.merge(
- :method => 'smugmug.images.getInfo'
+ image = web_method_call(
+ { :method => 'smugmug.images.getInfo' },
+ options
)
- params.merge!( options ) if( options )
- json = RestClient.post( Smile::Base::BASE, params ).body
- 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' )
- p = Smile::Photo.new( image )
- p.session_id = session_id
- p
+ Smile::Photo.new( image )
end
end
# This method will return camera and photograph details about the image specified by ImageID.
# The Album must be owned by the Session holder, or else be Public (if password-protected, a
@@ -95,23 +82,15 @@
#
# @param [options,Hash] options ruby and hashes are like.......
# @option options [String] :password a password field
# @option options [String] :site_password site password field
def details( options =nil )
- params = default_params.merge(
- :method => "smugmug.images.getEXIF",
- :ImageID => self.image_id,
- :ImageKey => self.key
+ image = web_method_call(
+ { :method => "smugmug.images.getEXIF", :ImageID => self.image_id, :ImageKey => self.key },
+ options
)
- params.merge!( options ) if( options )
- json = RestClient.post( Smile::Base::BASE, params ).body
-
- 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
@@ -154,23 +133,15 @@
# String "OriginalURL" (if available)
# struct "Album"
# integer "id"
# String "Key"
def info( options =nil )
- params = default_params.merge(
- :method => "smugmug.images.getInfo",
- :ImageID => self.image_id,
- :ImageKey => self.key
+ image = web_method_call(
+ { :method => "smugmug.images.getInfo", :ImageID => self.image_id, :ImageKey => self.key },
+ options
)
-
- params.merge!( options ) if( options )
- json = RestClient.post( Smile::Base::BASE, params ).body
-
- 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
@@ -205,27 +176,19 @@
# String "XLargeURL" (if available)
# String "X2LargeURL" (if available)
# String "X3LargeURL" (if available)
# String "OriginalURL" (if available)
def urls( options =nil )
- params = default_params.merge(
- :method => "smugmug.images.getURLs",
- :ImageID => self.image_id,
- :ImageKey => self.key
+ image = web_method_call(
+ { :method => "smugmug.images.getURLs", :ImageID => self.image_id, :ImageKey => self.key },
+ options
)
-
- params.merge!( options ) if( options )
- json = RestClient.post( Smile::Base::BASE, params ).body
-
- 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
def album
- Smile::Album.find( :AlbumID => album_id, :AlbumKey => album_key )
+ Smile::Album.find( :AlbumID => self.album_id, :AlbumKey => self.album_key )
end
end