smirk 0.0.4 → 0.0.5
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 +29 -1
- data/VERSION +1 -1
- data/lib/smirk/album.rb +4 -6
- data/lib/smirk/category.rb +0 -2
- data/lib/smirk/client.rb +11 -11
- data/lib/smirk/image.rb +0 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -1,7 +1,35 @@
|
|
1
1
|
= smirk
|
2
2
|
|
3
|
-
|
3
|
+
Smirk is a Ruby wrapper around the SmugMug 1.2.2 API. You can access the albums, images, and categories behind
|
4
|
+
an authenticated account.
|
4
5
|
|
6
|
+
== Usage
|
7
|
+
|
8
|
+
First, you need to start a session with your SmugMug username and password.
|
9
|
+
|
10
|
+
smug = Smirk::Client.new("you@example.com", "mypassword")
|
11
|
+
|
12
|
+
You can call albums, categories, find_image, and find_album methods on a Client object.
|
13
|
+
|
14
|
+
smug.albums.map(&:title).join(", ")
|
15
|
+
=> "Trees, Flowers, Birds"
|
16
|
+
|
17
|
+
smug.categories.map(&:nicename).join(", ")
|
18
|
+
=> "Airplanes, Animals, Aquariums, Architecture, Art"
|
19
|
+
|
20
|
+
You can gather all the images within albums.
|
21
|
+
|
22
|
+
smug.albums.each do |a|
|
23
|
+
a.images.map(&:filename).join(", ")
|
24
|
+
end
|
25
|
+
=> "IMG_513.jpg, IMG_514.jpg, IMG_515.jpg"
|
26
|
+
|
27
|
+
When you're done, you should logout to terminate the session:
|
28
|
+
|
29
|
+
smug.logout
|
30
|
+
|
31
|
+
More documentation to come.
|
32
|
+
|
5
33
|
== Note on Patches/Pull Requests
|
6
34
|
|
7
35
|
* Fork the project.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/lib/smirk/album.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module Smirk
|
2
2
|
class Album < Client
|
3
3
|
|
4
|
-
attr_reader :session_id
|
5
|
-
|
6
4
|
def initialize(session_id, info)
|
7
5
|
info.each do |key, value|
|
8
6
|
instance_variable_set("@#{key.downcase}", value)
|
@@ -13,11 +11,11 @@ module Smirk
|
|
13
11
|
@session_id = session_id
|
14
12
|
end
|
15
13
|
|
16
|
-
def images
|
17
|
-
params = default_params.merge!({:method => "smugmug.images.get", :AlbumID => id, :AlbumKey => key})
|
18
|
-
json = get(
|
14
|
+
def images(heavy = false)
|
15
|
+
params = default_params.merge!({:method => "smugmug.images.get", :AlbumID => id, :AlbumKey => key, :Heavy => heavy})
|
16
|
+
json = get(params)["Album"]["Images"]
|
19
17
|
json.inject([]) do |images, i|
|
20
|
-
images << Smirk::Image.new(session_id, i)
|
18
|
+
images << Smirk::Image.new(@session_id, i)
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
data/lib/smirk/category.rb
CHANGED
data/lib/smirk/client.rb
CHANGED
@@ -5,23 +5,23 @@ module Smirk
|
|
5
5
|
API_KEY = "26Kw6kit9TBk2yFcYEwv2wWajATGYs1F"
|
6
6
|
HOST = "api.smugmug.com/services/api/json/1.2.2/"
|
7
7
|
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :session_id
|
9
9
|
|
10
10
|
def initialize(user, password)
|
11
11
|
@user = user
|
12
12
|
@password = password
|
13
13
|
params = { :method => "smugmug.login.withPassword", :APIKey => API_KEY, :EmailAddress => user, :Password => password }
|
14
|
-
@session_id = get(
|
14
|
+
@session_id = get(params, true)['Login']['Session']['id']
|
15
15
|
end
|
16
16
|
|
17
17
|
def logout
|
18
18
|
params = default_params.merge!(:method => "smugmug.logout")
|
19
|
-
get(
|
19
|
+
get(params)
|
20
20
|
end
|
21
21
|
|
22
|
-
def albums
|
23
|
-
params = default_params.merge!(:method => "smugmug.albums.get")
|
24
|
-
json = get(
|
22
|
+
def albums(heavy => false)
|
23
|
+
params = default_params.merge!({:method => "smugmug.albums.get", :Heavy => heavy})
|
24
|
+
json = get(params)["Albums"]
|
25
25
|
json.inject([]) do |albums, a|
|
26
26
|
albums << Smirk::Album.new(session_id, a)
|
27
27
|
end
|
@@ -29,7 +29,7 @@ module Smirk
|
|
29
29
|
|
30
30
|
def categories
|
31
31
|
params = default_params.merge!(:method => "smugmug.categories.get")
|
32
|
-
json = get(
|
32
|
+
json = get(params)["Categories"]
|
33
33
|
json.inject([]) do |categories, c|
|
34
34
|
categories << Smirk::Category.new(session_id, c)
|
35
35
|
end
|
@@ -37,21 +37,21 @@ module Smirk
|
|
37
37
|
|
38
38
|
def find_album(id, key)
|
39
39
|
params = default_params.merge!({:method => "smugmug.albums.getInfo", :AlbumID => id, :AlbumKey => key})
|
40
|
-
a = get(
|
40
|
+
a = get(params)["Album"]
|
41
41
|
Smirk::Album.new(session_id, a)
|
42
42
|
end
|
43
43
|
|
44
44
|
def find_image(id, key)
|
45
45
|
params = default_params.merge!({:method => "smugmug.images.getInfo", :ImageID => id, :ImageKey => key})
|
46
|
-
i = get(
|
46
|
+
i = get(params)["Image"]
|
47
47
|
Smirk::Image.new(session_id, i)
|
48
48
|
end
|
49
49
|
|
50
50
|
private
|
51
51
|
|
52
|
-
def get(
|
52
|
+
def get(params = {}, ssl = false)
|
53
53
|
proto = ssl ? "https://" : "http://"
|
54
|
-
JSON.parse(RestClient.post proto+
|
54
|
+
JSON.parse(RestClient.post proto+HOST, params)
|
55
55
|
end
|
56
56
|
|
57
57
|
def default_params
|
data/lib/smirk/image.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smirk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Miller
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-12 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|