mugs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/mugs.rb +73 -0
  2. metadata +53 -0
data/lib/mugs.rb ADDED
@@ -0,0 +1,73 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'rexml/document'
4
+
5
+ include REXML
6
+
7
+ class SmugMug
8
+ def initialize
9
+ @end_point = "http://api.smugmug.com/hack/rest/1.2.0/"
10
+ @albums = Array.new
11
+ @images = Array.new
12
+ @image_urls = Array.new
13
+ end
14
+
15
+ def login_anonymously(key)
16
+ uri = "#{@end_point}?method=smugmug.login.anonymously&APIKey=#{key}"
17
+ content = Net::HTTP.get URI.parse(uri)
18
+ doc = Document.new content
19
+ @session_id = doc.root.elements["Login/Session"].attributes['id']
20
+ end
21
+
22
+ def albums_get(nickname)
23
+ uri = "#{@end_point}?method=smugmug.albums.get&SessionID=#{@session_id}&NickName=#{nickname}"
24
+ content = Net::HTTP.get URI.parse(uri)
25
+ doc = Document.new content
26
+ doc.root.elements.each("Albums/Album") do |album|
27
+ a = Album.new
28
+ a.id = album.attributes["id"]
29
+ a.title = album.attributes["Title"]
30
+ @albums.push a
31
+ end
32
+ return @albums
33
+ end
34
+
35
+ def images_get(album_id)
36
+ uri = "#{@end_point}?method=smugmug.images.get&SessionID=#{@session_id}&AlbumID=#{album_id}"
37
+ content = Net::HTTP.get URI.parse(uri)
38
+ doc = Document.new content
39
+ doc.root.elements.each("Images/Image") do |image|
40
+ i = Image.new
41
+ i.id = image.attributes["id"]
42
+ @images.push i
43
+ end
44
+ return @images
45
+ end
46
+
47
+ def images_get_urls(image_id)
48
+ uri = "#{@end_point}?method=smugmug.images.getURLs&SessionID=#{@session_id}&ImageID=#{image_id}"
49
+ content = Net::HTTP.get URI.parse(uri)
50
+ doc = Document.new content
51
+ i = ImageURLs.new
52
+ i.id = image_id
53
+ i.album_url = doc.root.elements["Image"].attributes["AlbumURL"]
54
+ i.tiny_url = doc.root.elements["Image"].attributes["TinyURL"]
55
+ i.thumb_url = doc.root.elements["Image"].attributes["ThumbURL"]
56
+ i.small_url = doc.root.elements["Image"].attributes["SmallURL"]
57
+ i.medium_url = doc.root.elements["Image"].attributes["MediumURL"]
58
+ i.large_url = doc.root.elements["Image"].attributes["LargeURL"]
59
+ return i
60
+ end
61
+ end
62
+
63
+ class Image
64
+ attr_accessor :id
65
+ end
66
+
67
+ class ImageURLs
68
+ attr_accessor :id, :album_url, :tiny_url, :thumb_url, :small_url, :medium_url, :large_url
69
+ end
70
+
71
+ class Album
72
+ attr_accessor :id, :title
73
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mugs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eric Alexander
8
+ autorequire: name
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-02-02 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: eric.alexander@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/mugs.rb
26
+ has_rdoc: true
27
+ homepage: http://ericalexander.tumblr.com
28
+ post_install_message:
29
+ rdoc_options: []
30
+
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: "0"
38
+ version:
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ requirements: []
46
+
47
+ rubyforge_project:
48
+ rubygems_version: 1.0.1
49
+ signing_key:
50
+ specification_version: 2
51
+ summary: Ruby wrapper for the SmugMug API
52
+ test_files: []
53
+