em-flickraw 0.8.5

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.
@@ -0,0 +1,48 @@
1
+ require 'rake/clean'
2
+ require 'rake/rdoctask'
3
+ require 'rake/packagetask'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/testtask'
6
+
7
+ # needed for the rdoc task
8
+ require './lib/em_rake'
9
+
10
+ FlickRawOptions = {'lazyload' => true}
11
+ require './lib/flickraw'
12
+ require './flickraw_rdoc' if RUBY_VERSION >= "1.9"
13
+
14
+ PKG_FILES = FileList["lib/flickraw.rb", "flickraw_rdoc.rb", "LICENSE", "README.rdoc", "rakefile", "examples/*.rb", "test/*.rb"].to_a
15
+
16
+ spec = Gem::Specification.new do |s|
17
+ s.summary = "Event machine based flickr library with a syntax close to the syntax described on http://www.flickr.com/services/api"
18
+ s.name = "em-flickraw"
19
+ s.authors = ["Mael Clerambault", "Jens Kraemer"]
20
+ s.email = "jk@jkraemer.net"
21
+ s.homepage = "http://github.com/jkraemer/flickraw/"
22
+ s.version = FlickRaw::VERSION
23
+ s.files = PKG_FILES
24
+ s.add_dependency 'json', '>= 1.1.1'
25
+ s.add_dependency 'eventmachine', ">= 1.0.0.beta.3"
26
+ s.add_dependency 'em-http-request', "= 1.0.0.beta.3"
27
+ s.add_dependency 'em-synchrony', "= 0.3.0.beta.1"
28
+ s.required_ruby_version = ::Gem::Requirement.new("~> 1.9")
29
+ end
30
+
31
+ Rake::GemPackageTask.new(spec).define
32
+
33
+ desc "Create default gemspec file"
34
+ file "flickraw.gemspec" do
35
+ open("flickraw.gemspec", "w") {|g| g.puts spec.to_ruby }
36
+ end
37
+ task :gem => ["flickraw.gemspec"]
38
+ CLOBBER.add "flickraw.gemspec"
39
+
40
+ Rake::RDocTask.new do |rd|
41
+ rd.main = "README.rdoc"
42
+ rd.rdoc_files.include "README.rdoc", "lib/flickraw.rb"
43
+ end
44
+
45
+ Rake::TestTask.new(:test) do |t|
46
+ t.libs << 'lib'
47
+ t.pattern = 'test/**/*_test.rb'
48
+ end
@@ -0,0 +1,426 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'test/unit'
4
+ require 'flickraw'
5
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')
6
+
7
+ # To run the tests, copy test/config.yml.example to test/config.yml and
8
+ # update with your flickr API key, shared secret and auth token (used for upload test)
9
+ class Basic < Test::Unit::TestCase
10
+ def test_request
11
+ flickr_objects = %w{activity auth blogs collections commons contacts
12
+ favorites galleries groups interestingness machinetags panda
13
+ people photos photosets places prefs reflection stats tags
14
+ test urls
15
+ }
16
+ assert_equal FlickRaw::Flickr.flickr_objects, flickr_objects
17
+ flickr_objects.each {|o|
18
+ assert_respond_to flickr, o
19
+ assert_kind_of FlickRaw::Request, eval("flickr." + o)
20
+ }
21
+ end
22
+
23
+ def test_known
24
+ known_methods = %w{
25
+ flickr.activity.userComments
26
+ flickr.activity.userPhotos
27
+ flickr.auth.checkToken
28
+ flickr.auth.getFrob
29
+ flickr.auth.getFullToken
30
+ flickr.auth.getToken
31
+ flickr.blogs.getList
32
+ flickr.blogs.getServices
33
+ flickr.blogs.postPhoto
34
+ flickr.collections.getInfo
35
+ flickr.collections.getTree
36
+ flickr.commons.getInstitutions
37
+ flickr.contacts.getList
38
+ flickr.contacts.getListRecentlyUploaded
39
+ flickr.contacts.getPublicList
40
+ flickr.favorites.add
41
+ flickr.favorites.getList
42
+ flickr.favorites.getPublicList
43
+ flickr.favorites.remove
44
+ flickr.galleries.addPhoto
45
+ flickr.galleries.create
46
+ flickr.galleries.editMeta
47
+ flickr.galleries.editPhoto
48
+ flickr.galleries.editPhotos
49
+ flickr.galleries.getInfo
50
+ flickr.galleries.getList
51
+ flickr.galleries.getListForPhoto
52
+ flickr.galleries.getPhotos
53
+ flickr.groups.browse
54
+ flickr.groups.getInfo
55
+ flickr.groups.members.getList
56
+ flickr.groups.pools.add
57
+ flickr.groups.pools.getContext
58
+ flickr.groups.pools.getGroups
59
+ flickr.groups.pools.getPhotos
60
+ flickr.groups.pools.remove
61
+ flickr.groups.search
62
+ flickr.interestingness.getList
63
+ flickr.machinetags.getNamespaces
64
+ flickr.machinetags.getPairs
65
+ flickr.machinetags.getPredicates
66
+ flickr.machinetags.getRecentValues
67
+ flickr.machinetags.getValues
68
+ flickr.panda.getList
69
+ flickr.panda.getPhotos
70
+ flickr.people.findByEmail
71
+ flickr.people.findByUsername
72
+ flickr.people.getInfo
73
+ flickr.people.getPhotos
74
+ flickr.people.getPhotosOf
75
+ flickr.people.getPublicGroups
76
+ flickr.people.getPublicPhotos
77
+ flickr.people.getUploadStatus
78
+ flickr.photos.addTags
79
+ flickr.photos.comments.addComment
80
+ flickr.photos.comments.deleteComment
81
+ flickr.photos.comments.editComment
82
+ flickr.photos.comments.getList
83
+ flickr.photos.comments.getRecentForContacts
84
+ flickr.photos.delete
85
+ flickr.photos.geo.batchCorrectLocation
86
+ flickr.photos.geo.correctLocation
87
+ flickr.photos.geo.getLocation
88
+ flickr.photos.geo.getPerms
89
+ flickr.photos.geo.photosForLocation
90
+ flickr.photos.geo.removeLocation
91
+ flickr.photos.geo.setContext
92
+ flickr.photos.geo.setLocation
93
+ flickr.photos.geo.setPerms
94
+ flickr.photos.getAllContexts
95
+ flickr.photos.getContactsPhotos
96
+ flickr.photos.getContactsPublicPhotos
97
+ flickr.photos.getContext
98
+ flickr.photos.getCounts
99
+ flickr.photos.getExif
100
+ flickr.photos.getFavorites
101
+ flickr.photos.getInfo
102
+ flickr.photos.getNotInSet
103
+ flickr.photos.getPerms
104
+ flickr.photos.getRecent
105
+ flickr.photos.getSizes
106
+ flickr.photos.getUntagged
107
+ flickr.photos.getWithGeoData
108
+ flickr.photos.getWithoutGeoData
109
+ flickr.photos.licenses.getInfo
110
+ flickr.photos.licenses.setLicense
111
+ flickr.photos.notes.add
112
+ flickr.photos.notes.delete
113
+ flickr.photos.notes.edit
114
+ flickr.photos.people.add
115
+ flickr.photos.people.delete
116
+ flickr.photos.people.deleteCoords
117
+ flickr.photos.people.editCoords
118
+ flickr.photos.people.getList
119
+ flickr.photos.recentlyUpdated
120
+ flickr.photos.removeTag
121
+ flickr.photos.search
122
+ flickr.photos.setContentType
123
+ flickr.photos.setDates
124
+ flickr.photos.setMeta
125
+ flickr.photos.setPerms
126
+ flickr.photos.setSafetyLevel
127
+ flickr.photos.setTags
128
+ flickr.photos.transform.rotate
129
+ flickr.photos.upload.checkTickets
130
+ flickr.photosets.addPhoto
131
+ flickr.photosets.comments.addComment
132
+ flickr.photosets.comments.deleteComment
133
+ flickr.photosets.comments.editComment
134
+ flickr.photosets.comments.getList
135
+ flickr.photosets.create
136
+ flickr.photosets.delete
137
+ flickr.photosets.editMeta
138
+ flickr.photosets.editPhotos
139
+ flickr.photosets.getContext
140
+ flickr.photosets.getInfo
141
+ flickr.photosets.getList
142
+ flickr.photosets.getPhotos
143
+ flickr.photosets.orderSets
144
+ flickr.photosets.removePhoto
145
+ flickr.photosets.removePhotos
146
+ flickr.photosets.reorderPhotos
147
+ flickr.photosets.setPrimaryPhoto
148
+ flickr.places.find
149
+ flickr.places.findByLatLon
150
+ flickr.places.getChildrenWithPhotosPublic
151
+ flickr.places.getInfo
152
+ flickr.places.getInfoByUrl
153
+ flickr.places.getPlaceTypes
154
+ flickr.places.getShapeHistory
155
+ flickr.places.getTopPlacesList
156
+ flickr.places.placesForBoundingBox
157
+ flickr.places.placesForContacts
158
+ flickr.places.placesForTags
159
+ flickr.places.placesForUser
160
+ flickr.places.resolvePlaceId
161
+ flickr.places.resolvePlaceURL
162
+ flickr.places.tagsForPlace
163
+ flickr.prefs.getContentType
164
+ flickr.prefs.getGeoPerms
165
+ flickr.prefs.getHidden
166
+ flickr.prefs.getPrivacy
167
+ flickr.prefs.getSafetyLevel
168
+ flickr.reflection.getMethodInfo
169
+ flickr.reflection.getMethods
170
+ flickr.stats.getCollectionDomains
171
+ flickr.stats.getCollectionReferrers
172
+ flickr.stats.getCollectionStats
173
+ flickr.stats.getCSVFiles
174
+ flickr.stats.getPhotoDomains
175
+ flickr.stats.getPhotoReferrers
176
+ flickr.stats.getPhotosetDomains
177
+ flickr.stats.getPhotosetReferrers
178
+ flickr.stats.getPhotosetStats
179
+ flickr.stats.getPhotoStats
180
+ flickr.stats.getPhotostreamDomains
181
+ flickr.stats.getPhotostreamReferrers
182
+ flickr.stats.getPhotostreamStats
183
+ flickr.stats.getPopularPhotos
184
+ flickr.stats.getTotalViews
185
+ flickr.tags.getClusterPhotos
186
+ flickr.tags.getClusters
187
+ flickr.tags.getHotList
188
+ flickr.tags.getListPhoto
189
+ flickr.tags.getListUser
190
+ flickr.tags.getListUserPopular
191
+ flickr.tags.getListUserRaw
192
+ flickr.tags.getRelated
193
+ flickr.test.echo
194
+ flickr.test.login
195
+ flickr.test.null
196
+ flickr.urls.getGroup
197
+ flickr.urls.getUserPhotos
198
+ flickr.urls.getUserProfile
199
+ flickr.urls.lookupGallery
200
+ flickr.urls.lookupGroup
201
+ flickr.urls.lookupUser
202
+ }
203
+ found_methods = flickr.reflection.getMethods
204
+ assert_instance_of FlickRaw::ResponseList, found_methods
205
+ assert_equal known_methods, found_methods.to_a
206
+ end
207
+
208
+ def test_list
209
+ list = flickr.photos.getRecent :per_page => '10'
210
+ assert_instance_of FlickRaw::ResponseList, list
211
+ assert_equal(list.size, 10)
212
+ end
213
+
214
+ def people(user)
215
+ assert_equal "41650587@N02", user.id
216
+ assert_equal "41650587@N02", user.nsid
217
+ assert_equal "ruby_flickraw", user.username
218
+ end
219
+
220
+ def photo(info)
221
+ assert_equal "3839885270", info.id
222
+ assert_equal "41650587@N02", info.owner
223
+ assert_equal "6fb8b54e06", info.secret
224
+ assert_equal "2485", info.server
225
+ assert_equal 3, info.farm
226
+ assert_equal "cat", info.title
227
+ assert_equal 1, info.ispublic
228
+ end
229
+
230
+ # favorites
231
+ def test_favorites_getPublicList
232
+ list = flickr.favorites.getPublicList :user_id => "41650587@N02"
233
+ assert_equal 1, list.size
234
+ assert_equal "3829093290", list[0].id
235
+ end
236
+
237
+ # groups
238
+ def test_groups_getInfo
239
+ info = flickr.groups.getInfo :group_id => "51035612836@N01"
240
+ assert_equal "51035612836@N01", info.id
241
+ assert_equal "Flickr API", info.name
242
+ end
243
+
244
+ def test_groups_search
245
+ list = flickr.groups.search :text => "Flickr API"
246
+ assert list.any? {|g| g.nsid == "51035612836@N01"}
247
+ end
248
+
249
+ # panda
250
+ def test_panda_getList
251
+ pandas = flickr.panda.getList
252
+ assert_equal ["ling ling", "hsing hsing", "wang wang"], pandas.to_a
253
+ end
254
+
255
+ def test_panda_getList
256
+ pandas = flickr.panda.getPhotos :panda_name => "wang wang"
257
+ assert_equal "wang wang", pandas.panda
258
+ assert_respond_to pandas[0], :title
259
+ end
260
+
261
+ # people
262
+ def test_people_findByEmail
263
+ user = flickr.people.findByEmail :find_email => "flickraw@yahoo.com"
264
+ people user
265
+ end
266
+
267
+ def test_people_findByUsername
268
+ user = flickr.people.findByUsername :username => "ruby_flickraw"
269
+ people user
270
+ end
271
+
272
+ def test_people_getInfo
273
+ user = flickr.people.getInfo :user_id => "41650587@N02"
274
+ people user
275
+ assert_equal "Flickraw", user.realname
276
+ assert_equal "http://www.flickr.com/photos/41650587@N02/", user.photosurl
277
+ assert_equal "http://www.flickr.com/people/41650587@N02/", user.profileurl
278
+ assert_equal "http://m.flickr.com/photostream.gne?id=41630239", user.mobileurl
279
+ assert_equal 0, user.ispro
280
+ end
281
+
282
+ def test_people_getPublicGroups
283
+ groups = flickr.people.getPublicGroups :user_id => "41650587@N02"
284
+ assert groups.to_a.empty?
285
+ end
286
+
287
+ def test_people_getPublicPhotos
288
+ info = flickr.people.getPublicPhotos :user_id => "41650587@N02"
289
+ assert_equal 1, info.size
290
+ assert_equal "1", info.total
291
+ assert_equal 1, info.pages
292
+ assert_equal 1, info.page
293
+ photo info[0]
294
+ end
295
+
296
+ # photos
297
+ def test_photos_getInfo
298
+ id = "3839885270"
299
+ info = nil
300
+ assert_nothing_raised(FlickRaw::FailedResponse) {
301
+ info = flickr.photos.getInfo(:photo_id => id)
302
+ }
303
+
304
+ %w{id secret server farm license owner title description dates comments tags media}.each {|m|
305
+ assert_respond_to info, m
306
+ assert_not_nil info[m]
307
+ }
308
+
309
+ assert_equal id, info.id
310
+ assert_equal "cat", info.title
311
+ assert_equal "This is my cat", info.description
312
+ assert_equal "ruby_flickraw", info.owner["username"]
313
+ assert_equal "Flickraw", info.owner["realname"]
314
+ assert_equal %w{cat pet}, info.tags.map {|t| t.to_s}.sort
315
+ end
316
+
317
+ def test_photos_getExif
318
+ info = flickr.photos.getExif :photo_id => "3839885270"
319
+ assert_equal "Canon DIGITAL IXUS 55", info.exif.find {|f| f.tag == "Model"}.raw
320
+ assert_equal "1/60", info.exif.find {|f| f.tag == "ExposureTime"}.raw
321
+ assert_equal "4.9", info.exif.find {|f| f.tag == "FNumber"}.raw
322
+ assert_equal "1600", info.exif.find {|f| f.tag == "RelatedImageWidth"}.raw
323
+ assert_equal "1200", info.exif.find {|f| f.tag == "RelatedImageHeight"}.raw
324
+ end
325
+
326
+ def test_photos_getSizes
327
+ info = flickr.photos.getSizes :photo_id => "3839885270"
328
+ assert_equal "http://www.flickr.com/photos/41650587@N02/3839885270/sizes/l/", info.find {|f| f.label == "Large"}.url
329
+ assert_equal "http://farm3.static.flickr.com/2485/3839885270_6fb8b54e06_b.jpg", info.find {|f| f.label == "Large"}.source
330
+ end
331
+
332
+ def test_photos_search
333
+ info = flickr.photos.search :user_id => "41650587@N02"
334
+ photo info[0]
335
+ end
336
+
337
+ # photos.comments
338
+ def test_photos_comments_getList
339
+ comments = flickr.photos.comments.getList :photo_id => "3839885270"
340
+ assert_equal 1, comments.size
341
+ assert_equal "3839885270", comments.photo_id
342
+ assert_equal "41630239-3839885270-72157621986549875", comments[0].id
343
+ assert_equal "41650587@N02", comments[0].author
344
+ assert_equal "ruby_flickraw", comments[0].authorname
345
+ assert_equal "http://www.flickr.com/photos/41650587@N02/3839885270/#comment72157621986549875", comments[0].permalink
346
+ assert_equal "This is a cute cat !", comments[0].to_s
347
+ end
348
+
349
+ # tags
350
+ def test_tags_getListPhoto
351
+ tags = flickr.tags.getListPhoto :photo_id => "3839885270"
352
+ assert_equal 2, tags.tags.size
353
+ assert_equal "3839885270", tags.id
354
+ assert_equal %w{cat pet}, tags.tags.map {|t| t.to_s}.sort
355
+ end
356
+
357
+ def test_tags_getListUser
358
+ tags = flickr.tags.getListUser :user_id => "41650587@N02"
359
+ assert_equal "41650587@N02", tags.id
360
+ assert_equal %w{cat pet}, tags.tags.sort
361
+ end
362
+
363
+ # urls
364
+ def test_urls_getGroup
365
+ info = flickr.urls.getGroup :group_id => "51035612836@N01"
366
+ assert_equal "51035612836@N01", info.nsid
367
+ assert_equal "http://www.flickr.com/groups/api/", info.url
368
+ end
369
+
370
+ def test_urls_getUserPhotos
371
+ info = flickr.urls.getUserPhotos :user_id => "41650587@N02"
372
+ assert_equal "41650587@N02", info.nsid
373
+ assert_equal "http://www.flickr.com/photos/41650587@N02/", info.url
374
+ end
375
+
376
+ def test_urls_getUserProfile
377
+ info = flickr.urls.getUserProfile :user_id => "41650587@N02"
378
+ assert_equal "41650587@N02", info.nsid
379
+ assert_equal "http://www.flickr.com/people/41650587@N02/", info.url
380
+ end
381
+
382
+ def test_urls_lookupGroup
383
+ info = flickr.urls.lookupGroup :url => "http://www.flickr.com/groups/api/"
384
+ assert_equal "51035612836@N01", info.id
385
+ assert_equal "Flickr API", info.groupname
386
+ end
387
+
388
+ def test_urls_lookupUser
389
+ info = flickr.urls.lookupUser :url => "http://www.flickr.com/photos/41650587@N02/"
390
+ assert_equal "41650587@N02", info.id
391
+ assert_equal "ruby_flickraw", info.username
392
+ end
393
+
394
+ def test_urls
395
+ id = "3839885270"
396
+ info = flickr.photos.getInfo(:photo_id => id)
397
+
398
+ assert_equal "http://farm3.static.flickr.com/2485/3839885270_6fb8b54e06.jpg", FlickRaw.url(info)
399
+ assert_equal "http://farm3.static.flickr.com/2485/3839885270_6fb8b54e06_m.jpg", FlickRaw.url_m(info)
400
+ assert_equal "http://farm3.static.flickr.com/2485/3839885270_6fb8b54e06_s.jpg", FlickRaw.url_s(info)
401
+ assert_equal "http://farm3.static.flickr.com/2485/3839885270_6fb8b54e06_t.jpg", FlickRaw.url_t(info)
402
+ assert_equal "http://farm3.static.flickr.com/2485/3839885270_6fb8b54e06_b.jpg", FlickRaw.url_b(info)
403
+
404
+ assert_equal "http://www.flickr.com/people/41650587@N02/", FlickRaw.url_profile(info)
405
+ assert_equal "http://www.flickr.com/photos/41650587@N02/", FlickRaw.url_photostream(info)
406
+ assert_equal "http://www.flickr.com/photos/41650587@N02/3839885270", FlickRaw.url_photopage(info)
407
+ assert_equal "http://www.flickr.com/photos/41650587@N02/sets/", FlickRaw.url_photosets(info)
408
+ assert_equal "http://flic.kr/p/6Rjq7s", FlickRaw.url_short(info)
409
+ end
410
+
411
+ def test_url_escape
412
+ result_set = nil
413
+ assert_nothing_raised {
414
+ result_set = flickr.photos.search :text => "family vacation"
415
+ }
416
+ assert_operator result_set.total.to_i, :>=, 0
417
+
418
+ # Unicode tests
419
+ echo = nil
420
+ utf8_text = "Hélène François, €uro"
421
+ assert_nothing_raised {
422
+ echo = flickr.test.echo :utf8_text => utf8_text
423
+ }
424
+ assert_equal echo.utf8_text, utf8_text
425
+ end
426
+ end