Module: FlickrMocks::Stubs::Api
- Defined in:
- lib/flickr_mocks/stubs.rb
Class Method Summary collapse
-
.all ⇒ Object
Once this method is called all subsequent calls to the following calls are stubbed:.
-
.commons_institutions ⇒ Object
Once method is called all subsequent calls to Api.commons_institutions are stubbed.
-
.interesting_photos ⇒ Object
Once this method is called, all subsequent calls to Api.interesting_photos are stubbed.
-
.photo ⇒ Object
Once this method is called, all subsequent calls to Api.photo are stubbed.
-
.photo_details ⇒ Object
Once this method is called, subsequent calls to Api.photo_details are stubbed.
-
.photo_sizes ⇒ Object
Once this method is called, all subsequent calls to Api.photo_sizes are stubbed.
-
.photos ⇒ Object
Once this method is called, all subsequent calls to Api.photos are stubbed.
Class Method Details
.all ⇒ Object
Once this method is called all subsequent calls to the following calls are stubbed:
Api.photos
Api.photo_details
Api.photo
Api.photo_sizes
Api.interesting_photos
Api.commons_institutions
15 16 17 18 19 20 |
# File 'lib/flickr_mocks/stubs.rb', line 15 def self.all [:photos,:photo_details,:photo,:photo_sizes, :interesting_photos,:commons_institutions].each do |method| self.send(method) end end |
.commons_institutions ⇒ Object
Once method is called all subsequent calls to Api.commons_institutions are stubbed.
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/flickr_mocks/stubs.rb', line 134 def self.commons_institutions lambda {::FlickrMocks::Api.stub(:commons_institutions) do |params| ::FlickrMocks::Stubs::Flickr.commons_institutions case params when Hash then CommonsInstitutions.new(::FlickrMocks::Api.flickr_commons_institutions,params) else raise ArgumentError end end}.call end |
.interesting_photos ⇒ Object
Once this method is called, all subsequent calls to Api.interesting_photos are stubbed. The stub returns an object of class Models::PhotoSearch. The return value for Api.interesting_photos stub depends on the supplied options hash:
:date => '2000-01-01' --> returns empty list of photos
:date => 'garbage' --> raises an error
:date => <valid_id> --> returns interesting list of photos; date is any string
other than 'garbage' and '2001-01-01'
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/flickr_mocks/stubs.rb', line 120 def self.interesting_photos lambda {::FlickrMocks::Api.stub(:interesting_photos) do |params| ::FlickrMocks::Stubs::Flickr.interestingness case params when Hash then Models::PhotoSearch.new(flickr.interestingness.getList(params),params) else raise ArgumentError end end}.call end |
.photo ⇒ Object
Once this method is called, all subsequent calls to Api.photo are stubbed. The stub returns an object of class Models::Photo. The return value for the Api.photo stub depends on the supplied options:
(:photo_id || :id) => 'garbage' --> raises Invaid ID error
(:photo_id || :id) => nil --> raises invalid ID error
(:photo_id || :id) => <valid_id> --> returns a photo fixture with detailed information;
valid_id is any string other than 'garbage'
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/flickr_mocks/stubs.rb', line 79 def self.photo lambda{::FlickrMocks::Api.stub(:photo) do |params| ::FlickrMocks::Stubs::Flickr.getInfo case params when Hash then Models::Photo.new(::FlickrMocks::Api::Flickr.photo(params)) else raise ArgumentError end end}.call end |
.photo_details ⇒ Object
Once this method is called, subsequent calls to Api.photo_details are stubbed. The stub returns an object of class Models::PhotoDetails. The return value for Api.photo_details stub depends on the state of the supplied options hash:
(:photo_id || :id) => 'garbage' --> raises FlickRaw::FailedResponse error
(:photo_id || :id) => nil --> raises FlickRaw::FailedResponse error
(:photo_id || :id) => <valid_id> --> returns a photo fixture with detailed information;
valid_id can be any string other than 'garbage'
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/flickr_mocks/stubs.rb', line 57 def self.photo_details lambda {::FlickrMocks::Api.stub(:photo_details) do |params| ::FlickrMocks::Stubs::Flickr.getInfo ::FlickrMocks::Stubs::Flickr.getSizes case params when Hash then Models::PhotoDetails.new(flickr.photos.getInfo(::FlickrMocks::Api::Options.photo(params)), flickr.photos.getSizes(::FlickrMocks::Api::Options.photo(params))) else raise ArgumentError end end}.call end |
.photo_sizes ⇒ Object
Once this method is called, all subsequent calls to Api.photo_sizes are stubbed. The stub returns an object of class Models::PhotoSizes. The return value of Api.photo_sizes stub depends on the supplied options:
(:photo_id || :id) => 'garbage' --> raises FlickRaw::FailedResponse error
(:photo_id || :id) => nil --> raises FlickRaw::FailedResponse error
(:photo_id || :id) => <valid_id> --> returns list of photo sizes; valid_id is
any string other than 'garbage'
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/flickr_mocks/stubs.rb', line 99 def self.photo_sizes lambda {::FlickrMocks::Api.stub(:photo_sizes) do |params| ::FlickrMocks::Stubs::Flickr.getSizes case params when Hash then Models::PhotoSizes.new(flickr.photos.getSizes(::FlickrMocks::Api::Options.photo(params))) else raise ArgumentError end end}.call end |
.photos ⇒ Object
Once this method is called, all subsequent calls to Api.photos are stubbed. The stub returns an object of class Flickr::PhotoSearch. The return value for Api.photos hash depends on the the options hash:
:search_terms => 'garbage' --> returns empy list of photos
:owner_id => 'garbage' --> returns empty list of photos
:owner_id => '<valid_id>' --> returns list of photos that contain same author photos;
valid_id is any string other than garbage
:search_terms => '<valid_tag>' --> returns list of photos with different author photos
only if :owner_id nil); valid_tag is any
string other than 'garbage'
(:search_terms && :owner_id) => nil --> raises FlickRaw::FailedResponse error
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/flickr_mocks/stubs.rb', line 36 def self.photos lambda {::FlickrMocks::Api.stub(:photos) do |params| ::FlickrMocks::Stubs::Flickr.search case params when Hash then Models::PhotoSearch.new flickr.photos.search(::FlickrMocks::Api::Options.search(params)),params else raise ArgumentError end end}.call end |