flickrie 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/README.md +1 -1
  2. data/lib/flickrie.rb +18 -92
  3. data/lib/flickrie/api_methods.rb +759 -11
  4. data/lib/flickrie/base58.rb +15 -0
  5. data/lib/flickrie/callable.rb +78 -0
  6. data/lib/flickrie/client.rb +25 -17
  7. data/lib/flickrie/instance.rb +10 -15
  8. data/lib/flickrie/middleware.rb +4 -21
  9. data/lib/flickrie/middleware/fix_flickr_data.rb +215 -0
  10. data/lib/flickrie/middleware/retry.rb +23 -0
  11. data/lib/flickrie/{license.rb → objects/license.rb} +0 -0
  12. data/lib/flickrie/{location.rb → objects/location.rb} +13 -13
  13. data/lib/flickrie/{media.rb → objects/media.rb} +30 -25
  14. data/lib/flickrie/{media → objects/media}/exif.rb +0 -0
  15. data/lib/flickrie/{media → objects/media}/note.rb +11 -12
  16. data/lib/flickrie/{media → objects/media}/tag.rb +10 -9
  17. data/lib/flickrie/objects/media/visibility.rb +28 -0
  18. data/lib/flickrie/objects/media_context.rb +17 -0
  19. data/lib/flickrie/objects/media_count.rb +46 -0
  20. data/lib/flickrie/{photo.rb → objects/photo.rb} +2 -3
  21. data/lib/flickrie/{set.rb → objects/set.rb} +9 -30
  22. data/lib/flickrie/{ticket.rb → objects/ticket.rb} +0 -0
  23. data/lib/flickrie/{user.rb → objects/user.rb} +10 -50
  24. data/lib/flickrie/{user → objects/user}/upload_status.rb +0 -0
  25. data/lib/flickrie/{video.rb → objects/video.rb} +3 -4
  26. data/lib/flickrie/version.rb +1 -1
  27. metadata +38 -37
  28. data/lib/flickrie/api_methods/media.rb +0 -698
  29. data/lib/flickrie/api_methods/set.rb +0 -23
  30. data/lib/flickrie/api_methods/user.rb +0 -45
  31. data/lib/flickrie/media/class_methods.rb +0 -217
  32. data/lib/flickrie/media/visibility.rb +0 -29
  33. data/lib/flickrie/media_count.rb +0 -54
@@ -1,23 +0,0 @@
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
@@ -1,45 +0,0 @@
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
@@ -1,217 +0,0 @@
1
- module Flickrie
2
- module Media
3
- # @private
4
- module ClassMethods
5
- def from_set(hash)
6
- collection = hash.delete('photo').map do |media_hash|
7
- media_hash['owner'] = {
8
- 'id' => hash['owner'],
9
- 'nsid' => hash['owner'],
10
- 'username' => hash['ownername'],
11
- }
12
- fix_extras(media_hash)
13
- new(media_hash)
14
- end
15
-
16
- Collection.new(hash).replace(collection)
17
- end
18
-
19
- def from_info(hash)
20
- fix_info(hash)
21
- new(hash)
22
- end
23
-
24
- def from_user(hash)
25
- collection = hash.delete('photo').map do |media_hash|
26
- media_hash['owner'] = {
27
- 'id' => media_hash['owner'],
28
- 'nsid' => media_hash.delete('owner'),
29
- 'username' => media_hash.delete('ownername')
30
- }
31
- fix_extras(media_hash)
32
- fix_visibility(media_hash)
33
- new(media_hash)
34
- end
35
-
36
- Collection.new(hash).replace(collection)
37
- end
38
-
39
- def from_sizes(hash)
40
- fix_sizes(hash)
41
- new(hash)
42
- end
43
-
44
- def from_search(hash)
45
- from_user(hash)
46
- end
47
-
48
- def from_contacts(hash)
49
- hash['photo'].each do |media_hash|
50
- media_hash['ownername'] = media_hash.delete('username')
51
- end
52
-
53
- from_user(hash)
54
- end
55
-
56
- def from_context(hash)
57
- count = hash['count']['_content'].to_i
58
- previous_photo = new(hash['prevphoto']) rescue nil
59
- next_photo = new(hash['nextphoto']) rescue nil
60
- Struct.new(:count, :previous, :next).new \
61
- count, previous_photo, next_photo
62
- end
63
-
64
- def from_not_in_set(hash)
65
- from_user(hash)
66
- end
67
-
68
- def of_user(hash)
69
- from_user(hash)
70
- end
71
-
72
- def from_perms(hash)
73
- fix_visibility(hash)
74
- hash['permissions'] = {
75
- 'permcomment' => hash.delete('permcomment'),
76
- 'permaddmeta' => hash.delete('permaddmeta')
77
- }
78
- new(hash)
79
- end
80
-
81
- def from_recent(hash)
82
- from_user(hash)
83
- end
84
-
85
- def from_untagged(hash)
86
- from_user(hash)
87
- end
88
-
89
- def from_geo_data(hash)
90
- from_user(hash)
91
- end
92
-
93
- def from_recently_updated(hash)
94
- from_user(hash)
95
- end
96
-
97
- private
98
-
99
- def fix_extras(hash)
100
- if hash['iconserver'] or hash['iconfarm']
101
- hash['owner'] ||= {}
102
- hash['owner'].update \
103
- 'iconserver' => hash.delete('iconserver'),
104
- 'iconfarm' => hash.delete('iconfarm')
105
- end
106
-
107
- if hash['place_id']
108
- geo_info = %w[latitude longitude accuracy context place_id woeid]
109
- hash['location'] = geo_info.inject({}) do |location, geo|
110
- location.update(geo => hash.delete(geo))
111
- end
112
- hash['geoperms'] = {
113
- 'isfamily' => hash['geo_is_family'],
114
- 'isfriend' => hash['geo_is_friend'],
115
- 'iscontact' => hash['geo_is_contact'],
116
- 'ispublic' => hash['geo_is_public']
117
- }
118
- end
119
-
120
- if hash['tags']
121
- hash['tags'] = hash['tags'].split(' ').map do |tag_content|
122
- {'_content' => tag_content, 'machine_tag' => 0}
123
- end
124
- end
125
- if hash['machine_tags']
126
- hash['tags'] ||= []
127
- hash['tags'] += hash.delete('machine_tags').split(' ').map do |tag_content|
128
- {'_content' => tag_content, 'machine_tag' => 1}
129
- end
130
- end
131
-
132
- hash['dates'] = {
133
- 'uploaded' => hash.delete('dateupload'),
134
- 'lastupdate' => hash.delete('lastupdate'),
135
- 'taken' => hash.delete('datetaken'),
136
- 'takengranularity' => hash.delete('datetakengranularity'),
137
- }
138
-
139
- hash
140
- end
141
-
142
- def fix_info(hash)
143
- hash['title'] = hash['title']['_content']
144
- hash['description'] = hash['description']['_content']
145
- hash['comments_count'] = hash.delete('comments')['_content']
146
- hash['dates']['uploaded'] = hash.delete('dateuploaded')
147
- hash['tags'] = hash['tags']['tag']
148
-
149
- hash
150
- end
151
-
152
- def fix_visibility(hash)
153
- hash['visibility'] = {
154
- 'ispublic' => hash.delete('ispublic'),
155
- 'isfriend' => hash.delete('isfriend'),
156
- 'isfamily' => hash.delete('isfamily')
157
- }
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
204
- end
205
- extend(ClassMethods)
206
-
207
- # @private
208
- def self.included(klass)
209
- klass.extend(ClassMethods)
210
- end
211
-
212
- # @private
213
- def self.new(hash)
214
- eval(hash['media'].capitalize).new(hash)
215
- end
216
- end
217
- end
@@ -1,29 +0,0 @@
1
- module Flickrie
2
- module Media
3
- class Visibility
4
- # @!parse attr_reader \
5
- # :public?, :friends?, :family?, :contacts?, :hash
6
-
7
- # @return [Boolean]
8
- def public?() @info['ispublic'].to_i == 1 if @info['ispublic'] end
9
- # @return [Boolean]
10
- def friends?() @info['isfriend'].to_i == 1 if @info['isfriend'] end
11
- # @return [Boolean]
12
- def family?() @info['isfamily'].to_i == 1 if @info['isfamily'] end
13
- # @return [Boolean]
14
- def contacts?() @info['iscontact'].to_i == 1 if @info['iscontact'] end
15
-
16
- def [](key) @info[key] end
17
- # @return [Hash]
18
- def hash() @info end
19
-
20
- private
21
-
22
- def initialize(info)
23
- raise ArgumentError if info.nil?
24
-
25
- @info = info
26
- end
27
- end
28
- end
29
- end
@@ -1,54 +0,0 @@
1
- require 'date'
2
-
3
- module Flickrie
4
- class MediaCount
5
- # @!parse attr_reader \
6
- # :value, :date_range, :from, :to, :hash
7
-
8
- def value() Integer(@info['count']) rescue nil end
9
-
10
- # @return [Range]
11
- def date_range
12
- dates =
13
- case @dates_kind
14
- when "mysql timestamp"
15
- [DateTime.parse(@info['fromdate']).to_time,
16
- DateTime.parse(@info['todate']).to_time]
17
- when "unix timestamp"
18
- [Time.at(Integer(@info['fromdate'])),
19
- Time.at(Integer(@info['todate']))]
20
- end
21
-
22
- dates.first..dates.last
23
- end
24
- alias time_interval date_range
25
-
26
- # @return [Time]
27
- def from() date_range.begin end
28
- # @return [Time]
29
- def to() date_range.end end
30
-
31
- def [](key) @info[key] end
32
- # Returns the raw hash from the response. Useful if something isn't available by methods.
33
- #
34
- # @return [Hash]
35
- def hash() @info end
36
-
37
- private
38
-
39
- def initialize(info, params)
40
- @info = info
41
- @dates_kind = (params[:dates].nil? ? "mysql timestamp" : "unix timestamp")
42
- end
43
-
44
- def self.ensure_utc(params)
45
- params.dup.tap do |hash|
46
- if hash[:taken_dates].is_a?(String)
47
- hash[:taken_dates] = hash[:taken_dates].split(',').
48
- map { |date| DateTime.parse(date) }.
49
- map(&:to_time).map(&:getutc).join(',')
50
- end
51
- end
52
- end
53
- end
54
- end