Class: IceRocket::Search

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/ice_rocket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(search_term, options = {}) ⇒ Search

Returns a new instance of Search.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ice_rocket.rb', line 14

def initialize(search_term, options={})
  opts = {
    :q   => search_term,
    :dh  => options[:dh]  || options[:date_high],
    :dl  => options[:dl]  || options[:date_low],
    :lng => options[:lng] || options[:language],
    :n   => options[:n]   || options[:per_page] || 10,
    :sourceid => options[:sourceid]
  }

  opts[:dh] = opts[:dh].strftime("%m/%d/%Y") if opts[:dh]
  opts[:dl] = opts[:dl].strftime("%m/%d/%Y") if opts[:dl]

  self.options = opts
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



12
13
14
# File 'lib/ice_rocket.rb', line 12

def options
  @options
end

Instance Method Details

#fetch(options = {}) ⇒ Object



30
31
32
# File 'lib/ice_rocket.rb', line 30

def fetch(options={})
  self.class.get('/search', params(options))
end

#params(options = {}) ⇒ Object



34
35
36
# File 'lib/ice_rocket.rb', line 34

def params(options={})
  { :query => self.options.merge( :p => options[:p] || options[:page] || 1 ) }
end