flickrie 0.6.1 → 0.7.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 +22 -0
- data/Gemfile +0 -6
- data/README.md +15 -1
- data/Rakefile +8 -13
- data/api_methods.md +1 -1
- data/flickrie.gemspec +2 -3
- data/lib/flickrie/api_methods.rb +17 -0
- data/lib/flickrie/client.rb +21 -5
- data/lib/flickrie/instance.rb +7 -2
- data/lib/flickrie/license.rb +2 -0
- data/lib/flickrie/location.rb +10 -8
- data/lib/flickrie/media/exif.rb +3 -1
- data/lib/flickrie/media/tag.rb +3 -3
- data/lib/flickrie/media/visibility.rb +6 -4
- data/lib/flickrie/media.rb +69 -84
- data/lib/flickrie/media_count.rb +3 -5
- data/lib/flickrie/photo.rb +55 -54
- data/lib/flickrie/set.rb +31 -25
- data/lib/flickrie/ticket.rb +4 -8
- data/lib/flickrie/upload_client.rb +7 -2
- data/lib/flickrie/user.rb +33 -34
- data/lib/flickrie/version.rb +1 -1
- data/lib/flickrie/video.rb +13 -12
- data/spec/api_methods_spec.rb +43 -0
- data/spec/error_spec.rb +32 -0
- data/{test → spec/files}/photo.jpg +0 -0
- data/{test → spec/files}/video.mov +0 -0
- data/spec/instance_spec.rb +22 -0
- data/spec/license_spec.rb +15 -0
- data/spec/location_spec.rb +11 -0
- data/spec/media_count_spec.rb +18 -0
- data/spec/media_spec.rb +271 -0
- data/spec/oauth_spec.rb +22 -0
- data/spec/photo_spec.rb +137 -0
- data/spec/set_spec.rb +68 -0
- data/spec/spec_helper.rb +68 -0
- data/spec/user_spec.rb +56 -0
- data/spec/video_spec.rb +54 -0
- metadata +47 -132
- data/test/error_test.rb +0 -20
- data/test/instance_test.rb +0 -20
- data/test/license_test.rb +0 -19
- data/test/location_test.rb +0 -29
- data/test/media_count_test.rb +0 -25
- data/test/media_test.rb +0 -432
- data/test/oauth_test.rb +0 -25
- data/test/photo_test.rb +0 -212
- data/test/set_test.rb +0 -92
- data/test/test_helper.rb +0 -14
- data/test/user_test.rb +0 -70
- data/test/vcr_cassettes/error/code.yml +0 -1165
- data/test/vcr_cassettes/instance/calling_api_methods.yml +0 -182
- data/test/vcr_cassettes/license/get_licenses.yml +0 -73
- data/test/vcr_cassettes/location/square_brackets.yml +0 -85
- data/test/vcr_cassettes/media/delete.yml +0 -1380
- data/test/vcr_cassettes/media/from_contacts.yml +0 -155
- data/test/vcr_cassettes/media/from_set.yml +0 -276
- data/test/vcr_cassettes/media/from_user.yml +0 -275
- data/test/vcr_cassettes/media/get_context.yml +0 -73
- data/test/vcr_cassettes/media/get_info.yml +0 -167
- data/test/vcr_cassettes/media/remove_tag.yml +0 -264
- data/test/vcr_cassettes/media/replace.yml +0 -2252
- data/test/vcr_cassettes/media/search.yml +0 -275
- data/test/vcr_cassettes/media/tags.yml +0 -346
- data/test/vcr_cassettes/media_count/get.yml +0 -135
- data/test/vcr_cassettes/media_count/square_brackets.yml +0 -69
- data/test/vcr_cassettes/oauth/tokens.yml +0 -400
- data/test/vcr_cassettes/photo/asynchronous_upload.yml +0 -1693
- data/test/vcr_cassettes/photo/from_set.yml +0 -273
- data/test/vcr_cassettes/photo/from_user.yml +0 -275
- data/test/vcr_cassettes/photo/get_exif.yml +0 -239
- data/test/vcr_cassettes/photo/get_sizes.yml +0 -147
- data/test/vcr_cassettes/photo/other_api_calls.yml +0 -506
- data/test/vcr_cassettes/photo/search.yml +0 -271
- data/test/vcr_cassettes/photo/square_brackets.yml +0 -85
- data/test/vcr_cassettes/photo/upload.yml +0 -1229
- data/test/vcr_cassettes/set/from_user.yml +0 -477
- data/test/vcr_cassettes/set/get_info.yml +0 -951
- data/test/vcr_cassettes/set/square_brackets.yml +0 -73
- data/test/vcr_cassettes/user/find_by_email_or_username.yml +0 -135
- data/test/vcr_cassettes/user/get_info.yml +0 -151
- data/test/vcr_cassettes/user/square_brackets.yml +0 -77
- data/test/vcr_cassettes/video/get_exif.yml +0 -135
- data/test/vcr_cassettes/video/get_info.yml +0 -86
- data/test/vcr_cassettes/video/get_sizes.yml +0 -151
- data/test/vcr_cassettes/video/other_api_calls.yml +0 -643
- data/test/vcr_cassettes/video/square_brackets.yml +0 -86
- data/test/vcr_cassettes/video/upload.yml +0 -308
- data/test/video_test.rb +0 -118
data/spec/media_spec.rb
ADDED
@@ -0,0 +1,271 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe Flickrie::Media do
|
4
|
+
before(:all) do
|
5
|
+
@attributes = {
|
6
|
+
:id => PHOTO_ID,
|
7
|
+
:secret => '25bb44852b',
|
8
|
+
:server => '7049',
|
9
|
+
:farm => 8,
|
10
|
+
:title => 'IMG_0796',
|
11
|
+
:description => 'Test',
|
12
|
+
:media_status => 'ready',
|
13
|
+
:path_alias => nil,
|
14
|
+
:camera => 'Canon PowerShot G12',
|
15
|
+
:views_count => 2,
|
16
|
+
:comments_count => 1,
|
17
|
+
:location => {
|
18
|
+
:latitude => 45.807258,
|
19
|
+
:longitude => 15.967599,
|
20
|
+
:accuracy => '11',
|
21
|
+
:context => 0,
|
22
|
+
:neighbourhood => nil,
|
23
|
+
:locality => {
|
24
|
+
:name => 'Zagreb',
|
25
|
+
:place_id => '00j4IylZV7scWik',
|
26
|
+
:woeid => '851128'
|
27
|
+
},
|
28
|
+
:county => {
|
29
|
+
:name => 'Zagreb',
|
30
|
+
:place_id => '306dHrhQV7o6jm.ZUQ',
|
31
|
+
:woeid => '15022257'
|
32
|
+
},
|
33
|
+
:region => {
|
34
|
+
:name => 'Grad Zagreb',
|
35
|
+
:place_id => 'Js1DU.pTUrpBCIKhVw',
|
36
|
+
:woeid => '20070170'
|
37
|
+
},
|
38
|
+
:country => {
|
39
|
+
:name => 'Croatia',
|
40
|
+
:place_id => 'FunRCI5TUb6a6soTyw',
|
41
|
+
:woeid => '23424843'
|
42
|
+
},
|
43
|
+
:place_id => '00j4IylZV7scWik',
|
44
|
+
:woeid => '851128'
|
45
|
+
},
|
46
|
+
:geo_permissions => {
|
47
|
+
:public? => true,
|
48
|
+
:contacts? => false,
|
49
|
+
:friends? => false,
|
50
|
+
:family? => false
|
51
|
+
},
|
52
|
+
:tags => {
|
53
|
+
:first => {
|
54
|
+
:content => 'luka',
|
55
|
+
:author => {
|
56
|
+
:nsid => USER_NSID
|
57
|
+
},
|
58
|
+
:raw => 'luka',
|
59
|
+
:machine_tag? => false
|
60
|
+
}
|
61
|
+
},
|
62
|
+
:machine_tags => [],
|
63
|
+
:license => {:id => '0'},
|
64
|
+
:taken_at_granularity => 0,
|
65
|
+
:owner => {
|
66
|
+
:nsid => USER_NSID,
|
67
|
+
:username => "Janko Marohnić",
|
68
|
+
:real_name => "Janko Marohnić",
|
69
|
+
:location => "Zagreb, Croatia",
|
70
|
+
:icon_server => "5464",
|
71
|
+
:icon_farm => 6
|
72
|
+
},
|
73
|
+
|
74
|
+
:safety_level => 0,
|
75
|
+
:safe? => true,
|
76
|
+
:moderate? => false,
|
77
|
+
:restricted? => false,
|
78
|
+
|
79
|
+
:visibility => {
|
80
|
+
:public? => true,
|
81
|
+
:family? => false,
|
82
|
+
:friends? => false,
|
83
|
+
:contacts? => nil
|
84
|
+
},
|
85
|
+
:favorite? => false,
|
86
|
+
|
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
|
+
:has_people? => false,
|
98
|
+
:faved? => false,
|
99
|
+
:notes => {
|
100
|
+
:first => {
|
101
|
+
:id => '72157629487842968',
|
102
|
+
:author => {
|
103
|
+
:nsid => '67131352@N04',
|
104
|
+
:username => 'Janko Marohnić'
|
105
|
+
},
|
106
|
+
:coordinates => [316, 0],
|
107
|
+
:width => 59,
|
108
|
+
:height => 50,
|
109
|
+
:content => 'Test'
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
context "get info" do
|
116
|
+
use_vcr_cassette "media/get_info"
|
117
|
+
|
118
|
+
it "should have all attributes correctly set" do
|
119
|
+
[
|
120
|
+
Flickrie.get_media_info(PHOTO_ID),
|
121
|
+
Flickrie::Photo.public_new('id' => PHOTO_ID).get_info,
|
122
|
+
Flickrie::Video.public_new('id' => PHOTO_ID).get_info
|
123
|
+
].
|
124
|
+
each do |media|
|
125
|
+
[
|
126
|
+
:id, :secret, :server, :farm, :title, :description,
|
127
|
+
:views_count, :comments_count, :location, :geo_permissions,
|
128
|
+
:tags, :machine_tags, :license, :taken_at_granularity, :owner,
|
129
|
+
:safety_level, :safe?, :moderate?, :restricted?, :visibility,
|
130
|
+
:favorite?, :can_comment?, :can_add_meta?, :can_everyone_comment?,
|
131
|
+
:can_everyone_add_meta?, :can_download?, :can_blog?,
|
132
|
+
:can_print?, :can_share?, :has_people?, :notes
|
133
|
+
].
|
134
|
+
each { |attribute| test_attribute(media, attribute) }
|
135
|
+
|
136
|
+
# other
|
137
|
+
media.url.empty?.should be_false
|
138
|
+
media['id'].should eq(PHOTO_ID)
|
139
|
+
|
140
|
+
# time
|
141
|
+
[:posted_at, :uploaded_at, :updated_at, :taken_at].each do |time_attribute|
|
142
|
+
media.send(time_attribute).should be_an_instance_of(Time)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
shared_context "common" do
|
149
|
+
def test_common_attributes(media)
|
150
|
+
[
|
151
|
+
:id, :secret, :server, :farm, :title, :media_status, :views_count,
|
152
|
+
:geo_permissions, :machine_tags, :license, :taken_at_granularity
|
153
|
+
].
|
154
|
+
each { |attribute| test_attribute(media, attribute) }
|
155
|
+
|
156
|
+
# the incomplete ones
|
157
|
+
test_attribute(media, :location, @attributes[:location].except(:locality, :county, :region, :country))
|
158
|
+
test_attribute(media.tags, :first, @attributes[:tags][:first].except(:author, :raw, :machine_tag?))
|
159
|
+
test_attribute(media, :owner, @attributes[:owner].except(:real_name, :location))
|
160
|
+
|
161
|
+
# other
|
162
|
+
media.url.empty?.should be_false
|
163
|
+
|
164
|
+
# time
|
165
|
+
[:uploaded_at, :updated_at, :taken_at].each do |time_attribute|
|
166
|
+
media.send(time_attribute).should be_an_instance_of(Time)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "from set" do
|
172
|
+
include_context "common"
|
173
|
+
use_vcr_cassette "media/from_set"
|
174
|
+
|
175
|
+
it "should have all attributes correctly set" do
|
176
|
+
media = Flickrie.media_from_set(SET_ID, :extras => EXTRAS).
|
177
|
+
find { |media| media.id == PHOTO_ID }
|
178
|
+
test_common_attributes(media)
|
179
|
+
media.primary?.should be_true
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context "public from user" do
|
184
|
+
include_context "common"
|
185
|
+
use_vcr_cassette "media/public_from_user"
|
186
|
+
|
187
|
+
it "should have all attributes correctly set" do
|
188
|
+
media = Flickrie.public_media_from_user(USER_NSID, :extras => EXTRAS).
|
189
|
+
find { |media| media.id == PHOTO_ID }
|
190
|
+
test_common_attributes(media)
|
191
|
+
test_attribute(media, :visibility)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
context "search" do
|
196
|
+
include_context "common"
|
197
|
+
use_vcr_cassette "media/search"
|
198
|
+
|
199
|
+
it "should have all attributes correctly set" do
|
200
|
+
media = Flickrie.search_media(:user_id => USER_NSID, :extras => EXTRAS).
|
201
|
+
find { |media| media.id == PHOTO_ID }
|
202
|
+
test_common_attributes(media)
|
203
|
+
test_attribute(media, :visibility)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
context "from contacts" do
|
208
|
+
use_vcr_cassette "media/from_contacts"
|
209
|
+
|
210
|
+
it "should have all attributes correctly set" do
|
211
|
+
params = {:include_self => 1, :single_photo => 1}
|
212
|
+
[
|
213
|
+
@flickrie.media_from_contacts(params).first,
|
214
|
+
@flickrie.public_media_from_user_contacts(USER_NSID, params).first
|
215
|
+
].
|
216
|
+
each do |media|
|
217
|
+
media.id.should eq('7093101501')
|
218
|
+
media.secret.should eq('9337f28800')
|
219
|
+
media.server.should eq('7090')
|
220
|
+
media.farm.should eq(8)
|
221
|
+
media.owner.nsid.should eq(USER_NSID)
|
222
|
+
media.owner.username.should eq('Janko Marohnić')
|
223
|
+
media.title.should eq('IMG_0917')
|
224
|
+
test_attribute(media, :visibility)
|
225
|
+
media.media_status.should eq('ready')
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
context "get context" do
|
231
|
+
use_vcr_cassette "media/get_context"
|
232
|
+
|
233
|
+
it "should have all attributes correctly set" do
|
234
|
+
context = Flickrie.get_media_context(PHOTO_ID)
|
235
|
+
context['count'].should eq(98)
|
236
|
+
context['prevphoto'].title.should eq('IMG_0795')
|
237
|
+
context['prevphoto'].url.should_not be_empty
|
238
|
+
context['prevphoto'].faved?.should be_false
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
context "blank media" do
|
243
|
+
it "should have all attributes equal to nil" do
|
244
|
+
attributes = Flickrie::Media.instance_methods -
|
245
|
+
Object.instance_methods -
|
246
|
+
[:[], :get_info, :get_exif, :get_favorites]
|
247
|
+
|
248
|
+
media = Flickrie::Photo.public_new
|
249
|
+
attributes.each do |attribute|
|
250
|
+
media.send(attribute).should be_nil
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
context "get exif" do
|
256
|
+
use_vcr_cassette "media/get_exif"
|
257
|
+
|
258
|
+
it "should get exif correctly" do
|
259
|
+
[
|
260
|
+
Flickrie.get_photo_exif(PHOTO_ID),
|
261
|
+
Flickrie::Photo.public_new('id' => PHOTO_ID).get_exif
|
262
|
+
].
|
263
|
+
each do |photo|
|
264
|
+
photo.camera.should eq('Canon PowerShot G12')
|
265
|
+
photo.exif.get('X-Resolution').should eq('180 dpi')
|
266
|
+
photo.exif.get('X-Resolution', :data => 'clean').should eq('180 dpi')
|
267
|
+
photo.exif.get('X-Resolution', :data => 'raw').should eq('180')
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
data/spec/oauth_spec.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
describe Flickrie::OAuth do
|
2
|
+
context "incorrect credentials" do
|
3
|
+
use_vcr_cassette "oauth/incorrect_credentials"
|
4
|
+
|
5
|
+
it "should raise exceptions" do
|
6
|
+
Flickrie.api_key = "foo"
|
7
|
+
Flickrie.shared_secret = "foo"
|
8
|
+
|
9
|
+
expect { Flickrie::OAuth.get_request_token }.
|
10
|
+
to raise_error(Flickrie::OAuth::Error)
|
11
|
+
|
12
|
+
Flickrie.api_key = ENV['FLICKR_API_KEY']
|
13
|
+
expect { Flickrie::OAuth.get_request_token }.
|
14
|
+
to raise_error(Flickrie::OAuth::Error)
|
15
|
+
|
16
|
+
Flickrie.shared_secret = ENV['FLICKR_SHARED_SECRET']
|
17
|
+
request_token = Flickrie::OAuth.get_request_token
|
18
|
+
expect { Flickrie::OAuth.get_access_token("foo", request_token) }.
|
19
|
+
to raise_error(Flickrie::OAuth::Error)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/photo_spec.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
SIZES = ['Square 75', 'Thumbnail', 'Square 150', 'Small 240', 'Small 320',
|
2
|
+
'Medium 500', 'Medium 640', 'Medium 800', 'Large 1024']
|
3
|
+
|
4
|
+
describe Flickrie::Photo do
|
5
|
+
def test_sizes(photo)
|
6
|
+
# TODO: simplify this
|
7
|
+
# non-bang versions
|
8
|
+
[
|
9
|
+
[[photo.square(75), photo.square75], ['Square 75', '75x75']],
|
10
|
+
[[photo.thumbnail], ['Thumbnail', '75x100']],
|
11
|
+
[[photo.square(150), photo.square150], ['Square 150', '150x150']],
|
12
|
+
[[photo.small(240), photo.small240], ['Small 240', '180x240']],
|
13
|
+
[[photo.small(320), photo.small320], ['Small 320', '240x320']],
|
14
|
+
[[photo.medium(500), photo.medium500], ['Medium 500', '375x500']],
|
15
|
+
[[photo.medium(640), photo.medium640], ['Medium 640', '480x640']],
|
16
|
+
[[photo.medium(800), photo.medium800], ['Medium 800', '600x800']],
|
17
|
+
[[photo.large(1024), photo.large1024], ['Large 1024', '768x1024']]
|
18
|
+
].
|
19
|
+
each do |photos, expected_values|
|
20
|
+
flickr_size, size = expected_values
|
21
|
+
photos.each do |photo|
|
22
|
+
photo.size.should eq(flickr_size)
|
23
|
+
[photo.width, photo.height].join('x').should eq(size)
|
24
|
+
photo.source_url.should_not be_empty
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# bang versions
|
29
|
+
[
|
30
|
+
[[proc { photo.square!(75) }, proc { photo.square75! }], ['Square 75', '75x75']],
|
31
|
+
[[proc { photo.thumbnail! }], ['Thumbnail', '75x100']],
|
32
|
+
[[proc { photo.square!(150) }, proc { photo.square150! }], ['Square 150', '150x150']],
|
33
|
+
[[proc { photo.small!(240) }, proc { photo.small240! }], ['Small 240', '180x240']],
|
34
|
+
[[proc { photo.small!(320) }, proc { photo.small320! }], ['Small 320', '240x320']],
|
35
|
+
[[proc { photo.medium!(500) }, proc { photo.medium500! }], ['Medium 500', '375x500']],
|
36
|
+
[[proc { photo.medium!(640) }, proc { photo.medium640! }], ['Medium 640', '480x640']],
|
37
|
+
[[proc { photo.medium!(800) }, proc { photo.medium800! }], ['Medium 800', '600x800']],
|
38
|
+
[[proc { photo.large!(1024) }, proc { photo.large1024! }], ['Large 1024', '768x1024']]
|
39
|
+
].
|
40
|
+
each do |blocks, expected_values|
|
41
|
+
flickr_size, size = expected_values
|
42
|
+
blocks.each do |block|
|
43
|
+
result_photo = block.call
|
44
|
+
[result_photo, photo].each do |photo|
|
45
|
+
photo.size.should eq(flickr_size)
|
46
|
+
[photo.width, photo.height].join('x').should eq(size)
|
47
|
+
photo.source_url.should_not be_empty
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "get sizes" do
|
54
|
+
use_vcr_cassette "photo/get_sizes"
|
55
|
+
|
56
|
+
it "should have attributes correctly set" do
|
57
|
+
[
|
58
|
+
Flickrie.get_photo_sizes(PHOTO_ID),
|
59
|
+
Flickrie::Photo.public_new('id' => PHOTO_ID).get_sizes
|
60
|
+
].
|
61
|
+
each do |photo|
|
62
|
+
photo.can_download?.should be_true
|
63
|
+
photo.can_blog?.should be_false
|
64
|
+
photo.can_print?.should be_false
|
65
|
+
|
66
|
+
test_sizes(photo)
|
67
|
+
photo.available_sizes.should eq(SIZES)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "search" do
|
73
|
+
use_vcr_cassette "photo/search"
|
74
|
+
|
75
|
+
it "should have all sizes available" do
|
76
|
+
photo = Flickrie.search_photos(:user_id => USER_NSID, :extras => EXTRAS).
|
77
|
+
find { |photo| photo.id == PHOTO_ID }
|
78
|
+
photo.available_sizes.should eq(SIZES)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "get info" do
|
83
|
+
use_vcr_cassette "photo/get_info"
|
84
|
+
|
85
|
+
it "should have all attributes correctly set" do
|
86
|
+
photo = Flickrie.get_photo_info(PHOTO_ID)
|
87
|
+
photo.rotation.should eq(90)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "blank" do
|
92
|
+
it "should have all attributes equal to nil" do
|
93
|
+
photo = Flickrie::Photo.public_new
|
94
|
+
|
95
|
+
photo.width.should be_nil
|
96
|
+
photo.height.should be_nil
|
97
|
+
photo.source_url.should be_nil
|
98
|
+
photo.rotation.should be_nil
|
99
|
+
photo.available_sizes.should be_empty
|
100
|
+
photo.size.should be_nil
|
101
|
+
|
102
|
+
[
|
103
|
+
photo.square(75), photo.square(150), photo.thumbnail,
|
104
|
+
photo.small(240), photo.small(320), photo.medium(500),
|
105
|
+
photo.medium(640), photo.medium(800), photo.large(1024),
|
106
|
+
photo.original, photo.square75, photo.square150,
|
107
|
+
photo.small240, photo.small320, photo.medium500,
|
108
|
+
photo.medium640, photo.medium800, photo.large1024,
|
109
|
+
photo.largest
|
110
|
+
].
|
111
|
+
each do |photo|
|
112
|
+
photo.source_url.should be_nil
|
113
|
+
photo.width.should be_nil
|
114
|
+
photo.height.should be_nil
|
115
|
+
end
|
116
|
+
|
117
|
+
[
|
118
|
+
proc { photo.square!(75) }, proc { photo.square!(150) },
|
119
|
+
proc { photo.thumbnail! }, proc { photo.small!(240) },
|
120
|
+
proc { photo.small!(320) }, proc { photo.medium!(500) },
|
121
|
+
proc { photo.medium!(640) }, proc { photo.medium!(800) },
|
122
|
+
proc { photo.large!(1024) }, proc { photo.original! },
|
123
|
+
proc { photo.square75! }, proc { photo.square150! },
|
124
|
+
proc { photo.small240! }, proc { photo.small320! },
|
125
|
+
proc { photo.medium500! }, proc { photo.medium640! },
|
126
|
+
proc { photo.medium800! }, proc { photo.large1024! },
|
127
|
+
proc { photo.largest! }
|
128
|
+
].
|
129
|
+
each do |prok|
|
130
|
+
prok.call
|
131
|
+
photo.source_url.should be_nil
|
132
|
+
photo.width.should be_nil
|
133
|
+
photo.height.should be_nil
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
data/spec/set_spec.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe Flickrie::Set do
|
4
|
+
before(:all) do
|
5
|
+
@attributes = {
|
6
|
+
:id => SET_ID,
|
7
|
+
:secret => '25bb44852b',
|
8
|
+
:server => '7049',
|
9
|
+
:farm => 8,
|
10
|
+
:title => 'Speleologija',
|
11
|
+
:description => 'Slike sa škole speleologije Velebit.',
|
12
|
+
:primary_media_id => PHOTO_ID,
|
13
|
+
:primary_photo_id => PHOTO_ID,
|
14
|
+
:primary_video_id => PHOTO_ID,
|
15
|
+
:views_count => 0,
|
16
|
+
:comments_count => 0,
|
17
|
+
:photos_count => 97,
|
18
|
+
:videos_count => 1,
|
19
|
+
:media_count => 98,
|
20
|
+
:owner => {
|
21
|
+
:nsid => USER_NSID
|
22
|
+
},
|
23
|
+
:can_comment? => false,
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_common_attributes(set)
|
28
|
+
@attributes.keys.each do |attribute|
|
29
|
+
test_attribute(set, attribute)
|
30
|
+
end
|
31
|
+
|
32
|
+
set.photos.all? { |photo| photo.is_a?(Flickrie::Photo) }.should be_true
|
33
|
+
set.videos.all? { |video| video.is_a?(Flickrie::Video) }.should be_true
|
34
|
+
set.media.all? do |media|
|
35
|
+
media.is_a?(Flickrie::Photo) or media.is_a?(Flickrie::Video)
|
36
|
+
end.should be_true
|
37
|
+
|
38
|
+
set.created_at.should be_an_instance_of(Time)
|
39
|
+
set.updated_at.should be_an_instance_of(Time)
|
40
|
+
|
41
|
+
set.url.should_not be_empty
|
42
|
+
end
|
43
|
+
|
44
|
+
context "get info" do
|
45
|
+
use_vcr_cassette "set/get_info"
|
46
|
+
|
47
|
+
it "should have all attributes correctly set" do
|
48
|
+
[
|
49
|
+
Flickrie.get_set_info(SET_ID),
|
50
|
+
Flickrie::Set.public_new('id' => SET_ID).get_info
|
51
|
+
].
|
52
|
+
each do |set|
|
53
|
+
test_common_attributes(set)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "from user" do
|
59
|
+
use_vcr_cassette "set/from_user"
|
60
|
+
|
61
|
+
it "should have all attributes correctly set" do
|
62
|
+
set = Flickrie.sets_from_user(USER_NSID).find { |set| set.id == SET_ID }
|
63
|
+
test_common_attributes(set)
|
64
|
+
set.needs_interstitial?.should be_false
|
65
|
+
set.visibility_can_see_set?.should be_true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'flickrie'
|
2
|
+
require 'vcr'
|
3
|
+
require 'active_support/core_ext/hash/except'
|
4
|
+
begin
|
5
|
+
require 'debugger'
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
|
9
|
+
VCR.configure do |config|
|
10
|
+
config.cassette_library_dir = 'spec/vcr_cassettes'
|
11
|
+
config.hook_into :faraday
|
12
|
+
config.default_cassette_options = {:record => :new_episodes}
|
13
|
+
end
|
14
|
+
|
15
|
+
module RSpecHelpers
|
16
|
+
def test_attribute(object, attribute, hash = nil)
|
17
|
+
expectation = hash || @attributes[attribute]
|
18
|
+
unless expectation.is_a?(Hash)
|
19
|
+
object.send(attribute).should eq(expectation)
|
20
|
+
else
|
21
|
+
iterate(object.send(attribute), expectation) do |actual, expected|
|
22
|
+
actual.should eq(expected)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def iterate(object, rest, &block)
|
28
|
+
rest.each do |key, value|
|
29
|
+
if value.is_a?(Hash)
|
30
|
+
iterate(object.send(key), value, &block)
|
31
|
+
else
|
32
|
+
yield [object.send(key), value]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
RSpec.configure do |config|
|
39
|
+
config.extend VCR::RSpec::Macros
|
40
|
+
config.include RSpecHelpers
|
41
|
+
config.before(:all) do
|
42
|
+
Flickrie.api_key = ENV['FLICKR_API_KEY']
|
43
|
+
Flickrie.shared_secret = ENV['FLICKR_SHARED_SECRET']
|
44
|
+
# so that I can use the '@instance' object when I want to make authenticated API calls
|
45
|
+
@flickrie = Flickrie::Instance.new(ENV['FLICKR_ACCESS_TOKEN'], ENV['FLICKR_ACCESS_SECRET'])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
PHOTO_PATH = File.join(File.expand_path(File.dirname(__FILE__)), 'files/photo.jpg').freeze
|
50
|
+
PHOTO_ID = '6946979188'.freeze
|
51
|
+
VIDEO_ID = '7093038981'.freeze
|
52
|
+
SET_ID = '72157629851991663'.freeze
|
53
|
+
USER_NSID = '67131352@N04'.freeze
|
54
|
+
EXTRAS = %w[license date_upload date_taken owner_name
|
55
|
+
icon_server original_format last_update geo tags machine_tags
|
56
|
+
o_dims views media path_alias url_sq url_q url_t url_s url_n
|
57
|
+
url_m url_z url_c url_l url_o].join(',').freeze
|
58
|
+
# for copying:
|
59
|
+
# 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
|
60
|
+
|
61
|
+
klasses = [Flickrie::Set, Flickrie::Photo, Flickrie::Video, Flickrie::User, Flickrie::Location]
|
62
|
+
klasses.each do |klass|
|
63
|
+
klass.instance_eval do
|
64
|
+
def public_new(*args)
|
65
|
+
new(*args)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/spec/user_spec.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe Flickrie::User do
|
4
|
+
context "get info" do
|
5
|
+
use_vcr_cassette "user/get_info"
|
6
|
+
|
7
|
+
it "should have all attributes correctly set" do
|
8
|
+
[
|
9
|
+
Flickrie.get_user_info(USER_NSID),
|
10
|
+
Flickrie::User.public_new('nsid' => USER_NSID).get_info
|
11
|
+
].
|
12
|
+
each do |user|
|
13
|
+
user.id.should eq(USER_NSID)
|
14
|
+
user.nsid.should eq(USER_NSID)
|
15
|
+
user.username.should eq('Janko Marohnić')
|
16
|
+
user.real_name.should eq('Janko Marohnić')
|
17
|
+
user.location.should eq('Zagreb, Croatia')
|
18
|
+
user.time_zone['label'].should eq('Sarajevo, Skopje, Warsaw, Zagreb')
|
19
|
+
user.time_zone['offset'].should eq('+01:00')
|
20
|
+
description = "I'm a programmer, and I'm gonna program a badass Ruby library for Flickr."
|
21
|
+
user.description.should eq(description)
|
22
|
+
|
23
|
+
user.profile_url.should_not be_empty
|
24
|
+
user.mobile_url.should_not be_empty
|
25
|
+
user.photos_url.should_not be_empty
|
26
|
+
|
27
|
+
user.icon_server.should eq('5464')
|
28
|
+
user.icon_farm.should eq(6)
|
29
|
+
user.buddy_icon_url.should_not be_empty
|
30
|
+
|
31
|
+
user.pro?.should be_false
|
32
|
+
|
33
|
+
user.first_taken.should be_an_instance_of(Time)
|
34
|
+
user.first_uploaded.should be_an_instance_of(Time)
|
35
|
+
|
36
|
+
user.media_count.should eq(98)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "find by username or email" do
|
42
|
+
use_vcr_cassette "user/find_by_username_or_email"
|
43
|
+
|
44
|
+
it "should have all attributes correctly set" do
|
45
|
+
[
|
46
|
+
Flickrie.find_user_by_username('Janko Marohnić'),
|
47
|
+
Flickrie.find_user_by_email('janko.marohnic@gmail.com')
|
48
|
+
].
|
49
|
+
each do |user|
|
50
|
+
user.id.should eq(USER_NSID)
|
51
|
+
user.nsid.should eq(USER_NSID)
|
52
|
+
user.username.should eq('Janko Marohnić')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/spec/video_spec.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
describe Flickrie::Video do
|
2
|
+
context "get info" do
|
3
|
+
use_vcr_cassette "video/get_info"
|
4
|
+
|
5
|
+
it "should have all attributes correctly set" do
|
6
|
+
video = Flickrie.get_video_info(VIDEO_ID)
|
7
|
+
|
8
|
+
video.ready?.should be_true
|
9
|
+
video.failed?.should be_false
|
10
|
+
video.pending?.should be_false
|
11
|
+
|
12
|
+
video.duration.should eq(16)
|
13
|
+
video.width.should eq(352)
|
14
|
+
video.height.should eq(288)
|
15
|
+
|
16
|
+
video.source_url.should be_nil
|
17
|
+
video.download_url.should be_nil
|
18
|
+
video.mobile_download_url.should be_nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "get sizes" do
|
23
|
+
use_vcr_cassette "video/get_sizes"
|
24
|
+
|
25
|
+
it "should have all attributes correctly set" do
|
26
|
+
[
|
27
|
+
Flickrie.get_video_sizes(VIDEO_ID),
|
28
|
+
Flickrie::Video.public_new('id' => VIDEO_ID).get_sizes
|
29
|
+
].
|
30
|
+
each do |video|
|
31
|
+
video.can_download?.should be_true
|
32
|
+
video.can_blog?.should be_false
|
33
|
+
video.can_blog?.should be_false
|
34
|
+
|
35
|
+
video.source_url.should_not be_empty
|
36
|
+
video.download_url.should_not be_empty
|
37
|
+
video.mobile_download_url.should_not be_empty
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "blank" do
|
43
|
+
it "should have attributes equal to nil" do
|
44
|
+
video = Flickrie::Video.public_new
|
45
|
+
[
|
46
|
+
:ready?, :failed?, :pending?, :duration, :width, :height,
|
47
|
+
:source_url, :download_url, :mobile_download_url
|
48
|
+
].
|
49
|
+
each do |attribute|
|
50
|
+
video.send(attribute).should be_nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|