flickrmocks 0.8.15 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/Gemfile.lock +123 -0
- data/README.rdoc +104 -30
- data/Rakefile +12 -0
- data/flickrmocks.gemspec +3 -1
- data/lib/flickr_mocks/api/api.rb +80 -27
- data/lib/flickr_mocks/api/flickr.rb +69 -23
- data/lib/flickr_mocks/api/helpers.rb +25 -12
- data/lib/flickr_mocks/api/options.rb +71 -53
- data/lib/flickr_mocks/api/sanitize.rb +129 -20
- data/lib/flickr_mocks/fixtures.rb +7 -1
- data/lib/flickr_mocks/flickraw/custom_clone.rb +3 -1
- data/lib/flickr_mocks/flickraw/custom_compare.rb +4 -0
- data/lib/flickr_mocks/flickraw/custom_marshal.rb +7 -2
- data/lib/flickr_mocks/flickraw/flickraw.rb +6 -0
- data/lib/flickr_mocks/helpers.rb +8 -1
- data/lib/flickr_mocks/models/commons_institution.rb +45 -34
- data/lib/flickr_mocks/models/commons_institutions.rb +85 -75
- data/lib/flickr_mocks/models/helpers.rb +13 -6
- data/lib/flickr_mocks/models/models.rb +7 -0
- data/lib/flickr_mocks/models/photo.rb +76 -75
- data/lib/flickr_mocks/models/photo_details.rb +71 -69
- data/lib/flickr_mocks/models/photo_dimensions.rb +80 -78
- data/lib/flickr_mocks/models/photo_search.rb +115 -88
- data/lib/flickr_mocks/models/photo_size.rb +57 -56
- data/lib/flickr_mocks/models/photo_sizes.rb +68 -67
- data/lib/flickr_mocks/models/photos.rb +104 -99
- data/lib/flickr_mocks/stubs.rb +151 -14
- data/lib/flickr_mocks/version.rb +7 -1
- data/spec/api/api_spec.rb +26 -8
- data/spec/api/flickr_spec.rb +19 -19
- data/spec/api/helper_spec.rb +20 -20
- data/spec/api/options_spec.rb +170 -124
- data/spec/api/sanitize_spec.rb +174 -59
- data/spec/base/stubs_spec.rb +37 -74
- data/spec/base/version_spec.rb +11 -4
- data/spec/models/commons_institution_spec.rb +3 -2
- data/spec/models/commons_institutions_spec.rb +34 -5
- data/spec/models/helpers_spec.rb +7 -6
- data/spec/models/photo_details_spec.rb +12 -11
- data/spec/models/photo_dimensions_spec.rb +5 -4
- data/spec/models/photo_search_spec.rb +50 -8
- data/spec/models/photo_size_spec.rb +4 -3
- data/spec/models/photo_sizes_spec.rb +6 -5
- data/spec/models/photo_spec.rb +6 -4
- data/spec/models/photos_spec.rb +9 -7
- data/spec/shared_examples/hash_options/date_hash_option.rb +42 -0
- data/spec/shared_examples/hash_options/page_hash_option.rb +23 -0
- data/spec/shared_examples/hash_options/perpage_hash_option.rb +43 -0
- data/spec/shared_examples/hash_options/tag_mode_hash_option.rb +31 -0
- data/spec/shared_examples/stub_helpers.rb +140 -0
- data/spec/spec_helper.rb +5 -5
- metadata +55 -16
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
flickrmocks (0.8.15)
|
5
|
+
chronic
|
6
|
+
flickraw (>= 0.8.2)
|
7
|
+
ruby-debug19 (>= 0.11.6)
|
8
|
+
will_paginate (>= 3.0.pre2)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: http://rubygems.org/
|
12
|
+
specs:
|
13
|
+
abstract (1.0.0)
|
14
|
+
actionmailer (3.0.3)
|
15
|
+
actionpack (= 3.0.3)
|
16
|
+
mail (~> 2.2.9)
|
17
|
+
actionpack (3.0.3)
|
18
|
+
activemodel (= 3.0.3)
|
19
|
+
activesupport (= 3.0.3)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
erubis (~> 2.6.6)
|
22
|
+
i18n (~> 0.4)
|
23
|
+
rack (~> 1.2.1)
|
24
|
+
rack-mount (~> 0.6.13)
|
25
|
+
rack-test (~> 0.5.6)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activemodel (3.0.3)
|
28
|
+
activesupport (= 3.0.3)
|
29
|
+
builder (~> 2.1.2)
|
30
|
+
i18n (~> 0.4)
|
31
|
+
activerecord (3.0.3)
|
32
|
+
activemodel (= 3.0.3)
|
33
|
+
activesupport (= 3.0.3)
|
34
|
+
arel (~> 2.0.2)
|
35
|
+
tzinfo (~> 0.3.23)
|
36
|
+
activeresource (3.0.3)
|
37
|
+
activemodel (= 3.0.3)
|
38
|
+
activesupport (= 3.0.3)
|
39
|
+
activesupport (3.0.3)
|
40
|
+
archive-tar-minitar (0.5.2)
|
41
|
+
arel (2.0.6)
|
42
|
+
builder (2.1.2)
|
43
|
+
chronic (0.3.0)
|
44
|
+
columnize (0.3.2)
|
45
|
+
diff-lcs (1.1.2)
|
46
|
+
erubis (2.6.6)
|
47
|
+
abstract (>= 1.0.0)
|
48
|
+
factory_girl (1.3.2)
|
49
|
+
factory_girl_rails (1.0)
|
50
|
+
factory_girl (~> 1.3)
|
51
|
+
rails (>= 3.0.0.beta4)
|
52
|
+
faker (0.3.1)
|
53
|
+
flickraw (0.8.3)
|
54
|
+
json (>= 1.1.1)
|
55
|
+
flickraw-cached (20100707.1)
|
56
|
+
flickraw
|
57
|
+
i18n (0.5.0)
|
58
|
+
json (1.4.6)
|
59
|
+
linecache19 (0.5.11)
|
60
|
+
ruby_core_source (>= 0.1.4)
|
61
|
+
mail (2.2.12)
|
62
|
+
activesupport (>= 2.3.6)
|
63
|
+
i18n (>= 0.4.0)
|
64
|
+
mime-types (~> 1.16)
|
65
|
+
treetop (~> 1.4.8)
|
66
|
+
mime-types (1.16)
|
67
|
+
polyglot (0.3.1)
|
68
|
+
rack (1.2.1)
|
69
|
+
rack-mount (0.6.13)
|
70
|
+
rack (>= 1.0.0)
|
71
|
+
rack-test (0.5.6)
|
72
|
+
rack (>= 1.0)
|
73
|
+
rails (3.0.3)
|
74
|
+
actionmailer (= 3.0.3)
|
75
|
+
actionpack (= 3.0.3)
|
76
|
+
activerecord (= 3.0.3)
|
77
|
+
activeresource (= 3.0.3)
|
78
|
+
activesupport (= 3.0.3)
|
79
|
+
bundler (~> 1.0)
|
80
|
+
railties (= 3.0.3)
|
81
|
+
railties (3.0.3)
|
82
|
+
actionpack (= 3.0.3)
|
83
|
+
activesupport (= 3.0.3)
|
84
|
+
rake (>= 0.8.7)
|
85
|
+
thor (~> 0.14.4)
|
86
|
+
rake (0.8.7)
|
87
|
+
rspec (2.3.0)
|
88
|
+
rspec-core (~> 2.3.0)
|
89
|
+
rspec-expectations (~> 2.3.0)
|
90
|
+
rspec-mocks (~> 2.3.0)
|
91
|
+
rspec-core (2.3.1)
|
92
|
+
rspec-expectations (2.3.0)
|
93
|
+
diff-lcs (~> 1.1.2)
|
94
|
+
rspec-mocks (2.3.0)
|
95
|
+
ruby-debug-base19 (0.11.24)
|
96
|
+
columnize (>= 0.3.1)
|
97
|
+
linecache19 (>= 0.5.11)
|
98
|
+
ruby_core_source (>= 0.1.4)
|
99
|
+
ruby-debug19 (0.11.6)
|
100
|
+
columnize (>= 0.3.1)
|
101
|
+
linecache19 (>= 0.5.11)
|
102
|
+
ruby-debug-base19 (>= 0.11.19)
|
103
|
+
ruby_core_source (0.1.4)
|
104
|
+
archive-tar-minitar (>= 0.5.2)
|
105
|
+
thor (0.14.6)
|
106
|
+
treetop (1.4.9)
|
107
|
+
polyglot (>= 0.3.1)
|
108
|
+
tzinfo (0.3.23)
|
109
|
+
will_paginate (3.0.pre2)
|
110
|
+
|
111
|
+
PLATFORMS
|
112
|
+
ruby
|
113
|
+
|
114
|
+
DEPENDENCIES
|
115
|
+
chronic
|
116
|
+
factory_girl_rails (>= 1.0)
|
117
|
+
faker (>= 0.3.1)
|
118
|
+
flickraw (>= 0.8.2)
|
119
|
+
flickraw-cached (>= 0.8.2)
|
120
|
+
flickrmocks!
|
121
|
+
rspec (>= 2.2.0)
|
122
|
+
ruby-debug19 (>= 0.11.6)
|
123
|
+
will_paginate (>= 3.0.pre2)
|
data/README.rdoc
CHANGED
@@ -1,41 +1,116 @@
|
|
1
|
-
|
1
|
+
= FlickrMocks
|
2
2
|
|
3
|
-
|
4
|
-
gem. This is useful for Mocking/Stubbing the Flickr interface for testing
|
5
|
-
purposes.
|
3
|
+
Wiki[http://wiki.github.com/takaltoo/flickrmocks] | RDocs[http://rdoc.info/projects/takaltoo/flickrmocks]
|
6
4
|
|
7
|
-
|
8
|
-
|
5
|
+
FlickrMocks simplifies access to the Flickr API by providing wrappers and helpers on top of
|
6
|
+
the FlickRaw[https://github.com/hanklords/flickraw] gem.
|
9
7
|
|
10
|
-
==
|
8
|
+
== Installation
|
9
|
+
In a standalone ruby project:
|
10
|
+
gem install flickrmocks
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
# in your code
|
13
|
+
require 'flickrmocks
|
14
14
|
|
15
|
-
|
15
|
+
In <b>Rails 3</b>, add this to your Gemfile.
|
16
16
|
|
17
|
-
|
18
|
-
classes.
|
17
|
+
gem "flickrmocks"
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
== Rails Installation (Test::Unit)
|
19
|
+
In <b>Rails 2</b>, add this to your environment.rb file.
|
20
|
+
|
21
|
+
config.gem "flickrmocks"
|
22
|
+
|
23
|
+
Alternatively, you can install it as a plugin.
|
27
24
|
|
28
|
-
|
25
|
+
rails plugin install git://github.com/takaltoo/flickrmocks.git
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
== Getting Started
|
28
|
+
FlickrMocks API helpers expect the FlickRaw.api_key to be initialized before they are called:
|
29
|
+
FlickRaw.api_key = your_flickr_api_key
|
30
|
+
|
31
|
+
In Rails you can automate the initialization by creating the initializer file
|
32
|
+
config/initializers/flickraw_config.rb with the content:
|
33
|
+
|
34
|
+
FlickRaw.api_key = your_flickr_api_key[http://www.flickr.com/services/api/misc.api_keys.html]
|
35
|
+
|
36
|
+
Alternatively, your flickr api key can be placed into a separate
|
37
|
+
YAML[http://railscasts.com/episodes/85-yaml-configuration-file] configuration file.
|
38
|
+
In this scenario the contents of the config/initializers/flickrwa_config.rb would be something like:
|
39
|
+
|
40
|
+
FlickRaw.api_key = APP_CONFIG['flickr_api_key']
|
41
|
+
|
42
|
+
Your config/config.yml could look something similar to this (Note: you can use
|
43
|
+
this file to place all your custom configurations):
|
44
|
+
|
45
|
+
development:
|
46
|
+
flickr_api_key: xyz
|
47
|
+
test:
|
48
|
+
flickr_api_key: xyz
|
49
|
+
production:
|
50
|
+
flickr_api_key: xyz
|
51
|
+
|
52
|
+
== Using the search API
|
53
|
+
FlickrMocks::Api.photo(options_hash), returns object of class FlickrMocks::Photo.
|
54
|
+
The options accepted include:
|
55
|
+
:photo_id => "id for photo"
|
56
|
+
:secret => "secret for photo"
|
57
|
+
FlickrMocks::Api.photo_details(options_hash), returns object of class FlickrMocks::PhotoDetails.
|
58
|
+
The options accepted include:
|
59
|
+
:photo_id => "id for photo"
|
60
|
+
:secret => "secret for photo"
|
61
|
+
FlickrMocks::Api.photos(options_hash), returns object of class FlickrMocks::PhotoSearch.
|
62
|
+
The options accepted include:
|
63
|
+
:search_terms => 'search terms' # comma separated list of search terms 'happy cow, pasture'
|
64
|
+
:owner_id => 'id for owner of photo' # either :owner_id or :search_terms must be specified
|
65
|
+
:tag_mode => 'all' # optional argument, can be either all or any
|
66
|
+
:per_page => '50' # optional argument, can be any number greater than 0
|
67
|
+
:page => '1' # optional argument, can be any number greater than 0
|
68
|
+
:base_url => 'url' # optional argument
|
69
|
+
FlickrMocks::Api.photo_sizes(options_hash), returns object of class FlickrMocks::PhotoSizes.
|
70
|
+
The options accepted include:
|
71
|
+
:photo_id => "id for photo"
|
72
|
+
:secret => "secret for photo" # optional argument
|
73
|
+
FlickrMocks::Api.interesting_photos(options_hash), returns object of class FlickrMocks::PhotoSearch.
|
74
|
+
The options accepted include:
|
75
|
+
:date => '2010-10-10' # date of format YYYY-MM-DD
|
76
|
+
:per_page => 'number' # optional argument
|
77
|
+
:page => 'number' # optional argument
|
78
|
+
FlickrMocks::Api.commons_institutions(options_hash), returns object of class FlickrMocks::CommonsInstitutions.
|
79
|
+
The options accepted include:
|
80
|
+
:per_page => 'number' # optional argument
|
81
|
+
:current_page => 'number' # optional argument
|
82
|
+
|
83
|
+
== Stubs for testing
|
84
|
+
FlickrMocks provides Rspec 2.0 stubs for the search API routines. To stub all the routines simply call:
|
85
|
+
|
86
|
+
FlickrMocks::Stubs::Api.all
|
87
|
+
|
88
|
+
By calling FlickrMocks::Stubs::Api.all the following methods will be stubbed.
|
89
|
+
FlickrMocks::Api.photo
|
90
|
+
FlickrMocks::Api.photos
|
91
|
+
FlickrMocks::Api.photo_details
|
92
|
+
FlickrMocks::Api.photo_sizes
|
93
|
+
FlickrMocks::Api.interesting_photos
|
94
|
+
FlickrMocks::Api.commons_institutions
|
95
|
+
|
96
|
+
NOTE: the stubs return errors when not called with proper options. Moreover, some of the stubs return
|
97
|
+
different objects depending on how they are called. For additional details please
|
98
|
+
refer RDocs[http://rdoc.info/projects/takaltoo/flickrmocks].
|
99
|
+
|
100
|
+
== Additional Docs
|
101
|
+
|
102
|
+
* {RDOCs}[http://rdoc.info/projects/takaltoo/flickrmocks]
|
103
|
+
* {See more}[http://wiki.github.com/takaltoo/flickrmocks/]
|
104
|
+
* Run the specs manually once you've checked out the repository:
|
105
|
+
rspec spec -f d
|
33
106
|
|
34
|
-
|
107
|
+
|
108
|
+
== Questions or Problems?
|
35
109
|
|
36
|
-
|
37
|
-
|
110
|
+
If you have any issues with FlickrMocks which you cannot find the solution to in the documentation,
|
111
|
+
please add an {issue on GitHub}[http://github.com/takaltoo/flickrmocks/issues] or fork the project and send a pull request.
|
38
112
|
|
113
|
+
To get the specs running you should call +bundle+ and then +rake+.
|
39
114
|
|
40
115
|
|
41
116
|
== Note on Patches/Pull Requests
|
@@ -45,15 +120,14 @@ Then:
|
|
45
120
|
* Add tests for it. This is important so I don't break it in a
|
46
121
|
future version unintentionally.
|
47
122
|
* Commit, do not mess with rakefile, version, or history.
|
48
|
-
(if you want to have your own version, that is fine but bump version in a commit
|
123
|
+
(if you want to have your own version, that is fine but bump version in a commit
|
124
|
+
by itself I can ignore when I pull)
|
49
125
|
* Send me a pull request. Bonus points for topic branches.
|
50
126
|
|
51
|
-
|
52
|
-
|
53
127
|
== License
|
54
128
|
|
55
129
|
FlickrMocks is released under the MIT license.
|
56
130
|
|
57
131
|
== Copyright
|
58
132
|
|
59
|
-
Copyright (c) 2010 Takaltoo
|
133
|
+
Copyright (c) 2010 Takaltoo
|
data/Rakefile
CHANGED
data/flickrmocks.gemspec
CHANGED
@@ -27,9 +27,11 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.require_paths = ["lib"]
|
28
28
|
s.add_runtime_dependency(%q<flickraw>, [">= 0.8.2"])
|
29
29
|
s.add_runtime_dependency(%q<chronic>, [">= 0"])
|
30
|
+
s.add_runtime_dependency(%q<ruby-debug19>, [">= 0.11.6"])
|
31
|
+
s.add_runtime_dependency(%q<will_paginate>, [">= 3.0.pre2"])
|
30
32
|
s.add_development_dependency(%q<rspec>, [">= 2.2.0"])
|
31
|
-
s.add_development_dependency(%q<capybara>, [">= 0"])
|
32
33
|
s.add_development_dependency(%q<factory_girl_rails>, [">= 1.0"])
|
33
34
|
s.add_development_dependency(%q<faker>, [">= 0.3.1"])
|
35
|
+
s.add_development_dependency(%q<flickraw-cached>, [">= 0.8.2"])
|
34
36
|
end
|
35
37
|
|
data/lib/flickr_mocks/api/api.rb
CHANGED
@@ -1,53 +1,106 @@
|
|
1
|
-
module FlickrMocks
|
2
|
-
|
1
|
+
module FlickrMocks
|
2
|
+
# Wrappers for performing queries against the Flickr API's. Uses the
|
3
|
+
# FlickRaw gem to perform the queries. Query results are encapsulated in easy-to-use
|
4
|
+
# Ruby classes.
|
5
|
+
#
|
6
|
+
# Before calling the API methods you must initialize FlickRaw with your api_key:
|
7
|
+
#
|
8
|
+
# FlickRaw.api_key = your_flickr_api_key
|
3
9
|
class Api
|
4
10
|
@defaults = {
|
11
|
+
:page => '1',
|
5
12
|
:per_page => '200',
|
6
13
|
:license => '4,5,6,7',
|
7
14
|
:media => 'photos',
|
8
15
|
:extras => 'license',
|
16
|
+
:max_entries => '4000',
|
9
17
|
:tag_mode => 'any',
|
10
|
-
:
|
18
|
+
:possible_tag_modes => ['any','all'],
|
19
|
+
:possible_sizes => [:square, :thumbnail, :small, :medium, :medium_640, :large, :original],
|
11
20
|
}
|
12
|
-
|
21
|
+
|
13
22
|
class << self
|
14
23
|
attr_accessor :defaults
|
15
24
|
end
|
16
25
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
PhotoSearch.new photos,Api.search_params(params)
|
26
|
+
# returns the default value stored in the class instance variable @defaults hash.
|
27
|
+
def self.default(value)
|
28
|
+
Api.defaults[value.to_sym]
|
21
29
|
end
|
22
30
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
31
|
+
# Searches for photos that match the user provided parameters.
|
32
|
+
# Sample usage:
|
33
|
+
# Api.photos(:search_terms => 'france')
|
34
|
+
# Options hash accepts:
|
35
|
+
# :search_terms : string with comma separated list of terms 'france,lyon'
|
36
|
+
# :owner_id : pptional string containing the id for the owner of the photo.
|
37
|
+
# :per_page : optional string containing the maximum number of photos returned in a single page. The default value is '200'
|
38
|
+
# :page : optional string containing the page for search results to be returned. The default is '1'
|
39
|
+
# :tag_mode : optionsl string containing either 'any' or 'all'. Affects the interpretation of the search terms to the FlickRaw API.
|
40
|
+
def self.photos(options)
|
41
|
+
raise ArgumentError.new("Expecting a Hash argument.") unless options.is_a?(Hash)
|
42
|
+
photos = Api::Flickr.photos(options)
|
43
|
+
Models::PhotoSearch.new photos,options
|
28
44
|
end
|
29
45
|
|
30
|
-
|
31
|
-
|
32
|
-
|
46
|
+
# Retrieves detailed information for a photo. A PhotoDetails object that encapsulates
|
47
|
+
# the retrieved data into an easy-to-use Ruby class is returned. Sample usage:
|
48
|
+
# Api.photo_details(:photo_id => '1234'
|
49
|
+
# Options hash accepts:
|
50
|
+
# :photo_id : required string that contains the id for the photo
|
51
|
+
# :secret : optional string that contains the flickr secret for photo. When provided query is slightly faster
|
52
|
+
def self.photo_details(options)
|
53
|
+
raise ArgumentError.new("Expecting a Hash argument.") unless options.is_a?(Hash)
|
54
|
+
photo = Api::Flickr.photo(options)
|
55
|
+
sizes = Api::Flickr.photo_sizes(options)
|
56
|
+
Models::PhotoDetails.new(photo,sizes)
|
33
57
|
end
|
34
58
|
|
35
|
-
|
36
|
-
|
37
|
-
|
59
|
+
# Retrieve basic information for a photo. Returns object of class Photo.
|
60
|
+
# Sample usage:
|
61
|
+
# Api.photo(:photo_id => '1234')
|
62
|
+
# Options hash accepts:
|
63
|
+
# :photo_id : required string that contains the id for the photo
|
64
|
+
# :secret : optional string that contains the flickr secret for photo. When provided query is slightly faster
|
65
|
+
def self.photo(options)
|
66
|
+
raise ArgumentError.new("Expecting a Hash argument") unless options.is_a?(Hash)
|
67
|
+
Models::Photo.new Api::Flickr.photo(options)
|
38
68
|
end
|
39
69
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
70
|
+
# Retrieves available sizes for a given photo. Returns object of class PhotoSize.
|
71
|
+
# Sample usage:
|
72
|
+
# Api.photo_sizes(:photo_id => '1234')
|
73
|
+
# Options hash accepts:
|
74
|
+
# :photo_id : required string that contains the id for the photo
|
75
|
+
# :secret : optional string that contains the flickr secret for photo. When provided query is slightly faster
|
76
|
+
def self.photo_sizes(options)
|
77
|
+
raise ArgumentError.new("Expecting a Hash argument") unless options.is_a?(Hash)
|
78
|
+
Models::PhotoSizes.new Api::Flickr.photo_sizes(options)
|
44
79
|
end
|
45
80
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
81
|
+
# Retrieves interesting photos for a given date. Returns object of class PhotoSearch.
|
82
|
+
# Sample usage:
|
83
|
+
# Api.interesting_photos(:date => '2000-01-01'
|
84
|
+
# Options hash accepts:
|
85
|
+
# :date : string with date in the format yyyy-mm-dd
|
86
|
+
# :per_page : optional string containing the maximum number of photos returned in a single page. The default value is '200'
|
87
|
+
# :page : optional string containing the page for search results to be returned. The default is '1'
|
88
|
+
def self.interesting_photos(options)
|
89
|
+
raise ArgumentError.new("Expecting a Hash argument") unless options.is_a?(Hash)
|
90
|
+
photos = Api::Flickr.interestingness(options)
|
91
|
+
Models::PhotoSearch.new photos,options
|
50
92
|
end
|
51
93
|
|
94
|
+
# Retrieves list of commons institutions. Returns object of class CommonsInstitutions.
|
95
|
+
# Sample usage:
|
96
|
+
# Api.commons_institutions({})
|
97
|
+
# Options hash accepts:
|
98
|
+
# :per_page : optional string containing the maximum number of photos returned in a single page. The default value is '200'
|
99
|
+
# :page : optional string containing the page for search results to be returned. The default is '1'
|
100
|
+
def self.commons_institutions(options)
|
101
|
+
raise ArgumentError.new("Expecting a Hash argument") unless options.is_a?(Hash)
|
102
|
+
institutions = Api::Flickr.commons_institutions
|
103
|
+
Models::CommonsInstitutions.new institutions,options
|
104
|
+
end
|
52
105
|
end
|
53
106
|
end
|
@@ -1,31 +1,77 @@
|
|
1
1
|
module FlickrMocks
|
2
|
-
|
3
2
|
class Api
|
4
|
-
#
|
5
|
-
|
6
|
-
flickr.photos.search
|
7
|
-
|
3
|
+
# Wrapper methods for accessing Flickr Api. Module is used internally.
|
4
|
+
module Flickr
|
5
|
+
# Wrapper for flickr.photos.search Flickr API call. Sample usage:
|
6
|
+
#
|
7
|
+
# self.photos(:search_terms => 'france')
|
8
|
+
#
|
9
|
+
# Options hash accepts:
|
10
|
+
# :search_terms : string with comma separated list of terms 'france,lyon'
|
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 returned in a single page. The default value is '200'
|
13
|
+
# :page : optional string containing the page for search results to be returned. The default is '1'
|
14
|
+
# :tag_mode : optionsl string containing either 'any' or 'all'. Affects the interpretation of the search terms to the FlickRaw API.
|
15
|
+
def self.photos(options)
|
16
|
+
flickr.photos.search Api::Options.search(options)
|
17
|
+
end
|
8
18
|
|
9
|
-
|
10
|
-
|
11
|
-
|
19
|
+
# Wrapper for flickr.photos.getInfo Flickr API call. Sample usage:
|
20
|
+
#
|
21
|
+
# self.photo(:photo_id => '123')
|
22
|
+
#
|
23
|
+
# Options hash accepts:
|
24
|
+
# :photo_id : required string that contains the id for the photo
|
25
|
+
# :secret : optional string that contains the flickr secret for photo. When provided query is slightly faster
|
26
|
+
def self.photo(options)
|
27
|
+
flickr.photos.getInfo Api::Options.photo(options)
|
28
|
+
end
|
12
29
|
|
13
|
-
|
14
|
-
|
15
|
-
|
30
|
+
# Wrapper for flickr.photos-getSizes Flickr API call. Sample usage:
|
31
|
+
#
|
32
|
+
# self.photo_sizes(:photo_id => '1', :secret => 'abcdef')
|
33
|
+
#
|
34
|
+
# Options hash accepts:
|
35
|
+
# :photo_id : required string that contains the id for the photo
|
36
|
+
# :secret : optional string that contains the flickr secret for photo. When provided query is slightly faster
|
37
|
+
def self.photo_sizes(options)
|
38
|
+
flickr.photos.getSizes Api::Options.photo(options)
|
39
|
+
end
|
16
40
|
|
17
|
-
|
18
|
-
|
19
|
-
|
41
|
+
# Wrapper for flickr.interestingness.getList Flickr API call. Sample usage:
|
42
|
+
#
|
43
|
+
# self.interestingness(:dage => '2010-10-10')
|
44
|
+
#
|
45
|
+
# Options hash accepts:
|
46
|
+
# :date : string containing date of format 'YYYY-MM-DD'
|
47
|
+
# :per_page : optional string containing maximum number of items per page
|
48
|
+
# :page : optional string containing the page to retrieve for the query
|
49
|
+
def self.interestingness(options)
|
50
|
+
flickr.interestingness.getList Api::Options.interesting(options)
|
51
|
+
end
|
20
52
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
53
|
+
# Wrapper for flickr.photos-search Flickr API call. Sample usage:
|
54
|
+
#
|
55
|
+
# self.author(:owner_id => '20')
|
56
|
+
#
|
57
|
+
# Options hash accepts:
|
58
|
+
# :owner_id : string containing owner for the photo. This gets mapped to :user_id
|
59
|
+
# :per_page : optional string containing maximum number of items per page
|
60
|
+
# :page : optional string containing the page to retrieve for the query
|
61
|
+
def self.author(options)
|
62
|
+
flickr.photos.search Api::Options.author(options)
|
63
|
+
end
|
64
|
+
|
65
|
+
# wrapper for flickr.commons.getInstitutions Flickr API call. Sample usage:
|
66
|
+
#
|
67
|
+
# self.commons_institutions
|
68
|
+
#
|
69
|
+
# Options hash accepts:
|
70
|
+
# :per_page : optional string containing maximum number of items per page
|
71
|
+
# :page : optional string containing the page to retrieve for the query
|
72
|
+
def self.commons_institutions
|
73
|
+
flickr.commons.getInstitutions
|
74
|
+
end
|
27
75
|
end
|
28
76
|
end
|
29
|
-
end
|
30
|
-
|
31
|
-
|
77
|
+
end
|
@@ -1,19 +1,32 @@
|
|
1
1
|
module FlickrMocks
|
2
2
|
class Api
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
date
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
module Helpers
|
4
|
+
# returns a date string of format YYYY-MM-DD. If the supplied date is ambiguous
|
5
|
+
# it returns yesterday's date in the format YYYY-MM-DD. Sample usage:
|
6
|
+
#
|
7
|
+
# self.date('2010-10-10')
|
8
|
+
# self.date('yesterday')
|
9
|
+
def self.date(date=nil)
|
10
|
+
self.valid_date?(date) ? self.parse_date(date) : self.parse_date('yesterday')
|
11
|
+
end
|
12
|
+
|
13
|
+
# returns true when supplied date is of format YYYY-MM-DD. Sample usage:
|
14
|
+
#
|
15
|
+
# self.valid_date?('2010-10-10')
|
16
|
+
def self.valid_date?(date)
|
17
|
+
begin
|
18
|
+
self.parse_date(date)
|
19
|
+
true
|
20
|
+
rescue
|
21
|
+
false
|
22
|
+
end
|
14
23
|
end
|
15
|
-
end
|
16
24
|
|
25
|
+
private
|
26
|
+
def self.parse_date(date)
|
27
|
+
Chronic.parse(date).strftime('%Y-%m-%d')
|
28
|
+
end
|
17
29
|
|
30
|
+
end
|
18
31
|
end
|
19
32
|
end
|