flickrie 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG.md +22 -0
  3. data/Gemfile +0 -6
  4. data/README.md +15 -1
  5. data/Rakefile +8 -13
  6. data/api_methods.md +1 -1
  7. data/flickrie.gemspec +2 -3
  8. data/lib/flickrie/api_methods.rb +17 -0
  9. data/lib/flickrie/client.rb +21 -5
  10. data/lib/flickrie/instance.rb +7 -2
  11. data/lib/flickrie/license.rb +2 -0
  12. data/lib/flickrie/location.rb +10 -8
  13. data/lib/flickrie/media/exif.rb +3 -1
  14. data/lib/flickrie/media/tag.rb +3 -3
  15. data/lib/flickrie/media/visibility.rb +6 -4
  16. data/lib/flickrie/media.rb +69 -84
  17. data/lib/flickrie/media_count.rb +3 -5
  18. data/lib/flickrie/photo.rb +55 -54
  19. data/lib/flickrie/set.rb +31 -25
  20. data/lib/flickrie/ticket.rb +4 -8
  21. data/lib/flickrie/upload_client.rb +7 -2
  22. data/lib/flickrie/user.rb +33 -34
  23. data/lib/flickrie/version.rb +1 -1
  24. data/lib/flickrie/video.rb +13 -12
  25. data/spec/api_methods_spec.rb +43 -0
  26. data/spec/error_spec.rb +32 -0
  27. data/{test → spec/files}/photo.jpg +0 -0
  28. data/{test → spec/files}/video.mov +0 -0
  29. data/spec/instance_spec.rb +22 -0
  30. data/spec/license_spec.rb +15 -0
  31. data/spec/location_spec.rb +11 -0
  32. data/spec/media_count_spec.rb +18 -0
  33. data/spec/media_spec.rb +271 -0
  34. data/spec/oauth_spec.rb +22 -0
  35. data/spec/photo_spec.rb +137 -0
  36. data/spec/set_spec.rb +68 -0
  37. data/spec/spec_helper.rb +68 -0
  38. data/spec/user_spec.rb +56 -0
  39. data/spec/video_spec.rb +54 -0
  40. metadata +47 -132
  41. data/test/error_test.rb +0 -20
  42. data/test/instance_test.rb +0 -20
  43. data/test/license_test.rb +0 -19
  44. data/test/location_test.rb +0 -29
  45. data/test/media_count_test.rb +0 -25
  46. data/test/media_test.rb +0 -432
  47. data/test/oauth_test.rb +0 -25
  48. data/test/photo_test.rb +0 -212
  49. data/test/set_test.rb +0 -92
  50. data/test/test_helper.rb +0 -14
  51. data/test/user_test.rb +0 -70
  52. data/test/vcr_cassettes/error/code.yml +0 -1165
  53. data/test/vcr_cassettes/instance/calling_api_methods.yml +0 -182
  54. data/test/vcr_cassettes/license/get_licenses.yml +0 -73
  55. data/test/vcr_cassettes/location/square_brackets.yml +0 -85
  56. data/test/vcr_cassettes/media/delete.yml +0 -1380
  57. data/test/vcr_cassettes/media/from_contacts.yml +0 -155
  58. data/test/vcr_cassettes/media/from_set.yml +0 -276
  59. data/test/vcr_cassettes/media/from_user.yml +0 -275
  60. data/test/vcr_cassettes/media/get_context.yml +0 -73
  61. data/test/vcr_cassettes/media/get_info.yml +0 -167
  62. data/test/vcr_cassettes/media/remove_tag.yml +0 -264
  63. data/test/vcr_cassettes/media/replace.yml +0 -2252
  64. data/test/vcr_cassettes/media/search.yml +0 -275
  65. data/test/vcr_cassettes/media/tags.yml +0 -346
  66. data/test/vcr_cassettes/media_count/get.yml +0 -135
  67. data/test/vcr_cassettes/media_count/square_brackets.yml +0 -69
  68. data/test/vcr_cassettes/oauth/tokens.yml +0 -400
  69. data/test/vcr_cassettes/photo/asynchronous_upload.yml +0 -1693
  70. data/test/vcr_cassettes/photo/from_set.yml +0 -273
  71. data/test/vcr_cassettes/photo/from_user.yml +0 -275
  72. data/test/vcr_cassettes/photo/get_exif.yml +0 -239
  73. data/test/vcr_cassettes/photo/get_sizes.yml +0 -147
  74. data/test/vcr_cassettes/photo/other_api_calls.yml +0 -506
  75. data/test/vcr_cassettes/photo/search.yml +0 -271
  76. data/test/vcr_cassettes/photo/square_brackets.yml +0 -85
  77. data/test/vcr_cassettes/photo/upload.yml +0 -1229
  78. data/test/vcr_cassettes/set/from_user.yml +0 -477
  79. data/test/vcr_cassettes/set/get_info.yml +0 -951
  80. data/test/vcr_cassettes/set/square_brackets.yml +0 -73
  81. data/test/vcr_cassettes/user/find_by_email_or_username.yml +0 -135
  82. data/test/vcr_cassettes/user/get_info.yml +0 -151
  83. data/test/vcr_cassettes/user/square_brackets.yml +0 -77
  84. data/test/vcr_cassettes/video/get_exif.yml +0 -135
  85. data/test/vcr_cassettes/video/get_info.yml +0 -86
  86. data/test/vcr_cassettes/video/get_sizes.yml +0 -151
  87. data/test/vcr_cassettes/video/other_api_calls.yml +0 -643
  88. data/test/vcr_cassettes/video/square_brackets.yml +0 -86
  89. data/test/vcr_cassettes/video/upload.yml +0 -308
  90. data/test/video_test.rb +0 -118
data/test/media_test.rb DELETED
@@ -1,432 +0,0 @@
1
- # encoding: utf-8
2
-
3
- Flickrie::Photo.instance_eval do
4
- def public_new(*args)
5
- new(*args)
6
- end
7
- end
8
-
9
- class MediaTest < Test::Unit::TestCase
10
- def setup
11
- @media_id = 6946979188
12
- @set_id = 72157629851991663
13
- @user_nsid = '67131352@N04'
14
-
15
- # license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo,tags,machine_tags,o_dims,views,media,path_alias,url_sq,url_q,url_t,url_s,url_n,url_m,url_z,url_c,url_l,url_o
16
- @all_extras = %w[license date_upload date_taken owner_name
17
- icon_server original_format last_update geo tags machine_tags
18
- o_dims views media path_alias
19
- url_sq url_q url_t url_s url_n url_m url_z url_c url_l url_o]
20
- end
21
-
22
- def test_get_info
23
- VCR.use_cassette 'media/get_info' do
24
- [Flickrie.get_media_info(@media_id),
25
- Flickrie::Photo.public_new('id' => @media_id.to_s).get_info].
26
- each do |media|
27
- assert_equal '6946979188', media.id
28
- assert_equal '25bb44852b', media.secret
29
- assert_equal '7049', media.server
30
- assert_equal 8, media.farm
31
- assert_equal 'IMG_0796', media.title
32
-
33
- assert_equal 'luka', media.tags.join(' ')
34
- assert_equal @user_nsid, media.tags.first.author.nsid
35
- assert_equal 'luka', media.tags.first.raw
36
- assert_equal false, media.tags.first.machine_tag?
37
-
38
- assert_equal 2, media.views_count
39
- assert_equal 1, media.comments_count
40
- assert_equal '0', media.license.id
41
- assert_equal 0, media.safety_level
42
- assert_equal 90, media.rotation
43
- assert_equal 'Test', media.description
44
- assert_not_nil media.url
45
-
46
- # Time
47
- assert_instance_of Time, media.uploaded_at
48
- assert_instance_of Time, media.updated_at
49
- assert_instance_of Time, media.taken_at
50
- assert_equal 0, media.taken_at_granularity
51
- assert_instance_of Time, media.posted_at
52
-
53
- # Owner
54
- assert_equal '67131352@N04', media.owner.nsid
55
- assert_equal 'Janko Marohnić', media.owner.username
56
- assert_equal 'Janko Marohnić', media.owner.real_name
57
- assert_equal 'Zagreb, Croatia', media.owner.location
58
- assert_equal '5464', media.owner.icon_server
59
- assert_equal 6, media.owner.icon_farm
60
- refute media.owner.buddy_icon_url.empty?
61
-
62
- # Predicates
63
- assert_equal true, media.visibility.public?
64
- assert_equal false, media.visibility.friends?
65
- assert_equal false, media.visibility.family?
66
- assert_equal nil, media.visibility.contacts?
67
-
68
- assert_equal true, media.can_comment?
69
- assert_equal true, media.can_add_meta?
70
- assert_equal true, media.can_everyone_comment?
71
- assert_equal false, media.can_everyone_add_meta?
72
-
73
- assert_equal true, media.can_download?
74
- assert_equal true, media.can_blog?
75
- assert_equal true, media.can_print?
76
- assert_equal false, media.can_share?
77
-
78
- assert_equal false, media.has_people?
79
-
80
- assert_equal true, media.safe?
81
- assert_equal false, media.moderate?
82
- assert_equal false, media.restricted?
83
-
84
- assert_equal false, media.favorite?
85
-
86
- assert_equal true, media.geo_permissions.public?
87
- assert_equal false, media.geo_permissions.contacts?
88
- assert_equal false, media.geo_permissions.friends?
89
- assert_equal false, media.geo_permissions.family?
90
-
91
- # Notes
92
- note = media.notes.first
93
- assert_equal '72157629487842968', note.id
94
- assert_equal '67131352@N04', note.author.nsid
95
- assert_equal 'Janko Marohnić', note.author.username
96
- assert_equal [316, 0], note.coordinates
97
- assert_equal [59, 50], [note.width, note.height]
98
- assert_equal 'Test', note.content
99
-
100
- # Location
101
- location = media.location
102
-
103
- assert_equal 45.807258, location.latitude
104
- assert_equal 15.967599, location.longitude
105
- assert_equal '11', location.accuracy
106
- assert_equal '0', location.context
107
-
108
- assert_equal nil, location.neighbourhood
109
- assert_equal 'Zagreb', location.locality.name
110
- assert_equal '00j4IylZV7scWik', location.locality.place_id
111
- assert_equal '851128', location.locality.woeid
112
- assert_equal 'Zagreb', location.county.name
113
- assert_equal '306dHrhQV7o6jm.ZUQ', location.county.place_id
114
- assert_equal '15022257', location.county.woeid
115
- assert_equal 'Grad Zagreb', location.region.name
116
- assert_equal 'Js1DU.pTUrpBCIKhVw', location.region.place_id
117
- assert_equal '20070170', location.region.woeid
118
- assert_equal 'Croatia', location.country.name
119
- assert_equal 'FunRCI5TUb6a6soTyw', location.country.place_id
120
- assert_equal '23424843', location.country.woeid
121
-
122
- assert_equal '00j4IylZV7scWik', location.place_id
123
- assert_equal '851128', location.woeid
124
- end
125
- end
126
- end
127
-
128
- def test_from_set
129
- VCR.use_cassette 'media/from_set' do
130
- media = Flickrie.media_from_set(@set_id, :extras => @all_extras).
131
- find { |media| media.id.to_i == @media_id }
132
-
133
- assert_equal '6946979188', media.id
134
- assert_equal '25bb44852b', media.secret
135
- assert_equal '7049', media.server
136
- assert_equal 8, media.farm
137
- assert_equal 'IMG_0796', media.title
138
- assert_equal 'luka', media.tags.join(' ')
139
- assert_equal '', media.machine_tags.join(' ')
140
- assert_equal 2, media.views_count
141
- assert_equal '0', media.license.id
142
- assert_equal true, media.primary?
143
- assert_not_nil media.url
144
- assert_equal 'ready', media.media_status
145
-
146
- # Time
147
- assert_instance_of Time, media.uploaded_at
148
- assert_instance_of Time, media.updated_at
149
- assert_instance_of Time, media.taken_at
150
- assert_equal 0, media.taken_at_granularity
151
-
152
- # Location
153
- assert_equal 45.807258, media.location.latitude
154
- assert_equal 15.967599, media.location.longitude
155
- assert_equal '11', media.location.accuracy
156
- assert_equal '0', media.location.context.to_s
157
- assert_equal '00j4IylZV7scWik', media.location.place_id
158
- assert_equal '851128', media.location.woeid
159
- assert_equal true, media.geo_permissions.public?
160
- assert_equal false, media.geo_permissions.contacts?
161
- assert_equal false, media.geo_permissions.friends?
162
- assert_equal false, media.geo_permissions.family?
163
-
164
- # Owner
165
- assert_equal '67131352@N04', media.owner.nsid
166
- assert_equal 'Janko Marohnić', media.owner.username
167
- assert_equal '5464', media.owner.icon_server
168
- assert_equal 6, media.owner.icon_farm
169
- refute media.owner.buddy_icon_url.empty?
170
- end
171
- end
172
-
173
- def test_public_from_user
174
- VCR.use_cassette 'media/from_user' do
175
- media = Flickrie.public_media_from_user(@user_nsid, :extras => @all_extras).
176
- find { |media| media.id.to_i == @media_id }
177
-
178
- assert_equal '6946979188', media.id
179
- assert_equal '25bb44852b', media.secret
180
- assert_equal '7049', media.server
181
- assert_equal 8, media.farm
182
- assert_equal 'IMG_0796', media.title
183
- assert_equal 'luka', media.tags.join(' ')
184
- assert_equal '', media.machine_tags.join(' ')
185
- assert_equal 2, media.views_count
186
- assert_equal '0', media.license.id
187
- assert_not_nil media.url
188
- assert_equal 'ready', media.media_status
189
-
190
- # Time
191
- assert_instance_of Time, media.uploaded_at
192
- assert_instance_of Time, media.updated_at
193
- assert_instance_of Time, media.taken_at
194
- assert_equal 0, media.taken_at_granularity
195
-
196
- # Location
197
- assert_equal 45.807258, media.location.latitude
198
- assert_equal 15.967599, media.location.longitude
199
- assert_equal '11', media.location.accuracy
200
- assert_equal '0', media.location.context.to_s
201
- assert_equal '00j4IylZV7scWik', media.location.place_id
202
- assert_equal '851128', media.location.woeid
203
- assert_equal true, media.geo_permissions.public?
204
- assert_equal false, media.geo_permissions.contacts?
205
- assert_equal false, media.geo_permissions.friends?
206
- assert_equal false, media.geo_permissions.family?
207
-
208
- # Owner
209
- assert_equal '67131352@N04', media.owner.nsid
210
- assert_equal 'Janko Marohnić', media.owner.username
211
- assert_equal '5464', media.owner.icon_server
212
- assert_equal 6, media.owner.icon_farm
213
- refute media.owner.buddy_icon_url.empty?
214
-
215
- # Visibility (This is the difference from Flickrie.media_from_set)
216
- assert_equal true, media.visibility.public?
217
- assert_equal false, media.visibility.friends?
218
- assert_equal false, media.visibility.family?
219
- assert_equal nil, media.visibility.contacts?
220
- end
221
- end
222
-
223
- def test_search
224
- VCR.use_cassette 'media/search' do
225
- media = Flickrie.search_media(:user_id => @user_nsid, :extras => @all_extras).
226
- find { |media| media.id.to_i == @media_id }
227
-
228
- assert_equal '6946979188', media.id
229
- assert_equal '25bb44852b', media.secret
230
- assert_equal '7049', media.server
231
- assert_equal 8, media.farm
232
- assert_equal 'IMG_0796', media.title
233
- assert_equal 'luka', media.tags.join(' ')
234
- assert_equal '', media.machine_tags.join(' ')
235
- assert_equal 2, media.views_count
236
- assert_equal '0', media.license.id
237
- assert_not_nil media.url
238
- assert_equal 'ready', media.media_status
239
-
240
- # Time
241
- assert_instance_of Time, media.uploaded_at
242
- assert_instance_of Time, media.updated_at
243
- assert_instance_of Time, media.taken_at
244
- assert_equal 0, media.taken_at_granularity
245
-
246
- # Location
247
- assert_equal 45.807258, media.location.latitude
248
- assert_equal 15.967599, media.location.longitude
249
- assert_equal '11', media.location.accuracy
250
- assert_equal '0', media.location.context.to_s
251
- assert_equal '00j4IylZV7scWik', media.location.place_id
252
- assert_equal '851128', media.location.woeid
253
- assert_equal true, media.geo_permissions.public?
254
- assert_equal false, media.geo_permissions.contacts?
255
- assert_equal false, media.geo_permissions.friends?
256
- assert_equal false, media.geo_permissions.family?
257
-
258
- # Owner
259
- assert_equal '67131352@N04', media.owner.nsid
260
- assert_equal 'Janko Marohnić', media.owner.username
261
- assert_equal '5464', media.owner.icon_server
262
- assert_equal 6, media.owner.icon_farm
263
- refute media.owner.buddy_icon_url.empty?
264
-
265
- # Visibility (This is the difference from Flickrie.media_from_set)
266
- assert_equal true, media.visibility.public?
267
- assert_equal false, media.visibility.friends?
268
- assert_equal false, media.visibility.family?
269
- assert_equal nil, media.visibility.contacts?
270
- end
271
- end
272
-
273
- def test_tags
274
- VCR.use_cassette 'media/tags' do
275
- media = Flickrie.get_media_info(@media_id)
276
- tags_before_change = media.tags.join(' ')
277
- Flickrie.add_media_tags(@media_id, "janko")
278
- media.get_info
279
- assert_equal [tags_before_change, "janko"].join(' '),
280
- media.tags.join(' ')
281
- tag_id = media.tags.find { |tag| tag.content == "janko" }.id
282
- Flickrie.remove_media_tag(tag_id)
283
- media.get_info
284
- assert_equal tags_before_change, media.tags.join(' ')
285
- end
286
- end
287
-
288
- def test_delete
289
- VCR.use_cassette 'media/delete' do
290
- media_path = File.join(File.expand_path(File.dirname(__FILE__)), 'photo.jpg')
291
- media_id = Flickrie.upload(media_path)
292
- assert_includes Flickrie.public_media_from_user(@user_nsid).map(&:id), media_id
293
- Flickrie.delete_media(media_id)
294
- refute_includes Flickrie.public_media_from_user(@user_nsid).map(&:id), media_id
295
- end
296
- end
297
-
298
- def test_from_contacts
299
- VCR.use_cassette 'media/from_contacts' do
300
- medias = [
301
- Flickrie.media_from_contacts(
302
- :include_self => 1, :single_photo => 1, :extras => @all_extras).first,
303
- Flickrie.public_media_from_user_contacts(@user_nsid,
304
- :include_self => 1, :single_photo => 1, :extras => @all_extras).first
305
- ]
306
-
307
- medias.each do |media|
308
- assert_equal '7093101501', media.id
309
- assert_equal '9337f28800', media.secret
310
- assert_equal '7090', media.server
311
- assert_equal 8, media.farm
312
- assert_equal 'IMG_0917', media.title
313
- assert_equal '', media.tags.join(' ')
314
- assert_equal '', media.machine_tags.join(' ')
315
- assert_equal 0, media.views_count
316
- assert_equal '0', media.license.id
317
- assert_not_nil media.url
318
- assert_equal 'ready', media.media_status
319
-
320
- # Time
321
- assert_instance_of Time, media.uploaded_at
322
- assert_instance_of Time, media.updated_at
323
- assert_instance_of Time, media.taken_at
324
- assert_equal 0, media.taken_at_granularity
325
-
326
- # Location
327
- assert_nil media.location
328
-
329
- # Owner
330
- assert_equal '67131352@N04', media.owner.nsid
331
- assert_equal 'Janko Marohnić', media.owner.username
332
- assert_equal '5464', media.owner.icon_server
333
- assert_equal 6, media.owner.icon_farm
334
- refute media.owner.buddy_icon_url.empty?
335
-
336
- # Visibility (This is the difference from Flickrie.media_from_set)
337
- assert_equal true, media.visibility.public?
338
- assert_equal false, media.visibility.friends?
339
- assert_equal false, media.visibility.family?
340
- assert_equal nil, media.visibility.contacts?
341
- end
342
- end
343
- end
344
-
345
- def test_get_context
346
- VCR.use_cassette 'media/get_context' do
347
- context = Flickrie.get_media_context(@media_id)
348
-
349
- assert_equal 98, context['count']
350
-
351
- previous_media = context['prevphoto']
352
- assert_equal '6946978706', previous_media.id
353
- assert_equal 'b38270bbd6', previous_media.secret
354
- assert_equal '7216', previous_media.server
355
- assert_equal 8, previous_media.farm
356
- assert_equal 'IMG_0795', previous_media.title
357
- refute previous_media.url.empty?
358
- assert_equal '0', previous_media.license.id
359
- assert_equal false, previous_media.faved?
360
-
361
- next_media = context['nextphoto']
362
- assert_equal '6946979704', next_media.id
363
- assert_equal '74513ff732', next_media.secret
364
- assert_equal '7234', next_media.server
365
- assert_equal 8, next_media.farm
366
- assert_equal 'IMG_0797', next_media.title
367
- refute next_media.url.empty?
368
- assert_equal '0', next_media.license.id
369
- assert_equal false, next_media.faved?
370
- end
371
- end
372
-
373
- def test_replace
374
- VCR.use_cassette 'media/replace' do
375
- media_path = File.join(File.expand_path(File.dirname(__FILE__)), 'photo.jpg')
376
- begin
377
- media_id = Flickrie.upload(media_path)
378
- Flickrie.replace(media_path, media_id)
379
- flunk
380
- rescue => exception
381
- assert_equal "Not a pro account", exception.message
382
- ensure
383
- Flickrie.delete_media(media_id)
384
- end
385
- end
386
- end
387
-
388
- def test_methods_returning_nil
389
- media = Flickrie::Photo.new
390
-
391
- assert_nil media.id
392
- assert_nil media.secret
393
- assert_nil media.server
394
- assert_nil media.farm
395
- assert_nil media.title
396
- assert_nil media.description
397
- assert_nil media.tags
398
- assert_nil media.machine_tags
399
- assert_nil media.media_status
400
- assert_nil media.path_alias
401
- assert_nil media.views_count
402
- assert_nil media.comments_count
403
- assert_nil media.location
404
- assert_nil media.geo_permissions
405
- assert_nil media.license
406
- assert_nil media.posted_at
407
- assert_nil media.uploaded_at
408
- assert_nil media.updated_at
409
- assert_nil media.taken_at
410
- assert_nil media.taken_at_granularity
411
- assert_nil media.owner
412
- assert_nil media.safety_level
413
- assert_nil media.safe?
414
- assert_nil media.moderate?
415
- assert_nil media.restricted?
416
- assert_nil media.url
417
- assert_nil media.visibility
418
- assert_nil media.primary?
419
- assert_nil media.favorite?
420
- assert_nil media.can_comment?
421
- assert_nil media.can_add_meta?
422
- assert_nil media.can_everyone_comment?
423
- assert_nil media.can_everyone_add_meta?
424
- assert_nil media.can_download?
425
- assert_nil media.can_blog?
426
- assert_nil media.can_print?
427
- assert_nil media.can_share?
428
- assert_nil media.has_people?
429
- assert_nil media.notes
430
- assert_nil media.media_status
431
- end
432
- end
data/test/oauth_test.rb DELETED
@@ -1,25 +0,0 @@
1
- class OAuthTest < Test::Unit::TestCase
2
- def test_tokens
3
- VCR.use_cassette 'oauth/tokens' do
4
- Flickrie.api_key = "foo"
5
- Flickrie.shared_secret = "foo"
6
-
7
- assert_raises(Flickrie::OAuth::Error) do
8
- Flickrie::OAuth.get_request_token
9
- end
10
-
11
- Flickrie.api_key = ENV['FLICKR_API_KEY']
12
- assert_raises(Flickrie::OAuth::Error) do
13
- Flickrie::OAuth.get_request_token
14
- end
15
-
16
- Flickrie.shared_secret = ENV['FLICKR_SHARED_SECRET']
17
- assert_nothing_raised { Flickrie::OAuth.get_request_token }
18
-
19
- request_token = Flickrie::OAuth.get_request_token
20
- assert_raises(Flickrie::OAuth::Error) do
21
- Flickrie::OAuth.get_access_token("foo", request_token)
22
- end
23
- end
24
- end
25
- end
data/test/photo_test.rb DELETED
@@ -1,212 +0,0 @@
1
- # encoding: utf-8
2
- Flickrie::Photo.instance_eval do
3
- def public_new(*args)
4
- new(*args)
5
- end
6
- end
7
-
8
- class PhotoTest < Test::Unit::TestCase
9
- def setup
10
- @photo_id = 6946979188
11
- @set_id = 72157629851991663
12
- @user_nsid = '67131352@N04'
13
-
14
- # license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo,tags,machine_tags,o_dims,views,media,path_alias,url_sq,url_q,url_t,url_s,url_n,url_m,url_z,url_c,url_l,url_o
15
- @all_extras = %w[license date_upload date_taken owner_name
16
- icon_server original_format last_update geo tags machine_tags
17
- o_dims views media path_alias
18
- url_sq url_q url_t url_s url_n url_m url_z url_c url_l url_o]
19
- end
20
-
21
- def test_square_brackets
22
- VCR.use_cassette 'photo/square_brackets' do
23
- photo = Flickrie.get_photo_info(@photo_id)
24
- assert_equal 1, photo['usage']['candownload'].to_i
25
- end
26
- end
27
-
28
- def test_from_set
29
- VCR.use_cassette 'photo/from_set' do
30
- photo = Flickrie.photos_from_set(@set_id, :extras => @all_extras).
31
- find { |photo| photo.id.to_i == @photo_id }
32
-
33
- assert_sizes(photo)
34
- end
35
- end
36
-
37
- def test_public_from_user
38
- VCR.use_cassette 'photo/from_user' do
39
- photo = Flickrie.public_photos_from_user(@user_nsid, :extras => @all_extras).
40
- find { |photo| photo.id.to_i == @photo_id }
41
-
42
- assert_sizes(photo, :exclude => ['Square 150', 'Small 320', 'Medium 800'])
43
- end
44
- end
45
-
46
- def test_get_sizes
47
- VCR.use_cassette 'photo/get_sizes' do
48
- [Flickrie.get_photo_sizes(@photo_id),
49
- Flickrie::Photo.public_new('id' => @photo_id.to_s).get_sizes].
50
- each do |photo|
51
- assert_equal true, photo.can_download?
52
- assert_equal true, photo.can_blog?
53
- assert_equal true, photo.can_print?
54
-
55
- assert_sizes(photo)
56
- end
57
- end
58
- end
59
-
60
- def test_search
61
- VCR.use_cassette 'photo/search' do
62
- photo = Flickrie.search_photos(:user_id => @user_nsid, :extras => @all_extras).
63
- find { |photo| photo.id.to_i == @photo_id }
64
-
65
- assert_sizes(photo)
66
- end
67
- end
68
-
69
- def assert_sizes(photo, options = {})
70
- options[:exclude] ||= []
71
- [
72
- [[photo.square(75), photo.square75], ['Square 75', '75x75']],
73
- [[photo.thumbnail], ['Thumbnail', '75x100']],
74
- [[photo.square(150), photo.square150], ['Square 150', '150x150']],
75
- [[photo.small(240), photo.small240], ['Small 240', '180x240']],
76
- [[photo.small(320), photo.small320], ['Small 320', '240x320']],
77
- [[photo.medium(500), photo.medium500], ['Medium 500', '375x500']],
78
- [[photo.medium(640), photo.medium640], ['Medium 640', '480x640']],
79
- [[photo.medium(800), photo.medium800], ['Medium 800', '600x800']],
80
- [[photo.large(1024), photo.large1024], ['Large 1024', '768x1024']]
81
- ].
82
- reject { |_, expected_values| options[:exclude].include?(expected_values.first) }.
83
- each do |photos, expected_values|
84
- flickr_size, size = expected_values
85
- photos.each do |photo|
86
- assert_equal flickr_size, photo.size
87
- assert_equal size, "#{photo.width}x#{photo.height}", "Non bang versions"
88
- refute photo.source_url.empty?
89
- end
90
- end
91
-
92
- [
93
- [[proc { photo.square!(75) }, proc { photo.square75! }], ['Square 75', '75x75']],
94
- [[proc { photo.thumbnail! }], ['Thumbnail', '75x100']],
95
- [[proc { photo.square!(150) }, proc { photo.square150! }], ['Square 150', '150x150']],
96
- [[proc { photo.small!(240) }, proc { photo.small240! }], ['Small 240', '180x240']],
97
- [[proc { photo.small!(320) }, proc { photo.small320! }], ['Small 320', '240x320']],
98
- [[proc { photo.medium!(500) }, proc { photo.medium500! }], ['Medium 500', '375x500']],
99
- [[proc { photo.medium!(640) }, proc { photo.medium640! }], ['Medium 640', '480x640']],
100
- [[proc { photo.medium!(800) }, proc { photo.medium800! }], ['Medium 800', '600x800']],
101
- [[proc { photo.large!(1024) }, proc { photo.large1024! }], ['Large 1024', '768x1024']]
102
- ].
103
- reject { |_, expected_values| options[:exclude].include?(expected_values.first) }.
104
- each do |proks, expected_values|
105
- flickr_size, size = expected_values
106
- proks.each do |prok|
107
- prok.call
108
- assert_equal flickr_size, photo.size
109
- assert_equal size, "#{photo.width}x#{photo.height}", "Bang versions"
110
- refute photo.source_url.empty?
111
- end
112
- end
113
- end
114
-
115
- def test_methods_returning_nil
116
- photo = Flickrie::Photo.new
117
-
118
- assert_nil photo.width
119
- assert_nil photo.height
120
- assert_nil photo.source_url
121
- assert_nil photo.rotation
122
- assert_equal [], photo.available_sizes
123
- assert_equal nil, photo.size
124
-
125
- [
126
- photo.square(75), photo.square(150), photo.thumbnail,
127
- photo.small(240), photo.small(320), photo.medium(500),
128
- photo.medium(640), photo.medium(800), photo.large(1024),
129
- photo.original, photo.square75, photo.square150,
130
- photo.small240, photo.small320, photo.medium500,
131
- photo.medium640, photo.medium800, photo.large1024,
132
- photo.largest
133
- ].
134
- each do |photo|
135
- assert_nil photo.source_url
136
- assert_nil photo.width
137
- assert_nil photo.height
138
- end
139
-
140
- [
141
- proc { photo.square!(75) }, proc { photo.square!(150) },
142
- proc { photo.thumbnail! }, proc { photo.small!(240) },
143
- proc { photo.small!(320) }, proc { photo.medium!(500) },
144
- proc { photo.medium!(640) }, proc { photo.medium!(800) },
145
- proc { photo.large!(1024) }, proc { photo.original! },
146
- proc { photo.square75! }, proc { photo.square150! },
147
- proc { photo.small240! }, proc { photo.small320! },
148
- proc { photo.medium500! }, proc { photo.medium640! },
149
- proc { photo.medium800! }, proc { photo.large1024! },
150
- proc { photo.largest! }
151
- ].
152
- each do |prok|
153
- prok.call
154
- assert_nil photo.source_url
155
- assert_nil photo.width
156
- assert_nil photo.height
157
- end
158
- end
159
-
160
- def test_upload
161
- VCR.use_cassette 'photo/upload' do
162
- photo_path = File.join(File.expand_path(File.dirname(__FILE__)), 'photo.jpg')
163
- photo_id = Flickrie.upload(photo_path)
164
- assert_nothing_raised(Flickrie::Error) { Flickrie.get_photo_info(photo_id) }
165
- Flickrie.delete_photo(photo_id)
166
- end
167
- end
168
-
169
- def test_asynchronous_upload
170
- VCR.use_cassette 'photo/asynchronous_upload' do
171
- photo_path = File.join(File.expand_path(File.dirname(__FILE__)), 'photo.jpg')
172
- ticket_id = Flickrie.upload(photo_path, :async => 1)
173
- begin
174
- ticket = Flickrie.check_upload_tickets([ticket_id]).first
175
- end until ticket.complete?
176
- photo_id = ticket.photo_id
177
- assert_nothing_raised(Flickrie::Error) { Flickrie.get_photo_info(photo_id) }
178
- Flickrie.delete_photo(photo_id)
179
- end
180
- end
181
-
182
- def test_get_exif
183
- VCR.use_cassette 'photo/get_exif' do
184
- [Flickrie.get_photo_exif(@photo_id),
185
- Flickrie::Photo.public_new('id' => @photo_id).get_exif].
186
- each do |photo|
187
- assert_equal "Canon PowerShot G12", photo.camera
188
- assert_equal "180 dpi", photo.exif.get('X-Resolution')
189
- assert_equal "180 dpi", photo.exif.get('X-Resolution', :data => 'clean')
190
- assert_equal "180", photo.exif.get('X-Resolution', :data => 'raw')
191
- end
192
- end
193
- end
194
-
195
- def test_other_api_calls
196
- VCR.use_cassette 'photo/other_api_calls' do
197
- # add_photo_tags, get_photo_info, remove_photo_tag,
198
- # search_photos, photos_from_contacts
199
-
200
- assert_nothing_raised do
201
- Flickrie.add_photo_tags(@photo_id, "janko")
202
- photo = Flickrie.get_photo_info(@photo_id)
203
- tag = photo.tags.find { |tag| tag.content == "janko" }
204
- Flickrie.remove_photo_tag(tag.id)
205
- Flickrie.photos_from_contacts(:include_self => 1)
206
- Flickrie.public_photos_from_user_contacts(@user_nsid, :include_self => 1)
207
- Flickrie.get_photo_context(@photo_id)
208
- Flickrie.search_photos(:user_id => @user_nsid)
209
- end
210
- end
211
- end
212
- end