Module: FlickrMocks::Stubs::Flickr
- Defined in:
- lib/flickr_mocks/stubs.rb
Overview
stubs low level FlickRaw Api calls to Flickr
Class Method Summary collapse
-
.all ⇒ Object
Once this method is called, the following calls are stubbed: flickr.photos.search flickr.photos.getInfo flickr.photos.getSizes flickr.interestingness.getList flickr.commons.getInstitutions.
-
.commons_institutions ⇒ Object
Once called, all subsequent calls to flickr.commons.getInstitutions are stubbed.
-
.getInfo ⇒ Object
Once this method is called, all subsequent calls to flickr.photos.getInfo are stubbed.
-
.getSizes ⇒ Object
Once this method is called all subsequent calls for flickr.photos.getSizes are stubbed.
-
.interestingness ⇒ Object
Once this method is called, all subsequent calls to flickr.interestingness.getList are stubbed.
-
.search ⇒ Object
only if valid author id is not provided.
Class Method Details
.all ⇒ Object
Once this method is called, the following calls are stubbed:
flickr.photos.search
flickr.photos.getInfo
flickr.photos.getSizes
flickr.interestingness.getList
flickr.commons.getInstitutions
156 157 158 159 160 |
# File 'lib/flickr_mocks/stubs.rb', line 156 def self.all [:search,:getInfo,:getSizes,:interestingness,:commons_institutions].each do |method| self.send(method) end end |
.commons_institutions ⇒ Object
Once called, all subsequent calls to flickr.commons.getInstitutions are stubbed. The flickr.commons.getInstitutions stub simply returns a list of commons institutions.
280 281 282 283 284 285 286 |
# File 'lib/flickr_mocks/stubs.rb', line 280 def self.commons_institutions lambda { flickr.commons.stub(:getInstitutions) do Fixtures.instance.commons_institutions end }.call end |
.getInfo ⇒ Object
Once this method is called, all subsequent calls to flickr.photos.getInfo are stubbed. The return value for the flickr.photos.getInfo stub depends on the supplied options hash:
:photo_id => 'garbage' --> raises Invaid ID error
:photo_id => nil --> raises invalid ID error
:photo_id => <valid_id> --> returns a photo fixture with detailed information
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/flickr_mocks/stubs.rb', line 202 def self.getInfo lambda { flickr.photos.stub(:getInfo) do |params| if !params.is_a?(Hash) raise FlickRaw::FailedResponse.new('Photo not found', 'code', 'flickr.photos.getInfo') elsif !params.has_key?(:photo_id) raise FlickRaw::FailedResponse.new('Photo not found', 'code', 'flickr.photos.getInfo') elsif params[:photo_id] == 'garbage' raise FlickRaw::FailedResponse.new('Photo "%s" not found (invalid ID)' % params[:photo_id], 'code','flickr.photos.getInfo') elsif params[:photo_id].nil? raise FlickRaw::FailedResponse.new('Photo "nil" not found (invalid ID)', 'code','flickr.photos.getInfo') else Fixtures.instance.photo_details end end }.call end |
.getSizes ⇒ Object
Once this method is called all subsequent calls for flickr.photos.getSizes are stubbed. The return value for the flickr.photos.getSizes stub depends on the supplied options hash:
:photo_id => nil --> raises FlickRaw::FailedResponse error)
:photo_id => 'garbage' --> raises FlickRaw::FailedResponse error)
:photo_id => '<valid_id>' --> returns a list of photo sizes)
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/flickr_mocks/stubs.rb', line 231 def self.getSizes lambda { flickr.photos.stub(:getSizes) do |params| if !params.is_a?(Hash) raise FlickRaw::FailedResponse.new('Photo not found', 'code', 'flickr.photos.getSizes') elsif !params.has_key?(:photo_id) raise FlickRaw::FailedResponse.new('Photo not found', 'code', 'flickr.photos.getSizes') elsif params[:photo_id] == 'garbage' raise FlickRaw::FailedResponse.new('Photo not found', 'code','flickr.photos.getSizes') elsif params[:photo_id] == nil raise FlickRaw::FailedResponse.new('Photo not found', 'code','flickr.photos.getSizes') else Fixtures.instance.photo_sizes end end }.call end |
.interestingness ⇒ Object
Once this method is called, all subsequent calls to flickr.interestingness.getList are stubbed. The return value for the flickr.interesting.getList stub depends on the supplied options hash.
:date => '2000-01-01' --> returns empy list of photos
:date => 'garbage' --> raises an error
:date => <valid_id> --> returns interesting list of photos
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/flickr_mocks/stubs.rb', line 260 def self.interestingness lambda { flickr.interestingness.stub(:getList) do |params| if !params.is_a?(Hash) Fixtures.instance.interesting_photos elsif params[:date] == '2000-01-01' Fixtures.instance.empty_photos elsif params[:date] == 'garbage' raise FlickRaw::FailedResponse.new('Not a valid date string', 'code','flickr.interestingness.getList' ) else Fixtures.instance.interesting_photos end end }.call end |
.search ⇒ Object
only if valid author id is not provided
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/flickr_mocks/stubs.rb', line 171 def self.search fixtures = Fixtures.instance lambda { flickr.photos.stub(:search) do |params| if !params.is_a?(Hash) raise FlickRaw::FailedResponse.new('Parameterless searches have been disabled. Please use flickr.photos.getRecent instead.', 'code','flickr.photos.search' ) elsif(params[:tags] == 'garbage' || params[:user_id] == 'garbage') fixtures.empty_photos elsif(params[:tags] && params[:user_id]) fixtures. elsif !params[:user_id].nil? fixtures. elsif !params[:tags].nil? fixtures.photos else raise FlickRaw::FailedResponse.new('Parameterless searches have been disabled. Please use flickr.photos.getRecent instead.', 'code','flickr.photos.search' ) end end }.call end |