flickrie 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG.md +13 -0
  3. data/Gemfile +0 -4
  4. data/flickrie.gemspec +2 -2
  5. data/lib/flickrie/api_methods.rb +4 -1
  6. data/lib/flickrie/license.rb +6 -1
  7. data/lib/flickrie/location.rb +29 -12
  8. data/lib/flickrie/media/exif.rb +3 -1
  9. data/lib/flickrie/media/note.rb +24 -13
  10. data/lib/flickrie/media/tag.rb +9 -6
  11. data/lib/flickrie/media/visibility.rb +8 -5
  12. data/lib/flickrie/media.rb +54 -55
  13. data/lib/flickrie/media_count.rb +8 -6
  14. data/lib/flickrie/photo.rb +48 -7
  15. data/lib/flickrie/set.rb +47 -31
  16. data/lib/flickrie/ticket.rb +8 -5
  17. data/lib/flickrie/user.rb +67 -25
  18. data/lib/flickrie/version.rb +1 -1
  19. data/lib/flickrie/video.rb +19 -11
  20. data/spec/custom_matchers.rb +51 -0
  21. data/spec/flickrie/api_methods_spec.rb +112 -31
  22. data/spec/flickrie/error_spec.rb +2 -4
  23. data/spec/flickrie/instance_spec.rb +11 -11
  24. data/spec/flickrie/media_spec.rb +74 -53
  25. data/spec/flickrie/photo_spec.rb +4 -5
  26. data/spec/flickrie/set_spec.rb +23 -12
  27. data/spec/flickrie/upload_client_spec.rb +3 -0
  28. data/spec/flickrie/user_spec.rb +31 -5
  29. data/spec/flickrie/video_spec.rb +13 -13
  30. data/spec/flickrie_spec.rb +15 -0
  31. data/spec/spec_helper.rb +13 -50
  32. data/spec/vcr_cassettes/api_methods/people/get_media_from_user.yml +108 -0
  33. data/spec/vcr_cassettes/api_methods/people/get_public_media_from_user.yml +108 -0
  34. data/spec/vcr_cassettes/api_methods/photos/add_and_remove_tags.yml +528 -0
  35. data/spec/vcr_cassettes/api_methods/photos/get_context.yml +108 -0
  36. data/spec/vcr_cassettes/api_methods/photos/get_counts.yml +108 -0
  37. data/spec/vcr_cassettes/api_methods/photos/get_exif.yml +73 -0
  38. data/spec/vcr_cassettes/api_methods/photos/get_favorites.yml +73 -0
  39. data/spec/vcr_cassettes/api_methods/photos/get_from_contacts.yml +73 -0
  40. data/spec/vcr_cassettes/api_methods/photos/get_info.yml +108 -0
  41. data/spec/vcr_cassettes/api_methods/photos/get_public_from_user_contacts.yml +73 -0
  42. data/spec/vcr_cassettes/api_methods/photos/get_sizes.yml +73 -0
  43. data/spec/vcr_cassettes/api_methods/photos/search.yml +108 -0
  44. data/spec/vcr_cassettes/api_methods/photosets/get_media.yml +108 -0
  45. data/spec/vcr_cassettes/api_methods/{replace.yml → upload/replace.yml} +16 -16
  46. data/spec/vcr_cassettes/api_methods/upload/upload.yml +82 -0
  47. data/spec/vcr_cassettes/api_methods/upload/upload_asynchronously.yml +117 -0
  48. data/spec/vcr_cassettes/error/{a_request_was_made_and_failed.yml → a_request_was_made_and_failed/be_raised.yml} +9 -9
  49. data/spec/vcr_cassettes/error/a_request_was_made_and_failed/have_code_attribute_present.yml +84 -0
  50. data/spec/vcr_cassettes/{api_methods/upload_and_delete.yml → flickrie/a_new_credential_is_filled_in/reset_the_client.yml} +113 -32
  51. data/spec/vcr_cassettes/instance/client_is_already_initialized/be_able_to_call_API_methods.yml +152 -0
  52. data/spec/vcr_cassettes/license/{get.yml → get/have_all_attributes_correctly_set.yml} +4 -4
  53. data/spec/vcr_cassettes/media/{from_contacts.yml → from_contacts/have_all_attributes_correctly_set.yml} +8 -8
  54. data/spec/vcr_cassettes/media/{from_set.yml → from_set/have_all_attributes_correctly_set.yml} +6 -6
  55. data/spec/vcr_cassettes/media/{from_user.yml → from_user/have_all_attributes_correctly_set.yml} +6 -6
  56. data/spec/vcr_cassettes/media/{get_context.yml → get_context/have_all_attributes_correctly_set.yml} +6 -6
  57. data/spec/vcr_cassettes/media/{get_exif.yml → get_exif/get_exif_correctly.yml} +8 -8
  58. data/spec/vcr_cassettes/media/get_info/have_all_attributes_correctly_set.yml +108 -0
  59. data/spec/vcr_cassettes/media/{public_from_user.yml → public_from_user/have_all_attributes_correctly_set.yml} +6 -6
  60. data/spec/vcr_cassettes/media/{search.yml → search/have_all_attributes_correctly_set.yml} +6 -6
  61. data/spec/vcr_cassettes/media_count/{get.yml → get/have_correctly_set_all_attributes.yml} +9 -9
  62. data/spec/vcr_cassettes/o_auth/{incorrect_credentials.yml → incorrect_credentials/raise_exceptions.yml} +42 -42
  63. data/spec/vcr_cassettes/photo/get_info/have_all_attributes_correctly_set.yml +38 -0
  64. data/spec/vcr_cassettes/photo/{get_sizes.yml → get_sizes/have_attributes_correctly_set.yml} +12 -12
  65. data/spec/vcr_cassettes/photo/{search.yml → search/have_all_sizes_available.yml} +6 -6
  66. data/spec/vcr_cassettes/set/{from_user.yml → from_user/have_all_attributes_correctly_set.yml} +18 -18
  67. data/spec/vcr_cassettes/set/{get_info.yml → get_info/have_all_attributes_correctly_set.yml} +36 -36
  68. data/spec/vcr_cassettes/upload_client/content_type/pass_the_content_type.yml +117 -0
  69. data/spec/vcr_cassettes/upload_client/invalid_credentials/raise_errors.yml +276 -0
  70. data/spec/vcr_cassettes/user/{find_by_username_or_email.yml → find_by_username_or_email/have_all_attributes_correctly_set.yml} +9 -9
  71. data/spec/vcr_cassettes/user/get_info/have_all_attributes_correctly_set.yml +73 -0
  72. data/spec/vcr_cassettes/video/get_info/have_all_attributes_correctly_set.yml +38 -0
  73. data/spec/vcr_cassettes/video/{get_sizes.yml → get_sizes/have_all_attributes_correctly_set.yml} +12 -12
  74. metadata +111 -74
  75. data/spec/vcr_cassettes/api_methods/asynchronous_upload.yml +0 -362
  76. data/spec/vcr_cassettes/api_methods/tag_manipulation.yml +0 -178
  77. data/spec/vcr_cassettes/instance/calling_api_methods.yml +0 -231
  78. data/spec/vcr_cassettes/media/get_info.yml +0 -108
  79. data/spec/vcr_cassettes/photo/get_info.yml +0 -38
  80. data/spec/vcr_cassettes/upload_client/content_type.yml +0 -117
  81. data/spec/vcr_cassettes/upload_client/invalid_credentials.yml +0 -208
  82. data/spec/vcr_cassettes/user/get_info.yml +0 -73
  83. data/spec/vcr_cassettes/video/get_info.yml +0 -38
@@ -12,7 +12,6 @@ describe Flickrie::Media do
12
12
  :media_status => 'ready',
13
13
  :path_alias => nil,
14
14
  :camera => 'Canon PowerShot G12',
15
- :views_count => 4,
16
15
  :comments_count => 1,
17
16
  :location => {
18
17
  :latitude => 45.807258,
@@ -84,18 +83,7 @@ describe Flickrie::Media do
84
83
  },
85
84
  :favorite? => false,
86
85
 
87
- :can_comment? => false,
88
- :can_add_meta? => false,
89
- :can_everyone_comment? => true,
90
- :can_everyone_add_meta? => false,
91
-
92
- :can_download? => true,
93
- :can_blog? => false,
94
- :can_print? => false,
95
- :can_share? => false,
96
-
97
86
  :has_people? => false,
98
- :faved? => false,
99
87
  :notes => {
100
88
  :first => {
101
89
  :id => '72157629487842968',
@@ -121,24 +109,35 @@ describe Flickrie::Media do
121
109
  ].
122
110
  each do |media|
123
111
  [
124
- :id, :secret, :server, :farm, :title, :description, :views_count,
112
+ :id, :secret, :server, :farm, :title, :description,
125
113
  :comments_count, :location, :geo_permissions, :tags,
126
114
  :machine_tags, :license, :taken_at_granularity, :owner,
127
115
  :safety_level, :safe?, :moderate?, :restricted?, :visibility,
128
- :favorite?, :can_comment?, :can_add_meta?, :can_everyone_comment?,
116
+ :favorite?, :has_people?, :notes
117
+ ].
118
+ each do |attribute|
119
+ media.send(attribute).should correspond_to(@attributes[attribute])
120
+ end
121
+
122
+ # can change, so just checking the type
123
+ [
124
+ :can_comment?, :can_add_meta?, :can_everyone_comment?,
129
125
  :can_everyone_add_meta?, :can_download?, :can_blog?,
130
- :can_print?, :can_share?, :has_people?, :notes
126
+ :can_print?, :can_share?
131
127
  ].
132
- each { |attribute| test_recursively(media, attribute) }
128
+ each { |attribute| media.send(attribute).should be_a_boolean }
133
129
 
134
- # other
135
- media.url.empty?.should be_false
136
- media['id'].should eq(PHOTO_ID)
130
+ media.views_count.should be_a_number
137
131
 
138
132
  # time
139
133
  [:posted_at, :uploaded_at, :updated_at, :taken_at].each do |time_attribute|
140
134
  media.send(time_attribute).should be_an_instance_of(Time)
141
135
  end
136
+
137
+ # other
138
+ media.url.should_not be_empty
139
+ media['id'].should eq(PHOTO_ID)
140
+ media.hash['id'].should eq(PHOTO_ID)
142
141
  end
143
142
  end
144
143
  end
@@ -146,23 +145,26 @@ describe Flickrie::Media do
146
145
  shared_context "common" do
147
146
  def test_common_attributes(media)
148
147
  [
149
- :id, :secret, :server, :farm, :title, :media_status, :views_count,
148
+ :id, :secret, :server, :farm, :title, :media_status,
150
149
  :geo_permissions, :machine_tags, :license, :taken_at_granularity
151
150
  ].
152
- each { |attribute| test_recursively(media, attribute) }
151
+ each do |attribute|
152
+ media.send(attribute).should correspond_to(@attributes[attribute])
153
+ end
153
154
 
154
155
  # the incomplete ones
155
- test_recursively(media, :location, @attributes[:location].except(:locality, :county, :region, :country))
156
- test_recursively(media.tags, :first, @attributes[:tags][:first].except(:author, :raw, :machine_tag?))
157
- test_recursively(media, :owner, @attributes[:owner].except(:real_name, :location))
158
-
159
- # other
160
- media.url.empty?.should be_false
156
+ media.location.should correspond_to(@attributes[:location].except(:locality, :county, :region, :country))
157
+ media.tags.first.should correspond_to(@attributes[:tags][:first].except(:author, :raw, :machine_tag?))
158
+ media.owner.should correspond_to(@attributes[:owner].except(:real_name, :location))
161
159
 
162
160
  # time
163
161
  [:uploaded_at, :updated_at, :taken_at].each do |time_attribute|
164
162
  media.send(time_attribute).should be_an_instance_of(Time)
165
163
  end
164
+
165
+ # other
166
+ media.url.should_not be_empty
167
+ media.views_count.should be_a_number
166
168
  end
167
169
  end
168
170
 
@@ -184,7 +186,7 @@ describe Flickrie::Media do
184
186
  media = Flickrie.media_from_user(USER_NSID, :extras => EXTRAS).
185
187
  find { |media| media.id == PHOTO_ID }
186
188
  test_common_attributes(media)
187
- test_recursively(media, :visibility)
189
+ media.visibility.should correspond_to(@attributes[:visibility])
188
190
  end
189
191
  end
190
192
 
@@ -195,7 +197,7 @@ describe Flickrie::Media do
195
197
  media = Flickrie.public_media_from_user(USER_NSID, :extras => EXTRAS).
196
198
  find { |media| media.id == PHOTO_ID }
197
199
  test_common_attributes(media)
198
- test_recursively(media, :visibility)
200
+ media.visibility.should correspond_to(@attributes[:visibility])
199
201
  end
200
202
  end
201
203
 
@@ -206,7 +208,7 @@ describe Flickrie::Media do
206
208
  media = Flickrie.search_media(:user_id => USER_NSID, :extras => EXTRAS).
207
209
  find { |media| media.id == PHOTO_ID }
208
210
  test_common_attributes(media)
209
- test_recursively(media, :visibility)
211
+ media.visibility.should correspond_to(@attributes[:visibility])
210
212
  end
211
213
  end
212
214
 
@@ -218,15 +220,23 @@ describe Flickrie::Media do
218
220
  Flickrie.public_media_from_user_contacts(USER_NSID, params).first
219
221
  ].
220
222
  each do |media|
221
- media.id.should eq('7093101501')
222
- media.secret.should eq('9337f28800')
223
- media.server.should eq('7090')
224
- media.farm.should eq(8)
225
- media.owner.nsid.should eq(USER_NSID)
226
- media.owner.username.should eq(USER_USERNAME)
227
- media.title.should eq('IMG_0917')
228
- test_recursively(media, :visibility)
229
- media.media_status.should eq('ready')
223
+ attributes = {
224
+ :id => '7093101501',
225
+ :secret => '9337f28800',
226
+ :server => '7090',
227
+ :farm => 8,
228
+ :owner => {
229
+ :nsid => USER_NSID,
230
+ :username => USER_USERNAME
231
+ },
232
+ :title => 'IMG_0917',
233
+ :visibility => {:public? => true},
234
+ :media_status => 'ready'
235
+ }
236
+
237
+ attributes.keys.each do |attribute|
238
+ media.send(attribute).should correspond_to(attributes[attribute])
239
+ end
230
240
  end
231
241
  end
232
242
  end
@@ -235,22 +245,20 @@ describe Flickrie::Media do
235
245
  it "should have all attributes correctly set", :vcr do
236
246
  context = Flickrie.get_media_context(PHOTO_ID)
237
247
  context.count.should eq(98)
238
- context.previous.title.should eq('IMG_0795')
239
- context.previous.url.should_not be_empty
240
- context.previous.faved?.should be_false
241
- end
242
- end
243
-
244
- context "blank media" do
245
- it "should have all attributes equal to nil" do
246
- attributes = Flickrie::Media.instance_methods -
247
- Object.instance_methods -
248
- [:[], :get_info, :get_exif, :get_favorites]
249
248
 
250
- media = Flickrie::Photo.public_new
251
- attributes.each do |attribute|
252
- media.send(attribute).should be_nil
249
+ attributes = {
250
+ :id => '6946978706',
251
+ :secret => 'b38270bbd6',
252
+ :server => '7216',
253
+ :farm => 8,
254
+ :title => 'IMG_0795',
255
+ :license => {:id => '0'},
256
+ :faved? => false
257
+ }
258
+ attributes.keys.each do |attribute|
259
+ context.previous.send(attribute).should correspond_to(attributes[attribute])
253
260
  end
261
+ context.previous.url.should_not be_empty
254
262
  end
255
263
  end
256
264
 
@@ -268,4 +276,17 @@ describe Flickrie::Media do
268
276
  end
269
277
  end
270
278
  end
279
+
280
+ context "blank media" do
281
+ it "should have all attributes equal to nil" do
282
+ attributes = Flickrie::Media.instance_methods -
283
+ Object.instance_methods -
284
+ [:[], :get_info, :get_exif, :get_favorites]
285
+
286
+ media = Flickrie::Photo.public_new
287
+ attributes.each do |attribute|
288
+ media.send(attribute).should be_nil
289
+ end
290
+ end
291
+ end
271
292
  end
@@ -5,7 +5,6 @@ SIZES = ['Square 75', 'Thumbnail', 'Square 150', 'Small 240', 'Small 320',
5
5
 
6
6
  describe Flickrie::Photo do
7
7
  def test_sizes(photo)
8
- # TODO: simplify this
9
8
  # non-bang versions
10
9
  [
11
10
  [[photo.square(75), photo.square75], ['Square 75', '75x75']],
@@ -59,9 +58,9 @@ describe Flickrie::Photo do
59
58
  Flickrie::Photo.public_new('id' => PHOTO_ID).get_sizes
60
59
  ].
61
60
  each do |photo|
62
- photo.can_download?.should be_true
63
- photo.can_blog?.should be_false
64
- photo.can_print?.should be_false
61
+ [:can_download?, :can_blog?, :can_print?].each do |attribute|
62
+ photo.send(attribute).should be_a_boolean
63
+ end
65
64
 
66
65
  test_sizes(photo)
67
66
  photo.available_sizes.should eq(SIZES)
@@ -84,7 +83,7 @@ describe Flickrie::Photo do
84
83
  end
85
84
  end
86
85
 
87
- context "blank" do
86
+ context "blank photo" do
88
87
  it "should have all attributes equal to nil" do
89
88
  photo = Flickrie::Photo.public_new
90
89
 
@@ -13,33 +13,33 @@ describe Flickrie::Set do
13
13
  :primary_media_id => PHOTO_ID,
14
14
  :primary_photo_id => PHOTO_ID,
15
15
  :primary_video_id => PHOTO_ID,
16
- :views_count => 0,
17
16
  :comments_count => 0,
18
17
  :photos_count => 97,
19
18
  :videos_count => 1,
20
19
  :media_count => 98,
21
20
  :owner => {
22
21
  :nsid => USER_NSID
23
- },
24
- :can_comment? => false,
22
+ }
25
23
  }
26
24
  end
27
25
 
28
26
  def test_common_attributes(set)
29
27
  @attributes.keys.each do |attribute|
30
- test_recursively(set, attribute)
28
+ set.send(attribute).should correspond_to(@attributes[attribute])
31
29
  end
32
30
 
33
- set.photos.all? { |photo| photo.is_a?(Flickrie::Photo) }.should be_true
34
- set.videos.all? { |video| video.is_a?(Flickrie::Video) }.should be_true
35
- set.media.all? do |media|
36
- media.is_a?(Flickrie::Photo) or media.is_a?(Flickrie::Video)
37
- end.should be_true
31
+ set.photos.each { |object| object.should be_a_photo }
32
+ set.videos.each { |object| object.should be_a_video }
33
+ set.media.each { |object| object.should be_a_media }
38
34
 
35
+ # Time
39
36
  set.created_at.should be_an_instance_of(Time)
40
37
  set.updated_at.should be_an_instance_of(Time)
41
38
 
39
+ # Other
42
40
  set.url.should_not be_empty
41
+ set.views_count.should be_a_number
42
+ set.can_comment?.should be_a_boolean
43
43
  end
44
44
 
45
45
  context "get info" do
@@ -48,9 +48,7 @@ describe Flickrie::Set do
48
48
  Flickrie.get_set_info(SET_ID),
49
49
  Flickrie::Set.public_new('id' => SET_ID).get_info
50
50
  ].
51
- each do |set|
52
- test_common_attributes(set)
53
- end
51
+ each { |set| test_common_attributes(set) }
54
52
  end
55
53
  end
56
54
 
@@ -62,4 +60,17 @@ describe Flickrie::Set do
62
60
  set.visibility_can_see_set?.should be_true
63
61
  end
64
62
  end
63
+
64
+ context "blank set" do
65
+ it "should have all attributes equal to nil" do
66
+ attributes = Flickrie::Set.instance_methods -
67
+ Object.instance_methods -
68
+ [:photos, :videos, :media, :[], :get_info]
69
+ set = Flickrie::Set.public_new
70
+
71
+ attributes.each do |attribute|
72
+ set.send(attribute).should be_nil
73
+ end
74
+ end
75
+ end
65
76
  end
@@ -35,6 +35,9 @@ describe Flickrie::UploadClient do
35
35
 
36
36
  Flickrie.access_secret = ENV['FLICKR_ACCESS_SECRET']
37
37
  expect { Flickrie.upload(PHOTO_PATH) }.to_not raise_error
38
+
39
+ photo = Flickrie.photos_from_user(USER_NSID).find { |photo| photo.title == "photo" }
40
+ Flickrie.delete_photo(photo.id)
38
41
  end
39
42
  end
40
43
  end
@@ -28,7 +28,7 @@ describe Flickrie::User do
28
28
  ].
29
29
  each do |user|
30
30
  @attributes.keys.each do |attribute|
31
- test_recursively(user, attribute)
31
+ user.send(attribute).should correspond_to(@attributes[attribute])
32
32
  end
33
33
 
34
34
  [:profile_url, :mobile_url, :photos_url, :buddy_icon_url].each do |attribute|
@@ -46,13 +46,39 @@ describe Flickrie::User do
46
46
  it "should have all attributes correctly set", :vcr do
47
47
  [
48
48
  Flickrie.find_user_by_username(USER_USERNAME),
49
- Flickrie.find_user_by_email('janko.marohnic@gmail.com')
49
+ Flickrie.find_user_by_email(USER_EMAIL)
50
50
  ].
51
51
  each do |user|
52
- [:id, :nsid, :username].each do |attribute|
53
- test_recursively(user, attribute)
54
- end
52
+ user.id.should == USER_NSID
53
+ user.nsid.should == USER_NSID
54
+ user.username.should == USER_USERNAME
55
55
  end
56
56
  end
57
57
  end
58
+
59
+ context "getting media" do
60
+ it "should get the right kind of media", :vcr do
61
+ user = Flickrie::User.public_new('nsid' => USER_NSID)
62
+ user.public_photos.each { |object| object.should be_a_photo }
63
+ user.public_videos.each { |object| object.should be_a_video }
64
+ user.public_media.each { |object| object.should be_a_media }
65
+ user.photos.each { |object| object.should be_a_photo }
66
+ user.videos.each { |object| object.should be_a_video }
67
+ user.media.each { |object| object.should be_a_media }
68
+ end
69
+ end
70
+
71
+ context "blank user" do
72
+ it "should have all attributes equal to nil" do
73
+ attributes = Flickrie::User.instance_methods -
74
+ Object.instance_methods -
75
+ [:public_photos, :public_videos, :public_media,
76
+ :photos, :videos, :media, :[], :get_info]
77
+ user = Flickrie::User.public_new
78
+
79
+ attributes.each do |attribute|
80
+ user.send(attribute).should be_nil
81
+ end
82
+ end
83
+ end
58
84
  end
@@ -9,9 +9,9 @@ describe Flickrie::Video do
9
9
  video.failed?.should be_false
10
10
  video.pending?.should be_false
11
11
 
12
- video.duration.should eq(16)
13
- video.width.should eq(352)
14
- video.height.should eq(288)
12
+ video.duration.should == 16
13
+ video.width.should == 352
14
+ video.height.should == 288
15
15
 
16
16
  video.source_url.should be_nil
17
17
  video.download_url.should be_nil
@@ -26,9 +26,9 @@ describe Flickrie::Video do
26
26
  Flickrie::Video.public_new('id' => VIDEO_ID).get_sizes
27
27
  ].
28
28
  each do |video|
29
- video.can_download?.should be_true
30
- video.can_blog?.should be_false
31
- video.can_blog?.should be_false
29
+ [:can_download?, :can_blog?, :can_print?].each do |attribute|
30
+ video.send(attribute).should be_a_boolean
31
+ end
32
32
 
33
33
  video.source_url.should_not be_empty
34
34
  video.download_url.should_not be_empty
@@ -39,14 +39,14 @@ describe Flickrie::Video do
39
39
 
40
40
  context "blank" do
41
41
  it "should have attributes equal to nil" do
42
+ attributes = Flickrie::Video.instance_methods -
43
+ Flickrie::Media.instance_methods -
44
+ Object.instance_methods -
45
+ [:get_info, :get_sizes, :[]]
42
46
  video = Flickrie::Video.public_new
43
- [
44
- :ready?, :failed?, :pending?, :duration, :width, :height,
45
- :source_url, :download_url, :mobile_download_url
46
- ].
47
- each do |attribute|
48
- video.send(attribute).should be_nil
49
- end
47
+ attributes.each do |attribute|
48
+ video.send(attribute).should be_nil
49
+ end
50
50
  end
51
51
  end
52
52
  end
@@ -0,0 +1,15 @@
1
+ describe Flickrie do
2
+ context "a new credential is filled in" do
3
+ it "should reset the client", :vcr do
4
+ Flickrie.api_key = nil
5
+ expect { Flickrie.get_licenses }.to raise_error(Flickrie::Error)
6
+ expect { Flickrie.upload(PHOTO_PATH) }.to raise_error(Flickrie::Error)
7
+ Flickrie.api_key = ENV['FLICKR_API_KEY']
8
+ expect { Flickrie.get_licenses }.to_not raise_error(Flickrie::Error)
9
+ expect { Flickrie.upload(PHOTO_PATH) }.to_not raise_error(Flickrie::Error)
10
+
11
+ photo = Flickrie.photos_from_user(USER_NSID).find { |photo| photo.title == "photo" }
12
+ Flickrie.delete_photo(photo.id)
13
+ end
14
+ end
15
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,43 +1,10 @@
1
1
  # encoding: utf-8
2
2
  require 'flickrie'
3
3
  require 'vcr'
4
- begin
5
- require 'debugger'
6
- rescue LoadError
7
- end
8
-
9
- module RSpecHelpers
10
- def test_recursively(object, attribute, hash = nil)
11
- expectation = hash || @attributes[attribute]
12
- unless expectation.is_a?(Hash)
13
- object.send(attribute).should eq(expectation)
14
- else
15
- iterate(object.send(attribute), expectation) do |actual, expected|
16
- actual.should eq(expected)
17
- end
18
- end
19
- end
20
-
21
- def iterate(object, rest, &block)
22
- rest.each do |key, value|
23
- if value.is_a?(Hash)
24
- iterate(object.send(key), value, &block)
25
- else
26
- yield [object.send(key), value]
27
- end
28
- end
29
- end
30
-
31
- # SomeModule::AnotherModule::Class => "some_module/another_module/class"
32
- def to_file_path(constants)
33
- constants.split("::").collect do |constant|
34
- constant.split(/(?=[A-Z])/).map(&:downcase).join('_')
35
- end.join('/')
36
- end
37
- end
4
+ begin require 'debugger'; rescue LoadError; end
5
+ require 'custom_matchers'
38
6
 
39
7
  RSpec.configure do |c|
40
- c.include RSpecHelpers
41
8
  c.before(:all) do
42
9
  Flickrie.api_key = ENV['FLICKR_API_KEY']
43
10
  Flickrie.shared_secret = ENV['FLICKR_SHARED_SECRET']
@@ -46,18 +13,12 @@ RSpec.configure do |c|
46
13
  end
47
14
  c.treat_symbols_as_metadata_keys_with_true_values = true
48
15
  c.around(:each, :vcr) do |example|
49
- if example.metadata[:cassette].nil?
50
- # the example is wrapped in a 'context' block
51
- class_name = example.metadata[:example_group][:example_group][:description_args].first.to_s
52
- cassette_name = example.metadata[:example_group][:description_args].first
53
- else
54
- # the example isn't wrapped in a 'context' block
55
- class_name = example.metadata[:example_group][:description_args].first.to_s
56
- cassette_name = example.metadata[:cassette]
57
- end
58
-
59
- folder = to_file_path(class_name.match(/^Flickrie::/).post_match)
60
- VCR.use_cassette("#{folder}/#{cassette_name}") { example.call }
16
+ # If you want to tag an example with :vcr, you have to wrap it in a context block
17
+ klass = example.metadata[:example_group][:example_group][:description_args].first
18
+ folder = klass.to_s.split('::').last.split(/(?=[A-Z])/).map(&:downcase).join('_')
19
+ subfolder = example.metadata[:example_group][:description_args].first
20
+ cassette_name = example.metadata[:description_args].first.match(/^should /).post_match
21
+ VCR.use_cassette("#{folder}/#{subfolder}/#{cassette_name}") { example.call }
61
22
  end
62
23
  c.fail_fast = true
63
24
  end
@@ -67,19 +28,21 @@ VCR.configure do |c|
67
28
  c.hook_into :faraday
68
29
  c.default_cassette_options = {
69
30
  :record => :new_episodes,
70
- :serialize_with => :syck,
71
- :match_requests_on => [:method, VCR.request_matchers.uri_without_param(:api_key)]
31
+ :serialize_with => :syck, # So it doesn't output in binary form
32
+ :match_requests_on => [:method, VCR.request_matchers.uri_without_param(:api_key)] # Don't require the API key
72
33
  }
73
34
  c.filter_sensitive_data('API_KEY') { ENV['FLICKR_API_KEY'] }
74
35
  c.filter_sensitive_data('ACCESS_TOKEN') { ENV['FLICKR_ACCESS_TOKEN'] }
75
36
  end
76
37
 
77
38
  PHOTO_PATH = File.expand_path('../files/photo.jpg', __FILE__).freeze
39
+ MEDIA_ID = '6946979188'.freeze
78
40
  PHOTO_ID = '6946979188'.freeze
79
41
  VIDEO_ID = '7093038981'.freeze
80
42
  SET_ID = '72157629851991663'.freeze
81
43
  USER_NSID = '67131352@N04'.freeze
82
44
  USER_USERNAME = 'Janko Marohnić'.freeze
45
+ USER_EMAIL = 'janko.marohnic@gmail.com'.freeze
83
46
  EXTRAS = %w[license date_upload date_taken owner_name
84
47
  icon_server original_format last_update geo tags machine_tags
85
48
  o_dims views media path_alias url_sq url_q url_t url_s url_n
@@ -87,7 +50,7 @@ EXTRAS = %w[license date_upload date_taken owner_name
87
50
  # for copying:
88
51
  # 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
89
52
 
90
- klasses = [Flickrie::Set, Flickrie::Photo, Flickrie::Video, Flickrie::User, Flickrie::Location]
53
+ klasses = [Flickrie::Set, Flickrie::Photo, Flickrie::Video, Flickrie::Location, Flickrie::User]
91
54
  klasses.each do |klass|
92
55
  klass.instance_eval do
93
56
  def public_new(*args)