smile 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardoc +0 -0
- data/VERSION.yml +1 -1
- data/lib/smile/album.rb +115 -14
- data/lib/smile/base.rb +21 -2
- data/lib/smile/param_converter.rb +2 -0
- data/lib/smile/photo.rb +20 -18
- data/lib/smile/smug.rb +28 -88
- data/lib/smile.rb +9 -3
- data/smile.gemspec +3 -3
- metadata +3 -3
data/.yardoc
CHANGED
Binary file
|
data/VERSION.yml
CHANGED
data/lib/smile/album.rb
CHANGED
@@ -1,6 +1,79 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Result
|
2
|
+
# STANDARD RESPONSE
|
3
|
+
#
|
4
|
+
# array Albums
|
5
|
+
# Album
|
6
|
+
# integer id
|
7
|
+
# string Key
|
8
|
+
# string Title
|
9
|
+
# struct Category
|
10
|
+
# string id
|
11
|
+
# string Name
|
12
|
+
# struct SubCategory
|
13
|
+
# string id
|
14
|
+
# string Name
|
15
|
+
#
|
16
|
+
# HEAVY RESPONSE
|
17
|
+
#
|
18
|
+
# array Albums
|
19
|
+
# Album
|
20
|
+
# integer id
|
21
|
+
# string Key
|
22
|
+
# string Title
|
23
|
+
# struct Category
|
24
|
+
# string id
|
25
|
+
# string Name
|
26
|
+
# struct SubCategory
|
27
|
+
# string id
|
28
|
+
# string Name
|
29
|
+
# string Description
|
30
|
+
# string Keywords
|
31
|
+
# boolean Geography (owner)
|
32
|
+
# integer Position
|
33
|
+
# struct Hightlight (owner)
|
34
|
+
# string id
|
35
|
+
# integer ImageCount
|
36
|
+
# string LastUpdated
|
37
|
+
# boolean Header (owner, power & pro only)
|
38
|
+
# boolean Clean (owner)
|
39
|
+
# boolean EXIF (owner)
|
40
|
+
# boolean Filenames (owner)
|
41
|
+
# struct Template (owner)
|
42
|
+
# string id
|
43
|
+
# string SortMethod (owner)
|
44
|
+
# boolean SortDirection (owner)
|
45
|
+
# string Password (owner)
|
46
|
+
# string PasswordHint (owner)
|
47
|
+
# boolean Public (owner)
|
48
|
+
# boolean WorldSearchable (owner)
|
49
|
+
# boolean SmugSearchable (owner)
|
50
|
+
# boolean External (owner)
|
51
|
+
# boolean Protected (owner, power & pro only)
|
52
|
+
# boolean Watermarking (owner, pro only)
|
53
|
+
# struct Watermark (owner, pro only)
|
54
|
+
# string id
|
55
|
+
# boolean HideOwner (owner)
|
56
|
+
# boolean Larges (owner, pro only)
|
57
|
+
# boolean XLarges (owner, pro only)
|
58
|
+
# boolean X2Larges (owner)
|
59
|
+
# boolean X3Larges (owner)
|
60
|
+
# boolean Originals (owner)
|
61
|
+
# boolean CanRank (owner)
|
62
|
+
# boolean FriendEdit (owner)
|
63
|
+
# boolean FamilyEdit (owner)
|
64
|
+
# boolean Comments (owner)
|
65
|
+
# boolean Share (owner)
|
66
|
+
# boolean Printable (owner)
|
67
|
+
# int ColorCorrection (owner)
|
68
|
+
# boolean DefaultColor (owner, pro only) deprecated
|
69
|
+
# integer ProofDays (owner, pro only)
|
70
|
+
# string Backprinting (owner, pro only)
|
71
|
+
# float UnsharpAmount (owner, power & pro only)
|
72
|
+
# float UnsharpRadius (owner, power & pro only)
|
73
|
+
# float UnsharpThreshold (owner, power & pro only)
|
74
|
+
# float UnsharpSigma (owner, power & pro only)
|
75
|
+
# struct Community (owner)
|
76
|
+
# string id
|
4
77
|
#
|
5
78
|
# Created by Zac Kleinpeter on 2009-04-28.
|
6
79
|
# Copyright 2009 Cajun Country. All rights reserved.
|
@@ -8,9 +81,11 @@
|
|
8
81
|
class Smile::Album < Smile::Base
|
9
82
|
|
10
83
|
class << self
|
11
|
-
def
|
12
|
-
|
13
|
-
|
84
|
+
def from_json( json, session_id )
|
85
|
+
result = JSON.parse( json )
|
86
|
+
result["Albums"].map do |album_upcase|
|
87
|
+
album = upper_hash_to_lower_hash( album_upcase )
|
88
|
+
|
14
89
|
album.merge!( :album_id => album["id"] )
|
15
90
|
|
16
91
|
a = Smile::Album.new( album )
|
@@ -34,9 +109,10 @@ class Smile::Album < Smile::Base
|
|
34
109
|
|
35
110
|
params.merge!( options ) if( options )
|
36
111
|
|
37
|
-
|
112
|
+
json = RestClient.post Smile::Base::BASE, params
|
38
113
|
|
39
|
-
|
114
|
+
album_upper = JSON.parse(json)
|
115
|
+
album = upper_hash_to_lower_hash( album_upper['Album'] )
|
40
116
|
album.merge!( :album_id => album["id"] )
|
41
117
|
|
42
118
|
a = Smile::Album.new( album )
|
@@ -62,8 +138,8 @@ class Smile::Album < Smile::Base
|
|
62
138
|
|
63
139
|
params.merge!( options ) if( options )
|
64
140
|
|
65
|
-
|
66
|
-
Smile::Photo.
|
141
|
+
json = RestClient.post BASE, params
|
142
|
+
Smile::Photo.from_json( json, session_id )
|
67
143
|
end
|
68
144
|
|
69
145
|
# * integer AlbumID
|
@@ -80,10 +156,35 @@ class Smile::Album < Smile::Base
|
|
80
156
|
|
81
157
|
params.merge!( options ) if( options )
|
82
158
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
159
|
+
json = RestClient.post Smile::Base::BASE, params
|
160
|
+
|
161
|
+
json = JSON.parse( json )
|
162
|
+
raise json["message"] if json["stat"] == 'fail'
|
163
|
+
|
164
|
+
image = upper_hash_to_lower_hash( json['Album'] )
|
87
165
|
OpenStruct.new( hash )
|
88
166
|
end
|
167
|
+
|
168
|
+
def add( payload, options={} )
|
169
|
+
if( File.exists?( payload ) )
|
170
|
+
RestClient.put BASE, payload,
|
171
|
+
:content_length => File.size( payload ),
|
172
|
+
:content_md5 => '?',
|
173
|
+
:x_smug_sessionid => session_id,
|
174
|
+
:x_smug_version => VERSION,
|
175
|
+
:x_smug_albumid => album_id,
|
176
|
+
:x_smug_filename => File.basename( payload ),
|
177
|
+
:x_smug_caption => options[:caption],
|
178
|
+
:x_smug_keywords => options[:keywords],
|
179
|
+
:x_smug_latitude => options[:latitude],
|
180
|
+
:x_smug_longitude => options[:longitude],
|
181
|
+
:x_smug_altitude => options[:altitude]
|
182
|
+
else
|
183
|
+
Exception.new( "Cannot find file #{payload}." )
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def category
|
188
|
+
['category']
|
189
|
+
end
|
89
190
|
end
|
data/lib/smile/base.rb
CHANGED
@@ -7,10 +7,12 @@
|
|
7
7
|
#
|
8
8
|
module Smile
|
9
9
|
class Base < OpenStruct
|
10
|
-
BASE = 'http://api.smugmug.com/hack/
|
11
|
-
BASE_SECURE = 'https://api.smugmug.com/hack/
|
10
|
+
BASE = 'http://api.smugmug.com/hack/json/1.2.0/'
|
11
|
+
BASE_SECURE = 'https://api.smugmug.com/hack/json/1.2.0/'
|
12
12
|
API = 'HSoqGCJ8ilF42BeThMGDZqqqOgj1eXqN'
|
13
13
|
|
14
|
+
VERSION = '1.2.0'
|
15
|
+
|
14
16
|
class << self
|
15
17
|
attr_accessor :session_id
|
16
18
|
# This will be included in every request once you have logged in
|
@@ -29,6 +31,19 @@ module Smile
|
|
29
31
|
self.session_id = smug.session_id
|
30
32
|
end
|
31
33
|
end
|
34
|
+
|
35
|
+
def upper_hash_to_lower_hash( upper )
|
36
|
+
if( Hash === upper )
|
37
|
+
lower ={}
|
38
|
+
upper.each_pair do |key, value|
|
39
|
+
lower[key.downcase] = upper_hash_to_lower_hash( value )
|
40
|
+
end
|
41
|
+
lower
|
42
|
+
else
|
43
|
+
upper
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
32
47
|
end
|
33
48
|
|
34
49
|
attr_accessor :session_id
|
@@ -36,5 +51,9 @@ module Smile
|
|
36
51
|
self.class.session_id = self.session_id
|
37
52
|
self.class.default_params
|
38
53
|
end
|
54
|
+
|
55
|
+
def upper_hash_to_lower_hash( hash )
|
56
|
+
self.class.upper_hash_to_lower_hash( hash )
|
57
|
+
end
|
39
58
|
end
|
40
59
|
end
|
data/lib/smile/photo.rb
CHANGED
@@ -9,10 +9,11 @@ class Smile::Photo < Smile::Base
|
|
9
9
|
|
10
10
|
class << self
|
11
11
|
# Convert the given xml into photo objects to play with
|
12
|
-
def
|
13
|
-
|
12
|
+
def from_json( json, session_id )
|
13
|
+
result = JSON.parse( json )
|
14
14
|
|
15
|
-
|
15
|
+
result["Images"].map do |image_upper|
|
16
|
+
image = upper_hash_to_lower_hash( image_upper )
|
16
17
|
image.merge!( :image_id => image["id"] )
|
17
18
|
image.merge!( :album_key => image["album"]["key"] )
|
18
19
|
image.merge!( :album_id => image["album"]["id"] )
|
@@ -40,8 +41,9 @@ class Smile::Photo < Smile::Base
|
|
40
41
|
)
|
41
42
|
|
42
43
|
params.merge!( options ) if( options )
|
43
|
-
|
44
|
-
|
44
|
+
json = RestClient.post Smile::Base::BASE, params
|
45
|
+
image_upper = JSON.parse( json )
|
46
|
+
image = upper_hash_to_lower_hash( image_upper['Image'] )
|
45
47
|
|
46
48
|
image.merge!( :image_id => image["id"] )
|
47
49
|
image.merge!( :album_key => image["album"]["key"] )
|
@@ -104,12 +106,12 @@ class Smile::Photo < Smile::Base
|
|
104
106
|
)
|
105
107
|
|
106
108
|
params.merge!( options ) if( options )
|
107
|
-
|
109
|
+
json = RestClient.post Smile::Base::BASE, params
|
108
110
|
|
109
|
-
|
110
|
-
raise
|
111
|
+
json = JSON.parse( json )
|
112
|
+
raise json["message"] if json["stat"] == 'fail'
|
111
113
|
|
112
|
-
image =
|
114
|
+
image = upper_hash_to_lower_hash( json['Image'] )
|
113
115
|
image.merge!( :image_id => image["id"] )
|
114
116
|
|
115
117
|
OpenStruct.new( image )
|
@@ -163,12 +165,12 @@ class Smile::Photo < Smile::Base
|
|
163
165
|
)
|
164
166
|
|
165
167
|
params.merge!( options ) if( options )
|
166
|
-
|
168
|
+
json = RestClient.post Smile::Base::BASE, params
|
167
169
|
|
168
|
-
|
169
|
-
raise
|
170
|
+
json = JSON.parse( json )
|
171
|
+
raise json["message"] if json["stat"] == 'fail'
|
170
172
|
|
171
|
-
image =
|
173
|
+
image = upper_hash_to_lower_hash( json['Image'] )
|
172
174
|
image.merge!( :image_id => image["id"] )
|
173
175
|
|
174
176
|
OpenStruct.new( image )
|
@@ -214,12 +216,12 @@ class Smile::Photo < Smile::Base
|
|
214
216
|
)
|
215
217
|
|
216
218
|
params.merge!( options ) if( options )
|
217
|
-
|
219
|
+
json = RestClient.post Smile::Base::BASE, params
|
218
220
|
|
219
|
-
|
220
|
-
raise
|
221
|
-
|
222
|
-
image =
|
221
|
+
json = JSON.parse( json )
|
222
|
+
raise json["message"] if json["stat"] == 'fail'
|
223
|
+
|
224
|
+
image = upper_hash_to_lower_hash( json['Image'] )
|
223
225
|
image.merge!( :image_id => image["id"] )
|
224
226
|
|
225
227
|
OpenStruct.new( image )
|
data/lib/smile/smug.rb
CHANGED
@@ -8,6 +8,12 @@
|
|
8
8
|
module Smile
|
9
9
|
class Smug < Smile::Base
|
10
10
|
|
11
|
+
# Login to SmugMug using a specific user account.
|
12
|
+
#
|
13
|
+
# @param [String] email The username ( Nickname ) for the SmugMug account
|
14
|
+
# @param [String] password The password for the SmugMug account
|
15
|
+
#
|
16
|
+
# @return [Smile::SmugMug.new] An Smug object that has been authenticated
|
11
17
|
def auth( email, pass )
|
12
18
|
params = default_params.merge(
|
13
19
|
:method => 'smugmug.login.withPassword',
|
@@ -15,28 +21,33 @@ module Smile
|
|
15
21
|
:Password => pass
|
16
22
|
)
|
17
23
|
|
18
|
-
|
19
|
-
result =
|
20
|
-
|
24
|
+
json = RestClient.post( BASE, params )
|
25
|
+
result = JSON.parse( json )
|
26
|
+
|
27
|
+
self.session_id = result["Login"]["Session"]["id"]
|
21
28
|
result
|
22
29
|
rescue NoMethodError => e
|
23
30
|
nil
|
24
31
|
end
|
25
32
|
|
26
|
-
|
33
|
+
# Login to SmugMug using an anonymously account
|
34
|
+
# This will allow you to execute many functions, but no user specific functions
|
35
|
+
#
|
36
|
+
# @return [Smile::SmugMug.new] An Smug object that has been authenticated
|
27
37
|
def auth_anonymously
|
28
38
|
params = default_params.merge(
|
29
39
|
:method => 'smugmug.login.anonymously'
|
30
40
|
)
|
31
41
|
|
32
|
-
|
33
|
-
result =
|
34
|
-
self.session_id = result["
|
42
|
+
json = RestClient.post( BASE, params )
|
43
|
+
result = JSON.parse( json )
|
44
|
+
self.session_id = result["Login"]["Session"]["id"]
|
35
45
|
result
|
36
46
|
rescue NoMethodError => e
|
37
47
|
nil
|
38
48
|
end
|
39
49
|
|
50
|
+
# Close the session
|
40
51
|
def logout
|
41
52
|
params = default_params.merge(
|
42
53
|
:method => 'smugmug.logout'
|
@@ -50,87 +61,16 @@ module Smile
|
|
50
61
|
# Retrieves a list of albums for a given user. If you are logged in it will return
|
51
62
|
# your albums.
|
52
63
|
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
64
|
+
# @param [optional,Hash] options The magic options hash all ruby devs love
|
65
|
+
# @option options [optional, String] :nick_name If no nick name is supplied then...
|
66
|
+
# @option options [optional, true or false ] :heavy ('true') This will control how much
|
67
|
+
# information is returned about the album
|
68
|
+
# @option options [optional, String] :site_password If you have not logged in then you can provide the
|
69
|
+
# password here to access private information.
|
57
70
|
#
|
58
|
-
#
|
59
|
-
# STANDARD RESPONSE
|
71
|
+
# @return [Array<Smile::Album>]
|
60
72
|
#
|
61
|
-
#
|
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
|
73
|
+
# @see Smug::Album#new For more information about heavy ( true and false ) responces
|
134
74
|
def albums( options=nil )
|
135
75
|
params = default_params.merge(
|
136
76
|
:method => 'smugmug.albums.get',
|
@@ -138,9 +78,9 @@ module Smile
|
|
138
78
|
)
|
139
79
|
|
140
80
|
params = params.merge( options ) if( options )
|
141
|
-
|
81
|
+
json = RestClient.post BASE, params
|
142
82
|
|
143
|
-
Smile::Album.
|
83
|
+
Smile::Album.from_json( json, session_id )
|
144
84
|
rescue
|
145
85
|
nil
|
146
86
|
end
|
data/lib/smile.rb
CHANGED
@@ -8,10 +8,15 @@ require 'lib/smile/photo'
|
|
8
8
|
require 'lib/smile/param_converter'
|
9
9
|
require 'cgi'
|
10
10
|
require 'rss'
|
11
|
+
require 'json'
|
11
12
|
|
12
13
|
module Smile
|
13
14
|
module_function
|
14
15
|
|
16
|
+
# Login to SmugMug using an anonymously account
|
17
|
+
# This will allow you to execute many functions, but no user specific functions
|
18
|
+
#
|
19
|
+
# @return [Smile::SmugMug.new] An Smug object that has been authenticated
|
15
20
|
def auth_anonymously
|
16
21
|
smug = Smile::Smug.new
|
17
22
|
smug.auth_anonymously
|
@@ -20,16 +25,17 @@ module Smile
|
|
20
25
|
|
21
26
|
# Login to SmugMug using a specific user account.
|
22
27
|
#
|
23
|
-
# @param [String]
|
28
|
+
# @param [String] email The username ( e-mail address ) for the SmugMug account
|
24
29
|
# @param [String] password The password for the SmugMug account
|
25
30
|
#
|
26
31
|
# @return [Smile::SmugMug.new] An Smug object that has been authenticated
|
27
|
-
def auth(
|
32
|
+
def auth( email, password )
|
28
33
|
smug = Smile::Smug.new
|
29
|
-
smug.auth(
|
34
|
+
smug.auth( email, password )
|
30
35
|
smug
|
31
36
|
end
|
32
37
|
|
38
|
+
|
33
39
|
def base_feed( options={} )
|
34
40
|
options.merge!( :format => 'rss' )
|
35
41
|
url = "http://api.smugmug.com/hack/feed.mg?"
|
data/smile.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{smile}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["cajun"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-08-21}
|
10
10
|
s.email = %q{zac@kleinpeter.org}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.rdoc_options = ["--charset=UTF-8"]
|
33
33
|
s.require_paths = ["lib"]
|
34
34
|
s.rubyforge_project = %q{cajun-gems}
|
35
|
-
s.rubygems_version = %q{1.3.
|
35
|
+
s.rubygems_version = %q{1.3.5}
|
36
36
|
s.summary = %q{Simple API for talking to SmugMug}
|
37
37
|
s.test_files = [
|
38
38
|
"test/smile_test.rb",
|
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.2.
|
4
|
+
version: 0.2.1
|
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-08-21 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
80
|
requirements: []
|
81
81
|
|
82
82
|
rubyforge_project: cajun-gems
|
83
|
-
rubygems_version: 1.3.
|
83
|
+
rubygems_version: 1.3.5
|
84
84
|
signing_key:
|
85
85
|
specification_version: 3
|
86
86
|
summary: Simple API for talking to SmugMug
|