smirk 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/lib/smirk.rb CHANGED
@@ -3,6 +3,7 @@ require 'json'
3
3
  require File.expand_path(File.dirname(__FILE__) + '/smirk/client')
4
4
  require File.expand_path(File.dirname(__FILE__) + '/smirk/album')
5
5
  require File.expand_path(File.dirname(__FILE__) + '/smirk/image')
6
+ require File.expand_path(File.dirname(__FILE__) + '/smirk/category')
6
7
 
7
8
  module Smirk
8
9
  class AccessDenied < StandardError; end
data/lib/smirk/album.rb CHANGED
@@ -13,8 +13,8 @@ module Smirk
13
13
  end
14
14
 
15
15
  def images
16
- params = {:APIKey => Smirk::Client::API_KEY, :method => "smugmug.images.get", :SessionID => session_id, :AlbumID => id, :AlbumKey => key }
17
- json = JSON.parse(get("http://#{Smirk::Client::HOST}/", params))["Album"]["Images"]
16
+ params = default_params.merge!({:method => "smugmug.images.get", :AlbumID => id, :AlbumKey => key})
17
+ json = get(HOST, params)["Album"]["Images"]
18
18
  json.inject([]) do |images, i|
19
19
  images << Smirk::Image.new(i["id"], i["Key"], session_id)
20
20
  end
@@ -0,0 +1,15 @@
1
+ module Smirk
2
+ class Category < Client
3
+
4
+ attr_reader :id, :name, :nice_name, :kind, :session_id
5
+
6
+ def initialize(id, name, nice_name, kind, session_id)
7
+ @id = id
8
+ @name = name
9
+ @nice_name = nice_name
10
+ @kind = kind
11
+ @session_id = session_id
12
+ end
13
+
14
+ end
15
+ end
data/lib/smirk/client.rb CHANGED
@@ -6,7 +6,7 @@ module Smirk
6
6
  HOST = "api.smugmug.com/services/api/json/1.2.2/"
7
7
 
8
8
  def self.version
9
- '0.0.2'
9
+ '0.0.3'
10
10
  end
11
11
 
12
12
  def self.gem_version_string
@@ -19,30 +19,51 @@ module Smirk
19
19
  @user = user
20
20
  @password = password
21
21
  params = { :method => "smugmug.login.withPassword", :APIKey => API_KEY, :EmailAddress => user, :Password => password }
22
- @session_id = JSON.parse(get("https://#{HOST}/", params))['Login']['Session']['id']
22
+ @session_id = get(HOST, params, true)['Login']['Session']['id']
23
23
  end
24
24
 
25
25
  def logout
26
26
  params = default_params.merge!(:method => "smugmug.logout")
27
- JSON.parse(get("http://#{host}/", params))
27
+ get(HOST, params)
28
28
  end
29
29
 
30
30
  def albums
31
31
  params = default_params.merge!(:method => "smugmug.albums.get")
32
- json = JSON.parse(get("http://#{HOST}/", params))["Albums"]
32
+ json = get(HOST, params)["Albums"]
33
33
  json.inject([]) do |albums, a|
34
34
  albums << Smirk::Album.new(a["id"], a["Key"], a["Title"], a["Category"]["id"], a["Category"]["Name"], session_id)
35
35
  end
36
36
  end
37
37
 
38
+ def categories
39
+ params = default_params.merge!(:method => "smugmug.categories.get")
40
+ json = get(HOST, params)["Categories"]
41
+ json.inject([]) do |categories, c|
42
+ categories << Smirk::Category.new(c["id"], c["Name"], c["NiceName"], c["Type"], session_id)
43
+ end
44
+ end
45
+
46
+ def find_album(id, key)
47
+ params = default_params.merge!({:method => "smugmug.albums.getInfo", :AlbumID => id, :AlbumKey => key})
48
+ a = get(HOST, params)["Album"]
49
+ Smirk::Album.new(a["id"], a["Key"], a["Title"], a["Category"]["id"], a["Category"]["Name"], session_id)
50
+ end
51
+
52
+ def find_image(id, key)
53
+ params = default_params.merge!({:method => "smugmug.images.getInfo", :ImageID => id, :ImageKey => key})
54
+ i = get(HOST, params)["Image"]
55
+ Smirk::Image.new(i["id"], i["Key"], session_id)
56
+ end
57
+
38
58
  private
39
59
 
40
- def get(uri, params = {})
41
- RestClient.post uri, params
60
+ def get(uri, params = {}, ssl = false)
61
+ proto = ssl ? "https://" : "http://"
62
+ JSON.parse(RestClient.post proto+uri, params)
42
63
  end
43
64
 
44
65
  def default_params
45
- { :APIKey => Smirk::Client::API_KEY, :SessionID => session_id }
66
+ { :APIKey => API_KEY, :SessionID => session_id }
46
67
  end
47
68
  end
48
69
  end
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.2
4
+ version: 0.0.3
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-09 00:00:00 -08:00
12
+ date: 2010-02-10 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -42,7 +42,7 @@ dependencies:
42
42
  - !ruby/object:Gem::Version
43
43
  version: 1.2.0
44
44
  version:
45
- description: Smirk is a simple ruby wrapper for the SmugMug 1.2.2 API specification. It currently supports initiating a session and getting all album information.
45
+ description: Smirk is a simple ruby wrapper for the SmugMug 1.2.2 API specification. It currently supports initiating a session, finding albums, images, and categories.
46
46
  email: james@jk-tech.com
47
47
  executables: []
48
48
 
@@ -60,6 +60,7 @@ files:
60
60
  - lib/smirk/client.rb
61
61
  - lib/smirk/album.rb
62
62
  - lib/smirk/image.rb
63
+ - lib/smirk/category.rb
63
64
  - test/helper.rb
64
65
  - test/test_smirk.rb
65
66
  has_rdoc: true