portero 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,8 +7,15 @@ module Portero
7
7
  requires_option :client_secret
8
8
 
9
9
  def search(conn, query, latitude, longitude, options = {})
10
- results = conn.get("https://api.foursquare.com/v2/venues/search", {query: query, client_id: @provider_options[:client_id], client_secret: @provider_options[:client_secret], v: "20120709",
11
- limit: options[:limit], radius: options[:radius], ll: [latitude, longitude].join(",")})
10
+ params = {}
11
+ params[:query] = query if query
12
+ params[:client_id] = @provider_options[:client_id]
13
+ params[:client_secret] = @provider_options[:client_secret]
14
+ params[:ll] = [latitude, longitude].join(",")
15
+ params[:v] = "20120709"
16
+ params[:limit] = options[:limit] || 50
17
+ params[:radius] = options[:radius] || 10000
18
+ results = conn.get("https://api.foursquare.com/v2/venues/search", params)
12
19
  parse_results(results)
13
20
  end
14
21
 
@@ -27,8 +34,8 @@ module Portero
27
34
  venue.state = found_venue["location"]["state"]
28
35
  venue.postal_code = found_venue["location"]["postalCode"]
29
36
  venue.country = found_venue["location"]["country"]
30
- venue.category = found_venue["categories"].first["name"]
31
- venue.icon = found_venue["categories"].first["icon"]["prefix"] + "64" + found_venue["categories"].first["icon"]["suffix"]
37
+ venue.category = found_venue["categories"].first["name"] if found_venue["categories"].first
38
+ venue.icon = found_venue["categories"].first["icon"]["prefix"] + "64" + found_venue["categories"].first["icon"]["suffix"] if found_venue["categories"].first
32
39
  venue.extra = {categories: found_venue["categories"], url: found_venue["url"]}
33
40
 
34
41
  results << venue
@@ -7,8 +7,15 @@ module Portero
7
7
  requires_option :key
8
8
 
9
9
  def search(conn, query, latitude, longitude, options = {})
10
- results = conn.get("https://maps.googleapis.com/maps/api/place/textsearch/json", {query: query, key: @provider_options[:key],
11
- radius: options[:radius], location: [latitude, longitude].join(","), sensor: false})
10
+ params = {}
11
+ params[:query] = query if query
12
+ params[:key] = @provider_options[:key]
13
+ params[:radius] = options[:radius] || 10000
14
+ params[:location] = [latitude, longitude].join(",")
15
+ params[:sensor] = false
16
+
17
+ url = query.present? ? "https://maps.googleapis.com/maps/api/place/textsearch/json" : "https://maps.googleapis.com/maps/api/place/search/json"
18
+ results = conn.get(url, params)
12
19
  parse_results(results)
13
20
  end
14
21
 
@@ -20,7 +27,7 @@ module Portero
20
27
  venue = Portero::SearchResult.new
21
28
  venue.id = found_venue["id"]
22
29
  venue.name = found_venue["name"]
23
- venue.address = found_venue["formatted_address"]
30
+ venue.address = found_venue["formatted_address"] || found_venue["vicinity"]
24
31
  venue.latitude = found_venue["geometry"]["location"]["lat"]
25
32
  venue.longitude = found_venue["geometry"]["location"]["lng"]
26
33
  venue.city = ""
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext/class/attribute'
2
+ require 'active_support/core_ext/object/blank'
2
3
 
3
4
  module Portero
4
5
  module SearchProvider
@@ -1,3 +1,3 @@
1
1
  module Portero
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end