flickrie 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +5 -0
- data/LICENSE +22 -0
- data/README.md +151 -0
- data/Rakefile +18 -0
- data/finished_api_methods.md +84 -0
- data/flickrie.gemspec +20 -0
- data/lib/flickrie/client.rb +103 -0
- data/lib/flickrie/license.rb +38 -0
- data/lib/flickrie/location.rb +62 -0
- data/lib/flickrie/media/note.rb +23 -0
- data/lib/flickrie/media/visibility.rb +14 -0
- data/lib/flickrie/media.rb +254 -0
- data/lib/flickrie/photo.rb +109 -0
- data/lib/flickrie/set.rb +89 -0
- data/lib/flickrie/user.rb +84 -0
- data/lib/flickrie/version.rb +3 -0
- data/lib/flickrie/video.rb +62 -0
- data/lib/flickrie.rb +98 -0
- data/test/client_test.rb +41 -0
- data/test/license_test.rb +30 -0
- data/test/location_test.rb +21 -0
- data/test/media_test.rb +309 -0
- data/test/photo_test.rb +149 -0
- data/test/set_test.rb +85 -0
- data/test/user_test.rb +63 -0
- data/test/video_test.rb +69 -0
- metadata +106 -0
data/lib/flickrie.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'flickrie/client'
|
2
|
+
require 'flickrie/license'
|
3
|
+
require 'flickrie/user'
|
4
|
+
require 'flickrie/media'
|
5
|
+
require 'flickrie/photo'
|
6
|
+
require 'flickrie/video'
|
7
|
+
require 'flickrie/set'
|
8
|
+
|
9
|
+
module Flickrie
|
10
|
+
class << self
|
11
|
+
# people
|
12
|
+
def find_user_by_email(email)
|
13
|
+
response = client.find_user_by_email(email)
|
14
|
+
User.from_find(response.body['user'])
|
15
|
+
end
|
16
|
+
|
17
|
+
def find_user_by_username(username)
|
18
|
+
response = client.find_user_by_username(username)
|
19
|
+
User.from_find(response.body['user'])
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_user_info(user_nsid)
|
23
|
+
response = client.get_user_info(user_nsid)
|
24
|
+
User.from_info(response.body['person'])
|
25
|
+
end
|
26
|
+
|
27
|
+
def public_media_from_user(user_nsid, params = {})
|
28
|
+
response = client.public_media_from_user(user_nsid, params)
|
29
|
+
Media.from_user(response.body['photos'])
|
30
|
+
end
|
31
|
+
def public_photos_from_user(user_nsid, params = {})
|
32
|
+
public_media_from_user(user_nsid, params).select do |media|
|
33
|
+
media.is_a?(Photo)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
def public_videos_from_user(user_nsid, params = {})
|
37
|
+
public_media_from_user(user_nsid, params).select do |media|
|
38
|
+
media.is_a?(Video)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# photos
|
43
|
+
def get_media_info(media_id)
|
44
|
+
response = client.get_media_info(media_id)
|
45
|
+
Media.from_info(response.body['photo'])
|
46
|
+
end
|
47
|
+
alias get_photo_info get_media_info
|
48
|
+
alias get_video_info get_media_info
|
49
|
+
|
50
|
+
def get_photo_sizes(photo_id)
|
51
|
+
response = client.get_media_sizes(photo_id)
|
52
|
+
Photo.from_sizes(response.body['sizes'])
|
53
|
+
end
|
54
|
+
def get_video_sizes(video_id)
|
55
|
+
response = client.get_media_sizes(video_id)
|
56
|
+
Video.from_sizes(response.body['sizes'])
|
57
|
+
end
|
58
|
+
|
59
|
+
def search_media(search_params = {})
|
60
|
+
response = client.search_media(search_params)
|
61
|
+
Media.from_search(response.body['photos'])
|
62
|
+
end
|
63
|
+
def search_photos(search_params = {})
|
64
|
+
search_media(search_params.merge(:media => 'photos'))
|
65
|
+
end
|
66
|
+
def search_videos(search_params = {})
|
67
|
+
search_media(search_params.merge(:media => 'videos'))
|
68
|
+
end
|
69
|
+
|
70
|
+
# licenses
|
71
|
+
def get_licenses
|
72
|
+
response = client.get_licenses
|
73
|
+
License.from_hash(response.body['licenses']['license'])
|
74
|
+
end
|
75
|
+
|
76
|
+
# photosets
|
77
|
+
def get_set_info(set_id)
|
78
|
+
response = client.get_set_info(set_id)
|
79
|
+
Set.from_info(response.body['photoset'])
|
80
|
+
end
|
81
|
+
|
82
|
+
def sets_from_user(user_nsid)
|
83
|
+
response = client.sets_from_user(user_nsid)
|
84
|
+
Set.from_user(response.body['photosets']['photoset'], user_nsid)
|
85
|
+
end
|
86
|
+
|
87
|
+
def media_from_set(set_id, params = {})
|
88
|
+
response = client.media_from_set(set_id, params)
|
89
|
+
Media.from_set(response.body['photoset'])
|
90
|
+
end
|
91
|
+
def photos_from_set(set_id, params = {})
|
92
|
+
media_from_set(set_id, params.merge(:media => 'photos'))
|
93
|
+
end
|
94
|
+
def videos_from_set(set_id, params = {})
|
95
|
+
media_from_set(set_id, params.merge(:media => 'videos'))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/test/client_test.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test/unit'
|
3
|
+
require 'flickrie/client'
|
4
|
+
|
5
|
+
class ClientTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
Flickrie.api_key = ENV['FLICKR_API_KEY']
|
8
|
+
@client = Flickrie.client
|
9
|
+
@set_id = 72157629851991663
|
10
|
+
@media_id = 7093038981
|
11
|
+
@user_nsid = '67131352@N04'
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_internals
|
15
|
+
assert_equal ENV['FLICKR_API_KEY'], Flickrie.api_key
|
16
|
+
assert_instance_of Flickrie::Client, @client
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_api_calls
|
20
|
+
assert_nothing_raised do
|
21
|
+
# people
|
22
|
+
@client.find_user_by_email('janko.marohnic@gmail.com')
|
23
|
+
@client.find_user_by_username('Janko Marohnić')
|
24
|
+
@client.get_user_info(@user_nsid)
|
25
|
+
@client.public_media_from_user(@user_nsid)
|
26
|
+
|
27
|
+
# photos
|
28
|
+
@client.get_media_info(@media_id)
|
29
|
+
@client.get_media_sizes(@media_id)
|
30
|
+
@client.search_media(:user_id => @user_nsid)
|
31
|
+
|
32
|
+
# licenses
|
33
|
+
@client.get_licenses
|
34
|
+
|
35
|
+
# photosets
|
36
|
+
@client.get_set_info(@set_id)
|
37
|
+
@client.sets_from_user(@user_nsid)
|
38
|
+
@client.media_from_set(@set_id)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'flickrie'
|
3
|
+
|
4
|
+
Flickrie::License.instance_eval do
|
5
|
+
def public_response_array
|
6
|
+
response_array
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class LicenseTest < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
Flickrie.api_key = ENV['FLICKR_API_KEY']
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_licenses_staying_the_same
|
16
|
+
licenses_array = Flickrie.client.get_licenses.body['licenses']['license']
|
17
|
+
assert_equal licenses_array.sort_by { |hash| hash['id'] },
|
18
|
+
Flickrie::License.public_response_array
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_get_licenses
|
22
|
+
licenses = Flickrie.get_licenses
|
23
|
+
|
24
|
+
licenses.each do |license|
|
25
|
+
assert_includes ('0'..'8'), license.id
|
26
|
+
assert_instance_of String, license.name
|
27
|
+
assert_instance_of String, license.url
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'flickrie/location'
|
3
|
+
|
4
|
+
class LocationTest < Test::Unit::TestCase
|
5
|
+
def test_attributes_returning_nil
|
6
|
+
location = Flickrie::Location.new
|
7
|
+
|
8
|
+
assert_nil location.latitude
|
9
|
+
assert_nil location.longitude
|
10
|
+
assert_nil location.accuracy
|
11
|
+
assert_nil location.context
|
12
|
+
assert_nil location.place_id
|
13
|
+
assert_nil location.woeid
|
14
|
+
|
15
|
+
assert_nil location.neighbourhood
|
16
|
+
assert_nil location.locality
|
17
|
+
assert_nil location.county
|
18
|
+
assert_nil location.region
|
19
|
+
assert_nil location.country
|
20
|
+
end
|
21
|
+
end
|
data/test/media_test.rb
ADDED
@@ -0,0 +1,309 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test/unit'
|
3
|
+
require 'flickrie'
|
4
|
+
|
5
|
+
Flickrie::Photo.instance_eval do
|
6
|
+
def public_new(*args)
|
7
|
+
new(*args)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class MediaTest < Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
Flickrie.api_key = ENV['FLICKR_API_KEY']
|
14
|
+
@media_id = 6946979188
|
15
|
+
@set_id = 72157629851991663
|
16
|
+
@user_nsid = '67131352@N04'
|
17
|
+
|
18
|
+
# 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
|
19
|
+
@all_extras = %w[license date_upload date_taken owner_name
|
20
|
+
icon_server original_format last_update geo tags machine_tags
|
21
|
+
o_dims views media path_alias
|
22
|
+
url_sq url_q url_t url_s url_n url_m url_z url_c url_l url_o]
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_get_media_info
|
26
|
+
get_info_assertions(Flickrie.get_media_info(@media_id))
|
27
|
+
get_info_assertions(Flickrie::Photo.public_new('id' => @media_id.to_s).get_info)
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_info_assertions(media)
|
31
|
+
assert_equal '6946979188', media.id
|
32
|
+
assert_equal '25bb44852b', media.secret
|
33
|
+
assert_equal '7049', media.server
|
34
|
+
assert_equal 8, media.farm
|
35
|
+
assert_equal 'IMG_0796', media.title
|
36
|
+
assert_equal 'luka', media.tags
|
37
|
+
assert_equal '', media.machine_tags
|
38
|
+
assert_equal 1, media.views_count
|
39
|
+
assert_equal 1, media.comments_count
|
40
|
+
assert_equal '0', media.license.id
|
41
|
+
assert_equal 0, media.safety_level
|
42
|
+
assert_equal 90, media.rotation
|
43
|
+
assert_equal 'Test', media.description
|
44
|
+
assert_not_nil media.url
|
45
|
+
|
46
|
+
# Time
|
47
|
+
assert_instance_of Time, media.uploaded_at
|
48
|
+
assert_instance_of Time, media.updated_at
|
49
|
+
assert_instance_of Time, media.taken_at
|
50
|
+
assert_equal 0, media.taken_at_granularity
|
51
|
+
assert_instance_of Time, media.posted_at
|
52
|
+
|
53
|
+
# Owner
|
54
|
+
assert_equal '67131352@N04', media.owner.nsid
|
55
|
+
assert_equal 'Janko Marohnić', media.owner.username
|
56
|
+
assert_equal 'Janko Marohnić', media.owner.real_name
|
57
|
+
assert_equal 'Zagreb, Croatia', media.owner.location
|
58
|
+
assert_equal '5464', media.owner.icon_server
|
59
|
+
assert_equal 6, media.owner.icon_farm
|
60
|
+
refute media.owner.buddy_icon_url.empty?
|
61
|
+
|
62
|
+
# Predicates
|
63
|
+
assert_equal true, media.visibility.public?
|
64
|
+
assert_equal false, media.visibility.friends?
|
65
|
+
assert_equal false, media.visibility.family?
|
66
|
+
assert_equal nil, media.visibility.contacts?
|
67
|
+
|
68
|
+
assert_equal false, media.can_comment?
|
69
|
+
assert_equal false, media.can_add_meta?
|
70
|
+
assert_equal true, media.can_everyone_comment?
|
71
|
+
assert_equal false, media.can_everyone_add_meta?
|
72
|
+
|
73
|
+
assert_equal true, media.can_download?
|
74
|
+
assert_equal false, media.can_blog?
|
75
|
+
assert_equal false, media.can_print?
|
76
|
+
assert_equal false, media.can_share?
|
77
|
+
|
78
|
+
assert_equal false, media.has_people?
|
79
|
+
|
80
|
+
assert_equal true, media.safe?
|
81
|
+
assert_equal false, media.moderate?
|
82
|
+
assert_equal false, media.restricted?
|
83
|
+
|
84
|
+
assert_equal false, media.favorite?
|
85
|
+
|
86
|
+
assert_equal true, media.geo_permissions.public?
|
87
|
+
assert_equal false, media.geo_permissions.contacts?
|
88
|
+
assert_equal false, media.geo_permissions.friends?
|
89
|
+
assert_equal false, media.geo_permissions.family?
|
90
|
+
|
91
|
+
# Notes
|
92
|
+
note = media.notes.first
|
93
|
+
assert_equal '72157629487842968', note.id
|
94
|
+
assert_equal '67131352@N04', note.author.nsid
|
95
|
+
assert_equal 'Janko Marohnić', note.author.username
|
96
|
+
assert_equal [316, 0], note.coordinates
|
97
|
+
assert_equal [59, 50], [note.width, note.height]
|
98
|
+
assert_equal 'Test', note.content
|
99
|
+
|
100
|
+
# Location
|
101
|
+
location = media.location
|
102
|
+
|
103
|
+
assert_equal 45.807258, location.latitude
|
104
|
+
assert_equal 15.967599, location.longitude
|
105
|
+
assert_equal '11', location.accuracy
|
106
|
+
assert_equal '0', location.context
|
107
|
+
|
108
|
+
assert_equal nil, location.neighbourhood
|
109
|
+
assert_equal 'Zagreb', location.locality.name
|
110
|
+
assert_equal '00j4IylZV7scWik', location.locality.place_id
|
111
|
+
assert_equal '851128', location.locality.woeid
|
112
|
+
assert_equal 'Zagreb', location.county.name
|
113
|
+
assert_equal '306dHrhQV7o6jm.ZUQ', location.county.place_id
|
114
|
+
assert_equal '15022257', location.county.woeid
|
115
|
+
assert_equal 'Grad Zagreb', location.region.name
|
116
|
+
assert_equal 'Js1DU.pTUrpBCIKhVw', location.region.place_id
|
117
|
+
assert_equal '20070170', location.region.woeid
|
118
|
+
assert_equal 'Croatia', location.country.name
|
119
|
+
assert_equal 'FunRCI5TUb6a6soTyw', location.country.place_id
|
120
|
+
assert_equal '23424843', location.country.woeid
|
121
|
+
|
122
|
+
assert_equal '00j4IylZV7scWik', location.place_id
|
123
|
+
assert_equal '851128', location.woeid
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_media_from_set
|
127
|
+
media = Flickrie.media_from_set(@set_id, :extras => @all_extras).
|
128
|
+
find { |media| media.id.to_i == @media_id }
|
129
|
+
|
130
|
+
assert_equal '6946979188', media.id
|
131
|
+
assert_equal '25bb44852b', media.secret
|
132
|
+
assert_equal '7049', media.server
|
133
|
+
assert_equal 8, media.farm
|
134
|
+
assert_equal 'IMG_0796', media.title
|
135
|
+
assert_equal 'luka', media.tags
|
136
|
+
assert_equal '', media.machine_tags
|
137
|
+
assert_equal 1, media.views_count
|
138
|
+
assert_equal '0', media.license.id
|
139
|
+
assert_equal true, media.primary?
|
140
|
+
assert_not_nil media.url
|
141
|
+
assert_equal 'ready', media.media_status
|
142
|
+
|
143
|
+
# Time
|
144
|
+
assert_instance_of Time, media.uploaded_at
|
145
|
+
assert_instance_of Time, media.updated_at
|
146
|
+
assert_instance_of Time, media.taken_at
|
147
|
+
assert_equal 0, media.taken_at_granularity
|
148
|
+
|
149
|
+
# Location
|
150
|
+
assert_equal 45.807258, media.location.latitude
|
151
|
+
assert_equal 15.967599, media.location.longitude
|
152
|
+
assert_equal '11', media.location.accuracy
|
153
|
+
assert_equal '0', media.location.context.to_s
|
154
|
+
assert_equal '00j4IylZV7scWik', media.location.place_id
|
155
|
+
assert_equal '851128', media.location.woeid
|
156
|
+
assert_equal true, media.geo_permissions.public?
|
157
|
+
assert_equal false, media.geo_permissions.contacts?
|
158
|
+
assert_equal false, media.geo_permissions.friends?
|
159
|
+
assert_equal false, media.geo_permissions.family?
|
160
|
+
|
161
|
+
# Owner
|
162
|
+
assert_equal '67131352@N04', media.owner.nsid
|
163
|
+
assert_equal 'Janko Marohnić', media.owner.username
|
164
|
+
assert_equal '5464', media.owner.icon_server
|
165
|
+
assert_equal 6, media.owner.icon_farm
|
166
|
+
refute media.owner.buddy_icon_url.empty?
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_public_media_from_user
|
170
|
+
media = Flickrie.public_media_from_user(@user_nsid, :extras => @all_extras).
|
171
|
+
find { |media| media.id.to_i == @media_id }
|
172
|
+
|
173
|
+
assert_equal '6946979188', media.id
|
174
|
+
assert_equal '25bb44852b', media.secret
|
175
|
+
assert_equal '7049', media.server
|
176
|
+
assert_equal 8, media.farm
|
177
|
+
assert_equal 'IMG_0796', media.title
|
178
|
+
assert_equal 'luka', media.tags
|
179
|
+
assert_equal '', media.machine_tags
|
180
|
+
assert_equal 1, media.views_count
|
181
|
+
assert_equal '0', media.license.id
|
182
|
+
assert_not_nil media.url
|
183
|
+
assert_equal 'ready', media.media_status
|
184
|
+
|
185
|
+
# Time
|
186
|
+
assert_instance_of Time, media.uploaded_at
|
187
|
+
assert_instance_of Time, media.updated_at
|
188
|
+
assert_instance_of Time, media.taken_at
|
189
|
+
assert_equal 0, media.taken_at_granularity
|
190
|
+
|
191
|
+
# Location
|
192
|
+
assert_equal 45.807258, media.location.latitude
|
193
|
+
assert_equal 15.967599, media.location.longitude
|
194
|
+
assert_equal '11', media.location.accuracy
|
195
|
+
assert_equal '0', media.location.context.to_s
|
196
|
+
assert_equal '00j4IylZV7scWik', media.location.place_id
|
197
|
+
assert_equal '851128', media.location.woeid
|
198
|
+
assert_equal true, media.geo_permissions.public?
|
199
|
+
assert_equal false, media.geo_permissions.contacts?
|
200
|
+
assert_equal false, media.geo_permissions.friends?
|
201
|
+
assert_equal false, media.geo_permissions.family?
|
202
|
+
|
203
|
+
# Owner
|
204
|
+
assert_equal '67131352@N04', media.owner.nsid
|
205
|
+
assert_equal 'Janko Marohnić', media.owner.username
|
206
|
+
assert_equal '5464', media.owner.icon_server
|
207
|
+
assert_equal 6, media.owner.icon_farm
|
208
|
+
refute media.owner.buddy_icon_url.empty?
|
209
|
+
|
210
|
+
# Visibility (This is the difference from Flickrie.media_from_set)
|
211
|
+
assert_equal true, media.visibility.public?
|
212
|
+
assert_equal false, media.visibility.friends?
|
213
|
+
assert_equal false, media.visibility.family?
|
214
|
+
assert_equal nil, media.visibility.contacts?
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_search_media
|
218
|
+
media = Flickrie.search_media(:user_id => @user_nsid, :extras => @all_extras).
|
219
|
+
find { |media| media.id.to_i == @media_id }
|
220
|
+
|
221
|
+
assert_equal '6946979188', media.id
|
222
|
+
assert_equal '25bb44852b', media.secret
|
223
|
+
assert_equal '7049', media.server
|
224
|
+
assert_equal 8, media.farm
|
225
|
+
assert_equal 'IMG_0796', media.title
|
226
|
+
assert_equal 'luka', media.tags
|
227
|
+
assert_equal '', media.machine_tags
|
228
|
+
assert_equal 1, media.views_count
|
229
|
+
assert_equal '0', media.license.id
|
230
|
+
assert_not_nil media.url
|
231
|
+
assert_equal 'ready', media.media_status
|
232
|
+
|
233
|
+
# Time
|
234
|
+
assert_instance_of Time, media.uploaded_at
|
235
|
+
assert_instance_of Time, media.updated_at
|
236
|
+
assert_instance_of Time, media.taken_at
|
237
|
+
assert_equal 0, media.taken_at_granularity
|
238
|
+
|
239
|
+
# Location
|
240
|
+
assert_equal 45.807258, media.location.latitude
|
241
|
+
assert_equal 15.967599, media.location.longitude
|
242
|
+
assert_equal '11', media.location.accuracy
|
243
|
+
assert_equal '0', media.location.context.to_s
|
244
|
+
assert_equal '00j4IylZV7scWik', media.location.place_id
|
245
|
+
assert_equal '851128', media.location.woeid
|
246
|
+
assert_equal true, media.geo_permissions.public?
|
247
|
+
assert_equal false, media.geo_permissions.contacts?
|
248
|
+
assert_equal false, media.geo_permissions.friends?
|
249
|
+
assert_equal false, media.geo_permissions.family?
|
250
|
+
|
251
|
+
# Owner
|
252
|
+
assert_equal '67131352@N04', media.owner.nsid
|
253
|
+
assert_equal 'Janko Marohnić', media.owner.username
|
254
|
+
assert_equal '5464', media.owner.icon_server
|
255
|
+
assert_equal 6, media.owner.icon_farm
|
256
|
+
refute media.owner.buddy_icon_url.empty?
|
257
|
+
|
258
|
+
# Visibility (This is the difference from Flickrie.media_from_set)
|
259
|
+
assert_equal true, media.visibility.public?
|
260
|
+
assert_equal false, media.visibility.friends?
|
261
|
+
assert_equal false, media.visibility.family?
|
262
|
+
assert_equal nil, media.visibility.contacts?
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_methods_returning_nil
|
266
|
+
media = Flickrie::Photo.new
|
267
|
+
|
268
|
+
assert_nil media.id
|
269
|
+
assert_nil media.secret
|
270
|
+
assert_nil media.server
|
271
|
+
assert_nil media.farm
|
272
|
+
assert_nil media.title
|
273
|
+
assert_nil media.description
|
274
|
+
assert_nil media.tags
|
275
|
+
assert_nil media.machine_tags
|
276
|
+
assert_nil media.media_status
|
277
|
+
assert_nil media.path_alias
|
278
|
+
assert_nil media.views_count
|
279
|
+
assert_nil media.comments_count
|
280
|
+
assert_nil media.location
|
281
|
+
assert_nil media.geo_permissions
|
282
|
+
assert_nil media.license
|
283
|
+
assert_nil media.posted_at
|
284
|
+
assert_nil media.uploaded_at
|
285
|
+
assert_nil media.updated_at
|
286
|
+
assert_nil media.taken_at
|
287
|
+
assert_nil media.taken_at_granularity
|
288
|
+
assert_nil media.owner
|
289
|
+
assert_nil media.safety_level
|
290
|
+
assert_nil media.safe?
|
291
|
+
assert_nil media.moderate?
|
292
|
+
assert_nil media.restricted?
|
293
|
+
assert_nil media.url
|
294
|
+
assert_nil media.visibility
|
295
|
+
assert_nil media.primary?
|
296
|
+
assert_nil media.favorite?
|
297
|
+
assert_nil media.can_comment?
|
298
|
+
assert_nil media.can_add_meta?
|
299
|
+
assert_nil media.can_everyone_comment?
|
300
|
+
assert_nil media.can_everyone_add_meta?
|
301
|
+
assert_nil media.can_download?
|
302
|
+
assert_nil media.can_blog?
|
303
|
+
assert_nil media.can_print?
|
304
|
+
assert_nil media.can_share?
|
305
|
+
assert_nil media.has_people?
|
306
|
+
assert_nil media.notes
|
307
|
+
assert_nil media.media_status
|
308
|
+
end
|
309
|
+
end
|
data/test/photo_test.rb
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test/unit'
|
3
|
+
require 'flickrie'
|
4
|
+
|
5
|
+
Flickrie::Photo.instance_eval do
|
6
|
+
def public_new(*args)
|
7
|
+
new(*args)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class PhotoTest < Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
Flickrie.api_key = ENV['FLICKR_API_KEY']
|
14
|
+
@photo_id = 6946979188
|
15
|
+
@set_id = 72157629851991663
|
16
|
+
@user_nsid = '67131352@N04'
|
17
|
+
|
18
|
+
# 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
|
19
|
+
@all_extras = %w[license date_upload date_taken owner_name
|
20
|
+
icon_server original_format last_update geo tags machine_tags
|
21
|
+
o_dims views media path_alias
|
22
|
+
url_sq url_q url_t url_s url_n url_m url_z url_c url_l url_o]
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_photos_from_set
|
26
|
+
photo = Flickrie.photos_from_set(@set_id, :extras => @all_extras).
|
27
|
+
find { |photo| photo.id.to_i == @photo_id }
|
28
|
+
|
29
|
+
assert_sizes(photo)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_public_photos_from_user
|
33
|
+
photo = Flickrie.public_photos_from_user(@user_nsid, :extras => @all_extras).
|
34
|
+
find { |photo| photo.id.to_i == @photo_id }
|
35
|
+
|
36
|
+
assert_sizes(photo, :exclude => ['Square 150', 'Small 320', 'Medium 800'])
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_get_photo_sizes
|
40
|
+
get_sizes_assertions(Flickrie.get_photo_sizes(@photo_id))
|
41
|
+
get_sizes_assertions(Flickrie::Photo.public_new('id' => @photo_id.to_s).get_sizes)
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_sizes_assertions(photo)
|
45
|
+
assert_equal true, photo.can_download?
|
46
|
+
assert_equal false, photo.can_blog?
|
47
|
+
assert_equal false, photo.can_print?
|
48
|
+
|
49
|
+
assert_sizes(photo)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_search_photos
|
53
|
+
photo = Flickrie.search_photos(:user_id => @user_nsid, :extras => @all_extras).
|
54
|
+
find { |photo| photo.id.to_i == @photo_id }
|
55
|
+
|
56
|
+
assert_sizes(photo)
|
57
|
+
end
|
58
|
+
|
59
|
+
def assert_sizes(photo, options = {})
|
60
|
+
options[:exclude] ||= []
|
61
|
+
[
|
62
|
+
[[photo.square(75), photo.square75], ['Square 75', '75x75']],
|
63
|
+
[[photo.thumbnail], ['Thumbnail', '75x100']],
|
64
|
+
[[photo.square(150), photo.square150], ['Square 150', '150x150']],
|
65
|
+
[[photo.small(240), photo.small240], ['Small 240', '180x240']],
|
66
|
+
[[photo.small(320), photo.small320], ['Small 320', '240x320']],
|
67
|
+
[[photo.medium(500), photo.medium500], ['Medium 500', '375x500']],
|
68
|
+
[[photo.medium(640), photo.medium640], ['Medium 640', '480x640']],
|
69
|
+
[[photo.medium(800), photo.medium800], ['Medium 800', '600x800']],
|
70
|
+
[[photo.large(1024), photo.large1024], ['Large 1024', '768x1024']]
|
71
|
+
].
|
72
|
+
reject { |_, expected_values| options[:exclude].include?(expected_values.first) }.
|
73
|
+
each do |photos, expected_values|
|
74
|
+
flickr_size, size = expected_values
|
75
|
+
photos.each do |photo|
|
76
|
+
assert_equal flickr_size, photo.size
|
77
|
+
assert_equal size, "#{photo.width}x#{photo.height}", "Non bang versions"
|
78
|
+
refute photo.source_url.empty?
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
[
|
83
|
+
[[proc { photo.square!(75) }, proc { photo.square75! }], ['Square 75', '75x75']],
|
84
|
+
[[proc { photo.thumbnail! }], ['Thumbnail', '75x100']],
|
85
|
+
[[proc { photo.square!(150) }, proc { photo.square150! }], ['Square 150', '150x150']],
|
86
|
+
[[proc { photo.small!(240) }, proc { photo.small240! }], ['Small 240', '180x240']],
|
87
|
+
[[proc { photo.small!(320) }, proc { photo.small320! }], ['Small 320', '240x320']],
|
88
|
+
[[proc { photo.medium!(500) }, proc { photo.medium500! }], ['Medium 500', '375x500']],
|
89
|
+
[[proc { photo.medium!(640) }, proc { photo.medium640! }], ['Medium 640', '480x640']],
|
90
|
+
[[proc { photo.medium!(800) }, proc { photo.medium800! }], ['Medium 800', '600x800']],
|
91
|
+
[[proc { photo.large!(1024) }, proc { photo.large1024! }], ['Large 1024', '768x1024']]
|
92
|
+
].
|
93
|
+
reject { |_, expected_values| options[:exclude].include?(expected_values.first) }.
|
94
|
+
each do |proks, expected_values|
|
95
|
+
flickr_size, size = expected_values
|
96
|
+
proks.each do |prok|
|
97
|
+
prok.call
|
98
|
+
assert_equal flickr_size, photo.size
|
99
|
+
assert_equal size, "#{photo.width}x#{photo.height}", "Bang versions"
|
100
|
+
refute photo.source_url.empty?
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_methods_returning_nil
|
106
|
+
photo = Flickrie::Photo.new
|
107
|
+
|
108
|
+
assert_nil photo.width
|
109
|
+
assert_nil photo.height
|
110
|
+
assert_nil photo.source_url
|
111
|
+
assert_nil photo.rotation
|
112
|
+
assert_equal [], photo.available_sizes
|
113
|
+
assert_equal nil, photo.size
|
114
|
+
|
115
|
+
[
|
116
|
+
photo.square(75), photo.square(150), photo.thumbnail,
|
117
|
+
photo.small(240), photo.small(320), photo.medium(500),
|
118
|
+
photo.medium(640), photo.medium(800), photo.large(1024),
|
119
|
+
photo.original, photo.square75, photo.square150,
|
120
|
+
photo.small240, photo.small320, photo.medium500,
|
121
|
+
photo.medium640, photo.medium800, photo.large1024,
|
122
|
+
photo.largest
|
123
|
+
].
|
124
|
+
each do |photo|
|
125
|
+
assert_nil photo.source_url
|
126
|
+
assert_nil photo.width
|
127
|
+
assert_nil photo.height
|
128
|
+
end
|
129
|
+
|
130
|
+
[
|
131
|
+
proc { photo.square!(75) }, proc { photo.square!(150) },
|
132
|
+
proc { photo.thumbnail! }, proc { photo.small!(240) },
|
133
|
+
proc { photo.small!(320) }, proc { photo.medium!(500) },
|
134
|
+
proc { photo.medium!(640) }, proc { photo.medium!(800) },
|
135
|
+
proc { photo.large!(1024) }, proc { photo.original! },
|
136
|
+
proc { photo.square75! }, proc { photo.square150! },
|
137
|
+
proc { photo.small240! }, proc { photo.small320! },
|
138
|
+
proc { photo.medium500! }, proc { photo.medium640! },
|
139
|
+
proc { photo.medium800! }, proc { photo.large1024! },
|
140
|
+
proc { photo.largest! }
|
141
|
+
].
|
142
|
+
each do |prok|
|
143
|
+
prok.call
|
144
|
+
assert_nil photo.source_url
|
145
|
+
assert_nil photo.width
|
146
|
+
assert_nil photo.height
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|