factual 0.1
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.
- data/.gitignore +9 -0
- data/README +47 -0
- data/Rakefile +1 -0
- data/factual.gemspec +26 -0
- data/lib/.DS_Store +0 -0
- data/lib/factual/categories.rb +11 -0
- data/lib/factual/categories_response.rb +40 -0
- data/lib/factual/client.rb +13 -0
- data/lib/factual/core.rb +15 -0
- data/lib/factual/core_response.rb +52 -0
- data/lib/factual/crossref.rb +32 -0
- data/lib/factual/crosswalk.rb +74 -0
- data/lib/factual/places.rb +33 -0
- data/lib/factual/places_response.rb +60 -0
- data/lib/factual/resolve.rb +16 -0
- data/lib/factual/version.rb +3 -0
- data/lib/factual.rb +16 -0
- metadata +103 -0
data/.gitignore
ADDED
data/README
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
Factual Gem
|
2
|
+
===========
|
3
|
+
Factual Gem is a Ruby wrapper for the Factual API v3. It is based on the HTTParty gem by John Nunemaker.
|
4
|
+
|
5
|
+
|
6
|
+
Factual API v3 Docs
|
7
|
+
===================
|
8
|
+
http://developer.factual.com/display/docs/Factual+Developer+APIs+Version+3
|
9
|
+
You will need to request a beta API key at http://www.factual.com/devtools/beta
|
10
|
+
|
11
|
+
|
12
|
+
CROSSWALK USAGE
|
13
|
+
===============
|
14
|
+
client = Factual::Client.new("YOUR_API_KEY")
|
15
|
+
crosswalk = Factual::Crosswalk.new(client)
|
16
|
+
|
17
|
+
# parameters: factual_id of the place
|
18
|
+
results = crosswalk.search_by_factual_id('1234567890')
|
19
|
+
|
20
|
+
# parameters: namespace, namespace_id
|
21
|
+
results = crosswalk.search_by_factual_id('foursquare', '54634563473')
|
22
|
+
|
23
|
+
|
24
|
+
CROSSREF USAGE
|
25
|
+
===============
|
26
|
+
client = Factual::Client.new("YOUR_API_KEY")
|
27
|
+
crossref = Factual::Crossref.new(client)
|
28
|
+
|
29
|
+
# parameters: factual_id of the place
|
30
|
+
results = crossref.search_by_factual_id('1234567890')
|
31
|
+
|
32
|
+
# parameters: url
|
33
|
+
results = crossref.search_by_url('http://www.yelp.com/some-business')
|
34
|
+
|
35
|
+
|
36
|
+
RESOLVE USAGE
|
37
|
+
===============
|
38
|
+
client = Factual::Client.new("YOUR_API_KEY")
|
39
|
+
resolve = Factual::Resolve.new(client)
|
40
|
+
|
41
|
+
# parameters: hash of values
|
42
|
+
results = resolve.search_by_values({:name => 'name', :latitude => 37.63326, :longitude => -127.35625})
|
43
|
+
|
44
|
+
|
45
|
+
INSTALLATION
|
46
|
+
============
|
47
|
+
gem install factual
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/factual.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "factual/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "factual"
|
7
|
+
s.version = Factual::VERSION
|
8
|
+
s.authors = ["Justin Copeland"]
|
9
|
+
s.email = ["justin@gootnau.com"]
|
10
|
+
s.homepage = "http://github.com/jmcopeland/factual"
|
11
|
+
s.summary = %q{Factual v3 API wrapper}
|
12
|
+
s.description = %q{Factual v3 API wrapper}
|
13
|
+
|
14
|
+
s.rubyforge_project = "factual"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
s.add_runtime_dependency "httparty"
|
24
|
+
s.add_runtime_dependency "hashie"
|
25
|
+
s.add_runtime_dependency "rash"
|
26
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Factual
|
2
|
+
class CategoriesResponse
|
3
|
+
|
4
|
+
attr_accessor :body
|
5
|
+
|
6
|
+
def initialize(response)
|
7
|
+
@body = rash_response(response)
|
8
|
+
end
|
9
|
+
|
10
|
+
def error_message
|
11
|
+
# @body.message.text unless success?
|
12
|
+
end
|
13
|
+
|
14
|
+
def data
|
15
|
+
if !@body.blank?
|
16
|
+
@body
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def rash_response(response)
|
23
|
+
if response.is_a?(Array)
|
24
|
+
@body = []
|
25
|
+
response.each do |b|
|
26
|
+
if b.is_a?(Hash)
|
27
|
+
@body << Hashie::Rash.new(b)
|
28
|
+
else
|
29
|
+
@body << b
|
30
|
+
end
|
31
|
+
end
|
32
|
+
elsif response.is_a?(Hash)
|
33
|
+
@body = Hashie::Rash.new(response)
|
34
|
+
else
|
35
|
+
@body = response
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/lib/factual/core.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
module Factual
|
2
|
+
class CoreResponse
|
3
|
+
|
4
|
+
attr_accessor :body
|
5
|
+
|
6
|
+
def initialize(response)
|
7
|
+
@body = rash_response(response)
|
8
|
+
end
|
9
|
+
|
10
|
+
def version
|
11
|
+
@body.version
|
12
|
+
end
|
13
|
+
|
14
|
+
def status
|
15
|
+
@body.status
|
16
|
+
end
|
17
|
+
|
18
|
+
def success?
|
19
|
+
@body.status == "ok"
|
20
|
+
end
|
21
|
+
|
22
|
+
def error_message
|
23
|
+
# @body.message.text unless success?
|
24
|
+
end
|
25
|
+
|
26
|
+
def schema
|
27
|
+
if !@body.response.view.blank?
|
28
|
+
@body.response.view
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def rash_response(response)
|
35
|
+
if response.is_a?(Array)
|
36
|
+
@body = []
|
37
|
+
response.each do |b|
|
38
|
+
if b.is_a?(Hash)
|
39
|
+
@body << Hashie::Rash.new(b)
|
40
|
+
else
|
41
|
+
@body << b
|
42
|
+
end
|
43
|
+
end
|
44
|
+
elsif response.is_a?(Hash)
|
45
|
+
@body = Hashie::Rash.new(response)
|
46
|
+
else
|
47
|
+
@body = response
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Factual
|
2
|
+
class Crossref
|
3
|
+
|
4
|
+
attr_accessor :client
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
# optional parameters include:
|
11
|
+
# limit: default is 500, must use OAuth to exceed
|
12
|
+
def search_by_factual_id(factual_id, optional = {})
|
13
|
+
options = {:factual_id => factual_id}
|
14
|
+
process(options, optional)
|
15
|
+
end
|
16
|
+
|
17
|
+
# optional parameters include:
|
18
|
+
# limit: default is 500, must use OAuth to exceed
|
19
|
+
def search_by_url(url, optional = {})
|
20
|
+
options = {:url => url}
|
21
|
+
process(options, optional)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def process(options, optional)
|
27
|
+
options.merge!(optional) unless optional.blank?
|
28
|
+
PlacesResponse.new(@client.class.get('/places/crossref', :query => options))
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Factual
|
2
|
+
class Crosswalk
|
3
|
+
|
4
|
+
attr_accessor :client
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
# optional parameters include:
|
11
|
+
# limit: default is 50, must use OAuth to exceed
|
12
|
+
# only: namespace_id to restrict returns
|
13
|
+
def search_by_factual_id(factual_id, optional = {})
|
14
|
+
options = {:factual_id => factual_id}
|
15
|
+
process(options, optional)
|
16
|
+
end
|
17
|
+
|
18
|
+
# optional parameters include:
|
19
|
+
# limit: default is 50, must use OAuth to exceed
|
20
|
+
# only: namespace_id to restrict returns
|
21
|
+
def search_by_namespace(namespace, namespace_id, optional = {})
|
22
|
+
options = {:namespace => namespace, :namespace_id => namespace_id}
|
23
|
+
process(options, optional)
|
24
|
+
end
|
25
|
+
|
26
|
+
def namespaces
|
27
|
+
[
|
28
|
+
"allmenus",
|
29
|
+
"allpages",
|
30
|
+
"aol",
|
31
|
+
"chow",
|
32
|
+
"citysearch",
|
33
|
+
"dexknows",
|
34
|
+
"explore_to",
|
35
|
+
"facebook",
|
36
|
+
"foursquare",
|
37
|
+
"fwix",
|
38
|
+
"gogobot",
|
39
|
+
"gowalla",
|
40
|
+
"greatschools",
|
41
|
+
"grubhub",
|
42
|
+
"hotelscombined",
|
43
|
+
"hunch",
|
44
|
+
"insiderpages",
|
45
|
+
"loopt",
|
46
|
+
"manta",
|
47
|
+
"menupages",
|
48
|
+
"menupix",
|
49
|
+
"menuplatform",
|
50
|
+
"merchantcircle",
|
51
|
+
"openmenu",
|
52
|
+
"opentable",
|
53
|
+
"restaurants",
|
54
|
+
"retailigence",
|
55
|
+
"simplegeo",
|
56
|
+
"superpages",
|
57
|
+
"urbanspoon",
|
58
|
+
"yahoolocal",
|
59
|
+
"yellowbook",
|
60
|
+
"yelp",
|
61
|
+
"yp",
|
62
|
+
"zagat"
|
63
|
+
]
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def process(options, optional)
|
69
|
+
options.merge!(optional) unless optional.blank?
|
70
|
+
PlacesResponse.new(@client.class.get('/places/crosswalk', :query => options))
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Factual
|
2
|
+
class Places
|
3
|
+
|
4
|
+
attr_accessor :client
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
# http://developer.factual.com/display/docs/Core+API+-+Read
|
11
|
+
# Optional parameters:
|
12
|
+
# filters: http://developer.factual.com/display/docs/Core+API+-+Row+Filters
|
13
|
+
# include_count: default is false
|
14
|
+
# facet: comma seperated list of fields; returns counts grouped by distinct fields
|
15
|
+
# geo: send a hash {:latitude => lat, :longitude => lng, :radius => rad}
|
16
|
+
# limit: default is 20, max is 50
|
17
|
+
# q: full-text search, "sushi bar" searches for sushi AND bar; "sushi,bar" searches sushi OR bar
|
18
|
+
# offset
|
19
|
+
# select: fields to include in the query response
|
20
|
+
# sort: field_name:(asc|desc), $distance:(asc|desc), or $relevance:(asc|desc)
|
21
|
+
|
22
|
+
def search_table(optional = {})
|
23
|
+
optional[:geo] = create_geo_filter(optional[:geo]) if optional[:geo].exists?
|
24
|
+
PlacesResponse.new(@client.class.get("/t/<table_id>", :query => optional))
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def create_geo_filter(geo_hash)
|
29
|
+
return "{'$circle':{'$center':[#{geo_hash['latitude']}, #{geo_hash['longitude']}],'$meters':#{geo_hash['radius']}}}".to_json
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Factual
|
2
|
+
class PlacesResponse
|
3
|
+
|
4
|
+
attr_accessor :body
|
5
|
+
|
6
|
+
def initialize(response)
|
7
|
+
@body = rash_response(response)
|
8
|
+
end
|
9
|
+
|
10
|
+
def version
|
11
|
+
@body.version
|
12
|
+
end
|
13
|
+
|
14
|
+
def status
|
15
|
+
@body.status
|
16
|
+
end
|
17
|
+
|
18
|
+
def success?
|
19
|
+
@body.status == "ok"
|
20
|
+
end
|
21
|
+
|
22
|
+
def error_message
|
23
|
+
# @body.message.text unless success?
|
24
|
+
end
|
25
|
+
|
26
|
+
def included_rows
|
27
|
+
@body.included_rows
|
28
|
+
end
|
29
|
+
|
30
|
+
def total_rows
|
31
|
+
@body.total_row_count
|
32
|
+
end
|
33
|
+
|
34
|
+
def data
|
35
|
+
if !@body.response.data.blank?
|
36
|
+
@body.response.data
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def rash_response(response)
|
43
|
+
if response.is_a?(Array)
|
44
|
+
@body = []
|
45
|
+
response.each do |b|
|
46
|
+
if b.is_a?(Hash)
|
47
|
+
@body << Hashie::Rash.new(b)
|
48
|
+
else
|
49
|
+
@body << b
|
50
|
+
end
|
51
|
+
end
|
52
|
+
elsif response.is_a?(Hash)
|
53
|
+
@body = Hashie::Rash.new(response)
|
54
|
+
else
|
55
|
+
@body = response
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Factual
|
2
|
+
class Resolve
|
3
|
+
|
4
|
+
attr_accessor :client
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def search_by_values(params)
|
11
|
+
values = params.to_json
|
12
|
+
PlacesResponse.new(@client.class.get('/places/resolve', :query => {:values => values}))
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/lib/factual.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'httparty'
|
3
|
+
require 'hashie'
|
4
|
+
require 'rash'
|
5
|
+
|
6
|
+
require 'factual/categories'
|
7
|
+
require 'factual/categories_response'
|
8
|
+
require 'factual/client'
|
9
|
+
require 'factual/core'
|
10
|
+
require 'factual/core_response'
|
11
|
+
require 'factual/crossref'
|
12
|
+
require 'factual/crosswalk'
|
13
|
+
require 'factual/places'
|
14
|
+
require 'factual/places_response'
|
15
|
+
require 'factual/resolve'
|
16
|
+
require "factual/version"
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: factual
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: "0.1"
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Justin Copeland
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-12-07 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: httparty
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: hashie
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rash
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id003
|
48
|
+
description: Factual v3 API wrapper
|
49
|
+
email:
|
50
|
+
- justin@gootnau.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- .gitignore
|
59
|
+
- README
|
60
|
+
- Rakefile
|
61
|
+
- factual.gemspec
|
62
|
+
- lib/.DS_Store
|
63
|
+
- lib/factual.rb
|
64
|
+
- lib/factual/categories.rb
|
65
|
+
- lib/factual/categories_response.rb
|
66
|
+
- lib/factual/client.rb
|
67
|
+
- lib/factual/core.rb
|
68
|
+
- lib/factual/core_response.rb
|
69
|
+
- lib/factual/crossref.rb
|
70
|
+
- lib/factual/crosswalk.rb
|
71
|
+
- lib/factual/places.rb
|
72
|
+
- lib/factual/places_response.rb
|
73
|
+
- lib/factual/resolve.rb
|
74
|
+
- lib/factual/version.rb
|
75
|
+
homepage: http://github.com/jmcopeland/factual
|
76
|
+
licenses: []
|
77
|
+
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "0"
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: "0"
|
95
|
+
requirements: []
|
96
|
+
|
97
|
+
rubyforge_project: factual
|
98
|
+
rubygems_version: 1.8.12
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: Factual v3 API wrapper
|
102
|
+
test_files: []
|
103
|
+
|