factual-api 1.3.16 → 1.3.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODNkNjcxNDJlNmFjODdhOGZiYmU1MGM4NzdiNjU4NzQ0MzdmMzQ0Zg==
4
+ OTM5OGExOTFmOGU0MzEwMTBkMGQyOGNiNmE3NWY1OTQ5ZDQ2MWUzMw==
5
5
  data.tar.gz: !binary |-
6
- NWQ1YjU4NTQ1YzI4ZGUwNTc5ZmFjZThmYzViNzM4NzhmYzJhZWRkYw==
6
+ NTNlNDNhNGU1M2JlMGY4M2UxNGVkZjM1YjE2YjI2NmJmYjRkMTBmMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Yjg0Mjc0ZWQ3NDRhMWY0NmMyN2MyZDBlOTVlNmJhYTlkMjcxZGVjMzI4N2Vj
10
- MjMyNjkxNDQ2NTQ2M2NkMmE5Mjg3YmY3NGFiNTNmNzlmMjYwOGU2M2EwNDM3
11
- NzgxOTZkNjdjYzc2NDQyYzQ3MGZmN2RiM2JmNzZkM2FkZWMzZjg=
9
+ NzFlZDE1YzkxNzcxYWQwMjQyM2ZkYzhiMzM0ODJjZDZjOTM5ZTM4NDhhOWUx
10
+ YjU1ZjI3M2NhOWJkZmY2NjhkZjQzZDBmODllNjIxMDYwMWQ0YTk0N2I1ZDJh
11
+ MmFmM2E4NTAwYjM3MmZkMjM3YTQ0OTM5NzdiYzgwYzcxNTEwM2U=
12
12
  data.tar.gz: !binary |-
13
- ZTNkYjNlMDUxZWE1NDFkMDQ2NGU0NzFlZWZiNTBiZGVkY2I3MTllODg1MzRm
14
- MzZjY2I1NjZmNjJlZTU4ODk1MmZhNjI4NGQ0MWRmYzQxYjc4OTk5ZTNiMjNk
15
- YTk5NTc0OTZjMDIxM2JlNGY1ZjY3MWZmOTViYjUxYjZkNzI1ODA=
13
+ MzVkYTcyMWZmNmM3ZjlmNGRiNWIxODNlYzU1OWE1Y2Y1YWNlMTQ2YjEwNWFm
14
+ NmEwMzQ2YmEyM2U5ZDhkODkwMjA1OTNmYTRjZTg1YjY4NWQ2MGMxMzNiZTI2
15
+ NTYwNTA0YWY4MDFmMDlmNzU4ODNkN2MzMDQ4YTFlZTM5NTBhNGI=
@@ -1,3 +1,6 @@
1
+ ## v1.3.17
2
+ * threshold support in facets
3
+
1
4
  ## v1.3.16
2
5
  * fixed flag closed #29
3
6
 
data/README.md CHANGED
@@ -1,141 +1,242 @@
1
1
  # About
2
2
 
3
- This is the Factual supported Ruby driver for [Factual's public API](http://developer.factual.com).
3
+ This is the Factual-supported Ruby driver for [Factual's public API](http://developer.factual.com).
4
4
 
5
+ # Install
5
6
 
6
- # Overview
7
+ ```bash
8
+ $ gem install factual-api
9
+ ```
7
10
 
8
- ## Basic Design
11
+ # Get Started
9
12
 
10
- The driver allows you to create an authenticated handle to Factual. With a Factual handle, you can send queries and get results back.
13
+ Include this driver in your project:
14
+ ```ruby
15
+ require 'factual'
16
+ factual = Factual.new("YOUR_KEY", "YOUR_SECRET")
17
+ ```
18
+ If you don't have a Factual API key yet, [it's free and easy to get one](https://www.factual.com/api-keys/request).
11
19
 
12
- Queries are created using the Factual handle, which provides a fluent interface to constructing your queries.
20
+ ## Schema
21
+ Use the schema API call to determine which fields are available, the datatypes of those fields, and which operations (sorting, searching, writing, facetting) can be performed on each field.
13
22
 
14
- ````ruby
15
- # You can chain the query methods, like this:
16
- factual.table("places").filters("category" => "Food & Beverage > Restaurants").search("sushi", "sashimi")
17
- .geo("$circle" => {"$center" => [34.06021, -118.41828], "$meters" => 5000})
18
- .sort("name").page(2, :per => 10)
19
- ````
23
+ Full documentation: http://developer.factual.com/api-docs/#Schema
24
+ ```ruby
25
+ factual.table("places-us").schema
26
+ ```
20
27
 
21
- Results are returned as Ruby Arrays of Hashes, where each Hash is a result record.
28
+ ## Read
29
+ Use the read API call to query data in Factual tables with any combination of full-text search, parametric filtering, and geo-location filtering.
22
30
 
23
- ## Setup
31
+ Full documentation: http://developer.factual.com/api-docs/#Read
24
32
 
25
- The driver's gems are hosted at [Rubygems.org](http://rubygems.org).
33
+ Related place-specific documentation:
34
+ * Categories: http://developer.factual.com/working-with-categories/
35
+ * Placerank, Sorting: http://developer.factual.com/search-placerank-and-boost/
26
36
 
27
- You can install the factual-api gem as follows:
37
+ ```ruby
28
38
 
29
- ````bash
30
- $ gem install factual-api
31
- ````
32
39
 
33
- Or add one line to the Gemfile of your Rails project, and run `bundle`:
40
+ # Full-text search:
41
+ factual.table("places-us").search("century city mall").rows
34
42
 
35
- ````ruby
36
- gem 'factual-api'
37
- ````
43
+ # Row filters:
44
+ # search restaurants (http://developer.factual.com/working-with-categories/)
45
+ # note that this will return all sub-categories of 347 as well.
46
+ factual.table("places-us").filters("category_ids" => {"$includes" => 347}).rows
38
47
 
39
- Once the gem is installed, you can use it in your Ruby project like:
48
+ # search restaurants or bars
49
+ factual.table("places-us").filters("category_ids" => {"$includes_any" => [312, 347]}).rows
40
50
 
41
- ````ruby
42
- require 'factual'
43
- factual = Factual.new("YOUR_KEY", "YOUR_SECRET")
44
- ````
45
- If you don't have a Factual API account yet, [it's free and easy to get one](https://www.factual.com/api-keys/request).
46
-
47
- ## Simple Read Examples
48
-
49
- `````ruby
50
- # Return entities from the Places dataset with names beginning with "starbucks"
51
- factual.table("places").filters("name" => {"$bw" => "starbucks"}).rows
52
- ````
53
-
54
- `````ruby
55
- # Return entity names and non-blank websites from the Global dataset, for entities located in Thailand
56
- factual.table("places").select(:name, :website)
57
- .filters({"country" => "TH", "website" => {"$blank" => false}})
58
- ````
59
-
60
- `````ruby
61
- # Return highly rated U.S. restaurants in Los Angeles with WiFi
62
- factual.table("restaurants")
63
- .filters({"locality" => "los angeles", "rating" => {"$gte" => 4}, "wifi" => true}).rows
64
- ````
65
-
66
- ## Simple Places Example
67
-
68
- ````ruby
69
- # Returns resolved entities as an array of hashes
70
- query = factual.resolve("name" => "McDonalds",
71
- "address" => "10451 Santa Monica Blvd",
72
- "region" => "CA",
73
- "postcode" => "90025")
74
-
75
- query.first["resolved"] # true or false
76
- query.rows # all candidate rows
77
- ````
78
-
79
- ````ruby
80
- # Returns the nearest valid address information
81
- query = factual.geocode(34.06021,-118.41828)
82
- query.first
83
- ````
84
-
85
- ````ruby
86
- # Returns georeferenced attributes generated by Factual
87
- query = factual.geopulse(34.06021,-118.41828).select("area_statistics", "income", "housing")
88
- query.first["income"]
89
- ````
90
-
91
- ## More Read Examples
92
-
93
- ````ruby
94
- # 1. Specify the table Global Places
95
- query = factual.table("places")
96
- ````
97
-
98
- ````ruby
99
- # 2. Filter results in country US
100
- query = query.filters("country" => "US")
101
- ````
102
-
103
- ````ruby
104
- # 3. Search for "sushi" or "sashimi"
105
- query = query.search("sushi", "sashimi")
106
- ````
107
-
108
- ````ruby
109
- # 4. Filter by geolocation
110
- query = query.geo("$circle" => {"$center" => [34.06021, -118.41828], "$meters" => 5000})
111
- ````
112
-
113
- ````ruby
114
- # 5. Sort it
115
- query = query.sort("name") # ascending
116
- query = query.sort_desc("name") # descending
117
- query = query.sort("address", "name") # sort by multiple columns
118
- ````
119
-
120
- ````ruby
121
- # 6. Page it
122
- query = query.page(2, :per => 10)
123
- ````
124
-
125
- ````ruby
126
- # 7. Finally, get response in a hash or array of hashes
127
- query.first # return one row
128
- query.rows # return many rows
129
- ````
130
-
131
- ````ruby
132
- # 8. Returns total row counts that matches the criteria
133
- query.total_count
134
- ````
51
+ # search entertainment venues but NOT adult entertainment
52
+ factual.table("places-us").filters("$and" => [{"category_ids" => {"$includes" => 317}}, {"category_ids" => {"$excludes" => 318}}]).rows
135
53
 
136
- # Where to Get Help
54
+ # search for Starbucks in Los Angeles
55
+ factual.table("places-us").search("starbucks").filters("locality" => "los angeles").rows
56
+
57
+ # search for starbucks in Los Angeles or Santa Monica
58
+ factual.table("places-us").search("starbucks").filters("$or" => [{"locality" => {"$eq" =>"los angeles"}}, {"locality" => {"$eq" => "santa monica"}}]).rows
59
+
60
+ # Paging:
61
+ # search for starbucks in Los Angeles or Santa Monica (second page of results):
62
+ factual.table("places-us").search("starbucks").filters("$or" => [{"locality" => {"$eq" =>"los angeles"}}, {"locality" => {"$eq" => "santa monica"}}]).page(2, :per => 20).rows
63
+
64
+ # Geo filter:
65
+ # coffee near the Factual office
66
+ factual.table("places-us").search("coffee").geo("$circle" => {"$center" => [34.058583, -118.416582], "$meters" => 1000}).rows
67
+
68
+ # Existence threshold:
69
+ # prefer precision over recall:
70
+ factual.table("places-us").threshold("confident").rows
71
+
72
+ # Get a row by factual id:
73
+ factual.table("places-us").row("03c26917-5d66-4de9-96bc-b13066173c65")
74
+
75
+ ```
76
+
77
+ ## Facets
78
+ Use the facets call to get summarized counts, grouped by specified fields.
79
+
80
+ Full documentation: http://developer.factual.com/api-docs/#Facets
81
+ ```ruby
82
+ # show top 5 cities that have more than 20 Starbucks in California
83
+ factual.facets("places-us").select("locality").search("starbucks").filters("region" => "CA").min_count(20).limit(5).columns
84
+ ```
85
+
86
+ ## Resolve
87
+ Use resolve to generate a confidence-based match to an existing set of place attributes.
88
+
89
+ Full documentation: http://developer.factual.com/api-docs/#Resolve
90
+ ```ruby
91
+ # resovle from name and address info
92
+ factual.resolve("places-us").values("name" => "McDonalds", "address" => "10451 Santa Monica Blvd", "region" => "CA", "postcode" => "90025").rows
93
+
94
+ # resolve from name and geo location
95
+ factual.match("places-us").values("name" => "McDonalds", "latitude" => 34.05671, "longitude" => -118.42586).rows
96
+ ```
97
+
98
+ ## Match
99
+ Match is similar to resolve, but returns only the Factual ID and is intended for high volume mapping.
100
+
101
+ Full documentation: http://developer.factual.com/api-docs/#Match
102
+ ```ruby
103
+ factual.table("places-us").match("name" => "McDonalds", "address" => "10451 Santa Monica Blvd", "region" => "CA", "postcode" => "90025").rows
104
+ ```
105
+
106
+ ## Crosswalk
107
+ Crosswalk contains third party mappings between entities.
108
+
109
+ Full documentation: http://developer.factual.com/places-crosswalk/
110
+
111
+ ```ruby
112
+ # Query with factual id, and only show entites from Yelp:
113
+ factual.table("crosswalk").filters("factual_id" => "3b9e2b46-4961-4a31-b90a-b5e0aed2a45e", "namespace" => "yelp").rows
114
+ ```
115
+
116
+ ```ruby
117
+ # query with an entity from Foursquare:
118
+ factual.table("crosswalk").filters("namespace" => "foursquare", "namespace_id" => "4ae4df6df964a520019f21e3").rows
119
+ ```
120
+
121
+ ## World Geographies
122
+ World Geographies contains administrative geographies (states, counties, countries), natural geographies (rivers, oceans, continents), and assorted geographic miscallaney. This resource is intended to complement the Global Places and add utility to any geo-related content.
123
+
124
+ ```ruby
125
+ # find California, USA
126
+ factual.table("world-geographies").select("contextname", "factual_id").search("los angeles").filters("name" => "California", "country" => "US", "placetype" => "region").rows
127
+ # returns 08649c86-8f76-11e1-848f-cfd5bf3ef515 as the Factual Id of "California, US"
128
+ ```
129
+
130
+ ```ruby
131
+ # find cities and town in California (first 20 rows)
132
+ factual.table("world-geographies").select("contextname", "factual_id").search("los angeles").filters("ancestors" => {"$includes" => "08649c86-8f76-11e1-848f-cfd5bf3ef515"}, "country" => "US", "placetype" => "locality").rows
133
+ ```
134
+
135
+ ## Submit
136
+ Submit new data, or update existing data. Submit behaves as an "upsert", meaning that Factual will attempt to match the provided data against any existing places first. Note: you should ALWAYS store the *commit ID* returned from the response for any future support requests.
137
137
 
138
- https://github.com/Factual/factual-ruby-driver/wiki/Debug-and-Support
138
+ Full documentation: http://developer.factual.com/api-docs/#Submit
139
+
140
+ Place-specific Write API documentation: http://developer.factual.com/write-api/
141
+
142
+ ```ruby
143
+ new_value = {
144
+ name: "Factual",
145
+ address: "1999 Avenue of the Stars",
146
+ address_extended: "34th floor",
147
+ locality: "Los Angeles",
148
+ region: "CA",
149
+ postcode: "90067",
150
+ country: "us",
151
+ latitude: 34.058743,
152
+ longitude: -118.41694,
153
+ category_ids: [209,213],
154
+ hours: "Mon 11:30am-2pm Tue-Fri 11:30am-2pm, 5:30pm-9pm Sat-Sun closed"
155
+ }
156
+ factual.submit("us-sandbox", "a_user_id").values(new_value).write
157
+ ```
158
+
159
+ Edit an existing row:
160
+ ```ruby
161
+ factual.submit("us-sandbox", "a_user_id", "4e4a14fe-988c-4f03-a8e7-0efc806d0a7f").values(address_extended: "35th floor").write
162
+ ```
163
+
164
+
165
+ ## Flag
166
+ Use the flag API to flag problems in existing data.
167
+
168
+ Full documentation: http://developer.factual.com/api-docs/#Flag
169
+
170
+ Flag a place that is a duplicate of another. The *preferred* entity that should persist is passed as a GET parameter.
171
+ ```ruby
172
+ factual.flag("us-sandbox", "a_user_id", "4e4a14fe-988c-4f03-a8e7-0efc806d0a7f", :duplicate).preferred("9d676355-6c74-4cf6-8c4a-03fdaaa2d66a").write
173
+ ```
174
+
175
+ Flag a place that is closed.
176
+ ```ruby
177
+ factual.flag("us-sandbox", "a_user_id", "4e4a14fe-988c-4f03-a8e7-0efc806d0a7f", :closed).comment("was shut down when I went there yesterday.").write
178
+ ```
179
+
180
+ Flag a place that has been relocated, so that it will redirect to the new location. The *preferred* entity (the current location) is passed as a GET parameter. The old location is identified in the URL.
181
+ ```ruby
182
+ factual.flag("us-sandbox", "a_user_id", "4e4a14fe-988c-4f03-a8e7-0efc806d0a7f", :relocated).preferred("9d676355-6c74-4cf6-8c4a-03fdaaa2d66a").write
183
+ ```
184
+
185
+ ## Clear
186
+ The clear API is used to signal that an existing attribute's value should be reset.
187
+
188
+ Full documentation: http://developer.factual.com/api-docs/#Clear
189
+ ```ruby
190
+ factual.clear("us-sandbox", "a_user_id", "4e4a14fe-988c-4f03-a8e7-0efc806d0a7f").fields(:latitude, :longitude).write
191
+ ```
192
+
193
+ ## Boost
194
+ The boost API is used to signal rows that should appear higher in search results.
195
+
196
+ Full documentation: http://developer.factual.com/api-docs/#Boost
197
+ ```ruby
198
+ factual.boost("us-sandbox", "a_user_id", "4e4a14fe-988c-4f03-a8e7-0efc806d0a7f", "local business data").write
199
+ ```
200
+
201
+ ## Multi
202
+ Make up to three simultaneous requests over a single HTTP connection. Note: while the requests are performed in parallel, the final response is not returned until all contained requests are complete. As such, you shouldn't use multi if you want non-blocking behavior. Also note that a contained response may include an API error message, if appropriate.
203
+
204
+ Full documentation: http://developer.factual.com/api-docs/#Multi
205
+
206
+ ```ruby
207
+ # Query read and facets in one request:
208
+ read_query = factual.table("places-us").search("starbucks").geo("$circle" => {"$center" => [34.041195, -118.331518], "$meters" => 1000})
209
+ facets_query = factual.facets("places-us").search("starbucks").filters("region" => "CA").select("locality").min_count(20).limit(5)
210
+ factual.multi(read: read_query, facets: facets_query)
211
+ ```
212
+
213
+
214
+ ## Error Handling
215
+ The errors are thrown as StandardError instances.
216
+
217
+ ## Debug Mode
218
+ To see detailed debug information at runtime, you can turn on Debug Mode:
219
+ ```ruby
220
+ # start debug mode
221
+ factual = Factual.new(key, secret, :debug => true)
222
+
223
+ # run your querie(s)
224
+
225
+ ```
226
+ Debug Mode will output useful information about what's going on, including the request sent to Factual and the response from Factual, outputting to stdout and stderr.
227
+
228
+
229
+ ## Custom timeouts
230
+ You can set the request timeout (in milliseconds):
231
+ ```ruby
232
+ # set the timeout as 1 second
233
+ factual = Factual.new(key, secret, :timeout => 1)
234
+
235
+ ```
236
+ You will get [Timeout::Error: execution expired] for custom timeout errors.
237
+
238
+
239
+ # Where to Get Help
139
240
 
140
241
  If you think you've identified a specific bug in this driver, please file an issue in the github repo. Please be as specific as you can, including:
141
242
 
@@ -144,7 +245,4 @@ If you think you've identified a specific bug in this driver, please file an iss
144
245
  * What actually happened
145
246
  * Detailed stack trace and/or line numbers
146
247
 
147
- If you are having any other kind of issue, such as unexpected data or strange behaviour from Factual's API (or you're just not sure WHAT'S going on), please contact us through [GetSatisfaction](http://support.factual.com/factual).
148
-
149
- # Ruby Driver Wiki
150
- https://github.com/Factual/factual-ruby-driver/wiki
248
+ If you are having any other kind of issue, such as unexpected data or strange behaviour from Factual's API (or you're just not sure WHAT'S going on), please contact us through the [Factual support site](http://support.factual.com/factual).
@@ -1,6 +1,6 @@
1
1
  class Factual
2
2
  class API
3
- VERSION = "1.3.16"
3
+ VERSION = "1.3.17"
4
4
  API_V3_HOST = "api.v3.factual.com"
5
5
  DRIVER_VERSION_TAG = "factual-ruby-driver-v" + VERSION
6
6
  PARAM_ALIASES = { :search => :q, :sort_asc => :sort }
@@ -98,7 +98,7 @@ class Factual
98
98
 
99
99
  def handle_payload(payload)
100
100
  raise StandardError.new(payload.to_json) unless payload["status"] == "ok"
101
- payload["response"]
101
+ payload["response"] || payload["status"]
102
102
  end
103
103
 
104
104
  def make_request(url, body=nil, method=:get)
@@ -6,6 +6,7 @@ class Factual
6
6
  :filters, :search, :geo,
7
7
  :select,
8
8
  :limit, :min_count,
9
+ :threshold,
9
10
  :include_count, :user
10
11
  ]
11
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factual-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.16
4
+ version: 1.3.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rudiger Lippert
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-10 00:00:00.000000000 Z
12
+ date: 2014-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth