smile 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.yardoc ADDED
Binary file
data/README.rdoc CHANGED
@@ -1,10 +1,17 @@
1
1
  = smile
2
2
 
3
3
  Smile is a simple gem to talk to SmugMug.com.
4
+ This gem wraps the 1.2.0 interface.
4
5
 
5
- New auth accessors
6
+ == New Features
7
+
8
+ === Search feeds
9
+ Smile.search( 'blueberries' ) => [Smile::Photo]
10
+ Smile.search_rss( 'bison' ) => RSS::Parser Feed
11
+ Smile.search_raw( 'grand' ) => Raw response from the feed
12
+
13
+ ===New auth accessors
6
14
  smug = Smile.auth_anonymously
7
- _and_
8
15
  smug = Smile.auth( 'nick', 'pass' )
9
16
 
10
17
 
@@ -16,8 +23,7 @@ New auth accessors
16
23
 
17
24
  album.photos # and see the pretty pics
18
25
 
19
- == or
20
-
26
+ ==== Old auth accessors ( NOTE: These are still supported )
21
27
  smug = Smile::Smug.new
22
28
  smug.auth( 'my_nick', 'my_pass' )
23
29
  albums = smug.albums # theses are mine
@@ -29,8 +35,8 @@ New auth accessors
29
35
 
30
36
  == TODO
31
37
  * Clean up params so they are not case sensitive
32
- * Add in RSS/Atom feeds as search options
33
- * Update Documentation
38
+ * Create better exception handlers
39
+ * Update Documentation ( getting there. it's being published on rdoc.info now )
34
40
  * Plugin in Cucumber
35
41
 
36
42
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 1
3
- :patch: 3
4
2
  :major: 0
3
+ :minor: 2
4
+ :patch: 0
data/lib/smile/base.rb CHANGED
@@ -16,7 +16,6 @@ module Smile
16
16
  # This will be included in every request once you have logged in
17
17
  def default_params
18
18
  base = { :APIKey => API }
19
- #set_session
20
19
  if( session_id )
21
20
  base.merge!( :SessionID => session_id )
22
21
  end
@@ -0,0 +1,61 @@
1
+ module Smile::ParamConverter
2
+ module_function
3
+
4
+ def convert( param, value=nil )
5
+ key = nil
6
+ case param.to_s.downcase.to_sym
7
+ when :popular_category
8
+ key = :popularCategory
9
+ when :geo_all
10
+ key = :geoAll
11
+ when :geo_keyword
12
+ key = :geoKeyword
13
+ when :geo_search
14
+ key = :geoSearch
15
+ when :geo_community
16
+ key = :geoCommunity
17
+ when :open_search_keyword
18
+ key = :openSearchKeyword
19
+ when :user_keyword
20
+ key = :userkeyword
21
+ when :nickname_recent
22
+ key = :nicknameRecent
23
+ when :nickname_popular
24
+ key = :nicknamePopular
25
+ when :user_comments
26
+ key = :userComments
27
+ when :geo_user
28
+ key = :geoUser
29
+ when :geo_album
30
+ key = :geoAlbum
31
+ when :size
32
+ key = :Size
33
+ value = value.titlecase
34
+ when :image_count
35
+ key = :ImageCount
36
+ when :data
37
+ key = :Data
38
+ when :type
39
+ key = :Type
40
+ when :image_id
41
+ key = :ImageID
42
+ when :image_key
43
+ key = :ImageKey
44
+ when :image_count
45
+ key = :ImageCount
46
+ else
47
+ key = param
48
+ end
49
+
50
+ [ key, value ]
51
+ end
52
+
53
+ def clean_hash_keys( hash_to_clean )
54
+ cleaned_hash ={}
55
+ hash_to_clean.each_pair do |key,value|
56
+ cleaned_hash[convert( key ).first] = value
57
+ end
58
+ cleaned_hash
59
+ end
60
+
61
+ end
data/lib/smile/photo.rb CHANGED
@@ -26,12 +26,15 @@ class Smile::Photo < Smile::Base
26
26
 
27
27
  # This will pull a single image from the smugmug
28
28
  #
29
- # * int ImageID
29
+ # * int image_id
30
30
  # * String Password optional
31
31
  # * String SitePassword optional
32
32
  # * String ImageKey
33
33
  #
34
34
  def find( options={} )
35
+ set_session if( session_id.nil? )
36
+ options = Smile::ParamConverter.clean_hash_keys( options )
37
+
35
38
  params = default_params.merge(
36
39
  :method => 'smugmug.images.getInfo'
37
40
  )
@@ -39,6 +42,7 @@ class Smile::Photo < Smile::Base
39
42
  params.merge!( options ) if( options )
40
43
  xml = RestClient.post Smile::Base::BASE, params
41
44
  image = Hash.from_xml( xml )["rsp"]["image"]
45
+
42
46
  image.merge!( :image_id => image["id"] )
43
47
  image.merge!( :album_key => image["album"]["key"] )
44
48
  image.merge!( :album_id => image["album"]["id"] )
data/lib/smile.rb CHANGED
@@ -5,105 +5,126 @@ require 'lib/smile/base'
5
5
  require 'lib/smile/smug'
6
6
  require 'lib/smile/album'
7
7
  require 'lib/smile/photo'
8
+ require 'lib/smile/param_converter'
8
9
  require 'cgi'
9
10
  require 'rss'
10
11
 
11
12
  module Smile
13
+ module_function
14
+
12
15
  def auth_anonymously
13
16
  smug = Smile::Smug.new
14
17
  smug.auth_anonymously
15
18
  smug
16
19
  end
17
- module_function( :auth_anonymously )
18
20
 
19
- def auth( user, pass )
21
+ # Login to SmugMug using a specific user account.
22
+ #
23
+ # @param [String] username The username ( Nickname ) for the SmugMug account
24
+ # @param [String] password The password for the SmugMug account
25
+ #
26
+ # @return [Smile::SmugMug.new] An Smug object that has been authenticated
27
+ def auth( username, password )
20
28
  smug = Smile::Smug.new
21
- smug.auth( user, pass )
29
+ smug.auth( username, password )
22
30
  smug
23
31
  end
24
- module_function( :auth )
25
32
 
26
33
  def base_feed( options={} )
27
34
  options.merge!( :format => 'rss' )
28
35
  url = "http://api.smugmug.com/hack/feed.mg?"
29
36
  url_params =[]
30
37
  options.each_pair do |k,value|
31
- case k.to_s.downcase.to_sym
32
- when :popular_category
33
- key = :popularCategory
34
- when :geo_all
35
- key = :geoAll
36
- when :geo_keyword
37
- key = :geoKeyword
38
- when :geo_search
39
- key = :geoSearch
40
- when :geo_community
41
- key = :geoCommunity
42
- when :open_search_keyword
43
- key = :openSearchKeyword
44
- when :user_keyword
45
- key = :userkeyword
46
- when :nickname_recent
47
- key = :nicknameRecent
48
- when :nickname_popular
49
- key = :nicknamePopular
50
- when :user_comments
51
- key = :userComments
52
- when :geo_user
53
- key = :geoUser
54
- when :geo_album
55
- key = :geoAlbum
56
- when :size
57
- key = :Size
58
- value = value.titlecase
59
- when :image_count
60
- key = :ImageCount
61
- else
62
- key = k
63
- end
38
+ key, value = Smile::ParamConverter.convert( k, value )
64
39
 
65
40
  url_params << "#{key.to_s}=#{ CGI.escape( value ) }"
66
41
  end
67
42
 
68
- content = RestClient.get( url + url_params.join( "&" ) )
69
- RSS::Parser.parse( content, false )
43
+ RestClient.get( url + url_params.join( "&" ) )
70
44
  end
71
- module_function( :base_feed )
45
+ private( :base_feed )
72
46
 
73
- # Search SmugMug for pics.
74
- # By Default it will use the keyword search.
47
+ # Search SmugMug for pics. This search is slower than the others, but returns Smile::Photo objects
48
+ #
49
+ # @param [String] data This is the search term that you want to use
50
+ # @param [optional, Hash] options Hash of options for the search method
51
+ # @option options [optional, String] :keyword override the keyword search
52
+ # @option options [optional, String] :popular Use term all or today
53
+ # @option options [optional, String] :popular_category Use term category ( e.g. cars )
54
+ # @option options [optional, String] :geo_all Geo Stuff
55
+ # @option options [optional, String] :geo_community More Geo Stuff
56
+ # @option options [optional, String] :geo_search Geo Search
57
+ # @option options [optional, String] :open_search_keyword Key word
58
+ # @option options [optional, String] :user_keyword Use term nickname
59
+ # @option options [optional, String] :gallery Use term albumID_albumKey
60
+ # @option options [optional, String] :nickname Use term nickname
61
+ # @option options [optional, String] :nickname_recent Use term nickname
62
+ # @option options [optional, String] :nickname_popular Use term nickname
63
+ # @option options [optional, String] :user_comments Use term nickname
64
+ # @option options [optional, String] :geo_user Use term nickname
65
+ # @option options [optional, String] :geo_album Use term nickname
75
66
  #
76
- # options
77
- # type => [
78
- # keyword
79
- # popular # Use term all or today
80
- # popularCategory # Use term category ( e.g. cars )
81
- # geoAll
82
- # geoKeyword
83
- # geoSearch
84
- # geoCommunity
85
- # openSearchKeyword
86
- # userkeyword # Use term nickname
87
- # gallery # Use term albumID_albumKey
88
- # nickname # Use term nickname
89
- # nicknameRecent # Use term nickname
90
- # nicknamePopular # Use term nickname
91
- # usercomments # Use term nickname
92
- # geoUser # Use term nickname
93
- # geoAlbum # Use term albumID_albumKey
94
- # ]
67
+ # @return [Array<Smile::Photo>] Smile::Photo objects will be returned. This take longer due to
68
+ # pulling more details from every photo.
95
69
  def search( data, options={} )
96
- rss = search_raw( data, options )
97
- rss.items.map{ |item| item.guid.content }
70
+ rss = search_rss( data, options )
98
71
 
72
+ rss.items.map do |item|
73
+ image_id, image_key = item.link.split('/').last.split('#').last.split('_')
74
+ Smile::Photo.find( :image_id => image_id, :image_key => image_key )
75
+ end
99
76
  end
100
- module_function( :search )
101
77
 
102
- # Get the RAW feed
78
+ # Search SmugMug for pics. This search is slower than the others, but returns Smile::Photo objects
79
+ #
80
+ # @param [String] data This is the search term that you want to use
81
+ # @param [optional, Hash] options Hash of options for the search method
82
+ # @option options [optional, String] :keyword override the keyword search
83
+ # @option options [optional, String] :popular Use term all or today
84
+ # @option options [optional, String] :popular_category Use term category ( e.g. cars )
85
+ # @option options [optional, String] :geo_all Geo Stuff
86
+ # @option options [optional, String] :geo_community More Geo Stuff
87
+ # @option options [optional, String] :geo_search Geo Search
88
+ # @option options [optional, String] :open_search_keyword Key word
89
+ # @option options [optional, String] :user_keyword Use term nickname
90
+ # @option options [optional, String] :gallery Use term albumID_albumKey
91
+ # @option options [optional, String] :nickname Use term nickname
92
+ # @option options [optional, String] :nickname_recent Use term nickname
93
+ # @option options [optional, String] :nickname_popular Use term nickname
94
+ # @option options [optional, String] :user_comments Use term nickname
95
+ # @option options [optional, String] :geo_user Use term nickname
96
+ # @option options [optional, String] :geo_album Use term nickname
97
+ #
98
+ # @return [Array<Smile::Photo>] RSS feed from the RSS::Parser.parse method
99
+ def search_rss( data, options={} )
100
+ raw = search_raw( data, options )
101
+ RSS::Parser.parse( raw, false )
102
+ end
103
+
104
+ # Raw feed from the SmugMug data feeds
105
+ #
106
+ # @param [String] data This is the search term that you want to use
107
+ # @param [optional, Hash] options Hash of options for the search method
108
+ # @option options [optional, String] :keyword override the keyword search
109
+ # @option options [optional, String] :popular Use term all or today
110
+ # @option options [optional, String] :popular_category Use term category ( e.g. cars )
111
+ # @option options [optional, String] :geo_all Geo Stuff
112
+ # @option options [optional, String] :geo_community More Geo Stuff
113
+ # @option options [optional, String] :geo_search Geo Search
114
+ # @option options [optional, String] :open_search_keyword Key word
115
+ # @option options [optional, String] :user_keyword Use term nickname
116
+ # @option options [optional, String] :gallery Use term albumID_albumKey
117
+ # @option options [optional, String] :nickname Use term nickname
118
+ # @option options [optional, String] :nickname_recent Use term nickname
119
+ # @option options [optional, String] :nickname_popular Use term nickname
120
+ # @option options [optional, String] :user_comments Use term nickname
121
+ # @option options [optional, String] :geo_user Use term nickname
122
+ # @option options [optional, String] :geo_album Use term nickname
123
+ #
124
+ # @return [RestClientResponse] The response from a RestClient.get request
103
125
  def search_raw( data, options={} )
104
126
  options.merge!( :type => 'keyword', :data => data )
105
127
  base_feed( options )
106
128
  end
107
- module_function( :search_raw )
108
129
  end
109
130
 
data/smile.gemspec CHANGED
@@ -2,24 +2,26 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{smile}
5
- s.version = "0.1.3"
5
+ s.version = "0.2.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["cajun"]
9
- s.date = %q{2009-06-16}
9
+ s.date = %q{2009-07-11}
10
10
  s.email = %q{zac@kleinpeter.org}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
13
13
  "README.rdoc"
14
14
  ]
15
15
  s.files = [
16
- "LICENSE",
16
+ ".yardoc",
17
+ "LICENSE",
17
18
  "README.rdoc",
18
19
  "Rakefile",
19
20
  "VERSION.yml",
20
21
  "lib/smile.rb",
21
22
  "lib/smile/album.rb",
22
23
  "lib/smile/base.rb",
24
+ "lib/smile/param_converter.rb",
23
25
  "lib/smile/photo.rb",
24
26
  "lib/smile/smug.rb",
25
27
  "smile.gemspec",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - cajun
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-16 00:00:00 -05:00
12
+ date: 2009-07-11 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -42,6 +42,7 @@ extra_rdoc_files:
42
42
  - LICENSE
43
43
  - README.rdoc
44
44
  files:
45
+ - .yardoc
45
46
  - LICENSE
46
47
  - README.rdoc
47
48
  - Rakefile
@@ -49,6 +50,7 @@ files:
49
50
  - lib/smile.rb
50
51
  - lib/smile/album.rb
51
52
  - lib/smile/base.rb
53
+ - lib/smile/param_converter.rb
52
54
  - lib/smile/photo.rb
53
55
  - lib/smile/smug.rb
54
56
  - smile.gemspec