flickrie 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -232,8 +232,8 @@ default.
232
232
 
233
233
  ## Issues
234
234
 
235
- Please, feel free to post any issues that you're having, I will be happy
236
- to help. I will also be happy if you let me know about any bugs.
235
+ Please, feel free to post any issues that you're having. You can also
236
+ post feature requests.
237
237
 
238
238
  ## Cedits
239
239
 
@@ -250,6 +250,7 @@ basis of this gem.
250
250
  "flickr.people.getInfo" -> Flickrie.get_user_info
251
251
  "flickr.people.getPhotos" -> Flickrie.photos_from_user
252
252
  "flickr.people.getPublicPhotos" -> Flickrie.public_photos_from_user
253
+ "flickr.people.getUploadStatus" -> Flickrie.get_upload_status
253
254
 
254
255
  # photos
255
256
  "flickr.photos.addTags" -> Flickrie.add_photo_tags
@@ -261,6 +262,7 @@ basis of this gem.
261
262
  "flickr.photos.getExif" -> Flickrie.get_photo_exif
262
263
  "flickr.photos.getFavorites" -> Flickrie.get_photo_favorites
263
264
  "flickr.photos.getInfo" -> Flickrie.get_photo_info
265
+ "flickr.photos.getNotInSet" -> Flickrie.photos_not_in_set
264
266
  "flickr.photos.getSizes" -> Flickrie.get_photo_sizes
265
267
  "flickr.photos.removeTag" -> Flickrie.remove_photo_tag
266
268
  "flickr.photos.search" -> Flickrie.search_photos
@@ -284,6 +286,10 @@ basis of this gem.
284
286
 
285
287
  You can see the changelog [here](https://github.com/janko-m/flickrie/blob/master/CHANGELOG.md).
286
288
 
289
+ ## Social
290
+
291
+ You can follow me on Twitter, I'm **@m_janko**.
292
+
287
293
  ## License
288
294
 
289
295
  [MIT](https://github.com/janko-m/flickrie/blob/master/LICENSE)
@@ -1,17 +1,3 @@
1
- require 'flickrie/middleware'
2
- require 'flickrie/client'
3
- require 'flickrie/upload_client'
4
- require 'flickrie/oauth'
5
- require 'flickrie/license'
6
- require 'flickrie/user'
7
- require 'flickrie/media'
8
- require 'flickrie/photo'
9
- require 'flickrie/video'
10
- require 'flickrie/set'
11
- require 'flickrie/media_count'
12
- require 'flickrie/ticket'
13
- require 'flickrie/core_ext'
14
-
15
1
  module Flickrie
16
2
  module ApiMethods
17
3
  # For uploading photos and videos to Flickr. Example:
@@ -93,7 +79,7 @@ module Flickrie
93
79
  # Fetches photos and videos from the Flickr user with the given NSID.
94
80
  #
95
81
  # @param nsid [String]
96
- # @return [Array<Flickrie::Photo, Flickrie::Video>]
82
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
97
83
  # @api_method [flickr.people.getPhotos](http://www.flickr.com/services/api/flickr.people.getPhotos.html)
98
84
  #
99
85
  # @note This method requires authentication with "read" permissions.
@@ -104,7 +90,7 @@ module Flickrie
104
90
  # Fetches photos from the Flickr user with the given NSID.
105
91
  #
106
92
  # @param nsid [String]
107
- # @return [Array<Flickrie::Photo>]
93
+ # @return [Flickrie::Collection<Flickrie::Photo>]
108
94
  # @api_method [flickr.people.getPhotos](http://www.flickr.com/services/api/flickr.people.getPhotos.html)
109
95
  #
110
96
  # @note This method requires authentication with "read" permissions.
@@ -115,7 +101,7 @@ module Flickrie
115
101
  # Fetches videos from the Flickr user with the given NSID.
116
102
  #
117
103
  # @param nsid [String]
118
- # @return [Array<Flickrie::Video>]
104
+ # @return [Flickrie::Collection<Flickrie::Video>]
119
105
  # @api_method [flickr.people.getPhotos](http://www.flickr.com/services/api/flickr.people.getPhotos.html)
120
106
  #
121
107
  # @note This method requires authentication with "read" permissions.
@@ -128,7 +114,7 @@ module Flickrie
128
114
  # NSID.
129
115
  #
130
116
  # @param nsid [String]
131
- # @return [Array<Flickrie::Photo, Flickrie::Video>]
117
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
132
118
  # @api_method [flickr.people.getPublicPhotos](http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html)
133
119
  def public_media_from_user(nsid, params = {})
134
120
  response = client.public_media_from_user(nsid, params)
@@ -137,7 +123,7 @@ module Flickrie
137
123
  # Fetches public photos from the Flickr user with the given NSID.
138
124
  #
139
125
  # @param nsid [String]
140
- # @return [Array<Flickrie::Photo>]
126
+ # @return [Flickrie::Collection<Flickrie::Photo>]
141
127
  # @api_method [flickr.people.getPublicPhotos](http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html)
142
128
  def public_photos_from_user(nsid, params = {})
143
129
  public_media_from_user(nsid, params).
@@ -146,13 +132,25 @@ module Flickrie
146
132
  # Fetches public videos from the Flickr user with the given NSID.
147
133
  #
148
134
  # @param nsid [String]
149
- # @return [Array<Flickrie::Video>]
135
+ # @return [Flickrie::Collection<Flickrie::Video>]
150
136
  # @api_method [flickr.people.getPublicPhotos](http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html)
151
137
  def public_videos_from_user(nsid, params = {})
152
138
  public_media_from_user(nsid, params).
153
139
  select { |media| media.is_a?(Video) }
154
140
  end
155
141
 
142
+ # Returns the upload status of the user who is currently authenticated.
143
+ #
144
+ # @return [Flickrie::User]
145
+ # @api_method [flickr.people.getUploadStatus](http://www.flickr.com/services/api/flickr.people.getUploadStatus.html)
146
+ # @see Flickrie::User#upload_status
147
+ #
148
+ # @note This method requires authentication with "read" permissions.
149
+ def get_upload_status(params = {})
150
+ response = client.get_upload_status(params)
151
+ User.from_upload_status(response.body['user'])
152
+ end
153
+
156
154
  # Add tags to the photo/video with the given ID.
157
155
  #
158
156
  # @param media_id [String, Fixnum]
@@ -185,7 +183,7 @@ module Flickrie
185
183
  # Fetches photos and videos from contacts of the user who authenticated.
186
184
  #
187
185
  # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
188
- # @return [Array<Flickrie::Photo, Flickrie::Video>]
186
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
189
187
  # @api_method [flickr.photos.getContactsPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html)
190
188
  #
191
189
  # @note This method requires authentication with "read" permissions.
@@ -196,7 +194,7 @@ module Flickrie
196
194
  # Fetches photos from contacts of the user who authenticated.
197
195
  #
198
196
  # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
199
- # @return [Array<Flickrie::Photo>]
197
+ # @return [Flickrie::Collection<Flickrie::Photo>]
200
198
  # @api_method [flickr.photos.getContactsPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html)
201
199
  #
202
200
  # @note This method requires authentication with "read" permissions.
@@ -206,7 +204,7 @@ module Flickrie
206
204
  # Fetches videos from contacts of the user who authenticated.
207
205
  #
208
206
  # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
209
- # @return [Array<Flickrie::Video>]
207
+ # @return [Flickrie::Collection<Flickrie::Video>]
210
208
  # @api_method [flickr.photos.getContactsPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html)
211
209
  #
212
210
  # @note This method requires authentication with "read" permissions.
@@ -219,6 +217,7 @@ module Flickrie
219
217
  #
220
218
  # @param nsid [String]
221
219
  # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
220
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
222
221
  # @api_method [flickr.photos.getContactsPublicPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html)
223
222
  def public_media_from_user_contacts(nsid, params = {})
224
223
  response = client.public_media_from_user_contacts(nsid, params)
@@ -229,6 +228,7 @@ module Flickrie
229
228
  #
230
229
  # @param nsid [String]
231
230
  # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
231
+ # @return [Flickrie::Collection<Flickrie::Photo>]
232
232
  # @api_method [flickr.photos.getContactsPublicPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html)
233
233
  def public_photos_from_user_contacts(nsid, params = {})
234
234
  public_media_from_user_contacts(nsid, params).
@@ -239,10 +239,11 @@ module Flickrie
239
239
  #
240
240
  # @param nsid [String]
241
241
  # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
242
+ # @return [Flickrie::Collection<Flickrie::Video>]
242
243
  # @api_method [flickr.photos.getContactsPublicPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html)
243
244
  def public_videos_from_user_contacts(nsid, params = {})
244
245
  public_media_from_user_contacts(nsid, params).
245
- select { |media| media.is_a?(Photo) }
246
+ select { |media| media.is_a?(Video) }
246
247
  end
247
248
 
248
249
  # Fetches context of the photo/video with the given ID. Example:
@@ -358,6 +359,38 @@ module Flickrie
358
359
  alias get_photo_info get_media_info
359
360
  alias get_video_info get_media_info
360
361
 
362
+ # Fetches photos and videos from the authenticated user
363
+ # that are not in any set.
364
+ #
365
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
366
+ # @api_method [flickr.photos.getNotInSet](http://www.flickr.com/services/api/flickr.photos.getNotInSet.html)
367
+ #
368
+ # @note This method requires authentication with "read" permissions.
369
+ def media_not_in_set(params = {})
370
+ response = client.media_not_in_set(params)
371
+ Media.from_not_in_set(response.body['photos'])
372
+ end
373
+ # Fetches photos from the authenticated user
374
+ # that are not in any set.
375
+ #
376
+ # @return [Flickrie::Collection<Flickrie::Photo>]
377
+ # @api_method [flickr.photos.getNotInSet](http://www.flickr.com/services/api/flickr.photos.getNotInSet.html)
378
+ #
379
+ # @note This method requires authentication with "read" permissions.
380
+ def photos_not_in_set(params = {})
381
+ media_not_in_set(params.merge(:media => "photos"))
382
+ end
383
+ # Fetches videos from the authenticated user
384
+ # that are not in any set.
385
+ #
386
+ # @return [Flickrie::Collection<Flickrie::Video>]
387
+ # @api_method [flickr.photos.getNotInSet](http://www.flickr.com/services/api/flickr.photos.getNotInSet.html)
388
+ #
389
+ # @note This method requires authentication with "read" permissions.
390
+ def videos_not_in_set(params = {})
391
+ media_not_in_set(params.merge(:media => "videos"))
392
+ end
393
+
361
394
  # Fetches the sizes of the photo with the given ID. Example:
362
395
  #
363
396
  # photo = Flickrie.get_photo_sizes(242348)
@@ -370,7 +403,7 @@ module Flickrie
370
403
  # @api_method [flickr.photos.getSizes](http://www.flickr.com/services/api/flickr.photos.getSizes.html)
371
404
  def get_photo_sizes(photo_id, params = {})
372
405
  response = client.get_media_sizes(photo_id, params)
373
- Photo.from_sizes(response.body['sizes'])
406
+ Photo.from_sizes(response.body['sizes'].merge('id' => photo_id.to_s))
374
407
  end
375
408
  # Fetches the sizes of the video with the given ID. Example:
376
409
  #
@@ -382,7 +415,7 @@ module Flickrie
382
415
  # @api_method [flickr.photos.getSizes](http://www.flickr.com/services/api/flickr.photos.getSizes.html)
383
416
  def get_video_sizes(video_id, params = {})
384
417
  response = client.get_media_sizes(video_id, params)
385
- Video.from_sizes(response.body['sizes'])
418
+ Video.from_sizes(response.body['sizes'].merge('id' => video_id.to_s))
386
419
  end
387
420
 
388
421
  # Remove the tag with the given ID
@@ -402,7 +435,7 @@ module Flickrie
402
435
  # Fetches photos and videos matching a certain criteria.
403
436
  #
404
437
  # @param search_params [Hash] Options for searching (see the link below under "Flickr API method")
405
- # @return [Array<Flickrie::Photo, Flickrie::Video>]
438
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
406
439
  # @api_method [flickr.photos.search](http://www.flickr.com/services/api/flickr.photos.search.html)
407
440
  def search_media(search_params = {})
408
441
  response = client.search_media(search_params)
@@ -411,7 +444,7 @@ module Flickrie
411
444
  # Fetches photos matching a certain criteria.
412
445
  #
413
446
  # @param search_params [Hash] Options for searching (see the link below under "Flickr API method")
414
- # @return [Array<Flickrie::Photo>]
447
+ # @return [Flickrie::Collection<Flickrie::Photo>]
415
448
  # @api_method [flickr.photos.search](http://www.flickr.com/services/api/flickr.photos.search.html)
416
449
  def search_photos(search_params = {})
417
450
  search_media(search_params.merge(:media => 'photos'))
@@ -419,7 +452,7 @@ module Flickrie
419
452
  # Fetches videos matching a certain criteria.
420
453
  #
421
454
  # @param search_params [Hash] Options for searching (see the link below under "Flickr API method")
422
- # @return [Array<Flickrie::Video>]
455
+ # @return [Flickrie::Collection<Flickrie::Video>]
423
456
  # @api_method [flickr.photos.search](http://www.flickr.com/services/api/flickr.photos.search.html)
424
457
  def search_videos(search_params = {})
425
458
  search_media(search_params.merge(:media => 'videos'))
@@ -468,7 +501,7 @@ module Flickrie
468
501
  # Fetches sets from a user with the given NSID.
469
502
  #
470
503
  # @param nsid [String]
471
- # @return [Array<Flickrie::Set>]
504
+ # @return [Flickrie::Collection<Flickrie::Set>]
472
505
  # @api_method [flickr.photosets.getList](http://www.flickr.com/services/api/flickr.photosets.getList.html)
473
506
  def sets_from_user(nsid, params = {})
474
507
  response = client.sets_from_user(nsid, params)
@@ -479,7 +512,7 @@ module Flickrie
479
512
  #
480
513
  # @param set_id [String]
481
514
  # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
482
- # @return [Array<Flickrie::Photo, Flickrie::Video>]
515
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
483
516
  # @api_method [flickr.photosets.getPhotos](http://www.flickr.com/services/api/flickr.photosets.getPhotos.html)
484
517
  def media_from_set(set_id, params = {})
485
518
  response = client.media_from_set(set_id, params)
@@ -489,7 +522,7 @@ module Flickrie
489
522
  #
490
523
  # @param set_id [String]
491
524
  # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
492
- # @return [Array<Flickrie::Photo>]
525
+ # @return [Flickrie::Collection<Flickrie::Photo>]
493
526
  # @api_method [flickr.photosets.getPhotos](http://www.flickr.com/services/api/flickr.photosets.getPhotos.html)
494
527
  def photos_from_set(set_id, params = {})
495
528
  media_from_set(set_id, params.merge(:media => 'photos'))
@@ -498,7 +531,7 @@ module Flickrie
498
531
  #
499
532
  # @param set_id [String]
500
533
  # @param params [Hash] Options for this API method (see the link below under "Flickr API method")
501
- # @return [Array<Flickrie::Video>]
534
+ # @return [Flickrie::Collection<Flickrie::Video>]
502
535
  # @api_method [flickr.photosets.getPhotos](http://www.flickr.com/services/api/flickr.photosets.getPhotos.html)
503
536
  def videos_from_set(set_id, params = {})
504
537
  media_from_set(set_id, params.merge(:media => 'videos'))
@@ -42,6 +42,10 @@ module Flickrie
42
42
  ensure_media({:user_id => nsid}.merge(params))
43
43
  end
44
44
 
45
+ def get_upload_status(params = {})
46
+ get 'flickr.people.getUploadStatus', params
47
+ end
48
+
45
49
  # photos
46
50
  def add_media_tags(media_id, tags, params = {})
47
51
  post 'flickr.photos.addTags',
@@ -86,6 +90,10 @@ module Flickrie
86
90
  {:photo_id => media_id}.merge(params)
87
91
  end
88
92
 
93
+ def media_not_in_set(params = {})
94
+ get 'flickr.photos.getNotInSet', ensure_media(params)
95
+ end
96
+
89
97
  def get_media_sizes(media_id, params = {})
90
98
  get 'flickr.photos.getSizes',
91
99
  {:photo_id => media_id}.merge(params)
@@ -0,0 +1,39 @@
1
+ if Flickrie.pagination == :will_paginate
2
+ require 'will_paginate/collection'
3
+ end
4
+
5
+ module Flickrie
6
+ # You can think of this as a richer Array. It defines some pagination attributes
7
+ # (you can evem use it with [will_paginate](https://github.com/mislav/will_paginate),
8
+ # see {Flickrie.pagination}). It also has the method {#find} which finds by ID
9
+ # (just like ActiveRecord).
10
+ class Collection < (defined?(WillPaginate) ? WillPaginate::Collection : Array)
11
+ attr_reader :current_page, :per_page, :total_entries, :total_pages
12
+
13
+ def initialize(params)
14
+ hash = params[:pagination]
15
+ if defined?(WillPaginate)
16
+ @current_page = WillPaginate::PageNumber(Integer(hash['page']))
17
+ else
18
+ @current_page = Integer(hash['page'])
19
+ end
20
+ @per_page = Integer(hash['per_page'] || hash['perpage'])
21
+ @total_entries = Integer(hash['total'])
22
+ @total_pages = Integer(hash['pages'])
23
+
24
+ Array.instance_method(:initialize).bind(self).call(params[:array])
25
+ end
26
+
27
+ # Finds an object by ID (just like ActiveRecord does). This is just a
28
+ # shorthand for
29
+ #
30
+ # find { |object| object.id == id }
31
+ def find(id = nil)
32
+ if block_given?
33
+ super
34
+ else
35
+ super() { |object| object.id == id.to_s }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,8 +1,4 @@
1
1
  class Hash
2
- def deep_merge(other_hash)
3
- dup.deep_merge!(other_hash)
4
- end
5
-
6
2
  def deep_merge!(other_hash)
7
3
  other_hash.each_pair do |k,v|
8
4
  tv = self[k]
@@ -10,4 +6,17 @@ class Hash
10
6
  end
11
7
  self
12
8
  end
9
+
10
+ def deep_merge(other_hash)
11
+ dup.deep_merge!(other_hash)
12
+ end
13
+
14
+ def except!(*keys)
15
+ keys.each { |key| delete(key) }
16
+ self
17
+ end
18
+
19
+ def except(*keys)
20
+ self.dup.except!(*keys)
21
+ end
13
22
  end
@@ -3,14 +3,18 @@ module Flickrie
3
3
  # @private
4
4
  module ClassMethods
5
5
  def from_set(hash)
6
- hash['photo'].map do |individual_hash|
6
+ hash['photo'].map! do |individual_hash|
7
7
  individual_hash['owner'] = {
8
+ 'id' => hash['owner'],
8
9
  'nsid' => hash['owner'],
9
10
  'username' => hash['ownername'],
10
11
  }
11
12
  fix_extras(individual_hash)
12
13
  new(individual_hash)
13
14
  end
15
+
16
+ Collection.new :array => hash.delete('photo'),
17
+ :pagination => hash
14
18
  end
15
19
 
16
20
  def from_info(hash)
@@ -19,8 +23,9 @@ module Flickrie
19
23
  end
20
24
 
21
25
  def from_user(hash)
22
- hash['photo'].map do |individual_hash|
26
+ hash['photo'].map! do |individual_hash|
23
27
  individual_hash['owner'] = {
28
+ 'id' => individual_hash['owner'],
24
29
  'nsid' => individual_hash.delete('owner'),
25
30
  'username' => individual_hash.delete('ownername')
26
31
  }
@@ -28,6 +33,9 @@ module Flickrie
28
33
  fix_visibility(individual_hash)
29
34
  new(individual_hash)
30
35
  end
36
+
37
+ Collection.new :array => hash.delete('photo'),
38
+ :pagination => hash
31
39
  end
32
40
 
33
41
  def from_sizes(hash)
@@ -55,6 +63,10 @@ module Flickrie
55
63
  count, previous_photo, next_photo
56
64
  end
57
65
 
66
+ def from_not_in_set(hash)
67
+ from_user(hash)
68
+ end
69
+
58
70
  def fix_extras(hash)
59
71
  if hash['iconserver'] or hash['iconfarm']
60
72
  hash['owner'] ||= {}
@@ -18,7 +18,7 @@ module Flickrie
18
18
  # :url, :visibility, :primary?, :favorite?, :can_comment?,
19
19
  # :can_add_meta?, :can_everyone_comment?, :can_everyone_add_meta?,
20
20
  # :can_download?, :can_blog?, :can_print?, :can_share?,
21
- # :has_people?, :faved?, :notes, :favorites, :hash
21
+ # :has_people?, :faved?, :notes, :favorites, :hash, :short_url
22
22
 
23
23
  # @return [String]
24
24
  def id() @hash['id'] end
@@ -100,6 +100,10 @@ module Flickrie
100
100
  "http://www.flickr.com" + @hash['url']
101
101
  end
102
102
  end
103
+ # @return [String]
104
+ def short_url
105
+ "http://flic.kr/p/#{to_base58(id)}" rescue nil
106
+ end
103
107
 
104
108
  # @return [Flickrie::Media::Visibility]
105
109
  def visibility() Visibility.new(@hash['visibility']) rescue nil end
@@ -181,5 +185,19 @@ module Flickrie
181
185
  def initialize(hash = {})
182
186
  @hash = hash
183
187
  end
188
+
189
+ private
190
+
191
+ BASE58_ALPHABET = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'.chars.to_a.freeze
192
+
193
+ def to_base58(id)
194
+ id = Integer(id)
195
+ begin
196
+ id, remainder = id.divmod(58)
197
+ result = BASE58_ALPHABET[remainder] + (result || '')
198
+ end while id > 0
199
+
200
+ result
201
+ end
184
202
  end
185
203
  end
data/lib/flickrie/set.rb CHANGED
@@ -43,19 +43,19 @@ module Flickrie
43
43
 
44
44
  # Same as calling `Flickrie.photos_from_set(set.id)`.
45
45
  #
46
- # @return [Array<Flickrie::Photo>]
46
+ # @return [Flickrie::Collection<Flickrie::Photo>]
47
47
  def photos(params = {})
48
48
  Flickrie.photos_from_set(id, params)
49
49
  end
50
50
  # Same as calling `Flickrie.videos_from_set(set.id)`.
51
51
  #
52
- # @return [Array<Flickrie::Video>]
52
+ # @return [Flickrie::Collection<Flickrie::Video>]
53
53
  def videos(params = {})
54
54
  Flickrie.videos_from_set(id, params)
55
55
  end
56
56
  # Same as calling `Flickrie.media_from_set(set.id)`.
57
57
  #
58
- # @return [Array<Flickrie::Photo, Flickrie::Video>]
58
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
59
59
  def media(params = {})
60
60
  Flickrie.media_from_set(id, params)
61
61
  end
@@ -0,0 +1,54 @@
1
+ module Flickrie
2
+ class User
3
+ class UploadStatus
4
+ # @!parse attr_reader :bandwidth, :maximum_photo_size,
5
+ # :maximum_video_size, :videos_uploaded, :videos_remaining,
6
+ # :sets_created, :sets_remaining
7
+
8
+ # Returns the monthly bandwidth. Example:
9
+ #
10
+ # user.bandwidth.maximum # => 300
11
+ # user.bandwidth.used # => 120
12
+ # user.bandwidth.remaining # => 180
13
+ # user.bandwidth.unlimited? # => false
14
+ #
15
+ # All numbers are in megabytes
16
+ #
17
+ # @return [Class]
18
+ def bandwidth
19
+ bandwidth = Class.new do
20
+ def maximum() @hash['maxkb'].to_f / 1024 end
21
+ def used() @hash['usedkb'].to_f / 1024 end
22
+ def remaining() @hash['remainingkb'].to_f / 1024 end
23
+
24
+ def unlimited?() @hash['unlimited'].to_i == 1 end
25
+
26
+ def initialize(hash)
27
+ raise ArgumentError if hash.nil?
28
+ @hash = hash
29
+ end
30
+ end
31
+
32
+ bandwidth.new(@hash['bandwidth']) rescue nil
33
+ end
34
+
35
+ # @return [Fixnum] In megabytes
36
+ def maximum_photo_size() Integer(@hash['filesize']['maxmb']) rescue nil end
37
+ # @return [Fixnum] In megabytes
38
+ def maximum_video_size() Integer(@hash['videosize']['maxmb']) rescue nil end
39
+ # @return [Fixnum]
40
+ def videos_uploaded() Integer(@hash['videos']['uploaded']) rescue nil end
41
+ # @return [Fixnum]
42
+ def videos_remaining() Integer(@hash['videos']['remaining']) rescue nil end
43
+ # @return [Fixnum]
44
+ def sets_created() Integer(@hash['sets']['created']) rescue nil end
45
+ # @return [Fixnum, String]
46
+ def sets_remaining() @hash['sets']['remaining'] rescue nil end
47
+
48
+ def initialize(hash)
49
+ raise ArgumentError if hash.nil?
50
+ @hash = hash
51
+ end
52
+ end
53
+ end
54
+ end
data/lib/flickrie/user.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'date'
2
+ require 'flickrie/user/upload_status'
2
3
 
3
4
  module Flickrie
4
5
  class User
@@ -6,26 +7,27 @@ module Flickrie
6
7
  # :id, :nsid, :username, :real_name, :location, :description,
7
8
  # :path_alias, :icon_server, :icon_farm, :buddy_icon_url,
8
9
  # :time_zone, :photos_url, :profile_url, :mobile_url,
9
- # :first_taken, :favorited_at, :media_count, :pro?, :hash
10
+ # :first_taken, :favorited_at, :media_count, :pro?, :hash,
11
+ # :upload_status
10
12
 
11
13
  # @return [String]
12
- def id() @info['id'] end
14
+ def id() @hash['id'] end
13
15
  # @return [String]
14
- def nsid() @info['nsid'] end
16
+ def nsid() @hash['nsid'] end
15
17
  # @return [String]
16
- def username() @info['username'] end
18
+ def username() @hash['username'] end
17
19
  # @return [String]
18
- def real_name() @info['realname'] end
20
+ def real_name() @hash['realname'] end
19
21
  # @return [String]
20
- def location() @info['location'] end
22
+ def location() @hash['location'] end
21
23
  # @return [String]
22
- def description() @info['description'] end
24
+ def description() @hash['description'] end
23
25
  # @return [String]
24
- def path_alias() @info['path_alias'] end
26
+ def path_alias() @hash['path_alias'] end
25
27
  # @return [String]
26
- def icon_server() @info['iconserver'] end
28
+ def icon_server() @hash['iconserver'] end
27
29
  # @return [Fixnum]
28
- def icon_farm() @info['iconfarm'] end
30
+ def icon_farm() @hash['iconfarm'] end
29
31
 
30
32
  # @return [String]
31
33
  def buddy_icon_url
@@ -44,110 +46,131 @@ module Flickrie
44
46
  # user.time_zone.label # => "Sarajevo, Skopje, Warsaw, Zagreb"
45
47
  #
46
48
  # @return [Struct]
47
- def time_zone() Struct.new(:label, :offset).new(*@info['timezone'].values) rescue nil end
49
+ def time_zone() Struct.new(:label, :offset).new(*@hash['timezone'].values) rescue nil end
48
50
 
49
51
  # @return [String]
50
- def photos_url() @info['photosurl'] || "http://www.flickr.com/photos/#{nsid || id}" if nsid || id end
52
+ def photos_url() @hash['photosurl'] || "http://www.flickr.com/photos/#{nsid || id}" if nsid || id end
51
53
  # @return [String]
52
- def profile_url() @info['profileurl'] || "http://www.flickr.com/people/#{nsid || id}" if nsid || id end
54
+ def profile_url() @hash['profileurl'] || "http://www.flickr.com/people/#{nsid || id}" if nsid || id end
53
55
  # @return [String]
54
- def mobile_url() @info['mobileurl'] end
56
+ def mobile_url() @hash['mobileurl'] end
55
57
 
56
58
  # @return [Time]
57
- def first_taken() DateTime.parse(@info['photos']['firstdatetaken']).to_time rescue nil end
59
+ def first_taken() DateTime.parse(@hash['photos']['firstdatetaken']).to_time rescue nil end
58
60
  # @return [Time]
59
- def first_uploaded() Time.at(Integer(@info['photos']['firstdate'])) rescue nil end
61
+ def first_uploaded() Time.at(Integer(@hash['photos']['firstdate'])) rescue nil end
60
62
 
61
63
  # @return [Time]
62
- def favorited_at() Time.at(Integer(@info['favedate'])) rescue nil end
64
+ def favorited_at() Time.at(Integer(@hash['favedate'])) rescue nil end
63
65
 
64
66
  # @return [Fixnum]
65
- def media_count() Integer(@info['photos']['count']) rescue nil end
67
+ def media_count() Integer(@hash['photos']['count']) rescue nil end
66
68
  alias photos_count media_count
67
69
  alias videos_count media_count
68
70
 
69
71
  # Same as calling `Flickrie.public_photos_from_user(user.nsid)`.
70
72
  #
71
- # @return [Array<Flickrie::Photo>]
73
+ # @return [Flickrie::Collection<Flickrie::Photo>]
72
74
  def public_photos(params = {})
73
75
  Flickrie.public_photos_from_user(nsid || id, params)
74
76
  end
75
77
  # Same as calling `Flickrie.public_videos_from_user(user.nsid)`.
76
78
  #
77
- # @return [Array<Flickrie::Video>]
79
+ # @return [Flickrie::Collection<Flickrie::Video>]
78
80
  def public_videos(params = {})
79
81
  Flickrie.public_videos_from_user(nsid || id, params)
80
82
  end
81
83
  # Same as calling `Flickrie.public_media_from_user(user.nsid)`.
82
84
  #
83
- # @return [Array<Flickrie::Photo, Flickrie::Video>]
85
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
84
86
  def public_media(params = {})
85
87
  Flickrie.public_media_from_user(nsid || id, params)
86
88
  end
87
89
 
88
90
  # Same as calling `Flickrie.photos_from_user(user.nsid)`.
89
91
  #
90
- # @return [Array<Flickrie::Photo>]
92
+ # @return [Flickrie::Collection<Flickrie::Photo>]
91
93
  def photos(params = {})
92
94
  Flickrie.photos_from_user(nsid || id, params)
93
95
  end
94
96
  # Same as calling `Flickrie.videos_from_user(user.nsid)`.
95
97
  #
96
- # @return [Array<Flickrie::Video>]
98
+ # @return [Flickrie::Collection<Flickrie::Video>]
97
99
  def videos(params = {})
98
100
  Flickrie.videos_from_user(nsid || id, params)
99
101
  end
100
102
  # Same as calling `Flickrie.media_from_user(user.nsid)`.
101
103
  #
102
- # @return [Array<Flickrie::Photo, Flickrie::Video>]
104
+ # @return [Flickrie::Collection<Flickrie::Photo, Flickrie::Video>]
103
105
  def media(params = {})
104
106
  Flickrie.media_from_user(nsid || id, params)
105
107
  end
106
108
 
107
109
  # @return [Boolean]
108
- def pro?() Integer(@info['ispro']) == 1 rescue nil end
110
+ def pro?() Integer(@hash['ispro']) == 1 rescue nil end
109
111
 
110
- def [](key) @info[key] end
112
+ # Returns the upload status of the user.
113
+ #
114
+ # @return [Flickrie::User::UploadStatus]
115
+ def upload_status() UploadStatus.new(@hash['upload_status']) rescue nil end
116
+
117
+ def [](key) @hash[key] end
111
118
  # @return [Hash]
112
- def hash() @info end
119
+ def hash() @hash end
113
120
 
114
121
  # The same as calling `Flickrie.get_user_info(user.nsid)`
115
122
  #
116
123
  # @return [self]
117
- def get_info(params = {}, info = nil)
118
- info ||= Flickrie.client.get_user_info(nsid || id, params).body['person']
119
- @info.update(info)
120
-
121
- %w[username realname location description profileurl
122
- mobileurl photosurl].each do |attribute|
123
- @info[attribute] = @info[attribute]['_content']
124
- end
125
- %w[count firstdatetaken firstdate].each do |photo_attribute|
126
- @info['photos'][photo_attribute] = @info['photos'][photo_attribute]['_content']
127
- end
124
+ def get_info(params = {})
125
+ hash = Flickrie.client.get_user_info(nsid || id, params).body['person']
126
+ self.class.fix_info(hash)
127
+ @hash.update(hash)
128
128
 
129
129
  self
130
130
  end
131
131
 
132
132
  private
133
133
 
134
- def initialize(info = {})
135
- raise ArgumentError if info.nil?
134
+ def initialize(hash = {})
135
+ raise ArgumentError if hash.nil?
136
136
 
137
- @info = info
137
+ @hash = hash
138
138
  end
139
139
 
140
- def self.from_info(info)
141
- new.get_info({}, info)
140
+ def self.from_info(hash)
141
+ fix_info(hash)
142
+ new(hash)
142
143
  end
143
144
 
144
- def self.from_find(info)
145
- info['username'] = info['username']['_content']
146
- new(info)
145
+ def self.from_find(hash)
146
+ hash['username'] = hash['username']['_content']
147
+ new(hash)
147
148
  end
148
149
 
149
- def self.from_test(info)
150
- from_find(info)
150
+ def self.from_test(hash)
151
+ from_find(hash)
152
+ end
153
+
154
+ def self.from_upload_status(hash)
155
+ hash['username'] = hash['username']['_content']
156
+ hash['upload_status'] = {
157
+ 'bandwidth' => hash.delete('bandwidth'),
158
+ 'filesize' => hash.delete('filesize'),
159
+ 'sets' => hash.delete('sets'),
160
+ 'videosize' => hash.delete('videosize'),
161
+ 'videos' => hash.delete('videos')
162
+ }
163
+ new(hash)
164
+ end
165
+
166
+ def self.fix_info(hash)
167
+ %w[username realname location description profileurl
168
+ mobileurl photosurl].each do |attribute|
169
+ hash[attribute] = hash[attribute]['_content']
170
+ end
171
+ %w[count firstdatetaken firstdate].each do |photo_attribute|
172
+ hash['photos'][photo_attribute] = hash['photos'][photo_attribute]['_content']
173
+ end
151
174
  end
152
175
  end
153
176
  end
@@ -1,3 +1,3 @@
1
1
  module Flickrie
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
data/lib/flickrie.rb CHANGED
@@ -61,6 +61,30 @@ module Flickrie
61
61
  # [omniauth-flickr](https://github.com/timbreitkreutz/omniauth-flickr) strategy
62
62
  attr_accessor :access_token, :access_secret
63
63
 
64
+ # If you're in a web application, and you want pagination with
65
+ # [will_paginate](https://github.com/mislav/will_paginate), you can specify it here.
66
+ #
67
+ # Flickrie.pagination = :will_paginate
68
+ #
69
+ # Now let's assume you have a collection of photos
70
+ #
71
+ # @photos = Flickrie.photos_from_set(2734243, :per_page => 20, :page => params[:page])
72
+ #
73
+ # This collection is now paginated. You can now call in your ERB template:
74
+ #
75
+ # ```erb
76
+ # <%= will_paginate @photos %>
77
+ # ```
78
+ #
79
+ # If you're using this, be sure to include the 'will_paginate' gem in your
80
+ # `Gemfile`.
81
+ #
82
+ # {Flickrie::Collection} has some basic pagination attributes by itself,
83
+ # these are independent of any pagination library.
84
+ #
85
+ # @see Flickrie::Collection
86
+ attr_accessor :pagination
87
+
64
88
  [
65
89
  :api_key, :shared_secret, :timeout,
66
90
  :open_timeout, :access_token, :access_secret
@@ -153,9 +177,20 @@ module Flickrie
153
177
  end
154
178
 
155
179
  require 'flickrie/api_methods'
180
+ require 'flickrie/core_ext'
156
181
 
157
182
  module Flickrie
183
+ autoload :Collection, 'flickrie/collection'
184
+ autoload :License, 'flickrie/license'
185
+ autoload :User, 'flickrie/user'
186
+ autoload :Media, 'flickrie/media'
187
+ autoload :Photo, 'flickrie/photo'
188
+ autoload :Video, 'flickrie/video'
189
+ autoload :Set, 'flickrie/set'
190
+ autoload :MediaCount, 'flickrie/media_count'
191
+ autoload :Ticket, 'flickrie/ticket'
192
+ autoload :Instance, 'flickrie/instance'
193
+ autoload :OAuth, 'flickrie/oauth'
194
+
158
195
  extend ApiMethods
159
196
  end
160
-
161
- require 'flickrie/instance'
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.2.0
4
+ version: 1.3.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-25 00:00:00.000000000 Z
12
+ date: 2012-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday_middleware
16
- requirement: &70097994385000 !ruby/object:Gem::Requirement
16
+ requirement: &70354735471460 !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: *70097994385000
27
+ version_requirements: *70354735471460
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: faraday
30
- requirement: &70097994381440 !ruby/object:Gem::Requirement
30
+ requirement: &70354735469600 !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: *70097994381440
41
+ version_requirements: *70354735469600
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: simple_oauth
44
- requirement: &70097994393820 !ruby/object:Gem::Requirement
44
+ requirement: &70354735467340 !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: *70097994393820
52
+ version_requirements: *70354735467340
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: multi_xml
55
- requirement: &70097994389540 !ruby/object:Gem::Requirement
55
+ requirement: &70354735466580 !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: *70097994389540
63
+ version_requirements: *70354735466580
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: bundler
66
- requirement: &70097994402680 !ruby/object:Gem::Requirement
66
+ requirement: &70354740714520 !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: *70097994402680
74
+ version_requirements: *70354740714520
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rake
77
- requirement: &70097994408960 !ruby/object:Gem::Requirement
77
+ requirement: &70354740713980 !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: *70097994408960
85
+ version_requirements: *70354740713980
86
86
  - !ruby/object:Gem::Dependency
87
87
  name: rspec
88
- requirement: &70097994407960 !ruby/object:Gem::Requirement
88
+ requirement: &70354740713460 !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: *70097994407960
99
+ version_requirements: *70354740713460
100
100
  - !ruby/object:Gem::Dependency
101
101
  name: vcr
102
- requirement: &70097994405700 !ruby/object:Gem::Requirement
102
+ requirement: &70354740712620 !ruby/object:Gem::Requirement
103
103
  none: false
104
104
  requirements:
105
105
  - - ~>
@@ -107,7 +107,7 @@ dependencies:
107
107
  version: '2.1'
108
108
  type: :development
109
109
  prerelease: false
110
- version_requirements: *70097994405700
110
+ version_requirements: *70354740712620
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: []
@@ -116,6 +116,7 @@ extra_rdoc_files: []
116
116
  files:
117
117
  - lib/flickrie/api_methods.rb
118
118
  - lib/flickrie/client.rb
119
+ - lib/flickrie/collection.rb
119
120
  - lib/flickrie/core_ext.rb
120
121
  - lib/flickrie/instance.rb
121
122
  - lib/flickrie/license.rb
@@ -133,6 +134,7 @@ files:
133
134
  - lib/flickrie/set.rb
134
135
  - lib/flickrie/ticket.rb
135
136
  - lib/flickrie/upload_client.rb
137
+ - lib/flickrie/user/upload_status.rb
136
138
  - lib/flickrie/user.rb
137
139
  - lib/flickrie/version.rb
138
140
  - lib/flickrie/video.rb
@@ -161,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
163
  version: '0'
162
164
  segments:
163
165
  - 0
164
- hash: -2517221758157184130
166
+ hash: -4020731564119486214
165
167
  requirements: []
166
168
  rubyforge_project:
167
169
  rubygems_version: 1.8.11