RailsMug 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in RailsMug.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 David Slone
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # RailsMug
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'RailsMug'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install RailsMug
18
+
19
+ ## Usage
20
+
21
+ Get all albums
22
+ ```
23
+ session = RailsMug::Session.new('APIKEY','APISECRET','TOKENKEY','TOKENSECRET')
24
+ rails_mug = RailsMug::Albums.new(session)
25
+ albums = rails_mug.get_albums
26
+ ```
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
data/RailsMug.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/RailsMug/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["David Slone"]
6
+ gem.email = ["dbslone@gmail.com"]
7
+ gem.description = %q{Retrieve SmugMug photo list}
8
+ gem.summary = %q{This gem allows an authenticated user to retrieve the album and photo list from an album}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "RailsMug"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = RailsMug::VERSION
17
+
18
+ gem.add_development_dependency "rspec", "~> 2.6"
19
+ gem.add_development_dependency "oauth"
20
+ end
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "net/http"
4
+ require "uri"
5
+ require "json"
data/lib/RailsMug.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "RailsMug/version"
2
+ require "RailsMug/session"
3
+ require "RailsMug/exceptions"
4
+ require "RailsMug/albums"
5
+ require "RailsMug/images"
6
+ require "RailsMug/record"
7
+ require "RailsMug/model/album"
8
+ require "RailsMug/model/image"
9
+
10
+ module RailsMug
11
+ # Your code goes here...
12
+ end
@@ -0,0 +1,106 @@
1
+ module RailsMug
2
+ class Albums
3
+ attr_accessor :albums
4
+ attr_accessor :images
5
+
6
+ # Initialize Albums
7
+ #
8
+ # @author David Slone
9
+ # @params {RailsMug::Session}
10
+ def initialize railsmug_session
11
+ raise RailsMug::SessionError, "Invalid Session (session cannot be nil)" if railsmug_session.nil?
12
+
13
+ self.albums = []
14
+ self.images = []
15
+ @access_token = railsmug_session.accesstoken
16
+ end
17
+
18
+ # Retrieve all albums for the current user
19
+ #
20
+ # @author David Slone
21
+ def get_albums
22
+ response = @access_token.get('/api/json/1.3.0/?method=smugmug.albums.get')
23
+ json_response = JSON.parse(response.body)
24
+
25
+ raise RailsMug::AlbumError, "SmugMug Error: #{json_response['code']} - #{json_response['message']}" if json_response['stat'] == "fail"
26
+
27
+ json_response['Albums'].each do |a|
28
+ sub_category = {}
29
+ sub_category = { :id => a['SubCategory']['id'], :name => a['SubCategory']['Name'] } unless a['SubCategory'].nil?
30
+
31
+ album_info = get_album_info a['id'], a['Key']
32
+
33
+ album = RailsMug::Model::Album.new(
34
+ :access_token => @access_token,
35
+ :id => a['id'],
36
+ :title => a['Title'],
37
+ :key => a['Key'],
38
+ :category => { :id => a['Category']['id'], :name => a['Category']['Name']},
39
+ :sub_category => sub_category,
40
+ :backprinting => album_info['Album']['Backprinting'],
41
+ :boutique_packaging => album_info['Album']['BoutiquePackaging'],
42
+ :can_rank => album_info['Album']['CanRank'],
43
+ :clean => album_info['Album']['Clean'],
44
+ :color_correction => album_info['Album']['ColorCorrection'],
45
+ :comments => album_info['Album']['Comments'],
46
+ :description => album_info['Album']['Description'],
47
+ :exif => album_info['Album']['EXIF'],
48
+ :external => album_info['Album']['External'],
49
+ :family_edit => album_info['Album']['FamilyEdit'],
50
+ :filenames => album_info['Album']['Filenames'],
51
+ :friend_edit => album_info['Album']['FriendEdit'],
52
+ :geography => album_info['Album']['Geography'],
53
+ :guest_upload_url => album_info['Album']['GuestUploadURL'],
54
+ :header => album_info['Album']['Header'],
55
+ :hide_owner => album_info['Album']['HideOwner'],
56
+ :hightlight => album_info['Album']['Highlight'],
57
+ :image_count => album_info['Album']['ImageCount'],
58
+ :keywords => album_info['Album']['Keywords'],
59
+ :url => album_info['Album']['URL']
60
+ )
61
+
62
+ self.albums << album
63
+ end
64
+
65
+ self.albums
66
+ end
67
+
68
+ # Retrieve the information for an album.
69
+ #
70
+ # @author David Slone
71
+ # @param [Integer] album_id The ID for a specific album.
72
+ # @param [String] album_key The key for a specific album.
73
+ # @param [Hash] opts Extra parameters for retrieving album information
74
+ # @option [String] password The password for an album.
75
+ # @return [Hash] Returns a JSON parsed hash of the response
76
+ def get_album_info album_id, album_key, opts = {}
77
+ response = @access_token.get("/api/json/1.3.0/?method=smugmug.albums.getInfo&AlbumID=#{album_id}&AlbumKey=#{album_key}")
78
+ json_response = JSON.parse(response.body)
79
+
80
+ raise RailsMug::AlbumError, "SmugMug albums.getInfo Error: #{json_response['code']} - #{json_response['message']}" if json_response['stat'] == "fail"
81
+
82
+ json_response
83
+ end
84
+
85
+ # Retrieve a list of images for an album
86
+ #
87
+ # @author David Slone
88
+ # @param {RailsMug::Model::Album} album The album object to find photos for.
89
+ def get_album_photos &album
90
+ response = @access_token.get("/api/json/1.3.0/?method=smugmug.images.get&AlbumID=#{album.id}&AlbumKey=#{album.key}")
91
+ json_response = JSON.parse(response.body)
92
+
93
+ raise RailsMug::AlbumError, "SmugMug images.get Error: #{json_response['code']} - #{json_response['message']}" if json_response['stat'] == "fail"
94
+
95
+ json_response['Album']['Images'].each do |img|
96
+ img = RailsMug::Model::Image.new(
97
+ :id => img['id'],
98
+ :key => img['Key']
99
+ )
100
+ img.get_photo_info @access_token
101
+ album.add_image img
102
+ end
103
+ end
104
+
105
+ end
106
+ end
@@ -0,0 +1,18 @@
1
+ module RailsMug
2
+ API_METHODS = {
3
+ "accounts" => {"browse" => true},
4
+ "albums" => {"applyWatermark" => true, "browse" => true, "changeSettings" => true, "comments" => true, "create" => true, "delete" => true, "get" => true, "getInfo" => true, "getStats" => true, "removeWatermark" => true, "reSort" => true},
5
+ "albumtemplates" => {"changeSettings" => true, "create" => true, "delete" => true, "get" => true}, "auth" => {"checkAccessToken" => true, "getAccessToken" => true, "getRequestToken" => true},
6
+ "categories" => {"create" => true, "delete" => true, "get" => true, "rename" => true}, "communities" => {"get" => true}, "coupons" => {"create" => true, "get" => true, "getInfo" => true, "modify" => true, "restrictions" => true},
7
+ "family" => {"add" => true, "get" => true, "remove" => true, "removeAll" => true}, "fans" => {"get" => true}, "featured" => {"albums" => true}, "friends" => {"add" => true, "get" => true, "remove" => true, "removeAll" => true},
8
+ "images" => {"applyWatermark" => true, "changePosition" => true, "changeSettings" => true, "collect" => true, "comments" => true, "crop" => true, "delete" => true, "get" => true, "getEXIF" => true, "getInfo" => true, "getStats" => true, "getURLs" => true, "removeWatermark" => true, "rotate" => true, "uploadFromURL" => true, "zoomThumbnail" => true},
9
+ "printmarks" => {"create" => true, "delete" => true, "get" => true, "getInfo" => true, "modify" => true},
10
+ "service" => {"ping" => true},
11
+ "sharegroups" => {"albums" => true, "browse" => true, "create" => true, "delete" => true, "get" => true, "getInfo" => true, "modify" => true},
12
+ "styles" => {"getTemplates" => true},
13
+ "subcategories" => {"create" => true, "delete" => true, "get" => true, "getAll" => true, "rename" => true},
14
+ "themes" => {"get" => true},
15
+ "users" => {"getInfo" => true, "getStats" => true, "getTree" => true},
16
+ "watermarks" => {"changeSettings" => true, "create" => true, "delete" => true, "get" => true, "getInfo" => true}
17
+ }
18
+ end
@@ -0,0 +1,27 @@
1
+ module RailsMug
2
+
3
+ # Generic RailsMug error class for all RailsMug errors
4
+ #
5
+ # @author David Slone
6
+ class RailsMugError < StandardError
7
+ end
8
+
9
+ # RailsMug Session Error
10
+ #
11
+ # @author David Slone
12
+ class SessionError < StandardError
13
+ end
14
+
15
+ # RailsMug Album Error
16
+ #
17
+ # @author David Slone
18
+ class AlbumError < StandardError
19
+ end
20
+
21
+ # RailsMug Images Error
22
+ #
23
+ # @author David Slone
24
+ class ImagesError < StandardError
25
+ end
26
+
27
+ end
@@ -0,0 +1,41 @@
1
+ module RailsMug
2
+ class Images
3
+ attr_accessor :images
4
+
5
+ # Initialize Images
6
+ #
7
+ # @author David Slone
8
+ def initialize railsmug_session
9
+ raise RailsMug::SessionError, "Invalid Session (session cannot be nil)" if railsmug_session.nil?
10
+
11
+ self.images = []
12
+ @access_token = railsmug_session.accesstoken
13
+ end
14
+
15
+ # Get all images for an Album
16
+ #
17
+ # @author David Slone
18
+ # @param [Integer] album_id The ID for the album
19
+ # @param [String] album_key The key for the album
20
+ def get_images album_id, album_key, opts = {}
21
+ raise RailsMug::ImagesError, "album_id is required." if album_id.nil?
22
+ raise RailsMug::ImagesError, "album_key is required." if album_key.nil?
23
+
24
+ response = @access_token.get("/api/json/1.3.0/?method=smugmug.images.get&AlbumID=#{album_id}&AlbumKey=#{album_key}")
25
+ json_response = JSON.parse(response.body)
26
+
27
+ raise RailsMug::ImagesError, "SmugMug images.get Error: #{json_response['code']} - #{json_response['message']}" if json_response['stat'] == "fail"
28
+
29
+ json_response['Album']['Images'].each do |img|
30
+ img = RailsMug::Model::Image.new(
31
+ :id => img['id'],
32
+ :key => img['Key']
33
+ )
34
+ img.get_photo_info @access_token unless opts[:no_info]
35
+ self.images << img
36
+ end
37
+
38
+ self.images
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,103 @@
1
+ module RailsMug
2
+ class Model
3
+ class Album < RailsMug::Record
4
+ # The Id for this album
5
+ attr_reader :id
6
+ # The key for this album
7
+ attr_reader :key
8
+ # The category that this album belongs to
9
+ attr_reader :category
10
+ # The sub category that this album belongs to
11
+ attr_reader :sub_category
12
+ # The title for this album
13
+ attr_reader :title
14
+ # The text to be printed on the back of prints purchased from this album
15
+ attr_reader :backprinting
16
+ # Enable boutique packaging for orders from this album
17
+ attr_reader :boutique_packaging
18
+ # Allow images from this album to be ranked using PhotoRank
19
+ attr_reader :can_rank
20
+ # Hide the Description and LastUpdated for this album on the homepage and category pages
21
+ attr_reader :clean
22
+ # The color correction setting for this album (0 - No, 1 - Yes, 2 - Inherit)
23
+ attr_reader :color_correction
24
+ # Allow visitors to leave comments on this album
25
+ attr_reader :comments
26
+ # The community that this album belongs to.
27
+ attr_reader :community
28
+ # The description for this album
29
+ attr_reader :description
30
+ # Allow EXIF data to be viewed for images from this album
31
+ attr_reader :exif
32
+ # Allow images from this album to be linked externally outside SmugMug
33
+ attr_reader :external
34
+ # Allow family to edit the captions and keywords of the images in this album
35
+ attr_reader :family_edit
36
+ # Show filename for images uploaded with no caption to this album
37
+ attr_reader :filenames
38
+ # Allow friends to edit the captions and keywords of the images in this album
39
+ attr_reader :friend_edit
40
+ # Enable mapping features for this album
41
+ attr_reader :geography
42
+ # The URL to allow guests to upload to this gallery
43
+ attr_reader :guest_upload_url
44
+ # Default this album to the standard SmugMug appearance. (false - Custom, true - SmugMug)
45
+ attr_reader :header
46
+ # Hide the owner of this album.
47
+ attr_reader :hide_owner
48
+ # The highlight image for this album {id, Key, Type}
49
+ attr_reader :highlight
50
+ # The number of images in this album
51
+ attr_reader :image_count
52
+ # The meta keyword string for this album
53
+ attr_reader :keywords
54
+ # The URL for this album
55
+ attr_reader :url
56
+
57
+ attr_accessor :images
58
+ attr_accessor :access_token
59
+
60
+ # Display Album in JSON format
61
+ #
62
+ # @author David Slone
63
+ def to_json
64
+ ret = {
65
+ :id => self.id,
66
+ :key => self.key,
67
+ :category => self.category,
68
+ :sub_category => self.sub_category,
69
+ :title => self.title,
70
+ :images => self.images
71
+ }
72
+ end
73
+
74
+ # Retrieve a list of images for an album
75
+ #
76
+ # @author David Slone
77
+ # @param {RailsMug::Model::Album} album The album object to find photos for.
78
+ def get_photos
79
+ response = self.access_token.get("/api/json/1.3.0/?method=smugmug.images.get&AlbumID=#{self.id}&AlbumKey=#{self.key}")
80
+ json_response = JSON.parse(response.body)
81
+
82
+ raise RailsMug::AlbumError, "SmugMug images.get Error: #{json_response['code']} - #{json_response['message']}" if json_response['stat'] == "fail"
83
+
84
+ json_response['Album']['Images'].each do |img|
85
+ img = RailsMug::Model::Image.new(
86
+ :id => img['id'],
87
+ :key => img['Key']
88
+ )
89
+ img.get_photo_info @access_token
90
+ self.add_image img
91
+ end
92
+ end
93
+
94
+ # Add image to album
95
+ #
96
+ # @author David Slone
97
+ def add_image image
98
+ self.images = [] if self.images.nil?
99
+ self.images << image
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,183 @@
1
+ module RailsMug
2
+ class Model
3
+ class Image < RailsMug::Record
4
+ # The Id for this image
5
+ attr_reader :id
6
+ # They key for this image
7
+ attr_reader :key
8
+ # The altitude at which this image (or video) was taken.
9
+ attr_accessor :altitude
10
+ # The caption for this image
11
+ attr_accessor :caption
12
+ # The date for this video
13
+ attr_accessor :date
14
+ # The filename for this image
15
+ attr_accessor :filename
16
+ # The original format of this image
17
+ attr_accessor :format
18
+ # The height of the crop
19
+ attr_accessor :height
20
+ # The visibility of this image
21
+ attr_accessor :hidden
22
+ # The keyword string for this image
23
+ attr_accessor :keywords
24
+ # The url for the Large version of this image
25
+ attr_accessor :large_url
26
+ # The date that this image was last updated
27
+ attr_accessor :last_updated
28
+ # The latitude at which this image was taken
29
+ attr_accessor :latitude
30
+ # The lightbox url for this image
31
+ attr_accessor :lightbox_url
32
+ # Longitude at which the image was taken
33
+ attr_accessor :longitude
34
+ # The MD5 sum for this image
35
+ attr_accessor :md5_sum
36
+ # The url for the Medium version of this image
37
+ attr_accessor :medium_url
38
+ # The url for the Original version of this image
39
+ attr_accessor :original_url
40
+ # The position of this image within the album
41
+ attr_accessor :position
42
+ # The current revision of this image
43
+ attr_accessor :serial
44
+ # The size of this image in bytes
45
+ attr_accessor :size
46
+ # The url for the Small version of this image
47
+ attr_accessor :small_url
48
+ # The status for this image
49
+ attr_accessor :status
50
+ # The url for the Thumb version of this image
51
+ attr_accessor :thumb_url
52
+ # The url for the Tiny version of this image
53
+ attr_accessor :tiny_url
54
+ # The width of the crop
55
+ attr_accessor :width
56
+ # The url for the X2Large version of this image
57
+ attr_accessor :x2large_url
58
+ # The url for the X3Large version of this image
59
+ attr_accessor :x3large_url
60
+ # The url for the XLarge version of this image
61
+ attr_accessor :xlarge_url
62
+ # EXIF Data for this image
63
+ attr_accessor :exif
64
+
65
+ # Retrieve information for an image
66
+ #
67
+ # @author David Slone
68
+ def get_photo_info access_token
69
+ response = access_token.get("/api/json/1.3.0/?method=smugmug.images.getInfo&ImageID=#{self.id}&ImageKey=#{self.key}")
70
+ json_response = JSON.parse(response.body)
71
+
72
+ raise RailsMug::ImagesError, "SmugMug images.getInfo Error: #{json_response['code']} - #{json_response['message']}" if json_response['stat'] == "fail"
73
+
74
+ self.altitude = json_response['Image']['Altitude']
75
+ self.caption = json_response['Image']['Caption']
76
+ self.date = json_response['Image']['Date']
77
+ self.filename = json_response['Image']['FileName']
78
+ self.format = json_response['Image']['Format']
79
+ self.height = json_response['Image']['Height']
80
+ self.hidden = json_response['Image']['Hidden']
81
+ self.keywords = json_response['Image']['Keywords']
82
+ self.large_url = json_response['Image']['LargeURL']
83
+ self.last_updated = json_response['Image']['LastUpdated']
84
+ self.latitude = json_response['Image']['Latitude']
85
+ self.md5_sum = json_response['Image']['MD5Sum']
86
+ self.medium_url = json_response['Image']['MediumURL']
87
+ self.original_url = json_response['Image']['OriginalURL']
88
+ self.position = json_response['Image']['Position']
89
+ self.serial = json_response['Image']['Serial']
90
+ self.size = json_response['Image']['Size']
91
+ self.small_url = json_response['Image']['SmallURL']
92
+ self.status = json_response['Image']['Status']
93
+ self.thumb_url = json_response['Image']['ThumbURL']
94
+ self.tiny_url = json_response['Image']['TinyURL']
95
+ self.width = json_response['Image']['Width']
96
+ self.x2large_url = json_response['Image']['X2LargeURL']
97
+ self.x3large_url = json_response['Image']['X3LargeURL']
98
+ self.xlarge_url = json_response['Image']['XLargeURL']
99
+
100
+ self.get_exif_data access_token
101
+ end
102
+
103
+ # Retrieve Photo EXIF data
104
+ #
105
+ # @author David Slone
106
+ # @param [Object] access_token
107
+ def get_exif_data access_token
108
+ response = access_token.get("/api/json/1.3.0/?method=smugmug.images.getEXIF&ImageID=#{self.id}&ImageKey=#{self.key}")
109
+ json_response = JSON.parse(response.body)
110
+
111
+ raise RailsMug::ImagesError, "SmugMug images.getEXIF Error: #{json_response['code']} - #{json_response['message']}" if json_response['stat'] == "fail"
112
+
113
+ exif = {}
114
+ exif[:id] = json_response['Image']['id']
115
+ exif[:key] = json_response['Image']['Key']
116
+ exif[:aperture] = json_response['Image']['Aperture']
117
+ exif[:brightness] = json_response['Image']['Brightness']
118
+ exif[:ccd_width] = json_response['Image']['CCDWidth']
119
+ exif[:color_space] = json_response['Image']['ColorSpace']
120
+ exif[:compressed_bits_per_pixel] = json_response['Image']['CompressedBitsPerPixel']
121
+ exif[:contrast] = json_response['Image']['Contrast']
122
+ exif[:date_time] = json_response['Image']['DateTime']
123
+ exif[:date_time_digitized] = json_response['Image']['DateTimeDigitized']
124
+ exif[:date_time_original] = json_response['Image']['DateTimeOriginal']
125
+ exif[:digital_zoom_ratio] = json_response['Image']['DigitalZoomRatio']
126
+ exif[:exposure_bias_value] = json_response['Image']['ExposureBiasValue']
127
+ exif[:exposure_mode] = json_response['Image']['ExposureMode']
128
+ exif[:exposure_program] = json_response['Image']['ExposureProgram']
129
+ exif[:exposure_time] = json_response['Image']['ExposureTime']
130
+ exif[:flash] = json_response['Image']['Flash']
131
+ exif[:focal_length] = json_response['Image']['FocalLength']
132
+ exif[:iso] = json_response['Image']['ISO']
133
+ exif[:light_source] = json_response['Image']['LightSource']
134
+ exif[:make] = json_response['Image']['Make']
135
+ exif[:metering] = json_response['Image']['Metering']
136
+ exif[:model] = json_response['Image']['Model']
137
+ exif[:saturation] = json_response['Image']['Saturation']
138
+ exif[:sensing_method] = json_response['Image']['SensingMethod']
139
+ exif[:sharpness] = json_response['Image']['Sharpness']
140
+ exif[:subject_distance] = json_response['Image']['SubjectDistance']
141
+ exif[:subject_distance_range] = json_response['Image']['SubjectDistanceRange']
142
+ exif[:white_balance] = json_response['Image']['WhiteBalance']
143
+
144
+ self.exif = exif
145
+ end
146
+
147
+ # Convert class to JSON object
148
+ #
149
+ # @author David Slone
150
+ def to_json
151
+ ret = {}
152
+ ret[:altitude] = self.altitude
153
+ ret[:caption] = self.caption
154
+ ret[:date] = self.date
155
+ ret[:filename] = self.filename
156
+ ret[:format] = self.format
157
+ ret[:height] = self.height
158
+ ret[:hidden] = self.hidden
159
+ ret[:keywords] = self.keywords
160
+ ret[:large_url] = self.large_url
161
+ ret[:last_updated] = self.last_updated
162
+ ret[:latitude] = self.latitude
163
+ ret[:md5_sum] = self.md5_sum
164
+ ret[:medium_url] = self.medium_url
165
+ ret[:original_url] = self.original_url
166
+ ret[:position] = self.position
167
+ ret[:serial] = self.serial
168
+ ret[:size] = self.size
169
+ ret[:small_url] = self.small_url
170
+ ret[:status] = self.status
171
+ ret[:thumb_url] = self.thumb_url
172
+ ret[:tiny_url] = self.tiny_url
173
+ ret[:width] = self.width
174
+ ret[:x2large_url] = self.x2large_url
175
+ ret[:x3large_url] = self.x3large_url
176
+ ret[:xlarge_url] = self.xlarge_url
177
+ ret[:exif] = self.exif
178
+
179
+ ret
180
+ end
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,12 @@
1
+ module RailsMug
2
+ class Record
3
+ def initialize (params)
4
+ return if params.nil?
5
+
6
+ params.each do |key, value|
7
+ name = key.to_s
8
+ instance_variable_set("@#{name}", value) if respond_to?(name)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,43 @@
1
+ require 'oauth'
2
+
3
+ module RailsMug
4
+
5
+ # Class to establish a RailsMug session. Use it like this:
6
+ #
7
+ # client = RailsMug::Client.new("API KEY", "API SECRET")
8
+ # @author David Slone
9
+ class Session
10
+ attr :session
11
+ attr :accesstoken
12
+
13
+ # Initialize the session
14
+ #
15
+ # @author David Slone
16
+ def initialize(api_key, api_secret, access_token, access_token_secret)
17
+ raise RailsMug::RailsMugError, "Missing parameter(api_key)" if api_key.nil? || api_key.length == 0
18
+ raise RailsMug::RailsMugError, "Missing parameter(api_secret)" if api_secret.nil? || api_secret.length == 0
19
+ raise RailsMug::RailsMugError, "Missing parameter(access_token)" if access_token.nil? || access_token.length == 0
20
+ raise RailsMug::RailsMugError, "Missing parameter(access_token_secret)" if access_token_secret.nil? || access_token_secret.length == 0
21
+
22
+ @consumer = OAuth::Consumer.new(api_key, api_secret, :site => "https://api.smugmug.com/services",
23
+ :request_token_path => "/oauth/getRequestToken.mg", :authorize_path => "/oauth/authorize.mg",
24
+ :access_token_path => "/oauth/getAccessToken.mg")
25
+ @accesstoken = OAuth::AccessToken.new(@consumer, access_token, access_token_secret)
26
+ end
27
+
28
+ # Determine if session is valid
29
+ #
30
+ # @author David Slone
31
+ # @return [Boolean] Returns if the session is valid or not
32
+ def valid_session?
33
+
34
+ end
35
+
36
+ # Method Missing
37
+ #
38
+ # @author David Slone
39
+ def method_missing(method_name, *args)
40
+ puts args
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module RailsMug
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'RailsMug'
2
+
3
+ class TestClient
4
+ def initialize
5
+
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsMug do
4
+ session = RailsMug::Session.new('<API KEY>','<API SECRET>','<ACCESS TOKEN>','<ACCESS TOKEN SECRET>')
5
+
6
+ it "should create oauth session" do
7
+ session.should_not be_nil
8
+ end
9
+
10
+ it "should retrieve album list" do
11
+ rails_mug = RailsMug::Albums.new(session)
12
+ albums = rails_mug.get_albums
13
+ albums.should_not be_nil
14
+ end
15
+
16
+ it "should get photos for an album" do
17
+ rails_mug = RailsMug::Albums.new(session)
18
+ albums = rails_mug.get_albums
19
+
20
+ albums.each do |album|
21
+ album.get_photos
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsMug do
4
+ session = RailsMug::Session.new('<API KEY>','<API SECRET>','<ACCESS TOKEN>','<ACCESS TOKEN SECRET>')
5
+
6
+ it "should get photos without detailed info" do
7
+ rails_mug = RailsMug::Images.new(session)
8
+ images = rails_mug.get_images 28536068, '4b4dGb', :no_info => true
9
+ images.should_not be_nil
10
+ end
11
+
12
+ it "should get photos with detailed info" do
13
+ rails_mug = RailsMug::Images.new(session)
14
+ rails_mug.get_images 28536068, '4b4dGb'
15
+ rails_mug.images.should_not be_nil
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ require 'rspec'
2
+ require 'RailsMug'
3
+ require 'RailsMug_helper'
4
+ require "net/http"
5
+ require "uri"
6
+ require "json"
7
+
8
+ RSpec.configure do |config|
9
+ config.color_enabled = true
10
+ config.formatter = 'documentation'
11
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: RailsMug
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Slone
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.6'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: oauth
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Retrieve SmugMug photo list
47
+ email:
48
+ - dbslone@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE
56
+ - README.md
57
+ - RailsMug.gemspec
58
+ - Rakefile
59
+ - lib/RailsMug.rb
60
+ - lib/RailsMug/albums.rb
61
+ - lib/RailsMug/api_methods.rb
62
+ - lib/RailsMug/exceptions.rb
63
+ - lib/RailsMug/images.rb
64
+ - lib/RailsMug/model/album.rb
65
+ - lib/RailsMug/model/image.rb
66
+ - lib/RailsMug/record.rb
67
+ - lib/RailsMug/session.rb
68
+ - lib/RailsMug/version.rb
69
+ - spec/RailsMug_helper.rb
70
+ - spec/RailsMug_spec.rb
71
+ - spec/images_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: ''
74
+ licenses: []
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.24
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: This gem allows an authenticated user to retrieve the album and photo list
97
+ from an album
98
+ test_files:
99
+ - spec/RailsMug_helper.rb
100
+ - spec/RailsMug_spec.rb
101
+ - spec/images_spec.rb
102
+ - spec/spec_helper.rb
103
+ has_rdoc: