smirk 0.0.1 → 0.0.2

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.1
1
+ 0.0.2
@@ -1,4 +1,8 @@
1
+ require 'rest_client'
2
+ require 'json'
1
3
  require File.expand_path(File.dirname(__FILE__) + '/smirk/client')
4
+ require File.expand_path(File.dirname(__FILE__) + '/smirk/album')
5
+ require File.expand_path(File.dirname(__FILE__) + '/smirk/image')
2
6
 
3
7
  module Smirk
4
8
  class AccessDenied < StandardError; end
@@ -0,0 +1,24 @@
1
+ module Smirk
2
+ class Album < Client
3
+
4
+ attr_reader :id, :key, :title, :category_id, :category_name, :session_id
5
+
6
+ def initialize(id, key, title, category_id, category_name, session_id)
7
+ @id = id
8
+ @key = key
9
+ @title = title
10
+ @category_id = category_id
11
+ @category_name = category_name
12
+ @session_id = session_id
13
+ end
14
+
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"]
18
+ json.inject([]) do |images, i|
19
+ images << Smirk::Image.new(i["id"], i["Key"], session_id)
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -1,53 +1,48 @@
1
- require 'rubygems'
2
- require 'rest_client'
3
- require 'json'
4
-
5
- # A Ruby class to call the SmugMug REST API.
6
-
7
1
  module Smirk
8
2
 
9
- class Smirk::Client
3
+ class Client
10
4
 
11
5
  API_KEY = "26Kw6kit9TBk2yFcYEwv2wWajATGYs1F"
6
+ HOST = "api.smugmug.com/services/api/json/1.2.2/"
12
7
 
13
8
  def self.version
14
- '0.0.1'
9
+ '0.0.2'
15
10
  end
16
11
 
17
12
  def self.gem_version_string
18
13
  "smirk-gem/#{version}"
19
14
  end
20
15
 
21
- attr_reader :host, :user, :password, :session_id
16
+ attr_reader :user, :password, :session_id
22
17
 
23
18
  def initialize(user, password)
24
19
  @user = user
25
20
  @password = password
26
- @host = "api.smugmug.com/services/api/json/1.2.2/"
27
- params = { :method => "smugmug.login.withPassword", :APIKey => API_KEY, :EmailAddress => @user, :Password => @password }
28
- @session_id = JSON.parse(get("https://#{@host}/", params))['Login']['Session']['id']
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']
29
23
  end
30
24
 
31
25
  def logout
32
26
  params = default_params.merge!(:method => "smugmug.logout")
33
- JSON.parse(get("http://#{@host}/", params))
34
- end
35
-
36
- def default_params
37
- { :APIKey => API_KEY, :SessionID => session_id }
27
+ JSON.parse(get("http://#{host}/", params))
38
28
  end
39
29
 
40
- # Albums
41
30
  def albums
42
31
  params = default_params.merge!(:method => "smugmug.albums.get")
43
- JSON.parse(get("http://#{@host}/", params))["Albums"]
32
+ json = JSON.parse(get("http://#{HOST}/", params))["Albums"]
33
+ json.inject([]) do |albums, a|
34
+ albums << Smirk::Album.new(a["id"], a["Key"], a["Title"], a["Category"]["id"], a["Category"]["Name"], session_id)
35
+ end
44
36
  end
45
37
 
46
38
  private
47
39
 
48
40
  def get(uri, params = {})
49
- # POST requests are the only ones that accept parameters -- ick
50
41
  RestClient.post uri, params
51
42
  end
43
+
44
+ def default_params
45
+ { :APIKey => Smirk::Client::API_KEY, :SessionID => session_id }
46
+ end
52
47
  end
53
48
  end
@@ -0,0 +1,13 @@
1
+ module Smirk
2
+ class Image < Client
3
+
4
+ attr_reader :id, :key, :session_id
5
+
6
+ def initialize(id, key, session_id)
7
+ @id = id
8
+ @key = key
9
+ @session_id = session_id
10
+ end
11
+
12
+ end
13
+ 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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Miller
@@ -58,6 +58,8 @@ files:
58
58
  - VERSION
59
59
  - lib/smirk.rb
60
60
  - lib/smirk/client.rb
61
+ - lib/smirk/album.rb
62
+ - lib/smirk/image.rb
61
63
  - test/helper.rb
62
64
  - test/test_smirk.rb
63
65
  has_rdoc: true