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/lib/flickrie/set.rb
CHANGED
@@ -1,74 +1,90 @@
|
|
1
1
|
module Flickrie
|
2
2
|
class Set
|
3
|
-
# @!parse attr_reader
|
3
|
+
# @!parse attr_reader \
|
4
|
+
# :id, :secret, :server, :farm, :title, :description,
|
5
|
+
# :primary_media_id, :views_count, :comments_count,
|
6
|
+
# :photos_count, :videos_count, :media_count, :owner,
|
7
|
+
# :can_comment?, :needs_interstitial?, :visibility_can_see_set?,
|
8
|
+
# :created_at, :updated_at, :url, :hash
|
9
|
+
|
10
|
+
# @return [String]
|
4
11
|
def id() @info['id'] end
|
5
|
-
#
|
12
|
+
# @return [String]
|
6
13
|
def secret() @info['secret'] end
|
7
|
-
#
|
14
|
+
# @return [String]
|
8
15
|
def server() @info['server'] end
|
9
|
-
#
|
16
|
+
# @return [Fixnum]
|
10
17
|
def farm() @info['farm'] end
|
11
|
-
#
|
18
|
+
# @return [String]
|
12
19
|
def title() @info['title'] end
|
13
|
-
#
|
20
|
+
# @return [String]
|
14
21
|
def description() @info['description'] end
|
15
22
|
|
16
|
-
#
|
23
|
+
# @return [String]
|
17
24
|
def primary_media_id() @info['primary'] end
|
18
25
|
alias primary_photo_id primary_media_id
|
19
26
|
alias primary_video_id primary_media_id
|
20
27
|
|
21
|
-
#
|
28
|
+
# @return [Fixnum]
|
22
29
|
def views_count() Integer(@info['count_views']) rescue nil end
|
23
|
-
#
|
30
|
+
# @return [Fixnum]
|
24
31
|
def comments_count() Integer(@info['count_comments']) rescue nil end
|
25
|
-
#
|
32
|
+
# @return [Fixnum]
|
26
33
|
def photos_count() Integer(@info['count_photos']) rescue nil end
|
27
|
-
#
|
34
|
+
# @return [Fixnum]
|
28
35
|
def videos_count() Integer(@info['count_videos']) rescue nil end
|
29
|
-
#
|
36
|
+
# @return [Fixnum]
|
30
37
|
def media_count
|
31
38
|
photos_count + videos_count rescue nil
|
32
39
|
end
|
33
40
|
|
34
41
|
# @return [Flickrie::User]
|
35
|
-
#
|
36
|
-
# @!parse attr_reader :owner
|
37
42
|
def owner() User.new('nsid' => @info['owner']) if @info['owner'] end
|
38
43
|
|
39
44
|
# Same as calling `Flickrie.photos_from_set(set.id)`.
|
40
|
-
|
45
|
+
#
|
46
|
+
# @return [Array<Flickrie::Photo>]
|
47
|
+
def photos(params = {})
|
48
|
+
Flickrie.photos_from_set(id, params)
|
49
|
+
end
|
41
50
|
# Same as calling `Flickrie.videos_from_set(set.id)`.
|
42
|
-
|
51
|
+
#
|
52
|
+
# @return [Array<Flickrie::Video>]
|
53
|
+
def videos(params = {})
|
54
|
+
Flickrie.videos_from_set(id, params)
|
55
|
+
end
|
43
56
|
# Same as calling `Flickrie.media_from_set(set.id)`.
|
44
|
-
|
57
|
+
#
|
58
|
+
# @return [Array<Flickrie::Photo, Flickrie::Video>]
|
59
|
+
def media(params = {})
|
60
|
+
Flickrie.media_from_set(id, params)
|
61
|
+
end
|
45
62
|
|
46
|
-
#
|
63
|
+
# @return [Boolean]
|
47
64
|
def can_comment?() Integer(@info['can_comment']) == 1 rescue nil end
|
48
65
|
|
49
|
-
# @
|
50
|
-
# @!parse attr_reader :needs_interstitial?
|
66
|
+
# @return [Boolean]
|
51
67
|
def needs_interstitial?() Integer(@info['needs_interstitial']) == 1 rescue nil end
|
52
|
-
#
|
68
|
+
# @return [Boolean]
|
53
69
|
def visibility_can_see_set?() Integer(@info['visibility_can_see_set']) == 1 rescue nil end
|
54
70
|
|
55
|
-
#
|
71
|
+
# @return [Time]
|
56
72
|
def created_at() Time.at(Integer(@info['date_create'])) rescue nil end
|
57
|
-
#
|
73
|
+
# @return [Time]
|
58
74
|
def updated_at() Time.at(Integer(@info['date_update'])) rescue nil end
|
59
75
|
|
60
|
-
#
|
61
|
-
def url
|
62
|
-
"http://www.flickr.com/photos/#{owner.nsid}/sets/#{id}"
|
63
|
-
end
|
76
|
+
# @return [String]
|
77
|
+
def url() "http://www.flickr.com/photos/#{owner.nsid}/sets/#{id}" rescue nil end
|
64
78
|
|
65
79
|
def [](key) @info[key] end
|
66
|
-
#
|
80
|
+
# @return [Hash]
|
67
81
|
def hash() @info end
|
68
82
|
|
69
83
|
# Same as calling `Flickrie.get_set_info(set.id)`
|
70
|
-
|
71
|
-
|
84
|
+
#
|
85
|
+
# @return [self]
|
86
|
+
def get_info(params = {}, info = nil)
|
87
|
+
info ||= Flickrie.client.get_set_info(id, params).body['photoset']
|
72
88
|
@info.update(info)
|
73
89
|
|
74
90
|
# Fixes
|
@@ -85,7 +101,7 @@ module Flickrie
|
|
85
101
|
end
|
86
102
|
|
87
103
|
def self.from_info(info)
|
88
|
-
new.get_info(info)
|
104
|
+
new.get_info({}, info)
|
89
105
|
end
|
90
106
|
|
91
107
|
def self.from_user(info, user_nsid)
|
data/lib/flickrie/ticket.rb
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
module Flickrie
|
2
2
|
class Ticket
|
3
|
-
# @!parse attr_reader
|
3
|
+
# @!parse attr_reader \
|
4
|
+
# :id, :media_id, :complete?, :imported_at, :hash
|
5
|
+
|
6
|
+
# @return [String]
|
4
7
|
def id() @info['id'] end
|
5
|
-
#
|
8
|
+
# @return [String]
|
6
9
|
def media_id() @info['photoid'] end
|
7
10
|
alias photo_id media_id
|
8
11
|
alias video_id media_id
|
9
12
|
|
10
|
-
#
|
13
|
+
# @return [Boolean]
|
11
14
|
def complete?() Integer(@info['complete']) == 1 rescue nil end
|
12
15
|
|
13
|
-
#
|
16
|
+
# @return [Time]
|
14
17
|
def imported_at() Time.at(Integer(@info['imported'])) rescue nil end
|
15
18
|
|
16
19
|
def [](key) @info[key] end
|
17
|
-
#
|
20
|
+
# @return [Hash]
|
18
21
|
def hash() @info end
|
19
22
|
|
20
23
|
private
|
data/lib/flickrie/user.rb
CHANGED
@@ -2,26 +2,32 @@ require 'date'
|
|
2
2
|
|
3
3
|
module Flickrie
|
4
4
|
class User
|
5
|
-
# @!parse attr_reader
|
5
|
+
# @!parse attr_reader \
|
6
|
+
# :id, :nsid, :username, :real_name, :location, :description,
|
7
|
+
# :path_alias, :icon_server, :icon_farm, :buddy_icon_url,
|
8
|
+
# :time_zone, :photos_url, :profile_url, :mobile_url,
|
9
|
+
# :first_taken, :favorited_at, :media_count, :pro?, :hash
|
10
|
+
|
11
|
+
# @return [String]
|
6
12
|
def id() @info['id'] end
|
7
|
-
#
|
13
|
+
# @return [String]
|
8
14
|
def nsid() @info['nsid'] end
|
9
|
-
#
|
15
|
+
# @return [String]
|
10
16
|
def username() @info['username'] end
|
11
|
-
#
|
17
|
+
# @return [String]
|
12
18
|
def real_name() @info['realname'] end
|
13
|
-
#
|
19
|
+
# @return [String]
|
14
20
|
def location() @info['location'] end
|
15
|
-
#
|
21
|
+
# @return [String]
|
16
22
|
def description() @info['description'] end
|
17
|
-
#
|
23
|
+
# @return [String]
|
18
24
|
def path_alias() @info['path_alias'] end
|
19
|
-
#
|
25
|
+
# @return [String]
|
20
26
|
def icon_server() @info['iconserver'] end
|
21
|
-
#
|
27
|
+
# @return [Fixnum]
|
22
28
|
def icon_farm() @info['iconfarm'] end
|
23
29
|
|
24
|
-
#
|
30
|
+
# @return [String]
|
25
31
|
def buddy_icon_url
|
26
32
|
if icon_farm
|
27
33
|
if icon_server.to_i > 0 && (nsid || id)
|
@@ -37,41 +43,77 @@ module Flickrie
|
|
37
43
|
# user.time_zone.offset # => "+01:00"
|
38
44
|
# user.time_zone.label # => "Sarajevo, Skopje, Warsaw, Zagreb"
|
39
45
|
#
|
40
|
-
#
|
46
|
+
# @return [Struct]
|
41
47
|
def time_zone() Struct.new(:label, :offset).new(*@info['timezone'].values) rescue nil end
|
42
48
|
|
43
|
-
#
|
44
|
-
def photos_url() @info['photosurl'] || "http://www.flickr.com/photos/#{nsid || id}" end
|
45
|
-
#
|
46
|
-
def profile_url() @info['profileurl'] || "http://www.flickr.com/people/#{nsid || id}" end
|
47
|
-
#
|
49
|
+
# @return [String]
|
50
|
+
def photos_url() @info['photosurl'] || "http://www.flickr.com/photos/#{nsid || id}" if nsid || id end
|
51
|
+
# @return [String]
|
52
|
+
def profile_url() @info['profileurl'] || "http://www.flickr.com/people/#{nsid || id}" if nsid || id end
|
53
|
+
# @return [String]
|
48
54
|
def mobile_url() @info['mobileurl'] end
|
49
55
|
|
50
|
-
#
|
56
|
+
# @return [Time]
|
51
57
|
def first_taken() DateTime.parse(@info['photos']['firstdatetaken']).to_time rescue nil end
|
52
|
-
#
|
58
|
+
# @return [Time]
|
53
59
|
def first_uploaded() Time.at(Integer(@info['photos']['firstdate'])) rescue nil end
|
54
60
|
|
55
|
-
#
|
61
|
+
# @return [Time]
|
56
62
|
def favorited_at() Time.at(Integer(@info['favedate'])) rescue nil end
|
57
63
|
|
58
|
-
#
|
64
|
+
# @return [Fixnum]
|
59
65
|
def media_count() Integer(@info['photos']['count']) rescue nil end
|
60
66
|
alias photos_count media_count
|
61
67
|
alias videos_count media_count
|
62
68
|
|
63
|
-
#
|
64
|
-
#
|
65
|
-
|
69
|
+
# Same as calling `Flickrie.public_photos_from_user(user.nsid)`.
|
70
|
+
#
|
71
|
+
# @return [Array<Flickrie::Photo>]
|
72
|
+
def public_photos(params = {})
|
73
|
+
Flickrie.public_photos_from_user(nsid || id, params)
|
74
|
+
end
|
75
|
+
# Same as calling `Flickrie.public_videos_from_user(user.nsid)`.
|
76
|
+
#
|
77
|
+
# @return [Array<Flickrie::Video>]
|
78
|
+
def public_videos(params = {})
|
79
|
+
Flickrie.public_videos_from_user(nsid || id, params)
|
80
|
+
end
|
81
|
+
# Same as calling `Flickrie.public_media_from_user(user.nsid)`.
|
82
|
+
#
|
83
|
+
# @return [Array<Flickrie::Photo, Flickrie::Video>]
|
84
|
+
def public_media(params = {})
|
85
|
+
Flickrie.public_media_from_user(nsid || id, params)
|
86
|
+
end
|
66
87
|
|
67
|
-
#
|
88
|
+
# Same as calling `Flickrie.photos_from_user(user.nsid)`.
|
89
|
+
#
|
90
|
+
# @return [Array<Flickrie::Photo>]
|
91
|
+
def photos(params = {})
|
92
|
+
Flickrie.photos_from_user(nsid || id, params)
|
93
|
+
end
|
94
|
+
# Same as calling `Flickrie.videos_from_user(user.nsid)`.
|
95
|
+
#
|
96
|
+
# @return [Array<Flickrie::Video>]
|
97
|
+
def videos(params = {})
|
98
|
+
Flickrie.videos_from_user(nsid || id, params)
|
99
|
+
end
|
100
|
+
# Same as calling `Flickrie.media_from_user(user.nsid)`.
|
101
|
+
#
|
102
|
+
# @return [Array<Flickrie::Photo, Flickrie::Video>]
|
103
|
+
def media(params = {})
|
104
|
+
Flickrie.media_from_user(nsid || id, params)
|
105
|
+
end
|
106
|
+
|
107
|
+
# @return [Boolean]
|
68
108
|
def pro?() Integer(@info['ispro']) == 1 rescue nil end
|
69
109
|
|
70
110
|
def [](key) @info[key] end
|
71
|
-
#
|
111
|
+
# @return [Hash]
|
72
112
|
def hash() @info end
|
73
113
|
|
74
114
|
# The same as calling `Flickrie.get_user_info(user.nsid)`
|
115
|
+
#
|
116
|
+
# @return [self]
|
75
117
|
def get_info(params = {}, info = nil)
|
76
118
|
info ||= Flickrie.client.get_user_info(nsid || id, params).body['person']
|
77
119
|
@info.update(info)
|
data/lib/flickrie/version.rb
CHANGED
data/lib/flickrie/video.rb
CHANGED
@@ -1,30 +1,36 @@
|
|
1
1
|
module Flickrie
|
2
2
|
class Video
|
3
3
|
include Media
|
4
|
+
# @!parse attr_reader \
|
5
|
+
# :ready?, :failed?, :pending?, :duration, :width, :height,
|
6
|
+
# :source_url, :download_url, :mobile_download_url
|
4
7
|
|
5
|
-
#
|
8
|
+
# @return [Boolean]
|
6
9
|
def ready?() Integer(@video['ready']) == 1 rescue nil end
|
7
|
-
#
|
10
|
+
# @return [Boolean]
|
8
11
|
def failed?() Integer(@video['failed']) == 1 rescue nil end
|
9
|
-
#
|
12
|
+
# @return [Boolean]
|
10
13
|
def pending?() Integer(@video['pending']) == 1 rescue nil end
|
11
14
|
|
12
|
-
#
|
15
|
+
# @return [Fixnum]
|
13
16
|
def duration() Integer(@video['duration']) rescue nil end
|
14
17
|
|
15
|
-
#
|
18
|
+
# @return [Fixnum]
|
16
19
|
def width() Integer(@video['width']) rescue nil end
|
17
|
-
#
|
20
|
+
# @return [Fixnum]
|
18
21
|
def height() Integer(@video['height']) rescue nil end
|
19
22
|
|
20
|
-
#
|
23
|
+
# @return [String]
|
21
24
|
def source_url() @video['source_url'] end
|
22
|
-
#
|
25
|
+
# @return [String]
|
23
26
|
def download_url() @video['download_url'] end
|
24
|
-
#
|
27
|
+
# @return [String]
|
25
28
|
def mobile_download_url() @video['mobile_download_url'] end
|
26
29
|
|
27
|
-
# This fetches the {#source\_url}, {#download\_url} and the {#mobile\_download\_url}
|
30
|
+
# This fetches the {#source\_url}, {#download\_url} and the {#mobile\_download\_url}.
|
31
|
+
# Same as calling `Flickrie.get_video_sizes(video.id)`
|
32
|
+
#
|
33
|
+
# @return [self]
|
28
34
|
def get_sizes(params = {}, info = nil)
|
29
35
|
info ||= Flickrie.client.get_media_sizes(id, params).body['sizes']
|
30
36
|
@info['usage'] ||= {}
|
@@ -44,6 +50,8 @@ module Flickrie
|
|
44
50
|
end
|
45
51
|
|
46
52
|
# Same as calling `Flickrie.get_video_info(video.id)`.
|
53
|
+
#
|
54
|
+
# @return [self]
|
47
55
|
def get_info(params = {}, info = nil)
|
48
56
|
super
|
49
57
|
@video = @info['video']
|
@@ -55,7 +63,7 @@ module Flickrie
|
|
55
63
|
|
56
64
|
def initialize(info = {})
|
57
65
|
super
|
58
|
-
@video = {}
|
66
|
+
@video = info['video'] || {}
|
59
67
|
end
|
60
68
|
end
|
61
69
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
RSpec::Matchers.define :correspond_to do |hash_or_value|
|
2
|
+
match { |object| test_recursively(object, hash_or_value) }
|
3
|
+
|
4
|
+
def test_recursively(object, hash_or_value)
|
5
|
+
if hash_or_value.is_a?(Hash)
|
6
|
+
iterate(object, hash_or_value) do |actual, expected|
|
7
|
+
actual.should == expected
|
8
|
+
end
|
9
|
+
else
|
10
|
+
object.should eq(hash_or_value)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def iterate(object, the_rest, &block)
|
15
|
+
the_rest.each do |key, value|
|
16
|
+
if value.is_a?(Hash)
|
17
|
+
iterate(object.send(key), value, &block)
|
18
|
+
else
|
19
|
+
yield [object.send(key), value]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
failure_message_for_should do |actual|
|
25
|
+
"expected: #{expected.first}\n got: #{actual}\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
RSpec::Matchers.define :be_a_number do
|
30
|
+
match { |object| object.instance_of?(Fixnum) }
|
31
|
+
end
|
32
|
+
|
33
|
+
RSpec::Matchers.define :be_a_boolean do
|
34
|
+
match { |object| object == true or object == false }
|
35
|
+
end
|
36
|
+
|
37
|
+
RSpec::Matchers.define :be_a_media do
|
38
|
+
match do |object|
|
39
|
+
object.instance_of?(Flickrie::Photo) \
|
40
|
+
or
|
41
|
+
object.instance_of?(Flickrie::Video)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
RSpec::Matchers.define :be_a_photo do
|
46
|
+
match { |object| object.instance_of?(Flickrie::Photo) }
|
47
|
+
end
|
48
|
+
|
49
|
+
RSpec::Matchers.define :be_a_video do
|
50
|
+
match { |object| object.instance_of?(Flickrie::Video) }
|
51
|
+
end
|
@@ -1,43 +1,124 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Flickrie::ApiMethods do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
context "upload" do
|
5
|
+
it "should upload", :vcr do
|
6
|
+
photo_id = Flickrie.upload(PHOTO_PATH)
|
7
|
+
expect { Flickrie.delete_photo(photo_id) }.to_not raise_error
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should upload asynchronously", :vcr do
|
11
|
+
ticket_id = Flickrie.upload(PHOTO_PATH, :async => 1)
|
12
|
+
ticket = Flickrie.check_upload_tickets(ticket_id).first
|
13
|
+
until ticket.complete?
|
14
|
+
ticket = Flickrie.check_upload_tickets(ticket_id).first
|
15
|
+
end
|
16
|
+
expect { Flickrie.delete_photo(ticket.photo_id) }.to_not raise_error
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should replace", :vcr do
|
20
|
+
begin
|
21
|
+
photo_id = Flickrie.upload(PHOTO_PATH)
|
22
|
+
Flickrie.replace(PHOTO_PATH, photo_id)
|
23
|
+
rescue => error
|
24
|
+
error.message.should == "Not a pro account"
|
25
|
+
ensure
|
26
|
+
Flickrie.delete_photo(photo_id)
|
27
|
+
end
|
28
|
+
end
|
9
29
|
end
|
10
30
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
31
|
+
context "people" do
|
32
|
+
it "should get media from user", :vcr do
|
33
|
+
Flickrie.media_from_user(USER_NSID).first.id.should_not be_nil
|
34
|
+
Flickrie.photos_from_user(USER_NSID).first.id.should_not be_nil
|
35
|
+
Flickrie.videos_from_user(USER_NSID).first.id.should_not be_nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should get public media from user", :vcr do
|
39
|
+
Flickrie.public_media_from_user(USER_NSID).first.id.should_not be_nil
|
40
|
+
Flickrie.public_photos_from_user(USER_NSID).first.id.should_not be_nil
|
41
|
+
Flickrie.public_videos_from_user(USER_NSID).first.id.should_not be_nil
|
42
|
+
end
|
19
43
|
end
|
20
44
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
45
|
+
# Here I test the media/photo/video aliases of the API methods (because I don't test them elsewhere)
|
46
|
+
context "photos" do
|
47
|
+
it "should add and remove tags", :vcr do
|
48
|
+
%w[media photo video].each do |word|
|
49
|
+
id = eval "#{word.upcase}_ID"
|
50
|
+
media = Flickrie.send("get_#{word}_info", id)
|
51
|
+
tags_before_change = media.tags.join(' ')
|
52
|
+
Flickrie.send("add_#{word}_tags", id, "janko")
|
53
|
+
media.get_info
|
54
|
+
media.tags.join(' ').should eq([tags_before_change, "janko"].join(' '))
|
55
|
+
tag_id = media.tags.find { |tag| tag.content == "janko" }.id
|
56
|
+
Flickrie.send("remove_#{word}_tag", tag_id)
|
57
|
+
media.get_info
|
58
|
+
media.tags.join(' ').should eq(tags_before_change)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should get from contacts", :vcr do
|
63
|
+
params = {:include_self => 1, :single_photo => 1}
|
64
|
+
Flickrie.media_from_contacts(params).first.id.should_not be_nil
|
65
|
+
Flickrie.photos_from_contacts(params).first.id.should_not be_nil
|
66
|
+
# Flickrie.videos_from_contacts(params).first.id.should_not be_nil
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should get public from user contacts", :vcr do
|
70
|
+
params = {:include_self => 1, :single_photo => 1}
|
71
|
+
Flickrie.public_media_from_user_contacts(USER_NSID, params).first.id.should_not be_nil
|
72
|
+
Flickrie.public_photos_from_user_contacts(USER_NSID, params).first.id.should_not be_nil
|
73
|
+
# Flickrie.public_videos_from_user_contacts(USER_NSID, params).each { |object| object.should be_a_video }
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should get context", :vcr do
|
77
|
+
Flickrie.get_media_context(MEDIA_ID).count.should_not be_nil
|
78
|
+
Flickrie.get_photo_context(PHOTO_ID).count.should_not be_nil
|
79
|
+
Flickrie.get_photo_context(VIDEO_ID).count.should_not be_nil
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should get counts", :vcr do
|
83
|
+
dates = [DateTime.parse("19th May 2009"), DateTime.parse("19th May 2012")]
|
84
|
+
Flickrie.get_media_counts(:taken_dates => dates.join(',')).first.value.should_not be_nil
|
85
|
+
Flickrie.get_photos_counts(:taken_dates => dates.join(',')).first.value.should_not be_nil
|
86
|
+
Flickrie.get_videos_counts(:taken_dates => dates.join(',')).first.value.should_not be_nil
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should get exif", :vcr do
|
90
|
+
Flickrie.get_photo_exif(PHOTO_ID).exif.should_not be_nil
|
91
|
+
Flickrie.get_video_exif(VIDEO_ID).exif.should_not be_nil
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should get favorites", :vcr do
|
95
|
+
Flickrie.get_photo_favorites(PHOTO_ID).favorites.should_not be_nil
|
96
|
+
Flickrie.get_video_favorites(PHOTO_ID).favorites.should_not be_nil
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should get info", :vcr do
|
100
|
+
Flickrie.get_media_info(MEDIA_ID).id.should_not be_nil
|
101
|
+
Flickrie.get_photo_info(PHOTO_ID).id.should_not be_nil
|
102
|
+
Flickrie.get_video_info(VIDEO_ID).id.should_not be_nil
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should get sizes", :vcr do
|
106
|
+
Flickrie.get_photo_sizes(PHOTO_ID).size.should_not be_nil
|
107
|
+
Flickrie.get_video_sizes(VIDEO_ID).download_url.should_not be_nil
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should search", :vcr do
|
111
|
+
Flickrie.search_media(:user_id => USER_NSID).first.id.should_not be_nil
|
112
|
+
Flickrie.search_photos(:user_id => USER_NSID).first.id.should_not be_nil
|
113
|
+
Flickrie.search_videos(:user_id => USER_NSID).first.id.should_not be_nil
|
29
114
|
end
|
30
115
|
end
|
31
116
|
|
32
|
-
|
33
|
-
media
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
tag_id = media.tags.find { |tag| tag.content == "janko" }.id
|
39
|
-
Flickrie.remove_media_tag(tag_id)
|
40
|
-
media.get_info
|
41
|
-
media.tags.join(' ').should eq(tags_before_change)
|
117
|
+
context "photosets" do
|
118
|
+
it "should get media", :vcr do
|
119
|
+
Flickrie.media_from_set(SET_ID).first.id.should_not be_nil
|
120
|
+
Flickrie.photos_from_set(SET_ID).first.id.should_not be_nil
|
121
|
+
Flickrie.videos_from_set(SET_ID).first.id.should_not be_nil
|
122
|
+
end
|
42
123
|
end
|
43
124
|
end
|
data/spec/flickrie/error_spec.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Flickrie::Error do
|
4
|
-
before(:all) do
|
5
|
-
Flickrie.api_key = nil
|
6
|
-
end
|
7
|
-
|
8
4
|
context "a request was made and failed" do
|
9
5
|
it "should be raised", :vcr do
|
6
|
+
Flickrie.api_key = nil
|
10
7
|
expect { Flickrie.get_licenses }.to raise_error(described_class)
|
11
8
|
expect { Flickrie.upload(PHOTO_PATH) }.to raise_error(described_class)
|
12
9
|
end
|
13
10
|
|
14
11
|
it "should have #code attribute present", :vcr do
|
12
|
+
Flickrie.api_key = nil
|
15
13
|
begin
|
16
14
|
Flickrie.get_licenses
|
17
15
|
rescue => exception
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Flickrie::Instance do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
context "client is already initialized" do
|
5
|
+
it "should be able to call API methods", :vcr do
|
6
|
+
# this is to see if the client and upload_client were reset
|
7
|
+
Flickrie.get_photo_info(PHOTO_ID)
|
8
|
+
id = Flickrie.upload(PHOTO_PATH)
|
9
|
+
Flickrie.delete_photo(id)
|
10
|
+
Flickrie.access_token = Flickrie.access_secret = nil
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
instance.delete_photo(id)
|
12
|
+
instance = Flickrie::Instance.new(ENV['FLICKR_ACCESS_TOKEN'], ENV['FLICKR_ACCESS_SECRET'])
|
13
|
+
user = instance.test_login
|
14
|
+
user.username.should eq(USER_USERNAME)
|
15
|
+
end
|
16
16
|
end
|
17
17
|
end
|