Class: Portero::SearchProvider::Foursquare

Inherits:
Object
  • Object
show all
Includes:
Portero::SearchProvider
Defined in:
lib/portero/providers/foursquare.rb

Instance Method Summary collapse

Methods included from Portero::SearchProvider

included

Instance Method Details

#parse_results(results) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/portero/providers/foursquare.rb', line 22

def parse_results(results)
  json = JSON.parse(results.body)
  venues = json["response"]["venues"]
  results = []
  venues.each do |found_venue|
    venue = Portero::SearchResult.new
    venue.id = found_venue["id"]
    venue.name = found_venue["name"]
    venue.address = found_venue["location"]["address"]
    venue.latitude = found_venue["location"]["lat"]
    venue.longitude = found_venue["location"]["lng"]
    venue.city = found_venue["location"]["city"]
    venue.state = found_venue["location"]["state"]
    venue.postal_code = found_venue["location"]["postalCode"]
    venue.country = found_venue["location"]["country"]
    venue.category = found_venue["categories"].first["name"] if found_venue["categories"].first
    venue.icon = found_venue["categories"].first["icon"]["prefix"] + "64" + found_venue["categories"].first["icon"]["suffix"] if found_venue["categories"].first
    venue.extra = HashWithIndifferentAccess.new({categories: found_venue["categories"], url: found_venue["url"], contact: found_venue["contact"]})

    results << venue
  end
  results
end

#search(conn, query, latitude, longitude, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/portero/providers/foursquare.rb', line 9

def search(conn, query, latitude, longitude, options = {})
  params = {}
  params[:query] = query if query
  params[:client_id] = @provider_options[:client_id]
  params[:client_secret] = @provider_options[:client_secret]
  params[:ll] = [latitude, longitude].join(",")
  params[:v] = "20120709"
  params[:limit] = options[:limit] || 50
  params[:radius] = options[:radius] || 10000
  results = conn.get("https://api.foursquare.com/v2/venues/search", params)
  parse_results(results)
end