Module: FlickrMocks::Api::Options

Defined in:
lib/flickr_mocks/api/options.rb

Overview

encapsulates methods that extract options from user-specified hash. Module is used internally.

Class Method Summary collapse

Class Method Details

.author(params) ⇒ Object

returns parameter hash used for searching for photos of a given author. Sample usage:

self.search(:owner_id => '1234')

Accepted options include:

:owner_id : id for the photo. (either :owner_id or :search_terms must be specified
:per_page : optional string containing the maximum number of items to return
             for a given page
:page : optional string containing page number for the results. When
         page number is <= 0, it returns 1.


87
88
89
90
91
# File 'lib/flickr_mocks/api/options.rb', line 87

def self.author(params)
  options = Api::Options.search(params)
  options.delete :tags
  options
end

.interesting(params) ⇒ Object

returns parameter hash that is supplied for a interesting photo search. Sample usage:

self.interesting(:date => '2010-10-10')

Accepted options include:

:date : string of format 'YYYY-MM-DD'. Photos of this date are retrieved.
         If none supplied, yesterday's date is used.
:per_page : optional string containing the maximum number of items to
             return for a given page
:page : optional string containing page number for the results. When page
         number is <= 0, it returns 1.


48
49
50
51
52
53
54
55
# File 'lib/flickr_mocks/api/options.rb', line 48

def self.interesting(params)
  return {
    :date => Api::Sanitize.date_hash(params),
    :per_page => Api::Sanitize.per_page_hash(params),
    :page =>  Api::Sanitize.page_hash(params),
    :extras => Api.default(:extras)
  }
end

.photo(params) ⇒ Object

returns parameter hash for a single photo. Sample usage:

self.photo(:photo_id => '123')

Accepted options include:

:photo_id : string containing photo_id of the photo.
:id : string containing photo id of the photo. It is an alias for :photo_id.
       If both are present :photo_id takes precedance.
:secret : optional string containing the secret for the photo. If supplied
           the query is slightly faster.
:photo_secret : optional string containing the secret for the photo. It
                 is an alias for :secret. If both supplied, :secret takes precedance.


69
70
71
72
73
74
# File 'lib/flickr_mocks/api/options.rb', line 69

def self.photo(params)
  {
    :photo_id => params[:photo_id] || params[:id] || nil,
    :secret => params[:photo_secret] || params[:secret] || nil
  }
end

.search(params) ⇒ Object

returns parameter hash required for a flickr photo search. Sample usage:

self.search(:search_terms => 'iran', :tag_mode => 'any')

Accepted options include:

:search_terms : comma string containing the flickr search tags. Sample
                 string 'lyon,france"
:owner_id : id for the photo. (either :owner_id or :search_terms
             must be specified
:per_page : optional string containing the maximum number of items to
             return for a given page
:page : optional string containing page number for the results. When
         page number is <= 0, it returns 1.
:tag_mode : optional string containing how the tags for :search_terms
             should be interpreted. Can be either 'any' or 'all'


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/flickr_mocks/api/options.rb', line 21

def self.search(params)
  return {
    :tags => Api::Sanitize.tags(params[:search_terms]),
    :user_id =>  params[:owner_id],
    :per_page =>  Api::Sanitize.per_page_hash(params),
    :page =>  Api::Sanitize.page_hash(params),
    :license => Api.default(:license),
    :media => Api.default(:media),
    :extras => Api.default(:extras),
    :tag_mode => Api::Sanitize.tag_mode_hash(params)
  }
end