Class: WigleApi::Scraper::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/wigle_api/scraper/search.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Search

Returns a new instance of Search.



28
29
30
31
32
33
34
35
# File 'lib/wigle_api/scraper/search.rb', line 28

def initialize(args)
  @search_arguments = {
    "variance"    => "0.010",
    "Query"       => "Query"
  }

  @search_arguments.merge!(clean(args))
end

Instance Method Details

#eachObject



64
65
66
# File 'lib/wigle_api/scraper/search.rb', line 64

def each
  results.each { |r| yield(r) }
end

#offset(num) ⇒ Object



37
38
39
40
# File 'lib/wigle_api/scraper/search.rb', line 37

def offset(num)
  @search_arguments.merge!(clean({pagestart: num}))
  self
end

#resultsObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/wigle_api/scraper/search.rb', line 47

def results
  conn = WigleApi::Connection.new
  response = conn.search(@search_arguments)

  unless [200, 301, 302, 303].include?(response.code.to_i)
    return nil
  end

  # Parse the response, then turn the keys into symbols
  WigleApi::Scraper::Parser.new(response.body).map do |row|
    row.inject({}) do |results, (key, value)|
      results[key.to_sym] = value.to_s
      results
    end
  end
end

#where(args) ⇒ Object



42
43
44
45
# File 'lib/wigle_api/scraper/search.rb', line 42

def where(args)
  @search_arguments.merge!(clean(args))
  self
end