flickrie 1.1.2 → 1.2.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
@@ -1,9 +1,11 @@
1
- # Flickrie [![Build Status](https://secure.travis-ci.org/janko-m/flickrie.png)](http://travis-ci.org/janko-m/flickrie)
2
-
3
- ## About
1
+ # Flickrie
4
2
 
5
3
  This gem is a nice wrapper for the Flickr API with an object-oriented interface.
6
4
 
5
+ [![Build Status](https://secure.travis-ci.org/janko-m/flickrie.png)](http://travis-ci.org/janko-m/flickrie)
6
+
7
+ ## About
8
+
7
9
  The reason why I did this gem is because the existing ones either weren't
8
10
  well maintained, or they weren't object oriented and provided a literal
9
11
  wrapper over the API. That didn't statisfy me, because Flickr API
@@ -10,6 +10,7 @@ require 'flickrie/video'
10
10
  require 'flickrie/set'
11
11
  require 'flickrie/media_count'
12
12
  require 'flickrie/ticket'
13
+ require 'flickrie/core_ext'
13
14
 
14
15
  module Flickrie
15
16
  module ApiMethods
@@ -299,7 +300,7 @@ module Flickrie
299
300
  # @api_method [flickr.photos.getExif](http://www.flickr.com/services/api/flickr.photos.getExif.html)
300
301
  def get_photo_exif(photo_id, params = {})
301
302
  response = client.get_media_exif(photo_id, params)
302
- Photo.from_exif(response.body['photo'])
303
+ Photo.new(response.body['photo'])
303
304
  end
304
305
  # Fetches the exif for the video with the given ID. Example:
305
306
  #
@@ -315,7 +316,7 @@ module Flickrie
315
316
  # @api_method [flickr.photos.getExif](http://www.flickr.com/services/api/flickr.photos.getExif.html)
316
317
  def get_video_exif(video_id, params = {})
317
318
  response = client.get_media_exif(video_id, params)
318
- Video.from_exif(response.body['photo'])
319
+ Video.new(response.body['photo'])
319
320
  end
320
321
 
321
322
  # Fetches the list of users who favorited the photo with the given ID.
@@ -0,0 +1,13 @@
1
+ class Hash
2
+ def deep_merge(other_hash)
3
+ dup.deep_merge!(other_hash)
4
+ end
5
+
6
+ def deep_merge!(other_hash)
7
+ other_hash.each_pair do |k,v|
8
+ tv = self[k]
9
+ self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
10
+ end
11
+ self
12
+ end
13
+ end
@@ -0,0 +1,131 @@
1
+ module Flickrie
2
+ module Media
3
+ # @private
4
+ module ClassMethods
5
+ def from_set(hash)
6
+ hash['photo'].map do |individual_hash|
7
+ individual_hash['owner'] = {
8
+ 'nsid' => hash['owner'],
9
+ 'username' => hash['ownername'],
10
+ }
11
+ fix_extras(individual_hash)
12
+ new(individual_hash)
13
+ end
14
+ end
15
+
16
+ def from_info(hash)
17
+ fix_info(hash)
18
+ new(hash)
19
+ end
20
+
21
+ def from_user(hash)
22
+ hash['photo'].map do |individual_hash|
23
+ individual_hash['owner'] = {
24
+ 'nsid' => individual_hash.delete('owner'),
25
+ 'username' => individual_hash.delete('ownername')
26
+ }
27
+ fix_extras(individual_hash)
28
+ fix_visibility(individual_hash)
29
+ new(individual_hash)
30
+ end
31
+ end
32
+
33
+ def from_sizes(hash)
34
+ fix_sizes(hash)
35
+ new(hash)
36
+ end
37
+
38
+ def from_search(hash)
39
+ from_user(hash)
40
+ end
41
+
42
+ def from_contacts(hash)
43
+ hash['photo'].each do |individual_hash|
44
+ individual_hash['ownername'] = individual_hash.delete('username')
45
+ end
46
+
47
+ from_user(hash)
48
+ end
49
+
50
+ def from_context(hash)
51
+ count = hash['count']['_content'].to_i
52
+ previous_photo = new(hash['prevphoto']) rescue nil
53
+ next_photo = new(hash['nextphoto']) rescue nil
54
+ Struct.new(:count, :previous, :next).new \
55
+ count, previous_photo, next_photo
56
+ end
57
+
58
+ def fix_extras(hash)
59
+ if hash['iconserver'] or hash['iconfarm']
60
+ hash['owner'] ||= {}
61
+ hash['owner'].update \
62
+ 'iconserver' => hash.delete('iconserver'),
63
+ 'iconfarm' => hash.delete('iconfarm')
64
+ end
65
+
66
+ if hash['place_id']
67
+ geo_info = %w[latitude longitude accuracy context place_id woeid]
68
+ hash['location'] = geo_info.inject({}) do |location, geo|
69
+ location.update(geo => hash.delete(geo))
70
+ end
71
+ hash['geoperms'] = {
72
+ 'isfamily' => hash['geo_is_family'],
73
+ 'isfriend' => hash['geo_is_friend'],
74
+ 'iscontact' => hash['geo_is_contact'],
75
+ 'ispublic' => hash['geo_is_public']
76
+ }
77
+ end
78
+
79
+ if hash['tags']
80
+ hash['tags'] = hash['tags'].split(' ').map do |tag_content|
81
+ {'_content' => tag_content, 'machine_tag' => 0}
82
+ end
83
+ end
84
+ if hash['machine_tags']
85
+ hash['tags'] ||= []
86
+ hash['tags'] += hash.delete('machine_tags').split(' ').map do |tag_content|
87
+ {'_content' => tag_content, 'machine_tag' => 1}
88
+ end
89
+ end
90
+
91
+ hash['dates'] = {
92
+ 'uploaded' => hash.delete('dateupload'),
93
+ 'lastupdate' => hash.delete('lastupdate'),
94
+ 'taken' => hash.delete('datetaken'),
95
+ 'takengranularity' => hash.delete('datetakengranularity'),
96
+ }
97
+
98
+ hash
99
+ end
100
+
101
+ def fix_info(hash)
102
+ hash['title'] = hash['title']['_content']
103
+ hash['description'] = hash['description']['_content']
104
+ hash['comments_count'] = hash.delete('comments')['_content']
105
+ hash['dates']['uploaded'] = hash.delete('dateuploaded')
106
+ hash['tags'] = hash['tags']['tag']
107
+
108
+ hash
109
+ end
110
+
111
+ def fix_visibility(hash)
112
+ hash['visibility'] = {
113
+ 'ispublic' => hash.delete('ispublic'),
114
+ 'isfriend' => hash.delete('isfriend'),
115
+ 'isfamily' => hash.delete('isfamily')
116
+ }
117
+ end
118
+ end
119
+ extend(ClassMethods)
120
+
121
+ # @private
122
+ def self.included(klass)
123
+ klass.extend(ClassMethods)
124
+ end
125
+
126
+ # @private
127
+ def self.new(hash)
128
+ eval(hash['media'].capitalize).new(hash)
129
+ end
130
+ end
131
+ end
@@ -1,3 +1,4 @@
1
+ require 'flickrie/media/class_methods'
1
2
  require 'flickrie/media/visibility'
2
3
  require 'flickrie/media/note'
3
4
  require 'flickrie/media/tag'
@@ -20,24 +21,24 @@ module Flickrie
20
21
  # :has_people?, :faved?, :notes, :favorites, :hash
21
22
 
22
23
  # @return [String]
23
- def id() @info['id'] end
24
+ def id() @hash['id'] end
24
25
  # @return [String]
25
- def secret() @info['secret'] end
26
+ def secret() @hash['secret'] end
26
27
  # @return [String]
27
- def server() @info['server'] end
28
+ def server() @hash['server'] end
28
29
  # @return [Fixnum]
29
- def farm() @info['farm'] end
30
+ def farm() @hash['farm'] end
30
31
  # @return [String]
31
- def title() @info['title'] end
32
+ def title() @hash['title'] end
32
33
  # @return [String]
33
- def description() @info['description'] end
34
+ def description() @hash['description'] end
34
35
  # @return [String]
35
- def media_status() @info['media_status'] end
36
+ def media_status() @hash['media_status'] end
36
37
  # @return [String]
37
- def path_alias() @info['pathalias'] end
38
+ def path_alias() @hash['pathalias'] end
38
39
 
39
40
  # @return [String]
40
- def camera() @info['camera'] end
41
+ def camera() @hash['camera'] end
41
42
  # Returns exif of the photo/video. Example:
42
43
  #
43
44
  # photo.exif.get('Model') # => 'Canon PowerShot G12'
@@ -47,42 +48,42 @@ module Flickrie
47
48
  # photo.exif.get('X-Resolution') # => '180 dpi'
48
49
  #
49
50
  # @return [Flickrie::Media::Exif]
50
- def exif() Exif.new(@info['exif']) rescue nil end
51
+ def exif() Exif.new(@hash['exif']) rescue nil end
51
52
 
52
53
  # @return [Fixnum]
53
- def views_count() Integer(@info['views']) rescue nil end
54
+ def views_count() Integer(@hash['views']) rescue nil end
54
55
  # @return [Fixnum]
55
- def comments_count() Integer(@info['comments_count']) rescue nil end
56
+ def comments_count() Integer(@hash['comments_count']) rescue nil end
56
57
 
57
58
  # @return [Flickrie::Location]
58
- def location() Location.new(@info['location']) rescue nil end
59
+ def location() Location.new(@hash['location']) rescue nil end
59
60
  # @return [Flickrie::Media::Visibility]
60
- def geo_permissions() Visibility.new(@info['geoperms']) rescue nil end
61
+ def geo_permissions() Visibility.new(@hash['geoperms']) rescue nil end
61
62
 
62
63
  # @return [Array<Flickrie::Media::Tag>]
63
- def tags() @info['tags'].map { |info| Tag.new(info) } rescue nil end
64
+ def tags() @hash['tags'].map { |info| Tag.new(info) } rescue nil end
64
65
  # @return [Array<Flickrie::Media::Tag>]
65
66
  def machine_tags() tags.select { |tag| tag.machine_tag? } rescue nil end
66
67
 
67
68
  # @return [Flickrie::License]
68
- def license() License.new(@info['license']) rescue nil end
69
+ def license() License.new(@hash['license']) rescue nil end
69
70
 
70
71
  # @return [Time]
71
- def posted_at() Time.at(Integer(@info['dates']['posted'])) rescue nil end
72
+ def posted_at() Time.at(Integer(@hash['dates']['posted'])) rescue nil end
72
73
  # @return [Time]
73
- def uploaded_at() Time.at(Integer(@info['dates']['uploaded'])) rescue nil end
74
+ def uploaded_at() Time.at(Integer(@hash['dates']['uploaded'])) rescue nil end
74
75
  # @return [Time]
75
- def updated_at() Time.at(Integer(@info['dates']['lastupdate'])) rescue nil end
76
+ def updated_at() Time.at(Integer(@hash['dates']['lastupdate'])) rescue nil end
76
77
  # @return [Time]
77
- def taken_at() DateTime.parse(@info['dates']['taken']).to_time rescue nil end
78
+ def taken_at() DateTime.parse(@hash['dates']['taken']).to_time rescue nil end
78
79
  # @return [Fixnum]
79
- def taken_at_granularity() Integer(@info['dates']['takengranularity']) rescue nil end
80
+ def taken_at_granularity() Integer(@hash['dates']['takengranularity']) rescue nil end
80
81
 
81
82
  # @return [Flickrie::User]
82
- def owner() User.new(@info['owner']) rescue nil end
83
+ def owner() User.new(@hash['owner']) rescue nil end
83
84
 
84
85
  # @return [Fixnum]
85
- def safety_level() Integer(@info['safety_level']) rescue nil end
86
+ def safety_level() Integer(@hash['safety_level']) rescue nil end
86
87
 
87
88
  # @return [Boolean]
88
89
  def safe?() safety_level <= 1 if safety_level end
@@ -95,201 +96,90 @@ module Flickrie
95
96
  def url
96
97
  if owner and id
97
98
  "http://www.flickr.com/photos/#{owner.nsid}/#{id}"
98
- elsif @info['url']
99
- "http://www.flickr.com" + @info['url']
99
+ elsif @hash['url']
100
+ "http://www.flickr.com" + @hash['url']
100
101
  end
101
102
  end
102
103
 
103
104
  # @return [Flickrie::Media::Visibility]
104
- def visibility() Visibility.new(@info['visibility']) rescue nil end
105
+ def visibility() Visibility.new(@hash['visibility']) rescue nil end
105
106
 
106
107
  # @return [Boolean]
107
- def primary?() Integer(@info['isprimary']) == 1 rescue nil end
108
+ def primary?() Integer(@hash['isprimary']) == 1 rescue nil end
108
109
 
109
110
  # @return [Boolean]
110
- def favorite?() Integer(@info['isfavorite']) == 1 rescue nil end
111
+ def favorite?() Integer(@hash['isfavorite']) == 1 rescue nil end
111
112
 
112
113
  # @return [Boolean]
113
- def can_comment?() Integer(@info['editability']['cancomment']) == 1 rescue nil end
114
+ def can_comment?() Integer(@hash['editability']['cancomment']) == 1 rescue nil end
114
115
  # @return [Boolean]
115
- def can_add_meta?() Integer(@info['editability']['canaddmeta']) == 1 rescue nil end
116
+ def can_add_meta?() Integer(@hash['editability']['canaddmeta']) == 1 rescue nil end
116
117
 
117
118
  # @return [Boolean]
118
- def can_everyone_comment?() Integer(@info['publiceditability']['cancomment']) == 1 rescue nil end
119
+ def can_everyone_comment?() Integer(@hash['publiceditability']['cancomment']) == 1 rescue nil end
119
120
  # @return [Boolean]
120
- def can_everyone_add_meta?() Integer(@info['publiceditability']['canaddmeta']) == 1 rescue nil end
121
+ def can_everyone_add_meta?() Integer(@hash['publiceditability']['canaddmeta']) == 1 rescue nil end
121
122
 
122
123
  # @return [Boolean]
123
- def can_download?() Integer(@info['usage']['candownload']) == 1 rescue nil end
124
+ def can_download?() Integer(@hash['usage']['candownload']) == 1 rescue nil end
124
125
  # @return [Boolean]
125
- def can_blog?() Integer(@info['usage']['canblog']) == 1 rescue nil end
126
+ def can_blog?() Integer(@hash['usage']['canblog']) == 1 rescue nil end
126
127
  # @return [Boolean]
127
- def can_print?() Integer(@info['usage']['canprint']) == 1 rescue nil end
128
+ def can_print?() Integer(@hash['usage']['canprint']) == 1 rescue nil end
128
129
  # @return [Boolean]
129
- def can_share?() Integer(@info['usage']['canshare']) == 1 rescue nil end
130
+ def can_share?() Integer(@hash['usage']['canshare']) == 1 rescue nil end
130
131
 
131
132
  # @return [Boolean]
132
- def has_people?() Integer(@info['people']['haspeople']) == 1 rescue nil end
133
+ def has_people?() Integer(@hash['people']['haspeople']) == 1 rescue nil end
133
134
 
134
135
  # @return [Boolean]
135
- def faved?() Integer(@info['is_faved']) == 1 rescue nil end
136
+ def faved?() Integer(@hash['is_faved']) == 1 rescue nil end
136
137
 
137
138
  # @return [Array<Flickrie::Media::Note>]
138
- def notes() @info['notes']['note'].map { |hash| Note.new(hash) } rescue nil end
139
+ def notes() @hash['notes']['note'].map { |info| Note.new(info) } rescue nil end
139
140
 
140
141
  # @return [Array<Flickrie::User>]
141
- def favorites() @info['person'].map { |info| User.new(info) } rescue nil end
142
+ def favorites() @hash['person'].map { |info| User.new(info) } rescue nil end
142
143
 
143
- def [](key) @info[key] end
144
+ def [](key) @hash[key] end
144
145
  # Returns the raw hash from the response. Useful if something isn't available by methods.
145
146
  #
146
147
  # @return [Hash]
147
- def hash() @info end
148
+ def hash() @hash end
148
149
 
149
150
  # Same as calling `Flickrie.get_(photo|video)_info(id)`.
150
151
  #
151
152
  # @return [self]
152
- def get_info(params = {}, info = nil)
153
- info ||= Flickrie.client.get_media_info(id, params).body['photo']
154
- @info.update(info)
155
-
156
- # Fixes
157
- @info['title'] = @info['title']['_content']
158
- @info['description'] = @info['description']['_content']
159
- @info['comments_count'] = @info.delete('comments')['_content']
160
- @info['dates']['uploaded'] = @info.delete('dateuploaded')
161
- @info['tags'] = @info['tags']['tag']
153
+ def get_info(params = {})
154
+ hash = Flickrie.client.get_media_info(id, params).body['photo']
155
+ self.class.fix_info(hash)
156
+ @hash.deep_merge!(hash)
162
157
 
163
158
  self
164
159
  end
165
160
 
166
- # Same as calling `Flickrie.get_(photo|video)_info(id)`.
161
+ # Same as calling `Flickrie.get_(photo|video)_exif(id)`.
167
162
  #
168
163
  # @return [self]
169
- def get_exif(params = {}, info = nil)
170
- info ||= Flickrie.client.get_media_exif(id, params).body['photo']
171
- @info.update(info)
164
+ def get_exif(params = {})
165
+ hash = Flickrie.client.get_media_exif(id, params).body['photo']
166
+ @hash.deep_merge!(hash)
172
167
 
173
168
  self
174
169
  end
175
170
 
176
- # Same as calling `Flickrie.get_(photo|video)_info(id)`.
171
+ # Same as calling `Flickrie.get_(photo|video)_favorites(id)`.
177
172
  #
178
173
  # @return [self]
179
- def get_favorites(params = {}, info = nil)
180
- info ||= Flickrie.client.get_media_favorites(id, params).body['photo']
181
- @info.update(info)
174
+ def get_favorites(params = {})
175
+ hash = Flickrie.client.get_media_favorites(id, params).body['photo']
176
+ @hash.deep_merge!(hash)
182
177
 
183
178
  self
184
179
  end
185
180
 
186
- def initialize(info = {})
187
- @info = info
188
- end
189
-
190
- # @private
191
- module ClassMethods
192
- def from_set(hash)
193
- hash['photo'].map do |info|
194
- info['owner'] = {
195
- 'nsid' => hash['owner'],
196
- 'username' => hash['ownername'],
197
- 'iconserver' => info.delete('iconserver'),
198
- 'iconfarm' => info.delete('iconfarm')
199
- }
200
- if info['place_id']
201
- geo_info = %w[latitude longitude accuracy context place_id woeid]
202
- info['location'] = geo_info.inject({}) do |location, geo|
203
- location.update(geo => info.delete(geo))
204
- end
205
- info['geoperms'] = {
206
- 'isfamily' => info['geo_is_family'],
207
- 'isfriend' => info['geo_is_friend'],
208
- 'iscontact' => info['geo_is_contact'],
209
- 'ispublic' => info['geo_is_public']
210
- }
211
- end
212
- info['dates'] = {
213
- 'uploaded' => info.delete('dateupload'),
214
- 'lastupdate' => info.delete('lastupdate'),
215
- 'taken' => info.delete('datetaken'),
216
- 'takengranularity' => info.delete('datetakengranularity'),
217
- }
218
-
219
- unless info['tags'].nil?
220
- info['tags'] = info['tags'].split(' ').map do |tag_content|
221
- {'_content' => tag_content, 'machine_tag' => 0}
222
- end
223
- end
224
- unless info['machine_tags'].nil?
225
- info['tags'] ||= []
226
- info['tags'] += info.delete('machine_tags').split(' ').map do |tag_content|
227
- {'_content' => tag_content, 'machine_tag' => 1}
228
- end
229
- end
230
-
231
- new(info)
232
- end
233
- end
234
-
235
- def from_info(info)
236
- new('media' => info['media']).get_info({}, info)
237
- end
238
-
239
- def from_user(hash)
240
- if hash['photo'].first
241
- hash['owner'] = hash['photo'].first['owner']
242
- hash['ownername'] = hash['photo'].first['ownername']
243
- end
244
- hash['photo'].each do |info|
245
- info['visibility'] = {
246
- 'ispublic' => info.delete('ispublic'),
247
- 'isfriend' => info.delete('isfriend'),
248
- 'isfamily' => info.delete('isfamily')
249
- }
250
- end
251
-
252
- from_set(hash)
253
- end
254
-
255
- def from_sizes(info)
256
- new.get_sizes({}, info)
257
- end
258
-
259
- def from_search(hash)
260
- from_user(hash)
261
- end
262
-
263
- def from_contacts(hash)
264
- hash['photo'].each do |info|
265
- info['ownername'] = info.delete('username')
266
- end
267
-
268
- from_user(hash)
269
- end
270
-
271
- def from_context(hash)
272
- count = hash['count']['_content'].to_i
273
- previous_photo = new(hash['prevphoto']) rescue nil
274
- next_photo = new(hash['nextphoto']) rescue nil
275
- Struct.new(:count, :previous, :next).new \
276
- count, previous_photo, next_photo
277
- end
278
-
279
- def from_exif(info)
280
- new.get_exif({}, info)
281
- end
282
- end
283
- extend(ClassMethods)
284
-
285
- # @private
286
- def self.included(klass)
287
- klass.extend(ClassMethods)
288
- end
289
-
290
- # @private
291
- def self.new(info)
292
- eval(info['media'].capitalize).new(info)
181
+ def initialize(hash = {})
182
+ @hash = hash
293
183
  end
294
184
  end
295
185
  end
@@ -4,7 +4,7 @@ module Flickrie
4
4
  # @!parse attr_reader \
5
5
  # :size, :width, :height, :source_url, :rotation
6
6
 
7
- SIZES = {
7
+ FLICKR_SIZES = {
8
8
  'Square 75' => 'sq',
9
9
  'Thumbnail' => 't',
10
10
  'Square 150' => 'q',
@@ -14,6 +14,8 @@ module Flickrie
14
14
  'Medium 640' => 'z',
15
15
  'Medium 800' => 'c',
16
16
  'Large 1024' => 'l',
17
+ 'Large 1600' => 'h',
18
+ 'Large 2048' => 'k',
17
19
  'Original' => 'o'
18
20
  }
19
21
 
@@ -52,35 +54,44 @@ module Flickrie
52
54
  # @return [self]
53
55
  def square75() square(75) end
54
56
  # @return [self]
55
- def square75!() square!(75) end
56
- # @return [self]
57
57
  def square150() square(150) end
58
58
  # @return [self]
59
- def square150!() square!(150) end
60
- # @return [self]
61
59
  def small240() small(240) end
62
60
  # @return [self]
63
- def small240!() small!(240) end
64
- # @return [self]
65
61
  def small320() small(320) end
66
62
  # @return [self]
67
- def small320!() small!(320) end
68
- # @return [self]
69
63
  def medium500() medium(500) end
70
64
  # @return [self]
71
- def medium500!() medium!(500) end
72
- # @return [self]
73
65
  def medium640() medium(640) end
74
66
  # @return [self]
75
- def medium640!() medium!(640) end
76
- # @return [self]
77
67
  def medium800() medium(800) end
78
68
  # @return [self]
79
- def medium800!() medium!(800) end
80
- # @return [self]
81
69
  def large1024() large(1024) end
82
70
  # @return [self]
71
+ def large1600() large(1600) end
72
+ # @return [self]
73
+ def large2048() large(2048) end
74
+
75
+ # @return [self]
76
+ def square75!() square!(75) end
77
+ # @return [self]
78
+ def square150!() square!(150) end
79
+ # @return [self]
80
+ def small240!() small!(240) end
81
+ # @return [self]
82
+ def small320!() small!(320) end
83
+ # @return [self]
84
+ def medium500!() medium!(500) end
85
+ # @return [self]
86
+ def medium640!() medium!(640) end
87
+ # @return [self]
88
+ def medium800!() medium!(800) end
89
+ # @return [self]
83
90
  def large1024!() large!(1024) end
91
+ # @return [self]
92
+ def large1600!() large!(1600) end
93
+ # @return [self]
94
+ def large2048!() large!(2048) end
84
95
 
85
96
  # @return [self]
86
97
  def largest!() @size = largest_size; self end
@@ -89,56 +100,35 @@ module Flickrie
89
100
 
90
101
  # @return [Array<String>]
91
102
  def available_sizes
92
- SIZES.select { |_,v| @info["url_#{v}"] }.keys
103
+ FLICKR_SIZES.select { |_,v| @hash["url_#{v}"] }.keys
93
104
  end
94
105
 
95
106
  # @return [Fixnum]
96
- def width() flickr_size.min rescue nil end
107
+ def width() Integer(@hash["width_#{size_abbr}"]) rescue nil end
97
108
  # @return [Fixnum]
98
- def height() flickr_size.max rescue nil end
109
+ def height() Integer(@hash["height_#{size_abbr}"]) rescue nil end
99
110
  # @return [String]
100
- def source_url() @info["url_#{size_abbr}"] end
111
+ def source_url() @hash["url_#{size_abbr}"] end
101
112
 
102
113
  # @return [Fixnum]
103
- def rotation() Integer(@info['rotation']) rescue nil end
114
+ def rotation() Integer(@hash['rotation']) rescue nil end
104
115
 
105
116
  # Same as calling `Flickrie.get_photo_sizes(photo.id)`.
106
117
  #
107
118
  # @return [self]
108
- def get_sizes(params = {}, info = nil)
109
- info ||= Flickrie.client.get_media_sizes(id, params).body['sizes']
110
- @info['usage'] ||= {}
111
- @info['usage'].update \
112
- 'canblog' => info['canblog'],
113
- 'canprint' => info['canprint'],
114
- 'candownload' => info['candownload']
115
- flickr_sizes = {
116
- 'Square' => SIZES['Square 75'],
117
- 'Large Square' => SIZES['Square 150'],
118
- 'Thumbnail' => SIZES['Thumbnail'],
119
- 'Small' => SIZES['Small 240'],
120
- 'Small 320' => SIZES['Small 320'],
121
- 'Medium' => SIZES['Medium 500'],
122
- 'Medium 640' => SIZES['Medium 640'],
123
- 'Medium 800' => SIZES['Medium 800'],
124
- 'Large' => SIZES['Large 1024'],
125
- 'Original' => SIZES['Original']
126
- }
127
- info['size'].each do |size_info|
128
- size_abbr = flickr_sizes[size_info['label']]
129
- @info["width_#{size_abbr}"] = size_info['width']
130
- @info["height_#{size_abbr}"] = size_info['height']
131
- @info["url_#{size_abbr}"] = size_info['source']
132
- end
119
+ 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)
133
123
 
134
124
  largest!
135
125
  end
136
126
 
137
127
  private
138
128
 
139
- def initialize(info = {}, size = nil)
140
- super(info)
141
- @size = size || largest_size
129
+ def initialize(info = {})
130
+ super
131
+ @size = largest_size
142
132
  end
143
133
 
144
134
  def largest_size
@@ -146,11 +136,35 @@ module Flickrie
146
136
  end
147
137
 
148
138
  def size_abbr
149
- SIZES[size]
139
+ FLICKR_SIZES[size]
150
140
  end
151
141
 
152
- def flickr_size
153
- [Integer(@info["width_#{size_abbr}"]), Integer(@info["height_#{size_abbr}"])]
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
154
168
  end
155
169
  end
156
170
  end
@@ -1,3 +1,3 @@
1
1
  module Flickrie
2
- VERSION = "1.1.2"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -31,20 +31,11 @@ module Flickrie
31
31
  # Same as calling `Flickrie.get_video_sizes(video.id)`
32
32
  #
33
33
  # @return [self]
34
- def get_sizes(params = {}, info = nil)
35
- info ||= Flickrie.client.get_media_sizes(id, params).body['sizes']
36
- @info['usage'] ||= {}
37
- @info['usage'].update \
38
- 'canblog' => info['canblog'],
39
- 'canprint' => info['canprint'],
40
- 'candownload' => info['candownload']
41
- info['size'].each do |hash|
42
- case hash['label']
43
- when 'Video Player' then @video['source_url'] = hash['source']
44
- when 'Site MP4' then @video['download_url'] = hash['source']
45
- when 'Mobile MP4' then @video['mobile_download_url'] = hash['source']
46
- end
47
- end
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)
38
+ @video = @hash['video']
48
39
 
49
40
  self
50
41
  end
@@ -52,18 +43,34 @@ module Flickrie
52
43
  # Same as calling `Flickrie.get_video_info(video.id)`.
53
44
  #
54
45
  # @return [self]
55
- def get_info(params = {}, info = nil)
46
+ def get_info(params = {})
56
47
  super
57
- @video = @info['video']
48
+ @video = @hash['video']
58
49
 
59
50
  self
60
51
  end
61
52
 
62
53
  private
63
54
 
64
- def initialize(info = {})
55
+ def initialize(hash = {})
65
56
  super
66
- @video = info['video'] || {}
57
+ @video = hash['video'] || {}
58
+ 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
67
74
  end
68
75
  end
69
76
  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.1.2
4
+ version: 1.2.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-22 00:00:00.000000000 Z
12
+ date: 2012-05-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday_middleware
16
- requirement: &70239060903700 !ruby/object:Gem::Requirement
16
+ requirement: &70097994385000 !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: *70239060903700
27
+ version_requirements: *70097994385000
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: faraday
30
- requirement: &70239060902580 !ruby/object:Gem::Requirement
30
+ requirement: &70097994381440 !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: *70239060902580
41
+ version_requirements: *70097994381440
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: simple_oauth
44
- requirement: &70239060900520 !ruby/object:Gem::Requirement
44
+ requirement: &70097994393820 !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: *70239060900520
52
+ version_requirements: *70097994393820
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: multi_xml
55
- requirement: &70239060899720 !ruby/object:Gem::Requirement
55
+ requirement: &70097994389540 !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: *70239060899720
63
+ version_requirements: *70097994389540
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: bundler
66
- requirement: &70239060898920 !ruby/object:Gem::Requirement
66
+ requirement: &70097994402680 !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: *70239060898920
74
+ version_requirements: *70097994402680
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rake
77
- requirement: &70239060897880 !ruby/object:Gem::Requirement
77
+ requirement: &70097994408960 !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: *70239060897880
85
+ version_requirements: *70097994408960
86
86
  - !ruby/object:Gem::Dependency
87
87
  name: rspec
88
- requirement: &70239060826840 !ruby/object:Gem::Requirement
88
+ requirement: &70097994407960 !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: *70239060826840
99
+ version_requirements: *70097994407960
100
100
  - !ruby/object:Gem::Dependency
101
101
  name: vcr
102
- requirement: &70239060825260 !ruby/object:Gem::Requirement
102
+ requirement: &70097994405700 !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: *70239060825260
110
+ version_requirements: *70097994405700
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,9 +116,11 @@ extra_rdoc_files: []
116
116
  files:
117
117
  - lib/flickrie/api_methods.rb
118
118
  - lib/flickrie/client.rb
119
+ - lib/flickrie/core_ext.rb
119
120
  - lib/flickrie/instance.rb
120
121
  - lib/flickrie/license.rb
121
122
  - lib/flickrie/location.rb
123
+ - lib/flickrie/media/class_methods.rb
122
124
  - lib/flickrie/media/exif.rb
123
125
  - lib/flickrie/media/note.rb
124
126
  - lib/flickrie/media/tag.rb
@@ -159,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
161
  version: '0'
160
162
  segments:
161
163
  - 0
162
- hash: 1105222983264993041
164
+ hash: -2517221758157184130
163
165
  requirements: []
164
166
  rubyforge_project:
165
167
  rubygems_version: 1.8.11