flickrmocks 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/flickr_mocks/api/api.rb +22 -11
- data/lib/flickr_mocks/api/flickr.rb +10 -5
- data/lib/flickr_mocks/api/options.rb +30 -15
- data/lib/flickr_mocks/api/sanitize.rb +10 -6
- data/lib/flickr_mocks/models/commons_institution.rb +1 -2
- data/lib/flickr_mocks/models/commons_institutions.rb +16 -7
- data/lib/flickr_mocks/models/photo.rb +20 -5
- data/lib/flickr_mocks/models/photo_details.rb +23 -7
- data/lib/flickr_mocks/models/photo_dimensions.rb +21 -5
- data/lib/flickr_mocks/models/photo_search.rb +38 -46
- data/lib/flickr_mocks/models/photo_size.rb +12 -1
- data/lib/flickr_mocks/models/photo_sizes.rb +19 -3
- data/lib/flickr_mocks/models/photos.rb +25 -2
- data/lib/flickr_mocks/stubs.rb +38 -31
- data/lib/flickr_mocks/version.rb +1 -1
- data/spec/api/api_spec.rb +3 -1
- data/spec/models/photo_search_spec.rb +1 -8
- metadata +3 -3
data/lib/flickr_mocks/api/api.rb
CHANGED
@@ -17,6 +17,7 @@ module FlickrMocks
|
|
17
17
|
:tag_mode => 'any',
|
18
18
|
:possible_tag_modes => ['any','all'],
|
19
19
|
:possible_sizes => [:square, :thumbnail, :small, :medium, :medium_640, :large, :original],
|
20
|
+
:usable_licenses => [4,5,6,7]
|
20
21
|
}
|
21
22
|
|
22
23
|
class << self
|
@@ -33,10 +34,13 @@ module FlickrMocks
|
|
33
34
|
# Api.photos(:search_terms => 'france')
|
34
35
|
# Options hash accepts:
|
35
36
|
# :search_terms : string with comma separated list of terms 'france,lyon'
|
36
|
-
# :owner_id :
|
37
|
-
# :per_page : optional string containing the maximum number of photos
|
38
|
-
#
|
39
|
-
# :
|
37
|
+
# :owner_id : optional string containing the id for the owner of the photo.
|
38
|
+
# :per_page : optional string containing the maximum number of photos
|
39
|
+
# returned in a single page. The default value is '200'
|
40
|
+
# :page : optional string containing the page for search results to be
|
41
|
+
# returned. The default is '1'
|
42
|
+
# :tag_mode : optionsl string containing either 'any' or 'all'. Affects the
|
43
|
+
# interpretation of the search terms to the FlickRaw API.
|
40
44
|
def self.photos(options)
|
41
45
|
raise ArgumentError.new("Expecting a Hash argument.") unless options.is_a?(Hash)
|
42
46
|
photos = Api::Flickr.photos(options)
|
@@ -48,7 +52,8 @@ module FlickrMocks
|
|
48
52
|
# Api.photo_details(:photo_id => '1234'
|
49
53
|
# Options hash accepts:
|
50
54
|
# :photo_id : required string that contains the id for the photo
|
51
|
-
# :secret : optional string that contains the flickr secret for photo.
|
55
|
+
# :secret : optional string that contains the flickr secret for photo.
|
56
|
+
# When provided query is slightly faster
|
52
57
|
def self.photo_details(options)
|
53
58
|
raise ArgumentError.new("Expecting a Hash argument.") unless options.is_a?(Hash)
|
54
59
|
photo = Api::Flickr.photo(options)
|
@@ -61,7 +66,8 @@ module FlickrMocks
|
|
61
66
|
# Api.photo(:photo_id => '1234')
|
62
67
|
# Options hash accepts:
|
63
68
|
# :photo_id : required string that contains the id for the photo
|
64
|
-
# :secret : optional string that contains the flickr secret for photo.
|
69
|
+
# :secret : optional string that contains the flickr secret for photo.
|
70
|
+
# When provided query is slightly faster
|
65
71
|
def self.photo(options)
|
66
72
|
raise ArgumentError.new("Expecting a Hash argument") unless options.is_a?(Hash)
|
67
73
|
Models::Photo.new Api::Flickr.photo(options)
|
@@ -72,7 +78,8 @@ module FlickrMocks
|
|
72
78
|
# Api.photo_sizes(:photo_id => '1234')
|
73
79
|
# Options hash accepts:
|
74
80
|
# :photo_id : required string that contains the id for the photo
|
75
|
-
# :secret : optional string that contains the flickr secret for photo.
|
81
|
+
# :secret : optional string that contains the flickr secret for photo.
|
82
|
+
# When provided query is slightly faster
|
76
83
|
def self.photo_sizes(options)
|
77
84
|
raise ArgumentError.new("Expecting a Hash argument") unless options.is_a?(Hash)
|
78
85
|
Models::PhotoSizes.new Api::Flickr.photo_sizes(options)
|
@@ -83,8 +90,10 @@ module FlickrMocks
|
|
83
90
|
# Api.interesting_photos(:date => '2000-01-01'
|
84
91
|
# Options hash accepts:
|
85
92
|
# :date : string with date in the format yyyy-mm-dd
|
86
|
-
# :per_page : optional string containing the maximum number of photos
|
87
|
-
#
|
93
|
+
# :per_page : optional string containing the maximum number of photos
|
94
|
+
# returned in a single page. The default value is '200'
|
95
|
+
# :page : optional string containing the page for search results to be
|
96
|
+
# returned. The default is '1'
|
88
97
|
def self.interesting_photos(options)
|
89
98
|
raise ArgumentError.new("Expecting a Hash argument") unless options.is_a?(Hash)
|
90
99
|
photos = Api::Flickr.interestingness(options)
|
@@ -95,8 +104,10 @@ module FlickrMocks
|
|
95
104
|
# Sample usage:
|
96
105
|
# Api.commons_institutions({})
|
97
106
|
# Options hash accepts:
|
98
|
-
# :per_page : optional string containing the maximum number of photos returned
|
99
|
-
#
|
107
|
+
# :per_page : optional string containing the maximum number of photos returned
|
108
|
+
# in a single page. The default value is '200'
|
109
|
+
# :page : optional string containing the page for search results to be returned.
|
110
|
+
# The default is '1'
|
100
111
|
def self.commons_institutions(options)
|
101
112
|
raise ArgumentError.new("Expecting a Hash argument") unless options.is_a?(Hash)
|
102
113
|
institutions = Api::Flickr.commons_institutions
|
@@ -9,9 +9,12 @@ module FlickrMocks
|
|
9
9
|
# Options hash accepts:
|
10
10
|
# :search_terms : string with comma separated list of terms 'france,lyon'
|
11
11
|
# :owner_id : pptional string containing the id for the owner of the photo.
|
12
|
-
# :per_page : optional string containing the maximum number of photos
|
13
|
-
#
|
14
|
-
# :
|
12
|
+
# :per_page : optional string containing the maximum number of photos
|
13
|
+
# returned in a single page. The default value is '200'
|
14
|
+
# :page : optional string containing the page for search
|
15
|
+
# results to be returned. The default is '1'
|
16
|
+
# :tag_mode : optionsl string containing either 'any' or 'all'.
|
17
|
+
# Affects the interpretation of the search terms to the FlickRaw API.
|
15
18
|
def self.photos(options)
|
16
19
|
flickr.photos.search Api::Options.search(options)
|
17
20
|
end
|
@@ -22,7 +25,8 @@ module FlickrMocks
|
|
22
25
|
#
|
23
26
|
# Options hash accepts:
|
24
27
|
# :photo_id : required string that contains the id for the photo
|
25
|
-
# :secret : optional string that contains the flickr secret for photo.
|
28
|
+
# :secret : optional string that contains the flickr secret for photo.
|
29
|
+
# When provided query is slightly faster
|
26
30
|
def self.photo(options)
|
27
31
|
flickr.photos.getInfo Api::Options.photo(options)
|
28
32
|
end
|
@@ -33,7 +37,8 @@ module FlickrMocks
|
|
33
37
|
#
|
34
38
|
# Options hash accepts:
|
35
39
|
# :photo_id : required string that contains the id for the photo
|
36
|
-
# :secret : optional string that contains the flickr secret for photo.
|
40
|
+
# :secret : optional string that contains the flickr secret for photo.
|
41
|
+
# When provided query is slightly faster
|
37
42
|
def self.photo_sizes(options)
|
38
43
|
flickr.photos.getSizes Api::Options.photo(options)
|
39
44
|
end
|
@@ -8,11 +8,16 @@ module FlickrMocks
|
|
8
8
|
# self.search(:search_terms => 'iran', :tag_mode => 'any')
|
9
9
|
#
|
10
10
|
# Accepted options include:
|
11
|
-
# :search_terms : comma string containing the flickr search tags. Sample
|
12
|
-
#
|
13
|
-
# :
|
14
|
-
#
|
15
|
-
# :
|
11
|
+
# :search_terms : comma string containing the flickr search tags. Sample
|
12
|
+
# string 'lyon,france"
|
13
|
+
# :owner_id : id for the photo. (either :owner_id or :search_terms
|
14
|
+
# must be specified
|
15
|
+
# :per_page : optional string containing the maximum number of items to
|
16
|
+
# return for a given page
|
17
|
+
# :page : optional string containing page number for the results. When
|
18
|
+
# page number is <= 0, it returns 1.
|
19
|
+
# :tag_mode : optional string containing how the tags for :search_terms
|
20
|
+
# should be interpreted. Can be either 'any' or 'all'
|
16
21
|
def self.search(params)
|
17
22
|
return {
|
18
23
|
:tags => Api::Sanitize.tags(params[:search_terms]),
|
@@ -27,14 +32,18 @@ module FlickrMocks
|
|
27
32
|
end
|
28
33
|
|
29
34
|
|
30
|
-
# returns parameter hash that is supplied for a interesting photo search.
|
35
|
+
# returns parameter hash that is supplied for a interesting photo search.
|
36
|
+
# Sample usage:
|
31
37
|
#
|
32
38
|
# self.interesting(:date => '2010-10-10')
|
33
39
|
#
|
34
40
|
# Accepted options include:
|
35
|
-
# :date : string of format 'YYYY-MM-DD'. Photos of this date are retrieved.
|
36
|
-
#
|
37
|
-
# :
|
41
|
+
# :date : string of format 'YYYY-MM-DD'. Photos of this date are retrieved.
|
42
|
+
# If none supplied, yesterday's date is used.
|
43
|
+
# :per_page : optional string containing the maximum number of items to
|
44
|
+
# return for a given page
|
45
|
+
# :page : optional string containing page number for the results. When page
|
46
|
+
# number is <= 0, it returns 1.
|
38
47
|
#
|
39
48
|
def self.interesting(params)
|
40
49
|
return {
|
@@ -51,9 +60,12 @@ module FlickrMocks
|
|
51
60
|
#
|
52
61
|
# Accepted options include:
|
53
62
|
# :photo_id : string containing photo_id of the photo.
|
54
|
-
# :id : string containing photo id of the photo. It is an alias for :photo_id.
|
55
|
-
#
|
56
|
-
# :
|
63
|
+
# :id : string containing photo id of the photo. It is an alias for :photo_id.
|
64
|
+
# If both are present :photo_id takes precedance.
|
65
|
+
# :secret : optional string containing the secret for the photo. If supplied
|
66
|
+
# the query is slightly faster.
|
67
|
+
# :photo_secret : optional string containing the secret for the photo. It
|
68
|
+
# is an alias for :secret. If both supplied, :secret takes precedance.
|
57
69
|
def self.photo(params)
|
58
70
|
{
|
59
71
|
:photo_id => params[:photo_id] || params[:id] || nil,
|
@@ -61,14 +73,17 @@ module FlickrMocks
|
|
61
73
|
}
|
62
74
|
end
|
63
75
|
|
64
|
-
# returns parameter hash used for searching for photos of a given author.
|
76
|
+
# returns parameter hash used for searching for photos of a given author.
|
77
|
+
# Sample usage:
|
65
78
|
#
|
66
79
|
# self.search(:owner_id => '1234')
|
67
80
|
#
|
68
81
|
# Accepted options include:
|
69
82
|
# :owner_id : id for the photo. (either :owner_id or :search_terms must be specified
|
70
|
-
# :per_page : optional string containing the maximum number of items to return
|
71
|
-
#
|
83
|
+
# :per_page : optional string containing the maximum number of items to return
|
84
|
+
# for a given page
|
85
|
+
# :page : optional string containing page number for the results. When
|
86
|
+
# page number is <= 0, it returns 1.
|
72
87
|
def self.author(params)
|
73
88
|
options = Api::Options.search(params)
|
74
89
|
options.delete :tags
|
@@ -3,7 +3,8 @@ module FlickrMocks
|
|
3
3
|
# helper methods that help to clean up user supplied values. Module is
|
4
4
|
# used internally.
|
5
5
|
module Sanitize
|
6
|
-
# returns a lowercase stripped version of the supplied comma separated string.
|
6
|
+
# returns a lowercase stripped version of the supplied comma separated string.
|
7
|
+
# Sample usage:
|
7
8
|
#
|
8
9
|
# Api.sanitize_tags('Shiraz , HeLLo goodbye, wow')
|
9
10
|
# returns 'shiraz,hello goodbye,wow'
|
@@ -18,8 +19,8 @@ module FlickrMocks
|
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
|
-
# returns lowercase stripped version of the supplied string stored in the
|
22
|
-
# supplied hash. Sample usage:
|
22
|
+
# returns lowercase stripped version of the supplied string stored in the
|
23
|
+
# :search_terms key of the supplied hash. Sample usage:
|
23
24
|
#
|
24
25
|
# self.sanitize_tags(:search_terms => 'Shiraz , HeLLo goodbye, wow')
|
25
26
|
# returns 'shiraz,hello goodbye,wow'
|
@@ -62,7 +63,8 @@ module FlickrMocks
|
|
62
63
|
end
|
63
64
|
|
64
65
|
# returns the page number. Ensures that return value is string containing an integer
|
65
|
-
# greater than 0. When nonsensical page supplied, default page '1' is returned.
|
66
|
+
# greater than 0. When nonsensical page supplied, default page '1' is returned.
|
67
|
+
# Sample usage:
|
66
68
|
#
|
67
69
|
# self.page('20')
|
68
70
|
# returns '20'
|
@@ -79,7 +81,8 @@ module FlickrMocks
|
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
82
|
-
# returns the page number contained in the :page key of the supplied hash.
|
84
|
+
# returns the page number contained in the :page key of the supplied hash.
|
85
|
+
# Sample usage:
|
83
86
|
#
|
84
87
|
# self.page(:page => '20')
|
85
88
|
# returns '20'
|
@@ -104,7 +107,8 @@ module FlickrMocks
|
|
104
107
|
end
|
105
108
|
end
|
106
109
|
|
107
|
-
# returns tag_mode contained in the :tag_mode key of the supplied hash.
|
110
|
+
# returns tag_mode contained in the :tag_mode key of the supplied hash.
|
111
|
+
# Sample usage:
|
108
112
|
#
|
109
113
|
# self.tag_mode(:tag_mode => 'any')
|
110
114
|
# returns 'any'
|
@@ -42,8 +42,7 @@ module FlickrMocks
|
|
42
42
|
@delegated_to_object == other.instance_eval('@delegated_to_object')
|
43
43
|
end
|
44
44
|
|
45
|
-
#
|
46
|
-
# will not point to original object.
|
45
|
+
# compares value for internal state rather than object_id
|
47
46
|
def initialize_copy(orig)
|
48
47
|
super
|
49
48
|
@delegated_to_object = @delegated_to_object.clone
|
@@ -6,6 +6,7 @@ module FlickrMocks
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
attr_writer :defaults
|
9
|
+
# returns defaults hash for the class
|
9
10
|
def defaults
|
10
11
|
@defaults ||= FlickrMocks::Models::Helpers.paging_defaults().clone
|
11
12
|
@defaults
|
@@ -28,43 +29,46 @@ module FlickrMocks
|
|
28
29
|
Api::Sanitize.page(options[:current_page] || options[:page])
|
29
30
|
end
|
30
31
|
|
31
|
-
# returns the default value
|
32
|
+
# returns the default value for a given symbol. The recognized defaults are:
|
33
|
+
# :per_page
|
34
|
+
# :current_page
|
35
|
+
# :max_entries
|
32
36
|
def default(value)
|
33
37
|
CommonsInstitutions.defaults[value.to_s.to_sym]
|
34
38
|
end
|
35
39
|
|
40
|
+
# compares value for internal state rather than object_id
|
36
41
|
def ==(other)
|
37
42
|
per_page == other.per_page and
|
38
43
|
current_page == other.current_page and
|
39
44
|
@delegated_to_object == other.instance_eval('@delegated_to_object')
|
40
45
|
end
|
41
46
|
|
42
|
-
|
43
|
-
super
|
44
|
-
@delegated_to_object = @delegated_to_object.clone
|
45
|
-
end
|
46
|
-
|
47
|
+
# returns the list of methods that are delegated by object
|
47
48
|
def delegated_instance_methods
|
48
49
|
FlickrMocks::Models::Helpers.array_accessor_methods
|
49
50
|
end
|
50
51
|
|
52
|
+
# delegates methods that are returned by delegated instance method
|
51
53
|
def method_missing(id,*args,&block)
|
52
54
|
return @delegated_to_object.send(id,*args,&block) if delegated_instance_methods.include?(id)
|
53
55
|
super
|
54
56
|
end
|
55
57
|
|
56
58
|
alias :old_respond_to? :respond_to?
|
59
|
+
# returns true for delegated and regular methods
|
57
60
|
def respond_to?(method,type=false)
|
58
61
|
return true if delegated_instance_methods.include?(method)
|
59
62
|
old_respond_to?(method,type)
|
60
63
|
end
|
61
64
|
|
62
65
|
alias :old_methods :methods
|
66
|
+
# returns delegated methods as well as regular methods
|
63
67
|
def methods
|
64
68
|
delegated_instance_methods + old_methods
|
65
69
|
end
|
66
70
|
|
67
|
-
# custom cloning
|
71
|
+
# custom cloning method that does a deep copy of the object's internal state
|
68
72
|
def initialize_copy(orig)
|
69
73
|
super
|
70
74
|
@delegated_to_object = @delegated_to_object.map do |institution|
|
@@ -72,20 +76,25 @@ module FlickrMocks
|
|
72
76
|
end
|
73
77
|
end
|
74
78
|
|
79
|
+
# returns total number of institutions
|
75
80
|
def total_entries
|
76
81
|
@delegated_to_object.size
|
77
82
|
end
|
78
83
|
|
84
|
+
# returns raw FlickRaw response for a commons institutions query
|
79
85
|
def institutions
|
80
86
|
@delegated_to_object
|
81
87
|
end
|
82
88
|
|
89
|
+
# returns a collection of institutions that can be used directly for WillPaginate.
|
83
90
|
def collection
|
84
91
|
::WillPaginate::Collection.create(current_page, per_page, total_entries) do |obj|
|
85
92
|
start = (current_page-1)*per_page
|
86
93
|
obj.replace(institutions[start, per_page])
|
87
94
|
end
|
88
95
|
end
|
96
|
+
|
97
|
+
|
89
98
|
private
|
90
99
|
def delegated_to_object=(object)
|
91
100
|
raise ArgumentError, "FlickRaw::ResponseList expected" unless object.class == FlickRaw::ResponseList
|
@@ -7,40 +7,47 @@ module FlickrMocks
|
|
7
7
|
@extended_photo = photo.methods.include?(:originalsecret)
|
8
8
|
end
|
9
9
|
|
10
|
-
# Return
|
10
|
+
# Return url for square sized photo
|
11
11
|
def square
|
12
12
|
FlickRaw.url_s self
|
13
13
|
end
|
14
14
|
|
15
|
+
# returns url for original sized photo
|
15
16
|
def original
|
16
17
|
respond_to?(:originalsecret) ? FlickRaw.url_o(self) : nil
|
17
18
|
end
|
18
19
|
|
20
|
+
# returns url for thumbnail sized photo
|
19
21
|
def thumbnail
|
20
22
|
FlickRaw.url_t self
|
21
23
|
end
|
22
24
|
|
25
|
+
# returns url for small sized photo
|
23
26
|
def small
|
24
27
|
FlickRaw.url_m self
|
25
28
|
end
|
26
29
|
|
30
|
+
# returns url for medium sized photo
|
27
31
|
def medium
|
28
32
|
FlickRaw.url self
|
29
33
|
end
|
30
34
|
|
35
|
+
# returns url for large sized photo
|
31
36
|
def large
|
32
37
|
FlickRaw.url_b self
|
33
38
|
end
|
34
39
|
|
40
|
+
# returns url for medium 640 sized photo
|
35
41
|
def medium_640
|
36
42
|
FlickRaw.url_z self
|
37
43
|
end
|
38
44
|
|
45
|
+
# return url for copyright owner of photo
|
39
46
|
def owner_url
|
40
47
|
FlickRaw.url_photopage self
|
41
48
|
end
|
42
49
|
|
43
|
-
|
50
|
+
# returns Flickr id for owner of photo
|
44
51
|
def owner_id
|
45
52
|
case owner
|
46
53
|
when String then owner
|
@@ -50,28 +57,34 @@ module FlickrMocks
|
|
50
57
|
end
|
51
58
|
end
|
52
59
|
|
60
|
+
# returns Flickr id for photo
|
53
61
|
def photo_id
|
54
62
|
id
|
55
63
|
end
|
56
64
|
|
65
|
+
# returns true if photo license can be used for commercial purposes
|
57
66
|
def usable?
|
58
|
-
license.to_i
|
67
|
+
FlickrMocks::Api.default(:usable_licenses).include?(license.to_i)
|
59
68
|
end
|
60
69
|
|
70
|
+
# compares two objects by value rather than object_id
|
61
71
|
def ==(other)
|
62
72
|
@delegated_to_object == other.instance_eval('@delegated_to_object')
|
63
73
|
end
|
64
74
|
|
75
|
+
# compares value for internal state rather than object_id
|
65
76
|
def initialize_copy(orig)
|
66
77
|
super
|
67
78
|
@delegated_to_object = @delegated_to_object.clone
|
68
79
|
end
|
69
|
-
|
80
|
+
|
81
|
+
# returns the list of methods that are delegated by object
|
70
82
|
def delegated_instance_methods
|
71
83
|
@delegated_instance_methods
|
72
84
|
end
|
73
85
|
|
74
|
-
|
86
|
+
# delegates methods that are returned by delegated instance method as well as method
|
87
|
+
# :'method 640'
|
75
88
|
def method_missing(id,*args,&block)
|
76
89
|
return @delegated_to_object.send(id,*args,&block) if delegated_instance_methods.include?(id)
|
77
90
|
return medium_640 if id.to_sym == :'medium 640'
|
@@ -79,6 +92,7 @@ module FlickrMocks
|
|
79
92
|
end
|
80
93
|
|
81
94
|
alias :old_respond_to? :respond_to?
|
95
|
+
# returns true for delegated and regular methods
|
82
96
|
def respond_to?(method,type=false)
|
83
97
|
return true if method.to_sym == :'medium 640'
|
84
98
|
return true if delegated_instance_methods.include?(method)
|
@@ -86,6 +100,7 @@ module FlickrMocks
|
|
86
100
|
end
|
87
101
|
|
88
102
|
alias :old_methods :methods
|
103
|
+
# returns delegated methods as well as regular methods
|
89
104
|
def methods
|
90
105
|
delegated_instance_methods + old_methods
|
91
106
|
end
|
@@ -9,36 +9,49 @@ module FlickrMocks
|
|
9
9
|
raise ArgumentError 'owner id for photo did not match owner id for at least one size' unless valid_owner_for_dimensions?
|
10
10
|
end
|
11
11
|
|
12
|
+
# returns the name of the author for the photo. When owner_name is not available
|
13
|
+
# owner_username is returned.
|
12
14
|
def author
|
13
15
|
owner_name.empty? ? owner_username : owner_name
|
14
16
|
end
|
15
17
|
|
18
|
+
# returns the owner name for the photo.
|
16
19
|
def owner_name
|
17
20
|
self.owner.realname
|
18
21
|
end
|
19
|
-
|
22
|
+
|
23
|
+
# returns the owner username for the photo
|
20
24
|
def owner_username
|
21
25
|
self.owner.username
|
22
26
|
end
|
23
|
-
|
27
|
+
|
28
|
+
# returns the array of PhotoSize objects available for the given photo
|
24
29
|
def dimensions
|
25
30
|
@dimensions
|
26
31
|
end
|
27
32
|
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
|
33
|
+
# returns the list of acceptable sizes for a photo. Not every photo will have
|
34
|
+
# all of these sizes.
|
32
35
|
def possible_sizes
|
33
36
|
FlickrMocks::Models::Helpers.possible_sizes
|
34
37
|
end
|
35
38
|
|
39
|
+
# returns the raw FlicrkRaw response for the photo from flickr
|
40
|
+
def photo
|
41
|
+
@delegated_to_object
|
42
|
+
end
|
43
|
+
|
44
|
+
# compares the complete internal state of two PhotoDetails objects rather than simply
|
45
|
+
# comparing object_id's
|
36
46
|
def ==(other)
|
37
47
|
return false unless other.class == PhotoDetails
|
38
48
|
(dimensions == other.dimensions) && (@delegated_to_object == other.instance_eval('@delegated_to_object'))
|
39
49
|
end
|
40
50
|
|
41
51
|
# metaprogramming methods
|
52
|
+
|
53
|
+
# delegates methods that are returned by delegated instance method. It also
|
54
|
+
# delegates array methods to the @dimensions object
|
42
55
|
def method_missing(id,*args,&block)
|
43
56
|
return dimensions.sizes.send(id,*args,&block) if array_accessor_methods.include?(id)
|
44
57
|
return @delegated_to_object.send(id,*args,&block) if delegated_instance_methods.include?(id)
|
@@ -46,20 +59,23 @@ module FlickrMocks
|
|
46
59
|
end
|
47
60
|
|
48
61
|
alias :old_respond_to? :respond_to?
|
62
|
+
# returns true for delegated and regular methods
|
49
63
|
def respond_to?(method,type=false)
|
50
64
|
delegated_instance_methods.include?(method) || old_respond_to?(method)
|
51
65
|
end
|
52
66
|
|
53
67
|
alias :old_methods :methods
|
68
|
+
# returns delegated methods as well as regular methods
|
54
69
|
def methods
|
55
70
|
delegated_instance_methods + old_methods
|
56
71
|
end
|
57
72
|
|
73
|
+
# returns list of methods that are delegated to other objects
|
58
74
|
def delegated_instance_methods
|
59
75
|
@delegated_to_object.delegated_instance_methods + array_accessor_methods + [:owner_id] + possible_sizes
|
60
76
|
end
|
61
77
|
|
62
|
-
#
|
78
|
+
# compares value for internal state rather than object_id
|
63
79
|
def initialize_copy(orig)
|
64
80
|
super
|
65
81
|
@dimensions = @dimensions.clone
|
@@ -15,29 +15,42 @@ module FlickrMocks
|
|
15
15
|
self.delegated_to_object = data
|
16
16
|
end
|
17
17
|
|
18
|
+
# returns array of symbols for the sizes available for a given photo
|
18
19
|
def available_sizes
|
19
20
|
map do |dimension|
|
20
21
|
dimension.size
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
25
|
+
# returns array of symbols for possible sizes of a given photo. Not every photo
|
26
|
+
# will have all of the returned sizes.
|
27
|
+
def possible_sizes
|
28
|
+
FlickrMocks::Models::Helpers.possible_sizes
|
29
|
+
end
|
30
|
+
|
31
|
+
# returns the array of OpenStruct objects available for the given photo size
|
24
32
|
def dimensions
|
25
33
|
@delegated_to_object
|
26
34
|
end
|
27
35
|
|
36
|
+
# returns a collection of photo sizes that can be used directly for WillPaginate.
|
28
37
|
def collection
|
29
38
|
@collection ||= ::WillPaginate::Collection.create(1, available_sizes.length, available_sizes.length) do |obj|
|
30
39
|
obj.replace(dimensions)
|
31
40
|
end
|
32
41
|
@collection
|
33
42
|
end
|
34
|
-
|
43
|
+
|
44
|
+
# returns a string that encodes the size, width and height for the photo.
|
45
|
+
# Sample string returned would be:
|
46
|
+
# "small:100x200,large:300x500" --> ie small photo, width of 100 and lenght of 200
|
35
47
|
def to_s
|
36
48
|
dimensions.map do |dimension|
|
37
49
|
[dimension.size,[dimension.width,dimension.height].join('x')].join(':')
|
38
50
|
end.join(',')
|
39
51
|
end
|
40
52
|
|
53
|
+
# compares value for internal state rather than object_id
|
41
54
|
def ==(other)
|
42
55
|
return false unless other.class.should == self.class
|
43
56
|
to_s == other.to_s
|
@@ -45,10 +58,13 @@ module FlickrMocks
|
|
45
58
|
|
46
59
|
# metaprogramming methods
|
47
60
|
alias :old_respond_to? :respond_to?
|
61
|
+
|
62
|
+
# returns true for delegated and regular methods
|
48
63
|
def respond_to?(method)
|
49
64
|
valid_size?(method) || delegated_instance_methods.include?(method) || old_respond_to?(method)
|
50
65
|
end
|
51
66
|
|
67
|
+
# delegates methods that are returned by delegated instance method
|
52
68
|
def method_missing(id,*args,&block)
|
53
69
|
return get_size(id,*args,&block) if valid_size?(id)
|
54
70
|
return dimensions.send(id,*args,&block) if delegated_instance_methods.include?(id)
|
@@ -56,15 +72,17 @@ module FlickrMocks
|
|
56
72
|
end
|
57
73
|
|
58
74
|
alias :old_methods :methods
|
75
|
+
# returns delegated methods as well as regular methods
|
59
76
|
def methods
|
60
77
|
available_sizes + delegated_instance_methods + old_methods
|
61
78
|
end
|
62
79
|
|
80
|
+
# returns the list of methods that are delegated by object
|
63
81
|
def delegated_instance_methods
|
64
82
|
Models::Helpers.array_accessor_methods
|
65
83
|
end
|
66
84
|
|
67
|
-
#
|
85
|
+
# compares value for internal state rather than object_id
|
68
86
|
def initialize_copy(other)
|
69
87
|
super
|
70
88
|
@delegated_to_object = @delegated_to_object.map do |object|
|
@@ -72,9 +90,7 @@ module FlickrMocks
|
|
72
90
|
end
|
73
91
|
end
|
74
92
|
|
75
|
-
|
76
|
-
FlickrMocks::Models::Helpers.possible_sizes
|
77
|
-
end
|
93
|
+
|
78
94
|
private
|
79
95
|
def delegated_to_object=(data)
|
80
96
|
raise(ArgumentError, "Invalid #{data} must respond to :to_s") unless data.respond_to?(:to_s)
|
@@ -3,34 +3,38 @@ module FlickrMocks
|
|
3
3
|
class PhotoSearch
|
4
4
|
attr_reader :search_terms,:page,:date
|
5
5
|
|
6
|
-
@defaults = {
|
7
|
-
:page => 1
|
8
|
-
}
|
9
|
-
|
10
6
|
@delegated_instance_methods = [:current_page, :per_page, :total_entries, :capped_entries,:perpage, :capped?,
|
11
7
|
:max_entries, :collection]
|
12
8
|
|
13
9
|
class << self
|
14
|
-
attr_accessor :defaults
|
15
10
|
attr_accessor :delegated_instance_methods
|
16
11
|
end
|
17
12
|
|
18
13
|
def initialize(data,options={})
|
19
14
|
self.delegated_to_object = data
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
@search_terms = extract_search_terms(options)
|
16
|
+
@page = extract_page(options).to_i
|
17
|
+
@date = extract_date(options)
|
23
18
|
end
|
24
19
|
|
25
20
|
|
26
|
-
# returns the string stored in the :search_terms
|
27
|
-
#
|
28
|
-
|
29
|
-
|
21
|
+
# returns the string stored in the :search_terms key for the supplied
|
22
|
+
# options hash.
|
23
|
+
# The string is stripped of non-required spaces and is made to be lower case.
|
24
|
+
# Sample usage:
|
25
|
+
#
|
26
|
+
# extract_search_terms(:search_terms => 'Lyon , France' --> 'lyon,france'
|
27
|
+
def extract_search_terms(options)
|
28
|
+
Api::Sanitize.tags(options[:search_terms])
|
30
29
|
end
|
31
30
|
|
32
|
-
|
33
|
-
|
31
|
+
# returns the date stored in the :date key for the supplied options hash.
|
32
|
+
# Values other than nil and strings of format 'YYYY-MM-DD' will raise an
|
33
|
+
# argument error. Sample usage:
|
34
|
+
#
|
35
|
+
# extract_date(:date => '2010-10-10') --> '2010-10-10'
|
36
|
+
def extract_date(options)
|
37
|
+
date = options[:date]
|
34
38
|
case date
|
35
39
|
when NilClass
|
36
40
|
nil
|
@@ -41,30 +45,34 @@ module FlickrMocks
|
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
44
|
-
|
45
|
-
|
48
|
+
# returns the sanitized version of the value stored in the :page key for the
|
49
|
+
# supplied options hash.
|
50
|
+
def extract_page(options)
|
51
|
+
Api::Sanitize.page(options[:page])
|
46
52
|
end
|
47
53
|
|
48
|
-
# returns the default class instance value corresponding to the supplied key.
|
49
|
-
def default(value)
|
50
|
-
PhotoSearch.defaults[value.to_sym]
|
51
|
-
end
|
52
54
|
|
53
|
-
# returns
|
55
|
+
# returns Photos object that contains information regarding the photos returned
|
56
|
+
# from Flickr
|
54
57
|
def photos
|
55
58
|
@delegated_to_object
|
56
59
|
end
|
57
|
-
|
60
|
+
|
61
|
+
# returns the total number of results available from Flickr for the given photo.
|
62
|
+
# note flickr only returns 4,000 maximum for a given query.
|
58
63
|
def total_results
|
59
64
|
total_entries
|
60
65
|
end
|
61
66
|
|
67
|
+
# returns hash of parameters that were used for performing the query.
|
62
68
|
def url_params
|
63
69
|
{ :search_terms => search_terms,
|
64
|
-
:date => (date.nil? && search_terms.empty?) ? Api::Helpers.date : date
|
70
|
+
:date => (date.nil? && (search_terms.nil? || search_terms.empty?)) ? Api::Helpers.date : date
|
65
71
|
}.keep_if do |k,v| !(v.nil? || v.to_s.empty?) end
|
66
72
|
end
|
67
73
|
|
74
|
+
# compares the complete internal state of two PhotoDetails objects rather than simply
|
75
|
+
# comparing object_id's
|
68
76
|
def ==(other)
|
69
77
|
return false unless other.class == self.class
|
70
78
|
(photos == other.photos) && [:search_terms,:page,:date].inject(true) do |state,method|
|
@@ -73,6 +81,9 @@ module FlickrMocks
|
|
73
81
|
end
|
74
82
|
|
75
83
|
# metaprogramming methods
|
84
|
+
|
85
|
+
# delegates methods that are returned by delegated instance method. It also
|
86
|
+
# delegates array methods to the @dimensions object
|
76
87
|
def method_missing(id,*args,&block)
|
77
88
|
return photos.photos.send(id,*args,&block) if delegated_array_accessor_methods.include?(id)
|
78
89
|
return photos.send(id,*args,&block) if delegated_instance_methods.include?(id)
|
@@ -80,21 +91,24 @@ module FlickrMocks
|
|
80
91
|
end
|
81
92
|
|
82
93
|
alias :old_respond_to? :respond_to?
|
94
|
+
# returns true for delegated and regular methods
|
83
95
|
def respond_to?(method)
|
84
96
|
delegated_instance_methods.include?(method) || old_respond_to?(method)
|
85
97
|
end
|
86
98
|
|
87
99
|
alias :old_methods :methods
|
100
|
+
# returns delegated methods as well as regular methods
|
88
101
|
def methods
|
89
102
|
delegated_instance_methods + old_methods
|
90
103
|
end
|
91
104
|
|
105
|
+
# returns list of methods that are delegated to other objects
|
92
106
|
def delegated_instance_methods
|
93
107
|
PhotoSearch.delegated_instance_methods + delegated_array_accessor_methods
|
94
108
|
end
|
95
109
|
|
96
110
|
|
97
|
-
#
|
111
|
+
# compares value for internal state rather than object_id
|
98
112
|
def initialize_copy(other)
|
99
113
|
super
|
100
114
|
@delegated_to_object = @delegated_to_object.clone
|
@@ -111,28 +125,6 @@ module FlickrMocks
|
|
111
125
|
|
112
126
|
end
|
113
127
|
|
114
|
-
def search_terms=(terms=nil)
|
115
|
-
terms ||= ''
|
116
|
-
raise ArgumentError, "Expecting String but got #{terms.class}" unless terms.is_a?(String)
|
117
|
-
@search_terms = terms
|
118
|
-
end
|
119
|
-
|
120
|
-
def page=(page=nil)
|
121
|
-
page ||= default(:page)
|
122
|
-
raise ArgumentError, "Expecting Fixnum but got #{page.class}" unless page.is_a?(Fixnum) or page.is_a?(String)
|
123
|
-
@page = page.to_i
|
124
|
-
end
|
125
|
-
|
126
|
-
def date=(date=nil)
|
127
|
-
raise ArgumentError, "Expecting String but got #{date.class}" unless date.is_a?(String) or date.nil?
|
128
|
-
begin
|
129
|
-
Chronic.parse(date) unless date.nil?
|
130
|
-
rescue
|
131
|
-
raise ArgumentError, "#{date} string can not be converted to Time object"
|
132
|
-
end
|
133
|
-
@date = date
|
134
|
-
end
|
135
|
-
|
136
128
|
def delegated_array_accessor_methods
|
137
129
|
FlickrMocks::Models::Helpers.array_accessor_methods
|
138
130
|
end
|
@@ -5,44 +5,55 @@ module FlickrMocks
|
|
5
5
|
self.delegated_to_object= object
|
6
6
|
end
|
7
7
|
|
8
|
+
# returns the string that contains the photo's size
|
8
9
|
def size
|
9
10
|
label.to_s.downcase.sub(/\s+/,'_')
|
10
11
|
end
|
11
12
|
|
13
|
+
# returns the flickr id for the given photo
|
12
14
|
def id
|
13
15
|
source.split('/')[-1].split('_')[0]
|
14
16
|
end
|
15
17
|
|
18
|
+
# returns the flickr secret for the given photo
|
16
19
|
def secret
|
17
20
|
source.split('/')[-1].split('_')[1]
|
18
21
|
end
|
19
22
|
|
23
|
+
# compares the complete internal state of two PhotoDetails objects rather than simply
|
24
|
+
# comparing object_id's
|
20
25
|
def ==(other)
|
21
26
|
@delegated_to_object == other.instance_eval('@delegated_to_object')
|
22
27
|
end
|
23
28
|
|
24
29
|
# metaprogramming methods
|
30
|
+
|
31
|
+
# returns list of methods that are delegated to other objects
|
25
32
|
def delegated_instance_methods
|
26
33
|
@delegated_to_object.methods(false).push(:flickr_type)
|
27
34
|
end
|
28
35
|
|
36
|
+
# delegates methods that are returned by delegated instance method. It also
|
37
|
+
# delegates array methods to the @dimensions object
|
29
38
|
def method_missing(id,*args,&block)
|
30
39
|
return @delegated_to_object.send(id,*args,&block) if delegated_instance_methods.include?(id)
|
31
40
|
super
|
32
41
|
end
|
33
42
|
|
34
43
|
alias :old_respond_to? :respond_to?
|
44
|
+
# returns true for delegated and regular methods
|
35
45
|
def respond_to?(method,type=false)
|
36
46
|
return true if delegated_instance_methods.include?(method)
|
37
47
|
old_respond_to?(method,type)
|
38
48
|
end
|
39
49
|
|
40
50
|
alias :old_methods :methods
|
51
|
+
# returns delegated methods as well as regular methods
|
41
52
|
def methods
|
42
53
|
delegated_instance_methods + old_methods
|
43
54
|
end
|
44
55
|
|
45
|
-
#
|
56
|
+
# compares value for internal state rather than object_id
|
46
57
|
def initialize_copy(orig)
|
47
58
|
super
|
48
59
|
@delegated_to_object = @delegated_to_object.clone
|
@@ -5,18 +5,22 @@ module FlickrMocks
|
|
5
5
|
self.delegated_to_object= object
|
6
6
|
end
|
7
7
|
|
8
|
+
# returns the flickr id for the stored photo
|
8
9
|
def id
|
9
10
|
@delegated_to_object.first.id
|
10
11
|
end
|
11
12
|
|
13
|
+
# returns the flickr secret for the stored photo
|
12
14
|
def secret
|
13
15
|
@delegated_to_object.first.secret
|
14
16
|
end
|
15
17
|
|
18
|
+
# returns array of PhotoSize objects available for the given photo
|
16
19
|
def sizes
|
17
20
|
@delegated_to_object
|
18
21
|
end
|
19
22
|
|
23
|
+
# returns an array of symbols for the available sizes for the given photo
|
20
24
|
def available_sizes
|
21
25
|
@available_sizes ||= sizes.map do |size|
|
22
26
|
size.size.to_sym
|
@@ -24,6 +28,7 @@ module FlickrMocks
|
|
24
28
|
@available_sizes
|
25
29
|
end
|
26
30
|
|
31
|
+
# returns a collection of sizes that can be used directly for WillPaginate.
|
27
32
|
def collection
|
28
33
|
@collection ||= ::WillPaginate::Collection.create(1, sizes.length, sizes.length) do |obj|
|
29
34
|
obj.replace(sizes)
|
@@ -31,28 +36,38 @@ module FlickrMocks
|
|
31
36
|
@collection
|
32
37
|
end
|
33
38
|
|
34
|
-
|
39
|
+
# returns a string that encodes the name, width and height for all dimensions
|
40
|
+
# available for the photo. Sample return string is:
|
41
|
+
#
|
42
|
+
# "square:75x75,thumbnail:67x100,small:161x240,medium:335x500"
|
35
43
|
def to_s
|
36
44
|
PhotoDimensions.new(@delegated_to_object.map do |size|
|
37
45
|
"#{size.size}:#{size.width}x#{size.height}"
|
38
46
|
end.join(',')).to_s
|
39
47
|
end
|
40
48
|
|
49
|
+
# compares the complete internal state of two PhotoDetails objects rather than simply
|
50
|
+
# comparing object_id's
|
41
51
|
def ==(other)
|
42
52
|
return false unless self.class == other.class
|
43
53
|
@delegated_to_object == other.instance_eval('@delegated_to_object')
|
44
54
|
end
|
45
55
|
|
56
|
+
# returns an array that contains the symbol names for the possible sizes
|
57
|
+
# that a photo can have. Please note that not all sizes are available for
|
58
|
+
# every photo.
|
46
59
|
def possible_sizes
|
47
60
|
Models::Helpers.possible_sizes
|
48
61
|
end
|
49
62
|
|
50
63
|
# metaprogramming methods
|
51
64
|
alias :old_methods :methods
|
65
|
+
# returns delegated methods as well as regular methods
|
52
66
|
def methods
|
53
67
|
delegated_instance_methods + old_methods
|
54
68
|
end
|
55
69
|
|
70
|
+
# delegates methods that are returned by delegated instance method.
|
56
71
|
def method_missing(id,*args,&block)
|
57
72
|
return @delegated_to_object.send(id,*args,&block) if delegated_instance_methods.include?(id)
|
58
73
|
return nil if possible_sizes.include?(name)
|
@@ -60,15 +75,17 @@ module FlickrMocks
|
|
60
75
|
end
|
61
76
|
|
62
77
|
alias :old_respond_to? :respond_to?
|
78
|
+
# returns true for delegated and regular methods
|
63
79
|
def respond_to?(method)
|
64
80
|
old_respond_to?(method) || delegated_instance_methods.include?(method)
|
65
81
|
end
|
66
82
|
|
83
|
+
# returns true for delegated and regular methods
|
67
84
|
def delegated_instance_methods
|
68
85
|
possible_sizes + FlickrMocks::Models::Helpers.array_accessor_methods
|
69
86
|
end
|
70
87
|
|
71
|
-
#
|
88
|
+
# compares value for internal state rather than object_id
|
72
89
|
def initialize_copy(orig)
|
73
90
|
super
|
74
91
|
@delegated_to_object = @delegated_to_object.map do |data|
|
@@ -76,7 +93,6 @@ module FlickrMocks
|
|
76
93
|
end
|
77
94
|
end
|
78
95
|
|
79
|
-
|
80
96
|
private
|
81
97
|
|
82
98
|
def delegated_to_object=(data)
|
@@ -8,6 +8,12 @@ module FlickrMocks
|
|
8
8
|
|
9
9
|
class << self
|
10
10
|
attr_writer :defaults
|
11
|
+
# returns a hash that contains the class defaults. The recognized
|
12
|
+
# default values include:
|
13
|
+
#
|
14
|
+
# :max_entries
|
15
|
+
# :per_page
|
16
|
+
# :current_page
|
11
17
|
def defaults
|
12
18
|
@defaults ||= FlickrMocks::Models::Helpers.paging_defaults().clone
|
13
19
|
@defaults
|
@@ -23,31 +29,42 @@ module FlickrMocks
|
|
23
29
|
self.photos = data.photo
|
24
30
|
end
|
25
31
|
|
32
|
+
# returns the default class value for the supplied symbol.
|
26
33
|
def default(value)
|
27
34
|
Photos.defaults[value.to_s.to_sym]
|
28
35
|
end
|
29
36
|
|
37
|
+
# returns the total number of entries that were returned from Flickr. Flickr
|
38
|
+
# caps the total number of returned photos to 4,000.
|
30
39
|
def capped_entries
|
31
40
|
total_entries > max_entries ? max_entries : total_entries
|
32
41
|
end
|
33
42
|
|
43
|
+
# returns true when the number of photos returned by Flickr is less than the total
|
44
|
+
# number of photos available on Flickr for the given results.
|
34
45
|
def capped?
|
35
46
|
max_entries < total_entries ? true : false
|
36
47
|
end
|
37
48
|
|
49
|
+
# returns 4,000, the default maximum number of entries returned by Flickr for
|
50
|
+
# any given query.
|
38
51
|
def max_entries
|
39
52
|
default(:max_entries)
|
40
53
|
end
|
41
54
|
|
55
|
+
# returns the number of pages that can be retrieved from Flickr for the given
|
56
|
+
# query.
|
42
57
|
def pages
|
43
58
|
max_pages = default(:max_entries)/perpage
|
44
59
|
total_pages > max_pages ? max_pages : total_pages
|
45
60
|
end
|
46
61
|
|
62
|
+
# returns only the photos with a license that can be used for commercial purposes
|
47
63
|
def usable_photos
|
48
64
|
photos.clone.keep_if(&:usable?)
|
49
65
|
end
|
50
66
|
|
67
|
+
# returns a collection of photos that can be used directly with WillPaginate.
|
51
68
|
def collection(usable=nil)
|
52
69
|
case usable
|
53
70
|
when true
|
@@ -62,7 +79,8 @@ module FlickrMocks
|
|
62
79
|
end
|
63
80
|
end
|
64
81
|
|
65
|
-
|
82
|
+
# compares the complete internal state of two PhotoDetails objects rather than simply
|
83
|
+
# comparing object_ids
|
66
84
|
def ==(other)
|
67
85
|
return false unless other.class == Photos
|
68
86
|
return false unless [:current_page,:per_page,:total_entries,:total_pages].inject(true) do |state,method|
|
@@ -73,26 +91,31 @@ module FlickrMocks
|
|
73
91
|
|
74
92
|
|
75
93
|
# metaprogramming methods
|
94
|
+
|
95
|
+
# delegates methods that are returned by delegated instance method.
|
76
96
|
def method_missing(id,*args,&block)
|
77
97
|
return photos.send(id,*args,&block) if delegated_instance_methods.include?(id)
|
78
98
|
super
|
79
99
|
end
|
80
100
|
|
81
101
|
alias :old_respond_to? :respond_to?
|
102
|
+
# returns true for delegated and regular methods
|
82
103
|
def respond_to?(method)
|
83
104
|
old_respond_to?(method) || delegated_instance_methods.include?(method)
|
84
105
|
end
|
85
106
|
|
86
107
|
alias :old_methods :methods
|
108
|
+
# returns delegated methods as well as regular methods
|
87
109
|
def methods
|
88
110
|
delegated_instance_methods + old_methods
|
89
111
|
end
|
90
112
|
|
113
|
+
# returns true for delegated and regular methods
|
91
114
|
def delegated_instance_methods
|
92
115
|
FlickrMocks::Models::Helpers.array_accessor_methods
|
93
116
|
end
|
94
117
|
|
95
|
-
#
|
118
|
+
# compares value for internal state rather than object_id
|
96
119
|
def initialize_copy(orig)
|
97
120
|
super
|
98
121
|
@photos = @photos.map do |photo|
|
data/lib/flickr_mocks/stubs.rb
CHANGED
@@ -13,7 +13,6 @@ module FlickrMocks
|
|
13
13
|
# Api.interesting_photos
|
14
14
|
# Api.commons_institutions
|
15
15
|
def self.all
|
16
|
-
# [:VERSION, :Stubs, :Helpers, :Fixtures, :Models, :Api, :CustomClone, :CustomCompare, :CustomMarshal]
|
17
16
|
[:photos,:photo_details,:photo,:photo_sizes,
|
18
17
|
:interesting_photos,:commons_institutions].each do |method|
|
19
18
|
self.send(method)
|
@@ -26,11 +25,14 @@ module FlickrMocks
|
|
26
25
|
# The return value for Api.photos hash depends on the
|
27
26
|
# the options hash:
|
28
27
|
#
|
29
|
-
# :search_terms => 'garbage'
|
30
|
-
# :owner_id => 'garbage'
|
31
|
-
# :owner_id => '<valid_id>'
|
32
|
-
#
|
33
|
-
# :search_terms =>
|
28
|
+
# :search_terms => 'garbage' --> returns empy list of photos
|
29
|
+
# :owner_id => 'garbage' --> returns empty list of photos
|
30
|
+
# :owner_id => '<valid_id>' --> returns list of photos that contain same author photos;
|
31
|
+
# valid_id is any string other than garbage
|
32
|
+
# :search_terms => '<valid_tag>' --> returns list of photos with different author photos
|
33
|
+
# only if :owner_id nil); valid_tag is any
|
34
|
+
# string other than 'garbage'
|
35
|
+
# (:search_terms && :owner_id) => nil --> raises FlickRaw::FailedResponse error
|
34
36
|
def self.photos
|
35
37
|
lambda {::FlickrMocks::Api.stub(:photos) do |params|
|
36
38
|
::FlickrMocks::Stubs::Flickr.search
|
@@ -48,9 +50,10 @@ module FlickrMocks
|
|
48
50
|
# The return value for Api.photo_details stub depends on the
|
49
51
|
# state of the supplied options hash:
|
50
52
|
#
|
51
|
-
# :photo_id
|
52
|
-
# :photo_id
|
53
|
-
# :photo_id
|
53
|
+
# (:photo_id || :id) => 'garbage' --> raises FlickRaw::FailedResponse error
|
54
|
+
# (:photo_id || :id) => nil --> raises FlickRaw::FailedResponse error
|
55
|
+
# (:photo_id || :id) => <valid_id> --> returns a photo fixture with detailed information;
|
56
|
+
# valid_id can be any string other than 'garbage'
|
54
57
|
def self.photo_details
|
55
58
|
lambda {::FlickrMocks::Api.stub(:photo_details) do |params|
|
56
59
|
::FlickrMocks::Stubs::Flickr.getInfo
|
@@ -69,9 +72,10 @@ module FlickrMocks
|
|
69
72
|
# The stub returns an object of class Models::Photo. The return value for the Api.photo
|
70
73
|
# stub depends on the supplied options:
|
71
74
|
#
|
72
|
-
# :photo_id
|
73
|
-
# :photo_id
|
74
|
-
# :photo_id
|
75
|
+
# (:photo_id || :id) => 'garbage' --> raises Invaid ID error
|
76
|
+
# (:photo_id || :id) => nil --> raises invalid ID error
|
77
|
+
# (:photo_id || :id) => <valid_id> --> returns a photo fixture with detailed information;
|
78
|
+
# valid_id is any string other than 'garbage'
|
75
79
|
def self.photo
|
76
80
|
lambda{::FlickrMocks::Api.stub(:photo) do |params|
|
77
81
|
::FlickrMocks::Stubs::Flickr.getInfo
|
@@ -88,9 +92,10 @@ module FlickrMocks
|
|
88
92
|
# The stub returns an object of class Models::PhotoSizes.
|
89
93
|
# The return value of Api.photo_sizes stub depends on the supplied options:
|
90
94
|
#
|
91
|
-
# :photo_id
|
92
|
-
# :photo_id
|
93
|
-
# :photo_id
|
95
|
+
# (:photo_id || :id) => 'garbage' --> raises FlickRaw::FailedResponse error
|
96
|
+
# (:photo_id || :id) => nil --> raises FlickRaw::FailedResponse error
|
97
|
+
# (:photo_id || :id) => <valid_id> --> returns list of photo sizes; valid_id is
|
98
|
+
# any string other than 'garbage'
|
94
99
|
def self.photo_sizes
|
95
100
|
lambda {::FlickrMocks::Api.stub(:photo_sizes) do |params|
|
96
101
|
::FlickrMocks::Stubs::Flickr.getSizes
|
@@ -108,9 +113,10 @@ module FlickrMocks
|
|
108
113
|
# The return value for Api.interesting_photos stub depends on the supplied
|
109
114
|
# options hash:
|
110
115
|
#
|
111
|
-
# :date => '2000-01-01'
|
112
|
-
# :date => 'garbage'
|
113
|
-
# :date => <valid_id>
|
116
|
+
# :date => '2000-01-01' --> returns empty list of photos
|
117
|
+
# :date => 'garbage' --> raises an error
|
118
|
+
# :date => <valid_id> --> returns interesting list of photos; date is any string
|
119
|
+
# other than 'garbage' and '2001-01-01'
|
114
120
|
def self.interesting_photos
|
115
121
|
lambda {::FlickrMocks::Api.stub(:interesting_photos) do |params|
|
116
122
|
::FlickrMocks::Stubs::Flickr.interestingness
|
@@ -157,10 +163,11 @@ module FlickrMocks
|
|
157
163
|
# are stubbed. The return value for the flickr.photos.search depends on
|
158
164
|
# the supplied options hash:
|
159
165
|
#
|
160
|
-
# :tags => 'garbage'
|
161
|
-
# :user_id => 'garbage'
|
162
|
-
# :user_id => '<valid_id>'
|
163
|
-
# :tags => '<valid_tag>'
|
166
|
+
# :tags => 'garbage' --> returns empy list of photos
|
167
|
+
# :user_id => 'garbage' --> returns empty list of photos
|
168
|
+
# :user_id => '<valid_id>' --> returns list of photos that contain same author photos
|
169
|
+
# :tags => '<valid_tag>' --> returns list of photos with different author photos
|
170
|
+
# only if valid author id is not provided
|
164
171
|
def self.search
|
165
172
|
fixtures = Fixtures.instance
|
166
173
|
lambda { flickr.photos.stub(:search) do |params|
|
@@ -189,9 +196,9 @@ module FlickrMocks
|
|
189
196
|
# are stubbed. The return value for the flickr.photos.getInfo stub depends on
|
190
197
|
# the supplied options hash:
|
191
198
|
#
|
192
|
-
# :photo_id => 'garbage'
|
193
|
-
# :photo_id => nil
|
194
|
-
# :photo_id => <valid_id>
|
199
|
+
# :photo_id => 'garbage' --> raises Invaid ID error
|
200
|
+
# :photo_id => nil --> raises invalid ID error
|
201
|
+
# :photo_id => <valid_id> --> returns a photo fixture with detailed information
|
195
202
|
def self.getInfo
|
196
203
|
lambda {
|
197
204
|
flickr.photos.stub(:getInfo) do |params|
|
@@ -218,9 +225,9 @@ module FlickrMocks
|
|
218
225
|
# are stubbed. The return value for the flickr.photos.getSizes stub depends
|
219
226
|
# on the supplied options hash:
|
220
227
|
#
|
221
|
-
# :photo_id => nil
|
222
|
-
# :photo_id => 'garbage'
|
223
|
-
# :photo_id => '<valid_id>'
|
228
|
+
# :photo_id => nil --> raises FlickRaw::FailedResponse error)
|
229
|
+
# :photo_id => 'garbage' --> raises FlickRaw::FailedResponse error)
|
230
|
+
# :photo_id => '<valid_id>' --> returns a list of photo sizes)
|
224
231
|
def self.getSizes
|
225
232
|
lambda {
|
226
233
|
flickr.photos.stub(:getSizes) do |params|
|
@@ -247,9 +254,9 @@ module FlickrMocks
|
|
247
254
|
# are stubbed. The return value for the flickr.interesting.getList stub depends
|
248
255
|
# on the supplied options hash.
|
249
256
|
#
|
250
|
-
# :date => '2000-01-01'
|
251
|
-
# :date => 'garbage'
|
252
|
-
# :date => <valid_id>
|
257
|
+
# :date => '2000-01-01' --> returns empy list of photos
|
258
|
+
# :date => 'garbage' --> raises an error
|
259
|
+
# :date => <valid_id> --> returns interesting list of photos
|
253
260
|
def self.interestingness
|
254
261
|
lambda {
|
255
262
|
flickr.interestingness.stub(:getList) do |params|
|
data/lib/flickr_mocks/version.rb
CHANGED
data/spec/api/api_spec.rb
CHANGED
@@ -24,7 +24,9 @@ describe APP::Api do
|
|
24
24
|
it "returns has with expected set of keys" do
|
25
25
|
klass.defaults.keys.sort.should == [:page,:per_page,:license,:media,
|
26
26
|
:max_entries,:extras,:tag_mode,
|
27
|
-
:possible_sizes,:possible_tag_modes
|
27
|
+
:possible_sizes,:possible_tag_modes,
|
28
|
+
:usable_licenses
|
29
|
+
].sort
|
28
30
|
|
29
31
|
|
30
32
|
end
|
@@ -10,13 +10,6 @@ describe APP::Models::PhotoSearch do
|
|
10
10
|
subject { klass.new fixtures.photos,options }
|
11
11
|
|
12
12
|
context "class instance variables" do
|
13
|
-
specify {klass.should respond_to(:defaults)}
|
14
|
-
context "defaults" do
|
15
|
-
it "returns expected set of defaults" do
|
16
|
-
klass.defaults.should == {:page => 1}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
13
|
specify {klass.should respond_to(:delegated_instance_methods)}
|
21
14
|
it "returns expected set of methods" do
|
22
15
|
klass.delegated_instance_methods.sort.should == [:current_page, :per_page,
|
@@ -124,7 +117,7 @@ describe APP::Models::PhotoSearch do
|
|
124
117
|
end
|
125
118
|
|
126
119
|
it "returns empty string when no search_terms supplied during initialization" do
|
127
|
-
klass.new(fixtures.photos,{}).search_terms.should
|
120
|
+
klass.new(fixtures.photos,{}).search_terms.should be_nil
|
128
121
|
end
|
129
122
|
end
|
130
123
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 1
|
9
|
+
version: 0.9.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Takaltoo
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-27 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|