flickrie 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/CHANGELOG.md +10 -0
- data/Gemfile +3 -2
- data/Rakefile +7 -2
- data/flickrie.gemspec +3 -0
- data/lib/flickrie/api_methods.rb +5 -0
- data/lib/flickrie/client.rb +17 -4
- data/lib/flickrie/location.rb +23 -50
- data/lib/flickrie/media/exif.rb +4 -0
- data/lib/flickrie/media/tag.rb +4 -0
- data/lib/flickrie/media/ticket.rb +4 -0
- data/lib/flickrie/media/visibility.rb +10 -6
- data/lib/flickrie/media.rb +7 -70
- data/lib/flickrie/media_count.rb +4 -0
- data/lib/flickrie/oauth.rb +5 -3
- data/lib/flickrie/set.rb +5 -21
- data/lib/flickrie/upload_client.rb +4 -2
- data/lib/flickrie/user.rb +4 -1
- data/lib/flickrie/version.rb +1 -1
- data/lib/flickrie/video.rb +0 -13
- data/test/error_test.rb +20 -0
- data/test/instance_test.rb +13 -14
- data/test/license_test.rb +7 -13
- data/test/location_test.rb +11 -2
- data/test/media_count_test.rb +20 -12
- data/test/media_test.rb +319 -311
- data/test/oauth_test.rb +17 -18
- data/test/photo_test.rb +78 -60
- data/test/set_test.rb +72 -63
- data/test/{test.rb → test_helper.rb} +7 -0
- data/test/user_test.rb +43 -34
- data/test/vcr_cassettes/error/code.yml +1165 -0
- data/test/vcr_cassettes/instance/calling_api_methods.yml +182 -0
- data/test/vcr_cassettes/license/get_licenses.yml +73 -0
- data/test/vcr_cassettes/location/square_brackets.yml +85 -0
- data/test/vcr_cassettes/media/delete.yml +1380 -0
- data/test/vcr_cassettes/media/from_contacts.yml +155 -0
- data/test/vcr_cassettes/media/from_set.yml +276 -0
- data/test/vcr_cassettes/media/from_user.yml +275 -0
- data/test/vcr_cassettes/media/get_context.yml +73 -0
- data/test/vcr_cassettes/media/get_info.yml +167 -0
- data/test/vcr_cassettes/media/remove_tag.yml +264 -0
- data/test/vcr_cassettes/media/replace.yml +2252 -0
- data/test/vcr_cassettes/media/search.yml +275 -0
- data/test/vcr_cassettes/media/tags.yml +346 -0
- data/test/vcr_cassettes/media_count/get.yml +135 -0
- data/test/vcr_cassettes/media_count/square_brackets.yml +69 -0
- data/test/vcr_cassettes/oauth/tokens.yml +400 -0
- data/test/vcr_cassettes/photo/asynchronous_upload.yml +1693 -0
- data/test/vcr_cassettes/photo/from_set.yml +273 -0
- data/test/vcr_cassettes/photo/from_user.yml +275 -0
- data/test/vcr_cassettes/photo/get_exif.yml +239 -0
- data/test/vcr_cassettes/photo/get_sizes.yml +147 -0
- data/test/vcr_cassettes/photo/other_api_calls.yml +506 -0
- data/test/vcr_cassettes/photo/search.yml +271 -0
- data/test/vcr_cassettes/photo/square_brackets.yml +85 -0
- data/test/vcr_cassettes/photo/upload.yml +1229 -0
- data/test/vcr_cassettes/set/from_user.yml +477 -0
- data/test/vcr_cassettes/set/get_info.yml +951 -0
- data/test/vcr_cassettes/set/square_brackets.yml +73 -0
- data/test/vcr_cassettes/user/find_by_email_or_username.yml +135 -0
- data/test/vcr_cassettes/user/get_info.yml +151 -0
- data/test/vcr_cassettes/user/square_brackets.yml +77 -0
- data/test/vcr_cassettes/video/get_exif.yml +135 -0
- data/test/vcr_cassettes/video/get_info.yml +86 -0
- data/test/vcr_cassettes/video/get_sizes.yml +151 -0
- data/test/vcr_cassettes/video/other_api_calls.yml +643 -0
- data/test/vcr_cassettes/video/square_brackets.yml +86 -0
- data/test/vcr_cassettes/video/upload.yml +308 -0
- data/test/video_test.rb +66 -53
- metadata +123 -12
data/test/oauth_test.rb
CHANGED
@@ -1,26 +1,25 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'flickrie'
|
3
|
-
|
4
1
|
class OAuthTest < Test::Unit::TestCase
|
5
|
-
def
|
6
|
-
|
7
|
-
|
2
|
+
def test_tokens
|
3
|
+
VCR.use_cassette 'oauth/tokens' do
|
4
|
+
Flickrie.api_key = "foo"
|
5
|
+
Flickrie.shared_secret = "foo"
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
assert_raises(Flickrie::OAuth::Error) do
|
8
|
+
Flickrie::OAuth.get_request_token
|
9
|
+
end
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
Flickrie.api_key = ENV['FLICKR_API_KEY']
|
12
|
+
assert_raises(Flickrie::OAuth::Error) do
|
13
|
+
Flickrie::OAuth.get_request_token
|
14
|
+
end
|
17
15
|
|
18
|
-
|
19
|
-
|
16
|
+
Flickrie.shared_secret = ENV['FLICKR_SHARED_SECRET']
|
17
|
+
assert_nothing_raised { Flickrie::OAuth.get_request_token }
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
data/test/photo_test.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require 'test'
|
3
|
-
|
4
2
|
Flickrie::Photo.instance_eval do
|
5
3
|
def public_new(*args)
|
6
4
|
new(*args)
|
@@ -20,38 +18,52 @@ class PhotoTest < Test::Unit::TestCase
|
|
20
18
|
url_sq url_q url_t url_s url_n url_m url_z url_c url_l url_o]
|
21
19
|
end
|
22
20
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
28
26
|
end
|
29
27
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
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 }
|
33
32
|
|
34
|
-
|
33
|
+
assert_sizes(photo)
|
34
|
+
end
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
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
|
40
44
|
end
|
41
45
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
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?
|
46
54
|
|
47
|
-
|
55
|
+
assert_sizes(photo)
|
56
|
+
end
|
57
|
+
end
|
48
58
|
end
|
49
59
|
|
50
|
-
def
|
51
|
-
|
52
|
-
|
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 }
|
53
64
|
|
54
|
-
|
65
|
+
assert_sizes(photo)
|
66
|
+
end
|
55
67
|
end
|
56
68
|
|
57
69
|
def assert_sizes(photo, options = {})
|
@@ -145,50 +157,56 @@ class PhotoTest < Test::Unit::TestCase
|
|
145
157
|
end
|
146
158
|
end
|
147
159
|
|
148
|
-
def
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
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
|
153
167
|
end
|
154
168
|
|
155
|
-
def
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
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
|
164
180
|
end
|
165
181
|
|
166
|
-
def
|
167
|
-
|
168
|
-
Flickrie.get_photo_exif(@photo_id),
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
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
|
177
193
|
end
|
178
194
|
|
179
195
|
def test_other_api_calls
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
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
|
192
210
|
end
|
193
211
|
end
|
194
212
|
end
|
data/test/set_test.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require 'test'
|
3
2
|
|
4
3
|
Flickrie::Set.instance_eval do
|
5
4
|
def public_new(*args)
|
@@ -13,71 +12,81 @@ class SetTest < Test::Unit::TestCase
|
|
13
12
|
@user_nsid = '67131352@N04'
|
14
13
|
end
|
15
14
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
15
|
+
def test_square_brackets
|
16
|
+
VCR.use_cassette 'set/square_brackets' do
|
17
|
+
set = Flickrie.get_set_info(@set_id)
|
18
|
+
assert_equal @set_id, set['id'].to_i
|
19
|
+
end
|
19
20
|
end
|
20
21
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
22
|
+
def test_get_info
|
23
|
+
VCR.use_cassette 'set/get_info' do
|
24
|
+
[Flickrie.get_set_info(@set_id),
|
25
|
+
Flickrie::Set.public_new('id' => @set_id.to_s).get_info].
|
26
|
+
each do |set|
|
27
|
+
assert_equal @set_id, set.id.to_i
|
28
|
+
assert_equal @user_nsid, set.owner.nsid
|
29
|
+
assert_equal '6946979188', set.primary_media_id
|
30
|
+
assert_equal '25bb44852b', set.secret
|
31
|
+
assert_equal '7049', set.server
|
32
|
+
assert_equal 8, set.farm
|
33
|
+
assert_equal 'Speleologija', set.title
|
34
|
+
assert_equal 'Slike sa škole speleologije Velebit.', set.description
|
35
|
+
|
36
|
+
assert_equal 98, set.media_count
|
37
|
+
assert_equal 97, set.photos_count
|
38
|
+
assert_equal 1, set.videos_count
|
39
|
+
assert_equal 0, set.comments_count
|
40
|
+
assert_equal 0, set.views_count
|
41
|
+
|
42
|
+
assert set.photos.all? { |photo| photo.is_a?(Flickrie::Photo) }
|
43
|
+
assert set.videos.all? { |video| video.is_a?(Flickrie::Video) }
|
44
|
+
assert set.media.find { |media| media.is_a?(Flickrie::Photo) }
|
45
|
+
assert set.media.find { |media| media.is_a?(Flickrie::Video) }
|
46
|
+
|
47
|
+
assert_equal true, set.can_comment?
|
48
|
+
|
49
|
+
assert_instance_of Time, set.created_at
|
50
|
+
assert_instance_of Time, set.updated_at
|
51
|
+
|
52
|
+
refute set.url.empty?
|
53
|
+
end
|
54
|
+
end
|
48
55
|
end
|
49
56
|
|
50
|
-
def
|
51
|
-
set
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
57
|
+
def test_from_user
|
58
|
+
VCR.use_cassette 'set/from_user' do
|
59
|
+
set = Flickrie.sets_from_user(@user_nsid).
|
60
|
+
find { |set| set.id.to_i == @set_id }
|
61
|
+
|
62
|
+
assert_equal @set_id, set.id.to_i
|
63
|
+
assert_equal @user_nsid, set.owner.nsid
|
64
|
+
assert_equal '6946979188', set.primary_media_id
|
65
|
+
assert_equal '25bb44852b', set.secret
|
66
|
+
assert_equal '7049', set.server
|
67
|
+
assert_equal 8, set.farm
|
68
|
+
assert_equal 'Speleologija', set.title
|
69
|
+
assert_equal 'Slike sa škole speleologije Velebit.', set.description
|
70
|
+
|
71
|
+
assert_equal 98, set.media_count
|
72
|
+
assert_equal 97, set.photos_count
|
73
|
+
assert_equal 1, set.videos_count
|
74
|
+
assert_equal 0, set.comments_count
|
75
|
+
assert_equal 0, set.views_count
|
76
|
+
|
77
|
+
assert set.photos.all? { |photo| photo.is_a?(Flickrie::Photo) }
|
78
|
+
assert set.videos.all? { |video| video.is_a?(Flickrie::Video) }
|
79
|
+
assert set.media.find { |media| media.is_a?(Flickrie::Photo) }
|
80
|
+
assert set.media.find { |media| media.is_a?(Flickrie::Video) }
|
81
|
+
|
82
|
+
assert_equal true, set.can_comment?
|
83
|
+
assert_equal false, set.needs_interstitial?
|
84
|
+
assert_equal true, set.visibility_can_see_set?
|
85
|
+
|
86
|
+
assert_instance_of Time, set.created_at
|
87
|
+
assert_instance_of Time, set.updated_at
|
88
|
+
|
89
|
+
refute set.url.empty?
|
90
|
+
end
|
82
91
|
end
|
83
92
|
end
|
@@ -5,3 +5,10 @@ Flickrie.api_key = ENV['FLICKR_API_KEY']
|
|
5
5
|
Flickrie.shared_secret = ENV['FLICKR_SHARED_SECRET']
|
6
6
|
Flickrie.access_token = ENV['FLICKR_ACCESS_TOKEN']
|
7
7
|
Flickrie.access_secret = ENV['FLICKR_ACCESS_SECRET']
|
8
|
+
|
9
|
+
require 'vcr'
|
10
|
+
|
11
|
+
VCR.configure do |c|
|
12
|
+
c.cassette_library_dir = 'test/vcr_cassettes'
|
13
|
+
c.hook_into :webmock
|
14
|
+
end
|
data/test/user_test.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require 'test'
|
3
2
|
|
4
3
|
Flickrie::User.instance_eval do
|
5
4
|
def public_new(*args)
|
@@ -12,50 +11,60 @@ class UserTest < Test::Unit::TestCase
|
|
12
11
|
@user_nsid = '67131352@N04'
|
13
12
|
end
|
14
13
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
14
|
+
def test_square_brackets
|
15
|
+
VCR.use_cassette 'user/square_brackets' do
|
16
|
+
user = Flickrie.get_user_info(@user_nsid)
|
17
|
+
assert_equal user['nsid'], user.nsid
|
18
|
+
end
|
18
19
|
end
|
19
20
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
21
|
+
def test_get_info
|
22
|
+
VCR.use_cassette 'user/get_info' do
|
23
|
+
[Flickrie.get_user_info(@user_nsid),
|
24
|
+
Flickrie::User.public_new('nsid' => @user_nsid).get_info].
|
25
|
+
each do |user|
|
26
|
+
assert_equal @user_nsid, user.id
|
27
|
+
assert_equal @user_nsid, user.nsid
|
28
|
+
assert_equal 'Janko Marohnić', user.username
|
29
|
+
assert_equal 'Janko Marohnić', user.real_name
|
30
|
+
assert_equal 'Zagreb, Croatia', user.location
|
31
|
+
assert_equal 'Sarajevo, Skopje, Warsaw, Zagreb', user.time_zone['label']
|
32
|
+
assert_equal '+01:00', user.time_zone['offset']
|
33
|
+
assert_equal <<-DESCRIPTION.chomp.lstrip, user.description
|
34
|
+
I'm a programmer, and I'm gonna program a badass Ruby library for Flickr.
|
35
|
+
DESCRIPTION
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
37
|
+
refute user.profile_url.empty?
|
38
|
+
refute user.mobile_url.empty?
|
39
|
+
refute user.photos_url.empty?
|
35
40
|
|
36
|
-
|
37
|
-
|
38
|
-
|
41
|
+
assert_equal '5464', user.icon_server
|
42
|
+
assert_equal 6, user.icon_farm
|
43
|
+
refute user.buddy_icon_url.empty?
|
39
44
|
|
40
|
-
|
45
|
+
assert_equal false, user.pro?
|
41
46
|
|
42
|
-
|
43
|
-
|
47
|
+
assert_instance_of Time, user.first_taken
|
48
|
+
assert_instance_of Time, user.first_uploaded
|
44
49
|
|
45
|
-
|
50
|
+
assert_equal 98, user.media_count
|
51
|
+
end
|
52
|
+
end
|
46
53
|
end
|
47
54
|
|
48
|
-
def
|
49
|
-
|
55
|
+
def test_find_by_username_or_email
|
56
|
+
VCR.use_cassette 'user/find_by_email_or_username' do
|
57
|
+
user = Flickrie.find_user_by_username('Janko Marohnić')
|
50
58
|
|
51
|
-
|
52
|
-
|
53
|
-
|
59
|
+
assert_equal @user_nsid, user.id
|
60
|
+
assert_equal @user_nsid, user.nsid
|
61
|
+
assert_equal 'Janko Marohnić', user.username
|
54
62
|
|
55
|
-
|
63
|
+
user = Flickrie.find_user_by_email('janko.marohnic@gmail.com')
|
56
64
|
|
57
|
-
|
58
|
-
|
59
|
-
|
65
|
+
assert_equal @user_nsid, user.id
|
66
|
+
assert_equal @user_nsid, user.nsid
|
67
|
+
assert_equal 'Janko Marohnić', user.username
|
68
|
+
end
|
60
69
|
end
|
61
70
|
end
|