flickrie 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +0 -4
- data/flickrie.gemspec +2 -2
- data/lib/flickrie/api_methods.rb +4 -1
- data/lib/flickrie/license.rb +6 -1
- data/lib/flickrie/location.rb +29 -12
- data/lib/flickrie/media/exif.rb +3 -1
- data/lib/flickrie/media/note.rb +24 -13
- data/lib/flickrie/media/tag.rb +9 -6
- data/lib/flickrie/media/visibility.rb +8 -5
- data/lib/flickrie/media.rb +54 -55
- data/lib/flickrie/media_count.rb +8 -6
- data/lib/flickrie/photo.rb +48 -7
- data/lib/flickrie/set.rb +47 -31
- data/lib/flickrie/ticket.rb +8 -5
- data/lib/flickrie/user.rb +67 -25
- data/lib/flickrie/version.rb +1 -1
- data/lib/flickrie/video.rb +19 -11
- data/spec/custom_matchers.rb +51 -0
- data/spec/flickrie/api_methods_spec.rb +112 -31
- data/spec/flickrie/error_spec.rb +2 -4
- data/spec/flickrie/instance_spec.rb +11 -11
- data/spec/flickrie/media_spec.rb +74 -53
- data/spec/flickrie/photo_spec.rb +4 -5
- data/spec/flickrie/set_spec.rb +23 -12
- data/spec/flickrie/upload_client_spec.rb +3 -0
- data/spec/flickrie/user_spec.rb +31 -5
- data/spec/flickrie/video_spec.rb +13 -13
- data/spec/flickrie_spec.rb +15 -0
- data/spec/spec_helper.rb +13 -50
- data/spec/vcr_cassettes/api_methods/people/get_media_from_user.yml +108 -0
- data/spec/vcr_cassettes/api_methods/people/get_public_media_from_user.yml +108 -0
- data/spec/vcr_cassettes/api_methods/photos/add_and_remove_tags.yml +528 -0
- data/spec/vcr_cassettes/api_methods/photos/get_context.yml +108 -0
- data/spec/vcr_cassettes/api_methods/photos/get_counts.yml +108 -0
- data/spec/vcr_cassettes/api_methods/photos/get_exif.yml +73 -0
- data/spec/vcr_cassettes/api_methods/photos/get_favorites.yml +73 -0
- data/spec/vcr_cassettes/api_methods/photos/get_from_contacts.yml +73 -0
- data/spec/vcr_cassettes/api_methods/photos/get_info.yml +108 -0
- data/spec/vcr_cassettes/api_methods/photos/get_public_from_user_contacts.yml +73 -0
- data/spec/vcr_cassettes/api_methods/photos/get_sizes.yml +73 -0
- data/spec/vcr_cassettes/api_methods/photos/search.yml +108 -0
- data/spec/vcr_cassettes/api_methods/photosets/get_media.yml +108 -0
- data/spec/vcr_cassettes/api_methods/{replace.yml → upload/replace.yml} +16 -16
- data/spec/vcr_cassettes/api_methods/upload/upload.yml +82 -0
- data/spec/vcr_cassettes/api_methods/upload/upload_asynchronously.yml +117 -0
- data/spec/vcr_cassettes/error/{a_request_was_made_and_failed.yml → a_request_was_made_and_failed/be_raised.yml} +9 -9
- data/spec/vcr_cassettes/error/a_request_was_made_and_failed/have_code_attribute_present.yml +84 -0
- data/spec/vcr_cassettes/{api_methods/upload_and_delete.yml → flickrie/a_new_credential_is_filled_in/reset_the_client.yml} +113 -32
- data/spec/vcr_cassettes/instance/client_is_already_initialized/be_able_to_call_API_methods.yml +152 -0
- data/spec/vcr_cassettes/license/{get.yml → get/have_all_attributes_correctly_set.yml} +4 -4
- data/spec/vcr_cassettes/media/{from_contacts.yml → from_contacts/have_all_attributes_correctly_set.yml} +8 -8
- data/spec/vcr_cassettes/media/{from_set.yml → from_set/have_all_attributes_correctly_set.yml} +6 -6
- data/spec/vcr_cassettes/media/{from_user.yml → from_user/have_all_attributes_correctly_set.yml} +6 -6
- data/spec/vcr_cassettes/media/{get_context.yml → get_context/have_all_attributes_correctly_set.yml} +6 -6
- data/spec/vcr_cassettes/media/{get_exif.yml → get_exif/get_exif_correctly.yml} +8 -8
- data/spec/vcr_cassettes/media/get_info/have_all_attributes_correctly_set.yml +108 -0
- data/spec/vcr_cassettes/media/{public_from_user.yml → public_from_user/have_all_attributes_correctly_set.yml} +6 -6
- data/spec/vcr_cassettes/media/{search.yml → search/have_all_attributes_correctly_set.yml} +6 -6
- data/spec/vcr_cassettes/media_count/{get.yml → get/have_correctly_set_all_attributes.yml} +9 -9
- data/spec/vcr_cassettes/o_auth/{incorrect_credentials.yml → incorrect_credentials/raise_exceptions.yml} +42 -42
- data/spec/vcr_cassettes/photo/get_info/have_all_attributes_correctly_set.yml +38 -0
- data/spec/vcr_cassettes/photo/{get_sizes.yml → get_sizes/have_attributes_correctly_set.yml} +12 -12
- data/spec/vcr_cassettes/photo/{search.yml → search/have_all_sizes_available.yml} +6 -6
- data/spec/vcr_cassettes/set/{from_user.yml → from_user/have_all_attributes_correctly_set.yml} +18 -18
- data/spec/vcr_cassettes/set/{get_info.yml → get_info/have_all_attributes_correctly_set.yml} +36 -36
- data/spec/vcr_cassettes/upload_client/content_type/pass_the_content_type.yml +117 -0
- data/spec/vcr_cassettes/upload_client/invalid_credentials/raise_errors.yml +276 -0
- data/spec/vcr_cassettes/user/{find_by_username_or_email.yml → find_by_username_or_email/have_all_attributes_correctly_set.yml} +9 -9
- data/spec/vcr_cassettes/user/get_info/have_all_attributes_correctly_set.yml +73 -0
- data/spec/vcr_cassettes/video/get_info/have_all_attributes_correctly_set.yml +38 -0
- data/spec/vcr_cassettes/video/{get_sizes.yml → get_sizes/have_all_attributes_correctly_set.yml} +12 -12
- metadata +111 -74
- data/spec/vcr_cassettes/api_methods/asynchronous_upload.yml +0 -362
- data/spec/vcr_cassettes/api_methods/tag_manipulation.yml +0 -178
- data/spec/vcr_cassettes/instance/calling_api_methods.yml +0 -231
- data/spec/vcr_cassettes/media/get_info.yml +0 -108
- data/spec/vcr_cassettes/photo/get_info.yml +0 -38
- data/spec/vcr_cassettes/upload_client/content_type.yml +0 -117
- data/spec/vcr_cassettes/upload_client/invalid_credentials.yml +0 -208
- data/spec/vcr_cassettes/user/get_info.yml +0 -73
- data/spec/vcr_cassettes/video/get_info.yml +0 -38
data/spec/flickrie/media_spec.rb
CHANGED
@@ -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,
|
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?, :
|
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
|
126
|
+
:can_print?, :can_share?
|
131
127
|
].
|
132
|
-
each { |attribute|
|
128
|
+
each { |attribute| media.send(attribute).should be_a_boolean }
|
133
129
|
|
134
|
-
|
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,
|
148
|
+
:id, :secret, :server, :farm, :title, :media_status,
|
150
149
|
:geo_permissions, :machine_tags, :license, :taken_at_granularity
|
151
150
|
].
|
152
|
-
each
|
151
|
+
each do |attribute|
|
152
|
+
media.send(attribute).should correspond_to(@attributes[attribute])
|
153
|
+
end
|
153
154
|
|
154
155
|
# the incomplete ones
|
155
|
-
|
156
|
-
|
157
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
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
|
-
|
251
|
-
|
252
|
-
|
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
|
data/spec/flickrie/photo_spec.rb
CHANGED
@@ -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
|
-
|
63
|
-
|
64
|
-
|
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
|
|
data/spec/flickrie/set_spec.rb
CHANGED
@@ -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
|
-
|
28
|
+
set.send(attribute).should correspond_to(@attributes[attribute])
|
31
29
|
end
|
32
30
|
|
33
|
-
set.photos.
|
34
|
-
set.videos.
|
35
|
-
set.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
|
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
|
data/spec/flickrie/user_spec.rb
CHANGED
@@ -28,7 +28,7 @@ describe Flickrie::User do
|
|
28
28
|
].
|
29
29
|
each do |user|
|
30
30
|
@attributes.keys.each do |attribute|
|
31
|
-
|
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(
|
49
|
+
Flickrie.find_user_by_email(USER_EMAIL)
|
50
50
|
].
|
51
51
|
each do |user|
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
data/spec/flickrie/video_spec.rb
CHANGED
@@ -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
|
13
|
-
video.width.should
|
14
|
-
video.height.should
|
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
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
45
|
-
|
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
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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::
|
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)
|