factual-api 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -0
- data/lib/factual/api.rb +12 -9
- data/lib/factual/multi.rb +5 -8
- data/lib/factual/query/resolve.rb +1 -1
- metadata +2 -2
data/CHANGELOG.md
CHANGED
data/lib/factual/api.rb
CHANGED
@@ -4,7 +4,7 @@ require 'timeout'
|
|
4
4
|
|
5
5
|
class Factual
|
6
6
|
class API
|
7
|
-
VERSION = "1.3.
|
7
|
+
VERSION = "1.3.4"
|
8
8
|
API_V3_HOST = "api.v3.factual.com"
|
9
9
|
DRIVER_VERSION_TAG = "factual-ruby-driver-v" + VERSION
|
10
10
|
PARAM_ALIASES = { :search => :q, :sort_asc => :sort }
|
@@ -22,9 +22,7 @@ class Factual
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def post(request)
|
25
|
-
|
26
|
-
payload = JSON.parse(response.body)
|
27
|
-
handle_payload(payload)
|
25
|
+
handle_request(nil, request.path, request.body, :post)
|
28
26
|
end
|
29
27
|
|
30
28
|
def schema(query)
|
@@ -68,12 +66,17 @@ class Factual
|
|
68
66
|
|
69
67
|
private
|
70
68
|
|
71
|
-
def handle_request(action, path, params)
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
def handle_request(action, path, params, method=:get)
|
70
|
+
if (method == :get)
|
71
|
+
url = "http://#{@host}" + full_path(action, path, params)
|
72
|
+
req = make_request(url)
|
73
|
+
else
|
74
|
+
url = "http://#{@host}#{path}"
|
75
|
+
req = make_request(url, params, :post)
|
76
|
+
end
|
77
|
+
payload = JSON.parse(req.body)
|
75
78
|
|
76
|
-
if (path ==
|
79
|
+
if (path == '/multi')
|
77
80
|
payload.inject({}) do |res, item|
|
78
81
|
name, p = item
|
79
82
|
res[name] = handle_payload(p)
|
data/lib/factual/multi.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
class Factual
|
2
2
|
class Multi
|
3
|
-
attr_reader :action, :path
|
3
|
+
attr_reader :action, :path
|
4
4
|
|
5
5
|
def initialize(api, queries)
|
6
6
|
@api = api
|
7
7
|
@queries = queries
|
8
8
|
|
9
9
|
@action = nil
|
10
|
-
@path =
|
11
|
-
@params = queries_param
|
10
|
+
@path = '/multi'
|
12
11
|
|
13
12
|
@responses = {}
|
14
13
|
end
|
15
14
|
|
16
15
|
def send
|
17
|
-
res = @api.
|
16
|
+
res = @api.post(self)
|
18
17
|
@queries.each do |name, query|
|
19
18
|
query.populate(res[name.to_s])
|
20
19
|
@responses[name] = query
|
@@ -23,15 +22,13 @@ class Factual
|
|
23
22
|
@responses
|
24
23
|
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
def queries_param
|
25
|
+
def body
|
29
26
|
query_urls = {}
|
30
27
|
@queries.each do |name, query|
|
31
28
|
query_urls[name] = query.full_path
|
32
29
|
end
|
33
30
|
|
34
|
-
{
|
31
|
+
"queries=#{ CGI.escape(query_urls.to_json) }"
|
35
32
|
end
|
36
33
|
|
37
34
|
end
|
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.
|
4
|
+
version: 1.3.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-01-
|
13
|
+
date: 2013-01-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: oauth
|