smile 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +33 -1
- data/Rakefile +1 -1
- data/VERSION.yml +2 -2
- data/lib/smile.rb +106 -4
- data/lib/smile/album.rb +72 -18
- data/lib/smile/base.rb +30 -5
- data/lib/smile/photo.rb +216 -3
- data/lib/smile/smug.rb +95 -7
- data/smile.gemspec +55 -0
- data/test/smile_test.rb +58 -2
- data/test/test_helper.rb +1 -1
- metadata +8 -7
- data/README +0 -0
data/README.rdoc
CHANGED
@@ -1,6 +1,38 @@
|
|
1
1
|
= smile
|
2
2
|
|
3
|
-
|
3
|
+
Smile is a simple gem to talk to SmugMug.com.
|
4
|
+
|
5
|
+
New auth accessors
|
6
|
+
smug = Smile.auth_anonymously
|
7
|
+
_and_
|
8
|
+
smug = Smile.auth( 'nick', 'pass' )
|
9
|
+
|
10
|
+
|
11
|
+
smug = Smile::Smug.new
|
12
|
+
smug.auth_anonymously
|
13
|
+
albums = smug.albums( :NickName => 'kleinpeter' )
|
14
|
+
|
15
|
+
album = albums.first # just test the first one
|
16
|
+
|
17
|
+
album.photos # and see the pretty pics
|
18
|
+
|
19
|
+
== or
|
20
|
+
|
21
|
+
smug = Smile::Smug.new
|
22
|
+
smug.auth( 'my_nick', 'my_pass' )
|
23
|
+
albums = smug.albums # theses are mine
|
24
|
+
|
25
|
+
album = albums.first # just test the first one
|
26
|
+
|
27
|
+
album.photos # and see the pretty pics
|
28
|
+
|
29
|
+
|
30
|
+
== TODO
|
31
|
+
* Clean up params so they are not case sensitive
|
32
|
+
* Add in RSS/Atom feeds as search options
|
33
|
+
* Update Documentation
|
34
|
+
* Plugin in Cucumber
|
35
|
+
|
4
36
|
|
5
37
|
== Copyright
|
6
38
|
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "smile"
|
8
|
-
gem.summary = %Q{
|
8
|
+
gem.summary = %Q{Simple API for talking to SmugMug}
|
9
9
|
gem.email = "zac@kleinpeter.org"
|
10
10
|
gem.homepage = "http://github.com/cajun/smile"
|
11
11
|
gem.authors = ["cajun"]
|
data/VERSION.yml
CHANGED
data/lib/smile.rb
CHANGED
@@ -1,7 +1,109 @@
|
|
1
1
|
require 'activesupport'
|
2
2
|
require 'restclient'
|
3
3
|
require 'ostruct'
|
4
|
-
require 'smile/base'
|
5
|
-
require 'smile/smug'
|
6
|
-
require 'smile/album'
|
7
|
-
require 'smile/photo'
|
4
|
+
require 'lib/smile/base'
|
5
|
+
require 'lib/smile/smug'
|
6
|
+
require 'lib/smile/album'
|
7
|
+
require 'lib/smile/photo'
|
8
|
+
require 'cgi'
|
9
|
+
require 'rss'
|
10
|
+
|
11
|
+
module Smile
|
12
|
+
def auth_anonymously
|
13
|
+
smug = Smile::Smug.new
|
14
|
+
smug.auth_anonymously
|
15
|
+
smug
|
16
|
+
end
|
17
|
+
module_function( :auth_anonymously )
|
18
|
+
|
19
|
+
def auth( user, pass )
|
20
|
+
smug = Smile::Smug.new
|
21
|
+
smug.auth( user, pass )
|
22
|
+
smug
|
23
|
+
end
|
24
|
+
module_function( :auth )
|
25
|
+
|
26
|
+
def base_feed( options={} )
|
27
|
+
options.merge!( :format => 'rss' )
|
28
|
+
url = "http://api.smugmug.com/hack/feed.mg?"
|
29
|
+
url_params =[]
|
30
|
+
options.each_pair do |k,value|
|
31
|
+
case k.to_s.downcase.to_sym
|
32
|
+
when :popular_category
|
33
|
+
key = :popularCategory
|
34
|
+
when :geo_all
|
35
|
+
key = :geoAll
|
36
|
+
when :geo_keyword
|
37
|
+
key = :geoKeyword
|
38
|
+
when :geo_search
|
39
|
+
key = :geoSearch
|
40
|
+
when :geo_community
|
41
|
+
key = :geoCommunity
|
42
|
+
when :open_search_keyword
|
43
|
+
key = :openSearchKeyword
|
44
|
+
when :user_keyword
|
45
|
+
key = :userkeyword
|
46
|
+
when :nickname_recent
|
47
|
+
key = :nicknameRecent
|
48
|
+
when :nickname_popular
|
49
|
+
key = :nicknamePopular
|
50
|
+
when :user_comments
|
51
|
+
key = :userComments
|
52
|
+
when :geo_user
|
53
|
+
key = :geoUser
|
54
|
+
when :geo_album
|
55
|
+
key = :geoAlbum
|
56
|
+
when :size
|
57
|
+
key = :Size
|
58
|
+
value = value.titlecase
|
59
|
+
when :image_count
|
60
|
+
key = :ImageCount
|
61
|
+
else
|
62
|
+
key = k
|
63
|
+
end
|
64
|
+
|
65
|
+
url_params << "#{key.to_s}=#{ CGI.escape( value ) }"
|
66
|
+
end
|
67
|
+
|
68
|
+
content = RestClient.get( url + url_params.join( "&" ) )
|
69
|
+
RSS::Parser.parse( content, false )
|
70
|
+
end
|
71
|
+
module_function( :base_feed )
|
72
|
+
|
73
|
+
# Search SmugMug for pics.
|
74
|
+
# By Default it will use the keyword search.
|
75
|
+
#
|
76
|
+
# options
|
77
|
+
# type => [
|
78
|
+
# keyword
|
79
|
+
# popular # Use term all or today
|
80
|
+
# popularCategory # Use term category ( e.g. cars )
|
81
|
+
# geoAll
|
82
|
+
# geoKeyword
|
83
|
+
# geoSearch
|
84
|
+
# geoCommunity
|
85
|
+
# openSearchKeyword
|
86
|
+
# userkeyword # Use term nickname
|
87
|
+
# gallery # Use term albumID_albumKey
|
88
|
+
# nickname # Use term nickname
|
89
|
+
# nicknameRecent # Use term nickname
|
90
|
+
# nicknamePopular # Use term nickname
|
91
|
+
# usercomments # Use term nickname
|
92
|
+
# geoUser # Use term nickname
|
93
|
+
# geoAlbum # Use term albumID_albumKey
|
94
|
+
# ]
|
95
|
+
def search( data, options={} )
|
96
|
+
rss = search_raw( data, options )
|
97
|
+
rss.items.map{ |item| item.guid.content }
|
98
|
+
|
99
|
+
end
|
100
|
+
module_function( :search )
|
101
|
+
|
102
|
+
# Get the RAW feed
|
103
|
+
def search_raw( data, options={} )
|
104
|
+
options.merge!( :type => 'keyword', :data => data )
|
105
|
+
base_feed( options )
|
106
|
+
end
|
107
|
+
module_function( :search_raw )
|
108
|
+
end
|
109
|
+
|
data/lib/smile/album.rb
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
#
|
2
|
+
# album.rb
|
3
|
+
# smile
|
4
|
+
#
|
5
|
+
# Created by Zac Kleinpeter on 2009-04-28.
|
6
|
+
# Copyright 2009 Cajun Country. All rights reserved.
|
7
|
+
#
|
1
8
|
class Smile::Album < Smile::Base
|
2
9
|
|
3
10
|
class << self
|
@@ -5,31 +12,78 @@ class Smile::Album < Smile::Base
|
|
5
12
|
hash = Hash.from_xml( xml )["rsp"]
|
6
13
|
hash["albums"]["album"].map do |album|
|
7
14
|
album.merge!( :album_id => album["id"] )
|
15
|
+
|
8
16
|
a = Smile::Album.new( album )
|
9
17
|
a.session_id = session_id
|
10
18
|
a
|
11
19
|
end
|
12
20
|
end
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
=
|
23
|
-
def photos( options=nil )
|
21
|
+
|
22
|
+
# This will pull a single album from the smugmug
|
23
|
+
#
|
24
|
+
# * SessionID - string. ( by default if logged in)
|
25
|
+
# * AlbumID - string.
|
26
|
+
# * Password - string (optional).
|
27
|
+
# * SitePassword - string (optional).
|
28
|
+
# * AlbumKey - string.
|
29
|
+
#
|
30
|
+
def find( options={} )
|
24
31
|
params = default_params.merge(
|
25
|
-
:method => 'smugmug.
|
26
|
-
:AlbumID => album_id,
|
27
|
-
:AlbumKey => key,
|
28
|
-
:Heavy => 1
|
32
|
+
:method => 'smugmug.albums.getInfo'
|
29
33
|
)
|
30
|
-
|
34
|
+
|
31
35
|
params.merge!( options ) if( options )
|
32
|
-
|
33
|
-
Smile::
|
36
|
+
|
37
|
+
xml = RestClient.post Smile::Base::BASE, params
|
38
|
+
|
39
|
+
album = Hash.from_xml( xml )["rsp"]["album"]
|
40
|
+
album.merge!( :album_id => album["id"] )
|
41
|
+
|
42
|
+
a = Smile::Album.new( album )
|
43
|
+
a.session_id = session_id
|
44
|
+
a
|
34
45
|
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# This will pull all the photos for a given album
|
49
|
+
# * SessionID - string. ( by default if logged in)
|
50
|
+
# * AlbumID - integer.
|
51
|
+
# * Heavy - boolean (optional).
|
52
|
+
# * Password - string (optional).
|
53
|
+
# * SitePassword - string (optional).
|
54
|
+
# * AlbumKey - string.
|
55
|
+
def photos( options=nil )
|
56
|
+
params = default_params.merge(
|
57
|
+
:method => 'smugmug.images.get',
|
58
|
+
:AlbumID => album_id,
|
59
|
+
:AlbumKey => key,
|
60
|
+
:Heavy => 1
|
61
|
+
)
|
62
|
+
|
63
|
+
params.merge!( options ) if( options )
|
64
|
+
|
65
|
+
xml = RestClient.post BASE, params
|
66
|
+
Smile::Photo.from_xml( xml, session_id )
|
67
|
+
end
|
68
|
+
|
69
|
+
# * integer AlbumID
|
70
|
+
# * integer Month
|
71
|
+
# * integer Year
|
72
|
+
# * boolean Heavy (optional)
|
73
|
+
def stats( options =nil )
|
74
|
+
params = default_params.merge(
|
75
|
+
:method => 'smugmug.albums.getStats',
|
76
|
+
:AlbumID => album_id,
|
77
|
+
:month => Date.today.month,
|
78
|
+
:year => Date.today.year
|
79
|
+
)
|
80
|
+
|
81
|
+
params.merge!( options ) if( options )
|
82
|
+
|
83
|
+
xml = RestClient.post BASE, params
|
84
|
+
rsp = Hash.from_xml( xml )["rsp"]
|
85
|
+
raise "invalid user" if rsp["stat"] == 'fail'
|
86
|
+
hash = Hash.from_xml( xml )["rsp"]
|
87
|
+
OpenStruct.new( hash )
|
88
|
+
end
|
35
89
|
end
|
data/lib/smile/base.rb
CHANGED
@@ -1,16 +1,41 @@
|
|
1
|
+
#
|
2
|
+
# base.rb
|
3
|
+
# smile
|
4
|
+
#
|
5
|
+
# Created by Zac Kleinpeter on 2009-04-28.
|
6
|
+
# Copyright 2009 Cajun Country. All rights reserved.
|
7
|
+
#
|
1
8
|
module Smile
|
2
9
|
class Base < OpenStruct
|
3
10
|
BASE = 'http://api.smugmug.com/hack/rest/1.2.0/'
|
4
11
|
BASE_SECURE = 'https://api.smugmug.com/hack/rest/1.2.0/'
|
5
12
|
API = 'HSoqGCJ8ilF42BeThMGDZqqqOgj1eXqN'
|
6
13
|
|
14
|
+
class << self
|
15
|
+
attr_accessor :session_id
|
16
|
+
# This will be included in every request once you have logged in
|
17
|
+
def default_params
|
18
|
+
base = { :APIKey => API }
|
19
|
+
#set_session
|
20
|
+
if( session_id )
|
21
|
+
base.merge!( :SessionID => session_id )
|
22
|
+
end
|
23
|
+
base
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_session
|
27
|
+
if( session_id.nil? )
|
28
|
+
smug = Smug.new
|
29
|
+
smug.auth_anonymously
|
30
|
+
self.session_id = smug.session_id
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
7
35
|
attr_accessor :session_id
|
8
36
|
def default_params
|
9
|
-
|
10
|
-
|
11
|
-
base.merge!( :SessionID => session_id )
|
12
|
-
end
|
13
|
-
base
|
37
|
+
self.class.session_id = self.session_id
|
38
|
+
self.class.default_params
|
14
39
|
end
|
15
40
|
end
|
16
41
|
end
|
data/lib/smile/photo.rb
CHANGED
@@ -1,14 +1,227 @@
|
|
1
|
+
#
|
2
|
+
# photo.rb
|
3
|
+
# smile
|
4
|
+
#
|
5
|
+
# Created by Zac Kleinpeter on 2009-04-28.
|
6
|
+
# Copyright 2009 Cajun Country. All rights reserved.
|
7
|
+
#
|
1
8
|
class Smile::Photo < Smile::Base
|
2
9
|
|
3
10
|
class << self
|
11
|
+
# Convert the given xml into photo objects to play with
|
4
12
|
def from_xml( xml, session_id )
|
5
13
|
hash = Hash.from_xml( xml )["rsp"]
|
14
|
+
|
6
15
|
hash["images"]["image"].map do |image|
|
7
16
|
image.merge!( :image_id => image["id"] )
|
8
|
-
|
9
|
-
|
10
|
-
|
17
|
+
image.merge!( :album_key => image["album"]["key"] )
|
18
|
+
image.merge!( :album_id => image["album"]["id"] )
|
19
|
+
image.delete( 'album' )
|
20
|
+
|
21
|
+
p = Smile::Photo.new( image )
|
22
|
+
p.session_id = session_id
|
23
|
+
p
|
11
24
|
end
|
12
25
|
end
|
26
|
+
|
27
|
+
# This will pull a single image from the smugmug
|
28
|
+
#
|
29
|
+
# * int ImageID
|
30
|
+
# * String Password optional
|
31
|
+
# * String SitePassword optional
|
32
|
+
# * String ImageKey
|
33
|
+
#
|
34
|
+
def find( options={} )
|
35
|
+
params = default_params.merge(
|
36
|
+
:method => 'smugmug.images.getInfo'
|
37
|
+
)
|
38
|
+
|
39
|
+
params.merge!( options ) if( options )
|
40
|
+
xml = RestClient.post Smile::Base::BASE, params
|
41
|
+
image = Hash.from_xml( xml )["rsp"]["image"]
|
42
|
+
image.merge!( :image_id => image["id"] )
|
43
|
+
image.merge!( :album_key => image["album"]["key"] )
|
44
|
+
image.merge!( :album_id => image["album"]["id"] )
|
45
|
+
image.delete( 'album' )
|
46
|
+
|
47
|
+
p = Smile::Photo.new( image )
|
48
|
+
p.session_id = session_id
|
49
|
+
p
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# This method will return camera and photograph details about the image specified by ImageID.
|
54
|
+
# The Album must be owned by the Session holder, or else be Public (if password-protected, a
|
55
|
+
# Password must be provided), to return results. Otherwise, an "invalid user" faultCode will
|
56
|
+
# result. Additionally, the album owner must have specified that EXIF data is allowed. Note that
|
57
|
+
# many photos have no EXIF data, so an empty or partially returned result is very normal.#
|
58
|
+
#
|
59
|
+
# Arguments:*
|
60
|
+
#
|
61
|
+
# String Password optional
|
62
|
+
# String SitePassword optional
|
63
|
+
#
|
64
|
+
# Result:* struct "Image" [some, none, or all may be returned]
|
65
|
+
#
|
66
|
+
# int "id"
|
67
|
+
# String "DateTime"
|
68
|
+
# String "DateTimeOriginal"
|
69
|
+
# String "DateTimeDigitized"
|
70
|
+
# String "Make"
|
71
|
+
# String "Model"
|
72
|
+
# String "ExposureTime"
|
73
|
+
# String "Aperture"
|
74
|
+
# int "ISO"
|
75
|
+
# String "FocalLength"
|
76
|
+
# int "FocalLengthIn35mmFilm"
|
77
|
+
# String "CCDWidth"
|
78
|
+
# String "CompressedBitsPerPixel"
|
79
|
+
# int "Flash"
|
80
|
+
# int "Metering"
|
81
|
+
# int "ExposureProgram"
|
82
|
+
# String "ExposureBiasValue"
|
83
|
+
# int "ExposureMode"
|
84
|
+
# int "LightSource"
|
85
|
+
# int "WhiteBalance"
|
86
|
+
# String "DigitalZoomRatio"
|
87
|
+
# int "Contrast"
|
88
|
+
# int "Saturation"
|
89
|
+
# int "Sharpness"
|
90
|
+
# String "SubjectDistance"
|
91
|
+
# int "SubjectDistanceRange"
|
92
|
+
# int "SensingMethod"
|
93
|
+
# String "ColorSpace"
|
94
|
+
# String "Brightness"
|
95
|
+
def details( options =nil )
|
96
|
+
params = default_params.merge(
|
97
|
+
:method => "smugmug.images.getEXIF",
|
98
|
+
:ImageID => self.image_id,
|
99
|
+
:ImageKey => self.key
|
100
|
+
)
|
101
|
+
|
102
|
+
params.merge!( options ) if( options )
|
103
|
+
xml = RestClient.post Smile::Base::BASE, params
|
104
|
+
|
105
|
+
rsp = Hash.from_xml( xml )["rsp"]
|
106
|
+
raise rsp["message"] if rsp["stat"] == 'fail'
|
107
|
+
|
108
|
+
image = Hash.from_xml( xml )["rsp"]["image"]
|
109
|
+
image.merge!( :image_id => image["id"] )
|
110
|
+
|
111
|
+
OpenStruct.new( image )
|
112
|
+
end
|
113
|
+
|
114
|
+
# This method will return details about the image specified by ImageID. The Album must be owned
|
115
|
+
# by the Session holder, or else be Public (if password-protected, a Password must be provided),
|
116
|
+
# to return results.. Otherwise, an "invalid user" faultCode will result. Additionally, some
|
117
|
+
# fields are only returned to the Album owner.
|
118
|
+
#
|
119
|
+
# Arguments:
|
120
|
+
#
|
121
|
+
# String Password optional
|
122
|
+
# String SitePassword optional
|
123
|
+
#
|
124
|
+
# Result:* struct "Image"
|
125
|
+
#
|
126
|
+
# int "id"
|
127
|
+
# String "Caption"
|
128
|
+
# int "Position"
|
129
|
+
# int "Serial"
|
130
|
+
# int "Size"
|
131
|
+
# int "Width"
|
132
|
+
# int "Height"
|
133
|
+
# String "LastUpdated"
|
134
|
+
# String "FileName" owner only
|
135
|
+
# String "MD5Sum" owner only
|
136
|
+
# String "Watermark" owner only
|
137
|
+
# Boolean "Hidden" owner only
|
138
|
+
# String "Format" owner only
|
139
|
+
# String "Keywords"
|
140
|
+
# String "Date" owner only
|
141
|
+
# String "AlbumURL"
|
142
|
+
# String "TinyURL"
|
143
|
+
# String "ThumbURL"
|
144
|
+
# String "SmallURL"
|
145
|
+
# String "MediumURL"
|
146
|
+
# String "LargeURL" (if available)
|
147
|
+
# String "XLargeURL" (if available)
|
148
|
+
# String "X2LargeURL" (if available)
|
149
|
+
# String "X3LargeURL" (if available)
|
150
|
+
# String "OriginalURL" (if available)
|
151
|
+
# struct "Album"
|
152
|
+
# integer "id"
|
153
|
+
# String "Key"
|
154
|
+
def info( options =nil )
|
155
|
+
params = default_params.merge(
|
156
|
+
:method => "smugmug.images.getInfo",
|
157
|
+
:ImageID => self.image_id,
|
158
|
+
:ImageKey => self.key
|
159
|
+
)
|
160
|
+
|
161
|
+
params.merge!( options ) if( options )
|
162
|
+
xml = RestClient.post Smile::Base::BASE, params
|
163
|
+
|
164
|
+
rsp = Hash.from_xml( xml )["rsp"]
|
165
|
+
raise rsp["message"] if rsp["stat"] == 'fail'
|
166
|
+
|
167
|
+
image = Hash.from_xml( xml )["rsp"]["image"]
|
168
|
+
image.merge!( :image_id => image["id"] )
|
169
|
+
|
170
|
+
OpenStruct.new( image )
|
171
|
+
end
|
172
|
+
|
173
|
+
# This method will return all the URLs for the various sizes of the image specified by
|
174
|
+
# ImageID. The Album must be owned by the Session holder, or else be Public (if
|
175
|
+
# password-protected, a Password must be provided), to return results. Otherwise, an "invalid
|
176
|
+
# user" faultCode will result. Additionally, obvious restrictions on Originals and Larges
|
177
|
+
# apply if so set by the owner. They will return as empty strings for those URLs if they're
|
178
|
+
# unavailable.
|
179
|
+
#
|
180
|
+
# Arguments:*
|
181
|
+
#
|
182
|
+
# int TemplateID
|
183
|
+
# optional, specifies which Style to build the AlbumURL with. Default: 3
|
184
|
+
# Possible values:
|
185
|
+
# Elegant: 3
|
186
|
+
# Traditional: 4
|
187
|
+
# All Thumbs: 7
|
188
|
+
# Slideshow: 8
|
189
|
+
# Journal: 9
|
190
|
+
# String Password optional
|
191
|
+
# String SitePassword optional
|
192
|
+
#
|
193
|
+
# Result:* struct
|
194
|
+
#
|
195
|
+
# String "AlbumURL"
|
196
|
+
# String "TinyURL"
|
197
|
+
# String "ThumbURL"
|
198
|
+
# String "SmallURL"
|
199
|
+
# String "MediumURL"
|
200
|
+
# String "LargeURL" (if available)
|
201
|
+
# String "XLargeURL" (if available)
|
202
|
+
# String "X2LargeURL" (if available)
|
203
|
+
# String "X3LargeURL" (if available)
|
204
|
+
# String "OriginalURL" (if available)
|
205
|
+
def urls( options =nil )
|
206
|
+
params = default_params.merge(
|
207
|
+
:method => "smugmug.images.getURLs",
|
208
|
+
:ImageID => self.image_id,
|
209
|
+
:ImageKey => self.key
|
210
|
+
)
|
211
|
+
|
212
|
+
params.merge!( options ) if( options )
|
213
|
+
xml = RestClient.post Smile::Base::BASE, params
|
214
|
+
|
215
|
+
rsp = Hash.from_xml( xml )["rsp"]
|
216
|
+
raise rsp["message"] if rsp["stat"] == 'fail'
|
217
|
+
|
218
|
+
image = Hash.from_xml( xml )["rsp"]["image"]
|
219
|
+
image.merge!( :image_id => image["id"] )
|
220
|
+
|
221
|
+
OpenStruct.new( image )
|
222
|
+
end
|
223
|
+
|
224
|
+
def album
|
225
|
+
Smile::Album.find( :AlbumID => album_id, :AlbumKey => album_key )
|
13
226
|
end
|
14
227
|
end
|
data/lib/smile/smug.rb
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
#
|
2
|
+
# smug.rb
|
3
|
+
# smile
|
4
|
+
#
|
5
|
+
# Created by Zac Kleinpeter on 2009-04-28.
|
6
|
+
# Copyright 2009 Cajun Country. All rights reserved.
|
7
|
+
#
|
1
8
|
module Smile
|
2
9
|
class Smug < Smile::Base
|
3
10
|
|
@@ -16,6 +23,7 @@ module Smile
|
|
16
23
|
nil
|
17
24
|
end
|
18
25
|
|
26
|
+
|
19
27
|
def auth_anonymously
|
20
28
|
params = default_params.merge(
|
21
29
|
:method => 'smugmug.login.anonymously'
|
@@ -37,21 +45,101 @@ module Smile
|
|
37
45
|
RestClient.post( BASE, params )
|
38
46
|
end
|
39
47
|
|
40
|
-
|
41
|
-
* SessionID - string.
|
42
|
-
* NickName - string (optional).
|
43
|
-
* Heavy - boolean (optional).
|
44
|
-
* SitePassword - string (optional).
|
48
|
+
|
45
49
|
|
46
|
-
|
50
|
+
# Retrieves a list of albums for a given user. If you are logged in it will return
|
51
|
+
# your albums.
|
52
|
+
#
|
53
|
+
# Arguments
|
54
|
+
# NickName - string (optional).
|
55
|
+
# Heavy - boolean (optional).
|
56
|
+
# SitePassword - string (optional).
|
57
|
+
#
|
58
|
+
# Result
|
59
|
+
# STANDARD RESPONSE
|
60
|
+
#
|
61
|
+
# array Albums
|
62
|
+
# Album
|
63
|
+
# integer id
|
64
|
+
# string Key
|
65
|
+
# string Title
|
66
|
+
# struct Category
|
67
|
+
# string id
|
68
|
+
# string Name
|
69
|
+
# struct SubCategory
|
70
|
+
# string id
|
71
|
+
# string Name
|
72
|
+
#
|
73
|
+
# HEAVY RESPONSE
|
74
|
+
#
|
75
|
+
# array Albums
|
76
|
+
# Album
|
77
|
+
# integer id
|
78
|
+
# string Key
|
79
|
+
# string Title
|
80
|
+
# struct Category
|
81
|
+
# string id
|
82
|
+
# string Name
|
83
|
+
# struct SubCategory
|
84
|
+
# string id
|
85
|
+
# string Name
|
86
|
+
# string Description
|
87
|
+
# string Keywords
|
88
|
+
# boolean Geography (owner)
|
89
|
+
# integer Position
|
90
|
+
# struct Hightlight (owner)
|
91
|
+
# string id
|
92
|
+
# integer ImageCount
|
93
|
+
# string LastUpdated
|
94
|
+
# boolean Header (owner, power & pro only)
|
95
|
+
# boolean Clean (owner)
|
96
|
+
# boolean EXIF (owner)
|
97
|
+
# boolean Filenames (owner)
|
98
|
+
# struct Template (owner)
|
99
|
+
# string id
|
100
|
+
# string SortMethod (owner)
|
101
|
+
# boolean SortDirection (owner)
|
102
|
+
# string Password (owner)
|
103
|
+
# string PasswordHint (owner)
|
104
|
+
# boolean Public (owner)
|
105
|
+
# boolean WorldSearchable (owner)
|
106
|
+
# boolean SmugSearchable (owner)
|
107
|
+
# boolean External (owner)
|
108
|
+
# boolean Protected (owner, power & pro only)
|
109
|
+
# boolean Watermarking (owner, pro only)
|
110
|
+
# struct Watermark (owner, pro only)
|
111
|
+
# string id
|
112
|
+
# boolean HideOwner (owner)
|
113
|
+
# boolean Larges (owner, pro only)
|
114
|
+
# boolean XLarges (owner, pro only)
|
115
|
+
# boolean X2Larges (owner)
|
116
|
+
# boolean X3Larges (owner)
|
117
|
+
# boolean Originals (owner)
|
118
|
+
# boolean CanRank (owner)
|
119
|
+
# boolean FriendEdit (owner)
|
120
|
+
# boolean FamilyEdit (owner)
|
121
|
+
# boolean Comments (owner)
|
122
|
+
# boolean Share (owner)
|
123
|
+
# boolean Printable (owner)
|
124
|
+
# int ColorCorrection (owner)
|
125
|
+
# boolean DefaultColor (owner, pro only) deprecated
|
126
|
+
# integer ProofDays (owner, pro only)
|
127
|
+
# string Backprinting (owner, pro only)
|
128
|
+
# float UnsharpAmount (owner, power & pro only)
|
129
|
+
# float UnsharpRadius (owner, power & pro only)
|
130
|
+
# float UnsharpThreshold (owner, power & pro only)
|
131
|
+
# float UnsharpSigma (owner, power & pro only)
|
132
|
+
# struct Community (owner)
|
133
|
+
# string id
|
47
134
|
def albums( options=nil )
|
48
135
|
params = default_params.merge(
|
49
136
|
:method => 'smugmug.albums.get',
|
50
137
|
:heavy => 1
|
51
|
-
)
|
138
|
+
)
|
52
139
|
|
53
140
|
params = params.merge( options ) if( options )
|
54
141
|
xml = RestClient.post BASE, params
|
142
|
+
|
55
143
|
Smile::Album.from_xml( xml, session_id )
|
56
144
|
rescue
|
57
145
|
nil
|
data/smile.gemspec
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{smile}
|
5
|
+
s.version = "0.1.3"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["cajun"]
|
9
|
+
s.date = %q{2009-06-16}
|
10
|
+
s.email = %q{zac@kleinpeter.org}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc",
|
18
|
+
"Rakefile",
|
19
|
+
"VERSION.yml",
|
20
|
+
"lib/smile.rb",
|
21
|
+
"lib/smile/album.rb",
|
22
|
+
"lib/smile/base.rb",
|
23
|
+
"lib/smile/photo.rb",
|
24
|
+
"lib/smile/smug.rb",
|
25
|
+
"smile.gemspec",
|
26
|
+
"test/smile_test.rb",
|
27
|
+
"test/test_helper.rb"
|
28
|
+
]
|
29
|
+
s.homepage = %q{http://github.com/cajun/smile}
|
30
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubyforge_project = %q{cajun-gems}
|
33
|
+
s.rubygems_version = %q{1.3.4}
|
34
|
+
s.summary = %q{Simple API for talking to SmugMug}
|
35
|
+
s.test_files = [
|
36
|
+
"test/smile_test.rb",
|
37
|
+
"test/test_helper.rb"
|
38
|
+
]
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<rest-client>, [">= 0"])
|
46
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<rest-client>, [">= 0"])
|
49
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
50
|
+
end
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<rest-client>, [">= 0"])
|
53
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
54
|
+
end
|
55
|
+
end
|
data/test/smile_test.rb
CHANGED
@@ -1,7 +1,63 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class SmileTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
4
|
+
def setup
|
5
|
+
@smug = Smile::Smug.new
|
6
|
+
@smug.auth_anonymously
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_auth
|
10
|
+
assert_not_nil( @smug.auth_anonymously )
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_have_albums
|
14
|
+
assert_nothing_raised(Exception) do
|
15
|
+
assert_not_nil( @smug.albums( :NickName => 'kleinpeter' ) )
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_have_photos
|
20
|
+
assert_nothing_raised(Exception) do
|
21
|
+
album = @smug.albums( :NickName => 'kleinpeter' ).first
|
22
|
+
assert_not_nil( album.photos )
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_photo_has_album
|
27
|
+
assert_nothing_raised(Exception) do
|
28
|
+
album = @smug.albums( :NickName => 'kleinpeter' ).first
|
29
|
+
photo = album.photos.first
|
30
|
+
assert_equal( album.album_id, photo.album.album_id )
|
31
|
+
assert_equal( album.key, photo.album.key )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_photo_has_album_has_photo
|
36
|
+
assert_nothing_raised(Exception) do
|
37
|
+
album = @smug.albums( :NickName => 'kleinpeter' ).first
|
38
|
+
photo = album.photos.first
|
39
|
+
alt_photo = photo.album.photos.first
|
40
|
+
|
41
|
+
assert_equal( photo.image_id, alt_photo.image_id )
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# NOTE have to be logged in to test this one
|
46
|
+
# def test_album_stats
|
47
|
+
# assert_nothing_raised(Exception) do
|
48
|
+
# album = @smug.albums( :NickName => 'kleinpeter' ).first
|
49
|
+
# assert_not_nil( album.stats )
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
|
53
|
+
def test_photo_extras
|
54
|
+
assert_nothing_raised(Exception) do
|
55
|
+
album = @smug.albums( :NickName => 'kleinpeter' ).first
|
56
|
+
photo = album.photos.first
|
57
|
+
|
58
|
+
assert_not_nil( photo.details )
|
59
|
+
assert_not_nil( photo.info )
|
60
|
+
assert_not_nil( photo.urls )
|
61
|
+
end
|
6
62
|
end
|
7
63
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cajun
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-16 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -40,7 +40,6 @@ extensions: []
|
|
40
40
|
|
41
41
|
extra_rdoc_files:
|
42
42
|
- LICENSE
|
43
|
-
- README
|
44
43
|
- README.rdoc
|
45
44
|
files:
|
46
45
|
- LICENSE
|
@@ -52,11 +51,13 @@ files:
|
|
52
51
|
- lib/smile/base.rb
|
53
52
|
- lib/smile/photo.rb
|
54
53
|
- lib/smile/smug.rb
|
54
|
+
- smile.gemspec
|
55
55
|
- test/smile_test.rb
|
56
56
|
- test/test_helper.rb
|
57
|
-
- README
|
58
57
|
has_rdoc: true
|
59
58
|
homepage: http://github.com/cajun/smile
|
59
|
+
licenses: []
|
60
|
+
|
60
61
|
post_install_message:
|
61
62
|
rdoc_options:
|
62
63
|
- --charset=UTF-8
|
@@ -77,10 +78,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
78
|
requirements: []
|
78
79
|
|
79
80
|
rubyforge_project: cajun-gems
|
80
|
-
rubygems_version: 1.3.
|
81
|
+
rubygems_version: 1.3.4
|
81
82
|
signing_key:
|
82
|
-
specification_version:
|
83
|
-
summary:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Simple API for talking to SmugMug
|
84
85
|
test_files:
|
85
86
|
- test/smile_test.rb
|
86
87
|
- test/test_helper.rb
|
data/README
DELETED
File without changes
|