Class: Fleakr::Objects::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/fleakr/objects/search.rb

Instance Method Summary collapse

Constructor Details

#initialize(*parameters) ⇒ Search

Create a new search



8
9
10
11
# File 'lib/fleakr/objects/search.rb', line 8

def initialize(*parameters)
  @parameters = Hash.new
  parameters.each {|param| add_parameter(param) }
end

Instance Method Details

#add_parameter(parameter) ⇒ Object



13
14
15
16
# File 'lib/fleakr/objects/search.rb', line 13

def add_parameter(parameter)
  value = parameter.is_a?(String) ? {:text => parameter} : parameter
  @parameters.merge!(value)
end

#resultsObject

Retrieve search results from the API



23
24
25
26
27
28
# File 'lib/fleakr/objects/search.rb', line 23

def results
  @results ||= begin
    response = Fleakr::Api::MethodRequest.with_response!('photos.search', parameters)
    (response.body/'rsp/photos/photo').map {|p| Photo.new(p) }
  end
end

#tagsObject



18
19
20
# File 'lib/fleakr/objects/search.rb', line 18

def tags
  Array(@parameters[:tags])
end