cajun-smile 0.1.1 → 0.1.2

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 CHANGED
@@ -1,6 +1,24 @@
1
1
  = smile
2
2
 
3
- Description goes here.
3
+ Smile is a simple gem to talk to SmugMug.com.
4
+
5
+ smug = Smile::Smug.new
6
+ smug.auth_anonymously
7
+ albums = smug.albums( :NickName => 'kleinpeter' )
8
+
9
+ album = albums.first # just test the first one
10
+
11
+ album.photos # and see the pretty pics
12
+
13
+ -- or --
14
+
15
+ smug = Smile::Smug.new
16
+ smug.auth( 'my_nick', 'my_pass' )
17
+ albums = smug.albums # theses are mine
18
+
19
+ album = albums.first # just test the first one
20
+
21
+ album.photos # and see the pretty pics
4
22
 
5
23
  == Copyright
6
24
 
data/Rakefile CHANGED
@@ -12,6 +12,7 @@ begin
12
12
  gem.files << "lib/**/*"
13
13
  gem.add_dependency( 'rest-client' )
14
14
  gem.add_dependency( 'activesupport' )
15
+ gem.rubyforge_project = 'cajun-gems'
15
16
 
16
17
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
18
  end
@@ -19,6 +20,34 @@ rescue LoadError
19
20
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
20
21
  end
21
22
 
23
+ # These are new tasks
24
+ # These are new tasks
25
+ begin
26
+ require 'rake/contrib/sshpublisher'
27
+ namespace :rubyforge do
28
+
29
+ desc "Release gem and RDoc documentation to RubyForge"
30
+ task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
31
+
32
+ namespace :release do
33
+ desc "Publish RDoc to RubyForge."
34
+ task :docs => [:rdoc] do
35
+ config = YAML.load(
36
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
37
+ )
38
+
39
+ host = "#{config['username']}@rubyforge.org"
40
+ remote_dir = "/var/www/gforge-projects/cajun-gems/"
41
+ local_dir = 'rdoc'
42
+
43
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
44
+ end
45
+ end
46
+ end
47
+ rescue LoadError
48
+ puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
49
+ end
50
+
22
51
  require 'rake/testtask'
23
52
  Rake::TestTask.new(:test) do |test|
24
53
  test.libs << 'lib' << 'test'
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
+ :patch: 2
2
3
  :major: 0
3
4
  :minor: 1
4
- :patch: 1
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
- end
14
-
15
- =begin
16
- * SessionID - string.
17
- * AlbumID - integer.
18
- * Heavy - boolean (optional).
19
- * Password - string (optional).
20
- * SitePassword - string (optional).
21
- * AlbumKey - string.
22
- =end
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.images.get',
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
- xml = RestClient.post BASE, params
33
- Smile::Photo.from_xml( xml, sesson_id )
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,32 @@
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
+ if( session_id )
20
+ base.merge!( :SessionID => session_id )
21
+ end
22
+ base
23
+ end
24
+ end
25
+
7
26
  attr_accessor :session_id
8
27
  def default_params
9
- base = { :APIKey => API }
10
- if( session_id )
11
- base.merge!( :SessionID => session_id )
12
- end
13
- base
28
+ self.class.session_id = self.session_id
29
+ self.class.default_params
14
30
  end
15
31
  end
16
32
  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
- a = Smile::Photo.new( image )
9
- a.session_id = session_id
10
- a
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,100 @@ module Smile
37
45
  RestClient.post( BASE, params )
38
46
  end
39
47
 
40
- =begin
41
- * SessionID - string.
42
- * NickName - string (optional).
43
- * Heavy - boolean (optional).
44
- * SitePassword - string (optional).
45
48
 
46
- =end
49
+ # Retrieves a list of albums for a given user. If you are logged in it will return
50
+ # your albums.
51
+ #
52
+ # Arguments
53
+ # NickName - string (optional).
54
+ # Heavy - boolean (optional).
55
+ # SitePassword - string (optional).
56
+ #
57
+ # Result
58
+ # STANDARD RESPONSE
59
+ #
60
+ # array Albums
61
+ # Album
62
+ # integer id
63
+ # string Key
64
+ # string Title
65
+ # struct Category
66
+ # string id
67
+ # string Name
68
+ # struct SubCategory
69
+ # string id
70
+ # string Name
71
+ #
72
+ # HEAVY RESPONSE
73
+ #
74
+ # array Albums
75
+ # Album
76
+ # integer id
77
+ # string Key
78
+ # string Title
79
+ # struct Category
80
+ # string id
81
+ # string Name
82
+ # struct SubCategory
83
+ # string id
84
+ # string Name
85
+ # string Description
86
+ # string Keywords
87
+ # boolean Geography (owner)
88
+ # integer Position
89
+ # struct Hightlight (owner)
90
+ # string id
91
+ # integer ImageCount
92
+ # string LastUpdated
93
+ # boolean Header (owner, power & pro only)
94
+ # boolean Clean (owner)
95
+ # boolean EXIF (owner)
96
+ # boolean Filenames (owner)
97
+ # struct Template (owner)
98
+ # string id
99
+ # string SortMethod (owner)
100
+ # boolean SortDirection (owner)
101
+ # string Password (owner)
102
+ # string PasswordHint (owner)
103
+ # boolean Public (owner)
104
+ # boolean WorldSearchable (owner)
105
+ # boolean SmugSearchable (owner)
106
+ # boolean External (owner)
107
+ # boolean Protected (owner, power & pro only)
108
+ # boolean Watermarking (owner, pro only)
109
+ # struct Watermark (owner, pro only)
110
+ # string id
111
+ # boolean HideOwner (owner)
112
+ # boolean Larges (owner, pro only)
113
+ # boolean XLarges (owner, pro only)
114
+ # boolean X2Larges (owner)
115
+ # boolean X3Larges (owner)
116
+ # boolean Originals (owner)
117
+ # boolean CanRank (owner)
118
+ # boolean FriendEdit (owner)
119
+ # boolean FamilyEdit (owner)
120
+ # boolean Comments (owner)
121
+ # boolean Share (owner)
122
+ # boolean Printable (owner)
123
+ # int ColorCorrection (owner)
124
+ # boolean DefaultColor (owner, pro only) deprecated
125
+ # integer ProofDays (owner, pro only)
126
+ # string Backprinting (owner, pro only)
127
+ # float UnsharpAmount (owner, power & pro only)
128
+ # float UnsharpRadius (owner, power & pro only)
129
+ # float UnsharpThreshold (owner, power & pro only)
130
+ # float UnsharpSigma (owner, power & pro only)
131
+ # struct Community (owner)
132
+ # string id
47
133
  def albums( options=nil )
48
134
  params = default_params.merge(
49
135
  :method => 'smugmug.albums.get',
50
136
  :heavy => 1
51
- )
137
+ )
52
138
 
53
139
  params = params.merge( options ) if( options )
54
140
  xml = RestClient.post BASE, params
141
+
55
142
  Smile::Album.from_xml( xml, session_id )
56
143
  rescue
57
144
  nil
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
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
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
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
- require 'shoulda'
3
+ require 'ruby-debug'
4
4
 
5
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
6
  $LOAD_PATH.unshift(File.dirname(__FILE__))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cajun-smile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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-04-08 00:00:00 -07:00
12
+ date: 2009-04-29 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -76,10 +76,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  version:
77
77
  requirements: []
78
78
 
79
- rubyforge_project:
79
+ rubyforge_project: cajun-gems
80
80
  rubygems_version: 1.2.0
81
81
  signing_key:
82
- specification_version: 2
82
+ specification_version: 3
83
83
  summary: TODO
84
84
  test_files:
85
85
  - test/smile_test.rb