bizratr 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bizratr (0.0.3)
4
+ bizratr (0.0.4)
5
+ factual-api
5
6
  foursquare2
6
7
  geocoder
7
8
  google_places
@@ -12,6 +13,9 @@ PATH
12
13
  GEM
13
14
  remote: http://rubygems.org/
14
15
  specs:
16
+ factual-api (1.3.1)
17
+ json (>= 1.2.0)
18
+ oauth (>= 0.4.4)
15
19
  faraday (0.8.4)
16
20
  multipart-post (~> 1.1)
17
21
  faraday_middleware (0.8.8)
data/README.rdoc CHANGED
@@ -1,11 +1,12 @@
1
1
  = BizRatr
2
- This gem pulls in business data from a variety of sources and synthesizes a singular view of the business. Right now Yelp, Google Places, and Foursquare are used as sources. Bizratr will collapse all of the matching sources into a singular view of each matching business.
2
+ This gem pulls in business data from a variety of sources and synthesizes a singular view of the business. Right now Yelp, Factual, Google Places, and Foursquare are used as sources. Bizratr will collapse all of the matching sources into a singular view of each matching business.
3
3
 
4
4
  >> require 'bizratr'
5
5
  >> config = {
6
6
  :foursquare => { :client_id => 'anid', :client_secret => 'asecret' },
7
7
  :yelp => { :consumer_key => 'akey', :consumer_secret => 'asecret', :token => 'atoken', :token_secret => 'atokensecret' },
8
- :google_places => { :key => "akey" }
8
+ :google_places => { :key => "akey" },
9
+ :factual => { :key => 'akey', :secret => 'asecret' }
9
10
  }
10
11
  >> finder = BizRatr::Finder.new(config)
11
12
  >> matches = finder.search_location([40.729401, -73.996061], 'third rail coffee')
@@ -23,6 +24,7 @@ You only need to specify the config options for the services you actually want t
23
24
  * Yelp: http://www.yelp.com/developers/getting_started
24
25
  * Google places: https://code.google.com/apis/console/b/0/
25
26
  * Foursquare: https://foursquare.com/oauth/
27
+ * Factual: https://www.factual.com/api-keys/request
26
28
 
27
29
  See http://findingscience.com/bizratr for more information.
28
30
 
@@ -3,6 +3,7 @@ require 'yelpster'
3
3
  require 'levenshtein'
4
4
  require 'google_places'
5
5
  require 'geocoder'
6
+ require 'factual'
6
7
 
7
8
  module BizRatr
8
9
  class Connector
@@ -15,6 +16,30 @@ module BizRatr
15
16
  end
16
17
  end
17
18
 
19
+ class FactualConnector < Connector
20
+ def initialize(config)
21
+ @client = Factual.new(config[:key], config[:secret])
22
+ end
23
+
24
+ def search_location(location, query)
25
+ location = geocode(location) if location.is_a? String
26
+ results = @client.table("places").filters("name" => query).geo("$circle" => { "$center" => location, "$meters" => 1000 })
27
+ results.map { |item| make_business(item) }
28
+ end
29
+
30
+ def make_business(item)
31
+ b = Business.new(item['latitude'], item['longitude'], item['name'])
32
+ b.add_id(:factual, item['factual_id'])
33
+ b.add_categories(:factual, item['category'].split(",").map(&:strip))
34
+ b.phone = item['tel'].gsub(/[\ ()-]*/, '')
35
+ b.city = item['locality']
36
+ b.country = item['country']
37
+ b.zip = item['postcode']
38
+ b.address = item['address']
39
+ b
40
+ end
41
+ end
42
+
18
43
  class GooglePlacesConnector < Connector
19
44
  def initialize(config)
20
45
  @client = GooglePlaces::Client.new(config[:key])
@@ -30,7 +55,7 @@ module BizRatr
30
55
  b = Business.new(item.lat, item.lng, item.name)
31
56
  b.add_id(:google_places, item.id)
32
57
  b.add_categories(:google_places, item.types)
33
- b.phone = item.formatted_phone_number
58
+ b.phone = (item.formatted_phone_number || "").gsub(/[\ ()-]*/, '')
34
59
  b.city = item.city || item.vicinity.split(',').last
35
60
  b.country = item.country
36
61
  b.zip = item.postal_code
@@ -59,7 +84,7 @@ module BizRatr
59
84
  b.add_id(:foursquare, item['id'])
60
85
  categories = item.categories.map { |c| [ c.name ] + c.parents }.flatten
61
86
  b.add_categories(:foursquare, categories)
62
- b.phone = item['contact'].fetch('phone', nil)
87
+ b.phone = item['contact'].fetch('phone', '').gsub(/[\ ()-]*/, '')
63
88
  b.twitter = item['contact'].fetch('twitter', nil)
64
89
  b.state = item['location']['state']
65
90
  b.city = item['location']['city']
@@ -96,7 +121,7 @@ module BizRatr
96
121
  b.country = item['location']['country_code']
97
122
  b.city = item['location']['city']
98
123
  b.address = item['location']['address'].first
99
- b.phone = item['phone']
124
+ b.phone = (item['phone'] || "").gsub(/[\ ()-]*/, '')
100
125
  b.add_rating(:yelp, item['rating'])
101
126
  b.add_review_counts(:yelp, item['review_count'])
102
127
  b
@@ -110,6 +135,7 @@ module BizRatr
110
135
  when :foursquare then FourSquareConnector.new(value)
111
136
  when :yelp then YelpConnector.new(value)
112
137
  when :google_places then GooglePlacesConnector.new(value)
138
+ when :factual then FactualConnector.new(value)
113
139
  else raise "No such connector found: #{key}"
114
140
  end
115
141
  }
@@ -1,3 +1,3 @@
1
1
  module BizRatr
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bizratr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-09-17 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: foursquare2
16
- requirement: &70178915319580 !ruby/object:Gem::Requirement
16
+ requirement: &70164411414400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70178915319580
24
+ version_requirements: *70164411414400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yelpster
27
- requirement: &70178915318840 !ruby/object:Gem::Requirement
27
+ requirement: &70164411413840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70178915318840
35
+ version_requirements: *70164411413840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: google_places
38
- requirement: &70178915318180 !ruby/object:Gem::Requirement
38
+ requirement: &70164411413260 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70178915318180
46
+ version_requirements: *70164411413260
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: levenshtein
49
- requirement: &70178915317580 !ruby/object:Gem::Requirement
49
+ requirement: &70164411412680 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70178915317580
57
+ version_requirements: *70164411412680
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: google_places
60
- requirement: &70178915305880 !ruby/object:Gem::Requirement
60
+ requirement: &70164411412020 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70178915305880
68
+ version_requirements: *70164411412020
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: geocoder
71
- requirement: &70178915305300 !ruby/object:Gem::Requirement
71
+ requirement: &70164411402160 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,18 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70178915305300
79
+ version_requirements: *70164411402160
80
+ - !ruby/object:Gem::Dependency
81
+ name: factual-api
82
+ requirement: &70164411401600 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: *70164411401600
80
91
  description: Get business ratings.
81
92
  email: bamuller@gmail.com
82
93
  executables: []
@@ -92,21 +103,6 @@ files:
92
103
  - LICENSE
93
104
  - Rakefile
94
105
  - README.rdoc
95
- - docs/BizRatr/Business.html
96
- - docs/BizRatr/Connector.html
97
- - docs/BizRatr/Finder.html
98
- - docs/BizRatr/FourSquareConnector.html
99
- - docs/BizRatr/GooglePlacesConnector.html
100
- - docs/BizRatr/YelpConnector.html
101
- - docs/BizRatr.html
102
- - docs/created.rid
103
- - docs/index.html
104
- - docs/lib/bizratr/business_rb.html
105
- - docs/lib/bizratr/connector_rb.html
106
- - docs/lib/bizratr/version_rb.html
107
- - docs/lib/bizratr_rb.html
108
- - docs/rdoc.css
109
- - docs/README_rdoc.html
110
106
  homepage: http://findingscience.com/bizratr
111
107
  licenses: []
112
108
  post_install_message: