flickr_fu 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README +110 -0
- data/Rakefile +22 -0
- data/flickr_fu.gemspec +35 -0
- data/lib/flickr/auth.rb +69 -0
- data/lib/flickr/base.rb +102 -0
- data/lib/flickr/comment.rb +16 -0
- data/lib/flickr/license.rb +14 -0
- data/lib/flickr/note.rb +16 -0
- data/lib/flickr/people.rb +54 -0
- data/lib/flickr/person.rb +82 -0
- data/lib/flickr/photo.rb +298 -0
- data/lib/flickr/photo_response.rb +37 -0
- data/lib/flickr/photos.rb +228 -0
- data/lib/flickr/size.rb +16 -0
- data/lib/flickr/status.rb +19 -0
- data/lib/flickr/test.rb +31 -0
- data/lib/flickr/token.rb +22 -0
- data/lib/flickr/uploader.rb +162 -0
- data/lib/flickr_fu.rb +25 -0
- metadata +92 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
# wrapping class to hold an flickr photo
|
2
|
+
#
|
3
|
+
class Flickr::People::Person
|
4
|
+
attr_accessor :username, :nsid, :is_admin, :is_pro, :icon_server, :icon_farm, :realname, :mbox_sha1sum, :location, :photos_url, :profile_url, :photo_count, :photo_first_upload, :photo_first_taken
|
5
|
+
|
6
|
+
# create a new instance of a flickr person.
|
7
|
+
#
|
8
|
+
# Params
|
9
|
+
# * flickr (Required)
|
10
|
+
# the flickr object
|
11
|
+
# * attributes (Required)
|
12
|
+
# a hash of attributes used to set the initial values of the person object
|
13
|
+
def initialize(flickr, attributes)
|
14
|
+
@flickr = flickr
|
15
|
+
attributes.each do |k,v|
|
16
|
+
send("#{k}=", v)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def buddy_icon
|
21
|
+
@buddy_icon ||= if icon_server.to_i > 0
|
22
|
+
"http://farm#{icon_farm}.static.flickr.com/#{icon_server}/buddyicons/#{nsid}.jpg"
|
23
|
+
else
|
24
|
+
'http://www.flickr.com/images/buddyicon.jpg'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Get a list of public photos for the given user.
|
29
|
+
#
|
30
|
+
# Options
|
31
|
+
# * safe_search (Optional)
|
32
|
+
# Safe search setting:
|
33
|
+
# 1 for safe.
|
34
|
+
# 2 for moderate.
|
35
|
+
# 3 for restricted.
|
36
|
+
# (Please note: Un-authed calls can only see Safe content.)
|
37
|
+
# * per_page (Optional)
|
38
|
+
# Number of photos to return per page. If this argument is omitted, it defaults to 100. The maximum allowed value is 500.
|
39
|
+
# * page (Optional)
|
40
|
+
# The page of results to return. If this argument is omitted, it defaults to 1.
|
41
|
+
def public_photos(options = {})
|
42
|
+
options.merge!({:user_id => self.nsid, :extras => "license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo,tags,machine_tags,o_dims,views,media"})
|
43
|
+
|
44
|
+
rsp = @flickr.send_request('flickr.people.getPublicPhotos', options)
|
45
|
+
|
46
|
+
returning Flickr::Photos::PhotoResponse.new(:page => rsp.photos[:page].to_i,
|
47
|
+
:pages => rsp.photos[:pages].to_i,
|
48
|
+
:per_page => rsp.photos[:perpage].to_i,
|
49
|
+
:total => rsp.photos[:total].to_i,
|
50
|
+
:photos => [],
|
51
|
+
:api => self,
|
52
|
+
:method => 'public_photos',
|
53
|
+
:options => options) do |photos|
|
54
|
+
rsp.photos.photo.each do |photo|
|
55
|
+
attributes = {:id => photo[:id],
|
56
|
+
:owner => photo[:owner],
|
57
|
+
:secret => photo[:secret],
|
58
|
+
:server => photo[:server],
|
59
|
+
:farm => photo[:farm],
|
60
|
+
:title => photo[:title],
|
61
|
+
:is_public => photo[:ispublic],
|
62
|
+
:is_friend => photo[:isfriend],
|
63
|
+
:is_family => photo[:isfamily],
|
64
|
+
:license_id => photo[:license].to_i,
|
65
|
+
:uploaded_at => (Time.at(photo[:dateupload].to_i) rescue nil),
|
66
|
+
:taken_at => (Time.parse(photo[:datetaken]) rescue nil),
|
67
|
+
:owner_name => photo[:ownername],
|
68
|
+
:icon_server => photo[:icon_server],
|
69
|
+
:original_format => photo[:originalformat],
|
70
|
+
:updated_at => (Time.at(photo[:lastupdate].to_i) rescue nil),
|
71
|
+
:geo => photo[:geo],
|
72
|
+
:tags => photo[:tags],
|
73
|
+
:machine_tags => photo[:machine_tags],
|
74
|
+
:o_dims => photo[:o_dims],
|
75
|
+
:views => photo[:views].to_i,
|
76
|
+
:media => photo[:media]}
|
77
|
+
|
78
|
+
photos << Flickr::Photos::Photo.new(@flickr, attributes)
|
79
|
+
end if rsp.photos.photo
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/flickr/photo.rb
ADDED
@@ -0,0 +1,298 @@
|
|
1
|
+
# wrapping class to hold an flickr photo
|
2
|
+
#
|
3
|
+
class Flickr::Photos::Photo
|
4
|
+
attr_accessor :id, :owner, :secret, :server, :farm, :title, :is_public, :is_friend, :is_family # standard attributes
|
5
|
+
attr_accessor :license_id, :uploaded_at, :taken_at, :owner_name, :icon_server, :original_format, :updated_at, :geo, :tags, :machine_tags, :o_dims, :views, :media # extra attributes
|
6
|
+
attr_accessor :info_added, :description, :original_secret, :owner_username, :owner_realname, :url_photopage, :notes # info attributes
|
7
|
+
attr_accessor :sizes_added, :sizes, :url_square, :url_thumbnail, :url_small, :url_medium, :url_large, :url_original # size attributes
|
8
|
+
attr_accessor :comments_added, :comments # comment attributes
|
9
|
+
|
10
|
+
# create a new instance of a flickr photo.
|
11
|
+
#
|
12
|
+
# Params
|
13
|
+
# * flickr (Required)
|
14
|
+
# the flickr object
|
15
|
+
# * attributes (Required)
|
16
|
+
# a hash of attributes used to set the initial values of the photo object
|
17
|
+
def initialize(flickr, attributes)
|
18
|
+
@flickr = flickr
|
19
|
+
attributes.each do |k,v|
|
20
|
+
send("#{k}=", v)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# retreive the url to the image stored on flickr
|
25
|
+
#
|
26
|
+
# == Params
|
27
|
+
# * size (Optional)
|
28
|
+
# the size of the image to return. Optional sizes are:
|
29
|
+
# :square - square 75x75
|
30
|
+
# :thumbnail - 100 on longest side
|
31
|
+
# :small - 240 on longest side
|
32
|
+
# :medium - 500 on longest side
|
33
|
+
# :large - 1024 on longest side (only exists for very large original images)
|
34
|
+
# :original - original image, either a jpg, gif or png, depending on source format
|
35
|
+
#
|
36
|
+
def url(size = :medium)
|
37
|
+
attach_sizes
|
38
|
+
send("url_#{size}")
|
39
|
+
end
|
40
|
+
|
41
|
+
# save the current photo to the local computer
|
42
|
+
#
|
43
|
+
# == Params
|
44
|
+
# * filename (Required)
|
45
|
+
# name of the new file omiting the extention (ex. photo_1)
|
46
|
+
# * size (Optional)
|
47
|
+
# the size of the image to return. Optional sizes are:
|
48
|
+
# :small - square 75x75
|
49
|
+
# :thumbnail - 100 on longest side
|
50
|
+
# :small - 240 on longest side
|
51
|
+
# :medium - 500 on longest side
|
52
|
+
# :large - 1024 on longest side (only exists for very large original images)
|
53
|
+
# :original - original image, either a jpg, gif or png, depending on source format
|
54
|
+
#
|
55
|
+
def save_as(filename, size = :medium)
|
56
|
+
format = size.to_sym == :original ? self.original_format : 'jpg'
|
57
|
+
filename = "#{filename}.#{format}"
|
58
|
+
|
59
|
+
if File.exists?(filename) or not self.url(size)
|
60
|
+
false
|
61
|
+
else
|
62
|
+
f = File.new(filename, 'w+')
|
63
|
+
f.puts open(self.url(size)).read
|
64
|
+
f.close
|
65
|
+
f
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Add tags to a photo.
|
70
|
+
#
|
71
|
+
# Params
|
72
|
+
# * tags (Required)
|
73
|
+
# comma seperated list of tags
|
74
|
+
#
|
75
|
+
def add_tags(tags)
|
76
|
+
rsp = @flickr.send_request('flickr.photos.addTags', {:photo_id => self.id, :tags => tags}, :post)
|
77
|
+
true
|
78
|
+
end
|
79
|
+
|
80
|
+
# Add comment to a photo as the currently authenticated user.
|
81
|
+
#
|
82
|
+
# Params
|
83
|
+
# * message (Required)
|
84
|
+
# text of the comment
|
85
|
+
#
|
86
|
+
def add_comment(message)
|
87
|
+
rsp = @flickr.send_request('flickr.photos.comments.addComment', {:photo_id => self.id, :comment_text => message}, :post)
|
88
|
+
true
|
89
|
+
end
|
90
|
+
|
91
|
+
# Add a note to a photo. Coordinates and sizes are in pixels, based on the 500px image size shown on individual photo pages.
|
92
|
+
#
|
93
|
+
# Params
|
94
|
+
# * message (Required)
|
95
|
+
# The text of the note
|
96
|
+
# * x (Required)
|
97
|
+
# The left coordinate of the note
|
98
|
+
# * y (Required)
|
99
|
+
# The top coordinate of the note
|
100
|
+
# * w (Required)
|
101
|
+
# The width of the note
|
102
|
+
# * h (Required)
|
103
|
+
# The height of the note
|
104
|
+
#
|
105
|
+
def add_note(message, x, y, w, h)
|
106
|
+
rsp = @flickr.send_request('flickr.photos.notes.add', {:photo_id => self.id, :note_x => x, :note_y => y, :note_w => w, :note_h => h, :note_text => message}, :post)
|
107
|
+
true
|
108
|
+
end
|
109
|
+
|
110
|
+
# Rotate a photo.
|
111
|
+
#
|
112
|
+
# Params
|
113
|
+
# * degrees (Required)
|
114
|
+
# The amount of degrees by which to rotate the photo (clockwise) from it's current orientation. Valid values are 90, 180 and 270.
|
115
|
+
#
|
116
|
+
def rotate(degrees)
|
117
|
+
rsp = @flickr.send_request('flickr.photos.transform.rotate', {:photo_id => self.id, :degrees => degrees}, :post)
|
118
|
+
true
|
119
|
+
end
|
120
|
+
|
121
|
+
# return the license associated with the photo
|
122
|
+
#
|
123
|
+
def license
|
124
|
+
@flickr.photos.licenses[self.license_id]
|
125
|
+
end
|
126
|
+
|
127
|
+
# Sets the license for a photo.
|
128
|
+
#
|
129
|
+
# Params
|
130
|
+
# * license_id (Required)
|
131
|
+
# The license to apply, or 0 (zero) to remove the current license.
|
132
|
+
def set_license(license_id)
|
133
|
+
rsp = @flickr.send_request('flickr.photos.licenses.setLicense', {:photo_id => self.id, :license_id => license_id}, :post)
|
134
|
+
true
|
135
|
+
end
|
136
|
+
|
137
|
+
def description # :nodoc:
|
138
|
+
attach_info
|
139
|
+
@description
|
140
|
+
end
|
141
|
+
|
142
|
+
def original_secret # :nodoc:
|
143
|
+
attach_info
|
144
|
+
@original_secret
|
145
|
+
end
|
146
|
+
|
147
|
+
def owner_username # :nodoc:
|
148
|
+
attach_info
|
149
|
+
@owner_username
|
150
|
+
end
|
151
|
+
|
152
|
+
def owner_realname # :nodoc:
|
153
|
+
attach_info
|
154
|
+
@owner_realname
|
155
|
+
end
|
156
|
+
|
157
|
+
def url_photopage # :nodoc:
|
158
|
+
attach_info
|
159
|
+
@url_photopage
|
160
|
+
end
|
161
|
+
|
162
|
+
def comments # :nodoc:
|
163
|
+
attach_comments
|
164
|
+
@comments
|
165
|
+
end
|
166
|
+
|
167
|
+
def sizes # :nodoc:
|
168
|
+
attach_sizes
|
169
|
+
@sizes
|
170
|
+
end
|
171
|
+
|
172
|
+
def notes # :nodoc:
|
173
|
+
attach_info
|
174
|
+
@notes
|
175
|
+
end
|
176
|
+
|
177
|
+
protected
|
178
|
+
def url_square # :nodoc:
|
179
|
+
attach_sizes
|
180
|
+
@url_square
|
181
|
+
end
|
182
|
+
|
183
|
+
def url_thumbnail # :nodoc:
|
184
|
+
attach_sizes
|
185
|
+
@url_thumbnail
|
186
|
+
end
|
187
|
+
|
188
|
+
def url_small # :nodoc:
|
189
|
+
attach_sizes
|
190
|
+
@url_small
|
191
|
+
end
|
192
|
+
|
193
|
+
def url_medium # :nodoc:
|
194
|
+
attach_sizes
|
195
|
+
@url_medium
|
196
|
+
end
|
197
|
+
|
198
|
+
def url_large # :nodoc:
|
199
|
+
attach_sizes
|
200
|
+
@url_large
|
201
|
+
end
|
202
|
+
|
203
|
+
def url_original # :nodoc:
|
204
|
+
attach_sizes
|
205
|
+
@url_original
|
206
|
+
end
|
207
|
+
|
208
|
+
private
|
209
|
+
attr_accessor :comment_count
|
210
|
+
|
211
|
+
# convert the size to the key used in the flickr url
|
212
|
+
def size_key(size)
|
213
|
+
case size.to_sym
|
214
|
+
when :square : 's'
|
215
|
+
when :thumb, :thumbnail : 't'
|
216
|
+
when :small : 'm'
|
217
|
+
when :medium : '-'
|
218
|
+
when :large : 'b'
|
219
|
+
when :original : 'o'
|
220
|
+
else ''
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
# loads photo info when a field is requested that requires additional info
|
225
|
+
def attach_info
|
226
|
+
unless self.info_added
|
227
|
+
rsp = @flickr.send_request('flickr.photos.getInfo', :photo_id => self.id, :secret => self.secret)
|
228
|
+
|
229
|
+
self.info_added = true
|
230
|
+
self.description = rsp.photo.description.to_s
|
231
|
+
self.original_secret = rsp.photo[:originalsecret]
|
232
|
+
self.owner_username = rsp.photo.owner[:username]
|
233
|
+
self.owner_realname = rsp.photo.owner[:realname]
|
234
|
+
self.url_photopage = rsp.photo.urls.url.to_s
|
235
|
+
self.comment_count = rsp.photo.comments.to_s.to_i
|
236
|
+
|
237
|
+
self.notes = []
|
238
|
+
|
239
|
+
rsp.photo.notes.note.each do |note|
|
240
|
+
self.notes << Flickr::Photos::Note.new(:id => note[:id],
|
241
|
+
:note => note.to_s,
|
242
|
+
:author => note[:author],
|
243
|
+
:author_name => note[:authorname],
|
244
|
+
:x => note[:x],
|
245
|
+
:y => note[:y],
|
246
|
+
:width => note[:w],
|
247
|
+
:height => note[:h])
|
248
|
+
end if rsp.photo.notes.note
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
# loads picture sizes only after one has been requested
|
253
|
+
def attach_sizes
|
254
|
+
unless self.sizes_added
|
255
|
+
rsp = @flickr.send_request('flickr.photos.getSizes', :photo_id => self.id)
|
256
|
+
|
257
|
+
self.sizes_added = true
|
258
|
+
self.sizes = []
|
259
|
+
|
260
|
+
# TODO: investigate the new video features and integrate better
|
261
|
+
rsp.sizes.size.each do |size|
|
262
|
+
method = "url_#{size[:label].downcase}="
|
263
|
+
next unless respond_to? method
|
264
|
+
send(method, size[:source])
|
265
|
+
|
266
|
+
# send("url_#{size[:label].downcase}=", size[:source])
|
267
|
+
|
268
|
+
self.sizes << Flickr::Photos::Size.new(:label => size[:label],
|
269
|
+
:width => size[:width],
|
270
|
+
:height => size[:height],
|
271
|
+
:source => size[:source],
|
272
|
+
:url => size[:url])
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
# loads comments once they have been requested
|
278
|
+
def attach_comments
|
279
|
+
if @comment_count == 0
|
280
|
+
self.comments = []
|
281
|
+
self.comments_added = true
|
282
|
+
elsif not self.comments_added
|
283
|
+
rsp = @flickr.send_request('flickr.photos.comments.getList', :photo_id => self.id)
|
284
|
+
|
285
|
+
self.comments = []
|
286
|
+
self.comments_added = true
|
287
|
+
|
288
|
+
rsp.comments.comment.each do |comment|
|
289
|
+
self.comments << Flickr::Photos::Comment.new(:id => comment[:id],
|
290
|
+
:comment => comment.to_s,
|
291
|
+
:author => comment[:author],
|
292
|
+
:author_name => comment[:authorname],
|
293
|
+
:permalink => comment[:permalink],
|
294
|
+
:created_at => (Time.at(comment[:datecreate].to_i) rescue nil))
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# wrapping class to hold a photos response from the flickr api
|
2
|
+
#
|
3
|
+
class Flickr::Photos::PhotoResponse
|
4
|
+
attr_accessor :page, :pages, :per_page, :total, :photos, :api, :method, :options
|
5
|
+
|
6
|
+
# creates an object to hold the search response.
|
7
|
+
#
|
8
|
+
# Params
|
9
|
+
# * attributes (Required)
|
10
|
+
# a hash of attributes used to set the initial values of the response object
|
11
|
+
def initialize(attributes)
|
12
|
+
attributes.each do |k,v|
|
13
|
+
send("#{k}=", v)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Add a Flickr::Photos::Photo object to the photos array. It does nothing if you pass a non photo object
|
18
|
+
def <<(photo)
|
19
|
+
self.photos ||= []
|
20
|
+
self.photos << photo if photo.is_a?(Flickr::Photos::Photo)
|
21
|
+
end
|
22
|
+
|
23
|
+
# gets the next page from flickr if there are anymore pages in the current photos object
|
24
|
+
def next_page
|
25
|
+
api.send(self.method, options.merge(:page => self.page.to_i + 1)) if self.page.to_i < self.pages.to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
# gets the previous page from flickr if there is a previous page in the current photos object
|
29
|
+
def previous_page
|
30
|
+
api.send(self.method, options.merge(:page => self.page.to_i - 1)) if self.page.to_i > 1
|
31
|
+
end
|
32
|
+
|
33
|
+
# passes all unknown request to the photos array if it responds to the method
|
34
|
+
def method_missing(method, *args, &block)
|
35
|
+
self.photos.respond_to?(method) ? self.photos.send(method, *args, &block) : super
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,228 @@
|
|
1
|
+
class Flickr::Photos < Flickr::Base
|
2
|
+
def initialize(flickr)
|
3
|
+
@flickr = flickr
|
4
|
+
end
|
5
|
+
|
6
|
+
# Return a list of photos matching some criteria. Only photos visible to the calling user will be returned. To return private or semi-private photos,
|
7
|
+
# the caller must be authenticated with 'read' permissions, and have permission to view the photos. Unauthenticated calls will only return public photos.
|
8
|
+
#
|
9
|
+
# == Authentication
|
10
|
+
# This method does not require authentication.
|
11
|
+
#
|
12
|
+
# == Options
|
13
|
+
# * user_id (Optional)
|
14
|
+
# The NSID of the user who's photo to search. If this parameter isn't passed then everybody's public photos will be searched. A value of "me" will
|
15
|
+
# search against the calling user's photos for authenticated calls.
|
16
|
+
# * tags (Optional)
|
17
|
+
# A comma-delimited list of tags. Photos with one or more of the tags listed will be returned.
|
18
|
+
# * tag_mode (Optional)
|
19
|
+
# Either 'any' for an OR combination of tags, or 'all' for an AND combination. Defaults to 'any' if not specified.
|
20
|
+
# * text (Optional)
|
21
|
+
# A free text search. Photos who's title, description or tags contain the text will be returned.
|
22
|
+
# * min_upload_date (Optional)
|
23
|
+
# Minimum upload date. Photos with an upload date greater than or equal to this value will be returned. The date should be in the form of a unix timestamp.
|
24
|
+
# * max_upload_date (Optional)
|
25
|
+
# Maximum upload date. Photos with an upload date less than or equal to this value will be returned. The date should be in the form of a unix timestamp.
|
26
|
+
# * min_taken_date (Optional)
|
27
|
+
# Minimum taken date. Photos with an taken date greater than or equal to this value will be returned. The date should be in the form of a mysql datetime.
|
28
|
+
# * max_taken_date (Optional)
|
29
|
+
# Maximum taken date. Photos with an taken date less than or equal to this value will be returned. The date should be in the form of a mysql datetime.
|
30
|
+
# * license (Optional)
|
31
|
+
# The license id for photos (for possible values see the flickr.photos.licenses.getInfo method). Multiple licenses may be comma-separated.
|
32
|
+
# * sort (Optional)
|
33
|
+
# The order in which to sort returned photos. Deafults to date-posted-desc. The possible values are: date-posted-asc, date-posted-desc, date-taken-asc,
|
34
|
+
# date-taken-desc, interestingness-desc, interestingness-asc, and relevance.
|
35
|
+
# * privacy_filter (Optional)
|
36
|
+
# Return photos only matching a certain privacy level. This only applies when making an authenticated call to view photos you own. Valid values are:
|
37
|
+
# 1 public photos
|
38
|
+
# 2 private photos visible to friends
|
39
|
+
# 3 private photos visible to family
|
40
|
+
# 4 private photos visible to friends & family
|
41
|
+
# 5 completely private photos
|
42
|
+
# * bbox (Optional)
|
43
|
+
# A comma-delimited list of 4 values defining the Bounding Box of the area that will be searched.
|
44
|
+
#
|
45
|
+
# The 4 values represent the bottom-left corner of the box and the top-right corner, minimum_longitude, minimum_latitude, maximum_longitude, maximum_latitude.
|
46
|
+
#
|
47
|
+
# Longitude has a range of -180 to 180 , latitude of -90 to 90. Defaults to -180, -90, 180, 90 if not specified.
|
48
|
+
#
|
49
|
+
# Unlike standard photo queries, geo (or bounding box) queries will only return 250 results per page.
|
50
|
+
#
|
51
|
+
# Geo queries require some sort of limiting agent in order to prevent the database from crying. This is basically like the check against "parameterless searches"
|
52
|
+
# for queries without a geo component.
|
53
|
+
#
|
54
|
+
# A tag, for instance, is considered a limiting agent as are user defined min_date_taken and min_date_upload parameters — If no limiting factor is passed we
|
55
|
+
# return only photos added in the last 12 hours (though we may extend the limit in the future).
|
56
|
+
# * accuracy (Optional)
|
57
|
+
# Recorded accuracy level of the location information. Current range is 1-16 :
|
58
|
+
# World level is 1
|
59
|
+
# Country is ~3
|
60
|
+
# Region is ~6
|
61
|
+
# City is ~11
|
62
|
+
# Street is ~16
|
63
|
+
# Defaults to maximum value if not specified.
|
64
|
+
# * safe_search (Optional)
|
65
|
+
# Safe search setting:
|
66
|
+
# 1 for safe.
|
67
|
+
# 2 for moderate.
|
68
|
+
# 3 for restricted.
|
69
|
+
# (Please note: Un-authed calls can only see Safe content.)
|
70
|
+
# * content_type (Optional)
|
71
|
+
# Content Type setting:
|
72
|
+
# 1 for photos only.
|
73
|
+
# 2 for screenshots only.
|
74
|
+
# 3 for 'other' only.
|
75
|
+
# 4 for photos and screenshots.
|
76
|
+
# 5 for screenshots and 'other'.
|
77
|
+
# 6 for photos and 'other'.
|
78
|
+
# 7 for photos, screenshots, and 'other' (all).
|
79
|
+
# * machine_tags (Optional)
|
80
|
+
# Aside from passing in a fully formed machine tag, there is a special syntax for searching on specific properties :
|
81
|
+
# Find photos using the 'dc' namespace : "machine_tags" => "dc:"
|
82
|
+
# Find photos with a title in the 'dc' namespace : "machine_tags" => "dc:title="
|
83
|
+
# Find photos titled "mr. camera" in the 'dc' namespace : "machine_tags" => "dc:title=\"mr. camera\"
|
84
|
+
# Find photos whose value is "mr. camera" : "machine_tags" => "*:*=\"mr. camera\""
|
85
|
+
# Find photos that have a title, in any namespace : "machine_tags" => "*:title="
|
86
|
+
# Find photos that have a title, in any namespace, whose value is "mr. camera" : "machine_tags" => "*:title=\"mr. camera\""
|
87
|
+
# Find photos, in the 'dc' namespace whose value is "mr. camera" : "machine_tags" => "dc:*=\"mr. camera\""
|
88
|
+
# Multiple machine tags may be queried by passing a comma-separated list. The number of machine tags you can pass in a single query depends on
|
89
|
+
# the tag mode (AND or OR) that you are querying with. "AND" queries are limited to (16) machine tags. "OR" queries are limited to (8).
|
90
|
+
# * machine_tag_mode (Required)
|
91
|
+
# Either 'any' for an OR combination of tags, or 'all' for an AND combination. Defaults to 'any' if not specified.
|
92
|
+
# * group_id (Optional)
|
93
|
+
# The id of a group who's pool to search. If specified, only matching photos posted to the group's pool will be returned.
|
94
|
+
# * woe_id (Optional)
|
95
|
+
# A 32-bit identifier that uniquely represents spatial entities. (not used if bbox argument is present). Experimental.
|
96
|
+
#
|
97
|
+
# Geo queries require some sort of limiting agent in order to prevent the database from crying. This is basically like the check against "parameterless searches"
|
98
|
+
# for queries without a geo component.
|
99
|
+
#
|
100
|
+
# A tag, for instance, is considered a limiting agent as are user defined min_date_taken and min_date_upload parameters &emdash; If no limiting factor is passed
|
101
|
+
# we return only photos added in the last 12 hours (though we may extend the limit in the future).
|
102
|
+
# * place_id (Optional)
|
103
|
+
# A Flickr place id. (not used if bbox argument is present). Experimental.
|
104
|
+
#
|
105
|
+
# Geo queries require some sort of limiting agent in order to prevent the database from crying. This is basically like the check against "parameterless searches"
|
106
|
+
# for queries without a geo component.
|
107
|
+
#
|
108
|
+
# A tag, for instance, is considered a limiting agent as are user defined min_date_taken and min_date_upload parameters &emdash; If no limiting factor is passed
|
109
|
+
# we return only photos added in the last 12 hours (though we may extend the limit in the future).
|
110
|
+
# * per_page (Optional)
|
111
|
+
# Number of photos to return per page. If this argument is omitted, it defaults to 100. The maximum allowed value is 500.
|
112
|
+
# * page (Optional)
|
113
|
+
# The page of results to return. If this argument is omitted, it defaults to 1.
|
114
|
+
#
|
115
|
+
def search(options)
|
116
|
+
options.merge!({:extras => "license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo,tags,machine_tags,o_dims,views,media"})
|
117
|
+
|
118
|
+
rsp = @flickr.send_request('flickr.photos.search', options)
|
119
|
+
|
120
|
+
returning PhotoResponse.new(:page => rsp.photos[:page].to_i,
|
121
|
+
:pages => rsp.photos[:pages].to_i,
|
122
|
+
:per_page => rsp.photos[:perpage].to_i,
|
123
|
+
:total => rsp.photos[:total].to_i,
|
124
|
+
:photos => [],
|
125
|
+
:api => self,
|
126
|
+
:method => 'search',
|
127
|
+
:options => options) do |photos|
|
128
|
+
rsp.photos.photo.each do |photo|
|
129
|
+
attributes = create_attributes(photo)
|
130
|
+
|
131
|
+
photos << Photo.new(@flickr, attributes)
|
132
|
+
end if rsp.photos.photo
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# Returns a list of the latest public photos uploaded to flickr.
|
137
|
+
#
|
138
|
+
# == Authentication
|
139
|
+
# This method does not require authentication.
|
140
|
+
#
|
141
|
+
# == Options
|
142
|
+
# * per_page (Optional)
|
143
|
+
# Number of photos to return per page. If this argument is omitted, it defaults to 100. The maximum allowed value is 500.
|
144
|
+
# * page (Optional)
|
145
|
+
# The page of results to return. If this argument is omitted, it defaults to 1.
|
146
|
+
#
|
147
|
+
def get_recent(options)
|
148
|
+
options.merge!({:extras => "license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo,tags,machine_tags,o_dims,views,media"})
|
149
|
+
|
150
|
+
rsp = @flickr.send_request('flickr.photos.getRecent', options)
|
151
|
+
|
152
|
+
returning PhotoResponse.new(:page => rsp.photos[:page].to_i,
|
153
|
+
:pages => rsp.photos[:pages].to_i,
|
154
|
+
:per_page => rsp.photos[:perpage].to_i,
|
155
|
+
:total => rsp.photos[:total].to_i,
|
156
|
+
:photos => [], :api => self,
|
157
|
+
:method => 'flickr.photos.getRecent',
|
158
|
+
:options => options) do |photos|
|
159
|
+
rsp.photos.photo.each do |photo|
|
160
|
+
attributes = create_attributes(photo)
|
161
|
+
|
162
|
+
photos << Photo.new(@flickr, attributes)
|
163
|
+
end if rsp.photos.photo
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def interesting(options)
|
168
|
+
options.merge!({:extras => "license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo,tags,machine_tags,o_dims,views,media"})
|
169
|
+
|
170
|
+
rsp = @flickr.send_request('flickr.interestingness.getList', options)
|
171
|
+
|
172
|
+
returning PhotoResponse.new(:page => rsp.photos[:page].to_i,
|
173
|
+
:pages => rsp.photos[:pages].to_i,
|
174
|
+
:per_page => rsp.photos[:perpage].to_i,
|
175
|
+
:total => rsp.photos[:total].to_i,
|
176
|
+
:photos => [],
|
177
|
+
:api => self,
|
178
|
+
:method => 'flickr.interestingness.getList',
|
179
|
+
:options => options) do |photos|
|
180
|
+
rsp.photos.photo.each do |photo|
|
181
|
+
attributes = create_attributes(photo)
|
182
|
+
|
183
|
+
|
184
|
+
photos << Photo.new(@flickr, attributes)
|
185
|
+
end if rsp.photos.photo
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def licenses
|
190
|
+
@licenses ||= get_licenses
|
191
|
+
end
|
192
|
+
|
193
|
+
protected
|
194
|
+
def create_attributes(photo)
|
195
|
+
{:id => photo[:id],
|
196
|
+
:owner => photo[:owner],
|
197
|
+
:secret => photo[:secret],
|
198
|
+
:server => photo[:server],
|
199
|
+
:farm => photo[:farm],
|
200
|
+
:title => photo[:title],
|
201
|
+
:is_public => photo[:ispublic],
|
202
|
+
:is_friend => photo[:isfriend],
|
203
|
+
:is_family => photo[:isfamily],
|
204
|
+
:license_id => photo[:license].to_i,
|
205
|
+
:uploaded_at => (Time.at(photo[:dateupload].to_i) rescue nil),
|
206
|
+
:taken_at => (Time.parse(photo[:datetaken]) rescue nil),
|
207
|
+
:owner_name => photo[:ownername],
|
208
|
+
:icon_server => photo[:icon_server],
|
209
|
+
:original_format => photo[:originalformat],
|
210
|
+
:updated_at => (Time.at(photo[:lastupdate].to_i) rescue nil),
|
211
|
+
:geo => photo[:geo],
|
212
|
+
:tags => photo[:tags],
|
213
|
+
:machine_tags => photo[:machine_tags],
|
214
|
+
:o_dims => photo[:o_dims],
|
215
|
+
:views => photo[:views].to_i,
|
216
|
+
:media => photo[:media]}
|
217
|
+
end
|
218
|
+
|
219
|
+
def get_licenses
|
220
|
+
rsp = @flickr.send_request('flickr.photos.licenses.getInfo')
|
221
|
+
|
222
|
+
returning Hash.new do |licenses|
|
223
|
+
rsp.licenses.license.each do |license|
|
224
|
+
licenses[license[:id].to_i] = Flickr::Photos::License.new(:id => license[:id].to_i, :name => license[:name], :url => license[:url])
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|