flickrie 1.4.2 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
1
+ module Flickrie
2
+ module ApiMethods
3
+ # Fetches information about the set with the given ID.
4
+ #
5
+ # @param set_id [String, Fixnum]
6
+ # @return [Flickrie::Set]
7
+ # @api_method [flickr.photosets.getInfo](http://www.flickr.com/services/api/flickr.photosets.getInfo.html)
8
+ def get_set_info(set_id, params = {})
9
+ response = client.get_set_info(set_id, params)
10
+ Set.from_info(response.body['photoset'])
11
+ end
12
+
13
+ # Fetches sets from a user with the given NSID.
14
+ #
15
+ # @param nsid [String]
16
+ # @return [Flickrie::Collection<Flickrie::Set>]
17
+ # @api_method [flickr.photosets.getList](http://www.flickr.com/services/api/flickr.photosets.getList.html)
18
+ def sets_from_user(nsid, params = {})
19
+ response = client.sets_from_user(nsid, params)
20
+ Set.from_user(response.body['photosets'], nsid)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,45 @@
1
+ module Flickrie
2
+ module ApiMethods
3
+ # Fetches the Flickr user with the given email.
4
+ #
5
+ # @param email [String]
6
+ # @return [Flickrie::User]
7
+ # @api_method [flickr.people.findByEmail](http://www.flickr.com/services/api/flickr.people.findByEmail.html)
8
+ def find_user_by_email(email, params = {})
9
+ response = client.find_user_by_email(email, params)
10
+ User.from_find(response.body['user'])
11
+ end
12
+
13
+ # Fetches the Flickr user with the given username.
14
+ #
15
+ # @param username [String]
16
+ # @return [Flickrie::User]
17
+ # @api_method [flickr.people.findByUsername](http://www.flickr.com/services/api/flickr.people.findByUsername.html)
18
+ def find_user_by_username(username, params = {})
19
+ response = client.find_user_by_username(username, params)
20
+ User.from_find(response.body['user'])
21
+ end
22
+
23
+ # Fetches the Flickr user with the given NSID.
24
+ #
25
+ # @param nsid [String]
26
+ # @return [Flickrie::User]
27
+ # @api_method [flickr.people.getInfo](http://www.flickr.com/services/api/flickr.people.getInfo.html)
28
+ def get_user_info(nsid, params = {})
29
+ response = client.get_user_info(nsid, params)
30
+ User.from_info(response.body['person'])
31
+ end
32
+
33
+ # Returns the upload status of the user who is currently authenticated.
34
+ #
35
+ # @return [Flickrie::User]
36
+ # @api_method [flickr.people.getUploadStatus](http://www.flickr.com/services/api/flickr.people.getUploadStatus.html)
37
+ # @see Flickrie::User#upload_status
38
+ #
39
+ # @note This method requires authentication with "read" permissions.
40
+ def get_upload_status(params = {})
41
+ response = client.get_upload_status(params)
42
+ User.from_upload_status(response.body['user'])
43
+ end
44
+ end
45
+ end
@@ -3,6 +3,11 @@ require 'faraday'
3
3
  module Flickrie
4
4
  class Client < Faraday::Connection
5
5
  def get(method, params = {})
6
+ if params.delete(:include_sizes)
7
+ urls = Photo::FLICKR_SIZES.values.map { |s| "url_#{s}" }.join(',')
8
+ params[:extras] = [params[:extras], urls].compact.join(',')
9
+ end
10
+
6
11
  super() do |req|
7
12
  req.params[:method] = method
8
13
  req.params.update(params)
@@ -179,6 +184,17 @@ module Flickrie
179
184
  get 'flickr.photos.licenses.getInfo', params
180
185
  end
181
186
 
187
+ def set_media_license(media_id, license_id, params = {})
188
+ post 'flickr.photos.licenses.setLicense',
189
+ {:photo_id => media_id, :license_id => license_id}.merge(params)
190
+ end
191
+
192
+ # photos.transform
193
+ def rotate_media(media_id, degrees, params = {})
194
+ post 'flickr.photos.transform.rotate',
195
+ {:photo_id => media_id, :degrees => degrees}.merge(params)
196
+ end
197
+
182
198
  # photosets
183
199
  def get_set_info(set_id, params = {})
184
200
  get 'flickr.photosets.getInfo',
@@ -168,10 +168,8 @@ module Flickrie
168
168
  #
169
169
  # @return [self]
170
170
  def get_info(params = {})
171
- hash = Flickrie.client.get_media_info(id, params).body['photo']
172
- self.class.fix_info(hash)
173
- @hash.deep_merge!(hash)
174
-
171
+ media = Flickrie.send("get_#{media_type}_info", id, params)
172
+ @hash.deep_merge!(media.hash)
175
173
  self
176
174
  end
177
175
 
@@ -179,9 +177,8 @@ module Flickrie
179
177
  #
180
178
  # @return [self]
181
179
  def get_exif(params = {})
182
- hash = Flickrie.client.get_media_exif(id, params).body['photo']
183
- @hash.deep_merge!(hash)
184
-
180
+ media = Flickrie.send("get_#{media_type}_exif", id, params)
181
+ @hash.deep_merge!(media.hash)
185
182
  self
186
183
  end
187
184
 
@@ -189,9 +186,8 @@ module Flickrie
189
186
  #
190
187
  # @return [self]
191
188
  def get_favorites(params = {})
192
- hash = Flickrie.client.get_media_favorites(id, params).body['photo']
193
- @hash.deep_merge!(hash)
194
-
189
+ media = Flickrie.send("get_#{media_type}_favorites", id, params)
190
+ @hash.deep_merge!(media.hash)
195
191
  self
196
192
  end
197
193
 
@@ -201,6 +197,10 @@ module Flickrie
201
197
 
202
198
  private
203
199
 
200
+ def media_type
201
+ self.class.name.split('::').last.downcase
202
+ end
203
+
204
204
  BASE58_ALPHABET = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'.chars.to_a.freeze
205
205
 
206
206
  def to_base58(id)
@@ -94,7 +94,7 @@ module Flickrie
94
94
  from_user(hash)
95
95
  end
96
96
 
97
- #------------------------------------------------------------
97
+ private
98
98
 
99
99
  def fix_extras(hash)
100
100
  if hash['iconserver'] or hash['iconfarm']
@@ -156,6 +156,51 @@ module Flickrie
156
156
  'isfamily' => hash.delete('isfamily')
157
157
  }
158
158
  end
159
+
160
+ def fix_sizes(hash)
161
+ case self.name.split('::').last
162
+ when "Photo"
163
+ hash['usage'] = {
164
+ 'canblog' => hash['canblog'],
165
+ 'canprint' => hash['canprint'],
166
+ 'candownload' => hash['candownload']
167
+ }
168
+ flickr_sizes = {
169
+ 'Square' => Photo::FLICKR_SIZES['Square 75'],
170
+ 'Large Square' => Photo::FLICKR_SIZES['Square 150'],
171
+ 'Thumbnail' => Photo::FLICKR_SIZES['Thumbnail'],
172
+ 'Small' => Photo::FLICKR_SIZES['Small 240'],
173
+ 'Small 320' => Photo::FLICKR_SIZES['Small 320'],
174
+ 'Medium' => Photo::FLICKR_SIZES['Medium 500'],
175
+ 'Medium 640' => Photo::FLICKR_SIZES['Medium 640'],
176
+ 'Medium 800' => Photo::FLICKR_SIZES['Medium 800'],
177
+ 'Large' => Photo::FLICKR_SIZES['Large 1024'],
178
+ 'Large 1600' => Photo::FLICKR_SIZES['Large 1600'],
179
+ 'Large 2048' => Photo::FLICKR_SIZES['Large 2048'],
180
+ 'Original' => Photo::FLICKR_SIZES['Original']
181
+ }
182
+ hash['size'].each do |size_info|
183
+ size_abbr = flickr_sizes[size_info['label']]
184
+ hash["width_#{size_abbr}"] = size_info['width']
185
+ hash["height_#{size_abbr}"] = size_info['height']
186
+ hash["url_#{size_abbr}"] = size_info['source']
187
+ end
188
+ when "Video"
189
+ hash['usage'] = {
190
+ 'canblog' => hash['canblog'],
191
+ 'canprint' => hash['canprint'],
192
+ 'candownload' => hash['candownload']
193
+ }
194
+ hash['video'] ||= {}
195
+ hash['size'].each do |info|
196
+ case info['label']
197
+ when 'Video Player' then hash['video']['source_url'] = info['source']
198
+ when 'Site MP4' then hash['video']['download_url'] = info['source']
199
+ when 'Mobile MP4' then hash['video']['mobile_download_url'] = info['source']
200
+ end
201
+ end
202
+ end
203
+ end
159
204
  end
160
205
  extend(ClassMethods)
161
206
 
@@ -50,7 +50,6 @@ module Flickrie
50
50
  # @return [self]
51
51
  def original() dup.original! end
52
52
 
53
- # @comment Alternate size methods
54
53
  # @return [self]
55
54
  def square75() square(75) end
56
55
  # @return [self]
@@ -117,10 +116,8 @@ module Flickrie
117
116
  #
118
117
  # @return [self]
119
118
  def get_sizes(params = {})
120
- hash = Flickrie.client.get_media_sizes(id, params).body['sizes']
121
- self.class.fix_sizes(hash)
122
- @hash.deep_merge!(hash)
123
-
119
+ photo = Flickrie.get_photo_sizes(id, params)
120
+ @hash.deep_merge!(photo.hash)
124
121
  largest!
125
122
  end
126
123
 
@@ -138,33 +135,5 @@ module Flickrie
138
135
  def size_abbr
139
136
  FLICKR_SIZES[size]
140
137
  end
141
-
142
- def self.fix_sizes(hash)
143
- hash['usage'] = {
144
- 'canblog' => hash['canblog'],
145
- 'canprint' => hash['canprint'],
146
- 'candownload' => hash['candownload']
147
- }
148
- flickr_sizes = {
149
- 'Square' => FLICKR_SIZES['Square 75'],
150
- 'Large Square' => FLICKR_SIZES['Square 150'],
151
- 'Thumbnail' => FLICKR_SIZES['Thumbnail'],
152
- 'Small' => FLICKR_SIZES['Small 240'],
153
- 'Small 320' => FLICKR_SIZES['Small 320'],
154
- 'Medium' => FLICKR_SIZES['Medium 500'],
155
- 'Medium 640' => FLICKR_SIZES['Medium 640'],
156
- 'Medium 800' => FLICKR_SIZES['Medium 800'],
157
- 'Large' => FLICKR_SIZES['Large 1024'],
158
- 'Large 1600' => FLICKR_SIZES['Large 1600'],
159
- 'Large 2048' => FLICKR_SIZES['Large 2048'],
160
- 'Original' => FLICKR_SIZES['Original']
161
- }
162
- hash['size'].each do |size_info|
163
- size_abbr = flickr_sizes[size_info['label']]
164
- hash["width_#{size_abbr}"] = size_info['width']
165
- hash["height_#{size_abbr}"] = size_info['height']
166
- hash["url_#{size_abbr}"] = size_info['source']
167
- end
168
- end
169
138
  end
170
139
  end
@@ -1,3 +1,3 @@
1
1
  module Flickrie
2
- VERSION = "1.4.2"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -32,11 +32,9 @@ module Flickrie
32
32
  #
33
33
  # @return [self]
34
34
  def get_sizes(params = {})
35
- hash = Flickrie.client.get_media_sizes(id, params).body['sizes']
36
- self.class.fix_sizes(hash)
37
- @hash.deep_merge!(hash)
35
+ video = Flickrie.get_video_sizes(id, params)
36
+ @hash.deep_merge!(video.hash)
38
37
  @video = @hash['video']
39
-
40
38
  self
41
39
  end
42
40
 
@@ -46,7 +44,6 @@ module Flickrie
46
44
  def get_info(params = {})
47
45
  super
48
46
  @video = @hash['video']
49
-
50
47
  self
51
48
  end
52
49
 
@@ -56,21 +53,5 @@ module Flickrie
56
53
  super
57
54
  @video = hash['video'] || {}
58
55
  end
59
-
60
- def self.fix_sizes(hash)
61
- hash['usage'] = {
62
- 'canblog' => hash['canblog'],
63
- 'canprint' => hash['canprint'],
64
- 'candownload' => hash['candownload']
65
- }
66
- hash['video'] ||= {}
67
- hash['size'].each do |info|
68
- case info['label']
69
- when 'Video Player' then hash['video']['source_url'] = info['source']
70
- when 'Site MP4' then hash['video']['download_url'] = info['source']
71
- when 'Mobile MP4' then hash['video']['mobile_download_url'] = info['source']
72
- end
73
- end
74
- end
75
56
  end
76
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flickrie
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-31 00:00:00.000000000 Z
12
+ date: 2012-06-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday_middleware
16
- requirement: &70280592734220 !ruby/object:Gem::Requirement
16
+ requirement: &70316886740000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: '0.9'
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *70280592734220
27
+ version_requirements: *70316886740000
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: faraday
30
- requirement: &70280592731780 !ruby/object:Gem::Requirement
30
+ requirement: &70316886737500 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -38,10 +38,10 @@ dependencies:
38
38
  version: '0.9'
39
39
  type: :runtime
40
40
  prerelease: false
41
- version_requirements: *70280592731780
41
+ version_requirements: *70316886737500
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: simple_oauth
44
- requirement: &70280592729520 !ruby/object:Gem::Requirement
44
+ requirement: &70316886735040 !ruby/object:Gem::Requirement
45
45
  none: false
46
46
  requirements:
47
47
  - - ~>
@@ -49,10 +49,10 @@ dependencies:
49
49
  version: '0.1'
50
50
  type: :runtime
51
51
  prerelease: false
52
- version_requirements: *70280592729520
52
+ version_requirements: *70316886735040
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: multi_xml
55
- requirement: &70280592727860 !ruby/object:Gem::Requirement
55
+ requirement: &70316886733520 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
58
  - - ~>
@@ -60,10 +60,10 @@ dependencies:
60
60
  version: '0.4'
61
61
  type: :runtime
62
62
  prerelease: false
63
- version_requirements: *70280592727860
63
+ version_requirements: *70316886733520
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: bundler
66
- requirement: &70280592726880 !ruby/object:Gem::Requirement
66
+ requirement: &70316886723980 !ruby/object:Gem::Requirement
67
67
  none: false
68
68
  requirements:
69
69
  - - ~>
@@ -71,10 +71,10 @@ dependencies:
71
71
  version: '1.0'
72
72
  type: :development
73
73
  prerelease: false
74
- version_requirements: *70280592726880
74
+ version_requirements: *70316886723980
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rake
77
- requirement: &70280592712880 !ruby/object:Gem::Requirement
77
+ requirement: &70316886722120 !ruby/object:Gem::Requirement
78
78
  none: false
79
79
  requirements:
80
80
  - - ~>
@@ -82,10 +82,10 @@ dependencies:
82
82
  version: '0.9'
83
83
  type: :development
84
84
  prerelease: false
85
- version_requirements: *70280592712880
85
+ version_requirements: *70316886722120
86
86
  - !ruby/object:Gem::Dependency
87
87
  name: rspec
88
- requirement: &70280592710720 !ruby/object:Gem::Requirement
88
+ requirement: &70316886720440 !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
91
  - - ! '>='
@@ -96,10 +96,10 @@ dependencies:
96
96
  version: '3'
97
97
  type: :development
98
98
  prerelease: false
99
- version_requirements: *70280592710720
99
+ version_requirements: *70316886720440
100
100
  - !ruby/object:Gem::Dependency
101
101
  name: vcr
102
- requirement: &70280592708920 !ruby/object:Gem::Requirement
102
+ requirement: &70316886719040 !ruby/object:Gem::Requirement
103
103
  none: false
104
104
  requirements:
105
105
  - - ~>
@@ -107,13 +107,16 @@ dependencies:
107
107
  version: '2.1'
108
108
  type: :development
109
109
  prerelease: false
110
- version_requirements: *70280592708920
110
+ version_requirements: *70316886719040
111
111
  description: This gem wraps the Flickr API with a nice object-oriented interface.
112
112
  email: janko.marohnic@gmail.com
113
113
  executables: []
114
114
  extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
+ - lib/flickrie/api_methods/media.rb
118
+ - lib/flickrie/api_methods/set.rb
119
+ - lib/flickrie/api_methods/user.rb
117
120
  - lib/flickrie/api_methods.rb
118
121
  - lib/flickrie/client.rb
119
122
  - lib/flickrie/collection.rb
@@ -142,7 +145,7 @@ files:
142
145
  - README.md
143
146
  - LICENSE
144
147
  - .yardopts
145
- homepage: https://github.com/janko-m/flickrie
148
+ homepage: http://janko-m.github.com/flickrie/
146
149
  licenses:
147
150
  - MIT
148
151
  post_install_message:
@@ -163,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
166
  version: '0'
164
167
  segments:
165
168
  - 0
166
- hash: -4441436478789796734
169
+ hash: 3210841569562279184
167
170
  requirements: []
168
171
  rubyforge_project:
169
172
  rubygems_version: 1.8.11