factual-api 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/lib/factual.rb +35 -3
- data/lib/factual/api.rb +7 -5
- data/lib/factual/write/clear.rb +36 -0
- data/lib/factual/write/insert.rb +36 -0
- metadata +4 -2
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## v1.3.2
|
2
|
+
* added integration test for unicode queries
|
3
|
+
* added insert
|
4
|
+
* changed factual-auth yaml file from under the integration test folder to ~/.factual
|
5
|
+
* added clear
|
6
|
+
* timeout support
|
7
|
+
|
1
8
|
## v1.3.1
|
2
9
|
* removed sugar crosswalk, switch to normal table
|
3
10
|
|
data/lib/factual.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'oauth'
|
3
|
+
|
1
4
|
require 'oauth'
|
2
5
|
require 'factual/api'
|
3
6
|
require 'factual/query/table'
|
@@ -9,13 +12,16 @@ require 'factual/query/geocode'
|
|
9
12
|
require 'factual/query/geopulse'
|
10
13
|
require 'factual/write/flag'
|
11
14
|
require 'factual/write/submit'
|
15
|
+
require 'factual/write/clear'
|
16
|
+
require 'factual/write/insert'
|
12
17
|
require 'factual/multi'
|
13
18
|
|
14
19
|
class Factual
|
15
20
|
def initialize(key, secret, options = {})
|
16
21
|
debug_mode = options[:debug].nil? ? false : options[:debug]
|
17
22
|
host = options[:host]
|
18
|
-
|
23
|
+
timeout = options[:timeout]
|
24
|
+
@api = API.new(generate_token(key, secret), debug_mode, host, timeout)
|
19
25
|
end
|
20
26
|
|
21
27
|
def table(table_id_or_alias)
|
@@ -63,7 +69,21 @@ class Factual
|
|
63
69
|
multi.send
|
64
70
|
end
|
65
71
|
|
66
|
-
def
|
72
|
+
def clear(*params)
|
73
|
+
fields = []
|
74
|
+
fields = params.pop if params.last.is_a? Array
|
75
|
+
|
76
|
+
table, user, factual_id = params
|
77
|
+
clear_params = {
|
78
|
+
:table => table,
|
79
|
+
:factual_id => factual_id,
|
80
|
+
:fields => fields.join(","),
|
81
|
+
:user => user }
|
82
|
+
|
83
|
+
Write::Clear.new(@api, clear_params)
|
84
|
+
end
|
85
|
+
|
86
|
+
def flag(table, user, factual_id, problem)
|
67
87
|
flag_params = {
|
68
88
|
:table => table,
|
69
89
|
:factual_id => factual_id,
|
@@ -75,7 +95,7 @@ class Factual
|
|
75
95
|
|
76
96
|
def submit(*params)
|
77
97
|
values = {}
|
78
|
-
values = params.
|
98
|
+
values = params.pop if params.last.is_a? Hash
|
79
99
|
|
80
100
|
table, user, factual_id = params
|
81
101
|
submit_params = {
|
@@ -86,6 +106,18 @@ class Factual
|
|
86
106
|
Write::Submit.new(@api, submit_params)
|
87
107
|
end
|
88
108
|
|
109
|
+
def insert(*params)
|
110
|
+
values = {}
|
111
|
+
values = params.pop if params.last.is_a? Hash
|
112
|
+
|
113
|
+
table, user = params
|
114
|
+
insert_params = {
|
115
|
+
:table => table,
|
116
|
+
:user => user,
|
117
|
+
:values => values }
|
118
|
+
Write::Insert.new(@api, insert_params)
|
119
|
+
end
|
120
|
+
|
89
121
|
private
|
90
122
|
|
91
123
|
def generate_token(key, secret)
|
data/lib/factual/api.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'cgi'
|
3
|
+
require 'timeout'
|
3
4
|
|
4
5
|
class Factual
|
5
6
|
class API
|
6
|
-
VERSION = "1.3.
|
7
|
+
VERSION = "1.3.2"
|
7
8
|
API_V3_HOST = "api.v3.factual.com"
|
8
9
|
DRIVER_VERSION_TAG = "factual-ruby-driver-v" + VERSION
|
9
10
|
PARAM_ALIASES = { :search => :q, :sort_asc => :sort }
|
10
11
|
|
11
|
-
def initialize(access_token, debug_mode = false, host = nil)
|
12
|
+
def initialize(access_token, debug_mode = false, host = nil, timeout = nil)
|
12
13
|
@access_token = access_token
|
13
14
|
@debug_mode = debug_mode
|
15
|
+
@timeout = timeout
|
14
16
|
@host = host || API_V3_HOST
|
15
17
|
end
|
16
18
|
|
@@ -92,9 +94,9 @@ class Factual
|
|
92
94
|
headers = { "X-Factual-Lib" => DRIVER_VERSION_TAG }
|
93
95
|
|
94
96
|
res = if (method == :get)
|
95
|
-
@access_token.get(url, headers)
|
97
|
+
Timeout::timeout(@timeout){ @access_token.get(url, headers) }
|
96
98
|
elsif (method == :post)
|
97
|
-
@access_token.post(url, body, headers)
|
99
|
+
Timeout::timeout(@timeout){ @access_token.post(url, body, headers) }
|
98
100
|
else
|
99
101
|
raise StandardError.new("Unknown http method")
|
100
102
|
end
|
@@ -125,7 +127,7 @@ class Factual
|
|
125
127
|
puts "--- Driver version: #{DRIVER_VERSION_TAG}"
|
126
128
|
puts "--- request debug ---"
|
127
129
|
puts "req url: #{url}"
|
128
|
-
puts "req method: #{method.upcase}"
|
130
|
+
puts "req method: #{method.to_s.upcase}"
|
129
131
|
puts "req headers: #{JSON.pretty_generate(headers)}"
|
130
132
|
puts "req body: #{body}" if body
|
131
133
|
puts "---------------------"
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'factual/write/base'
|
2
|
+
|
3
|
+
class Factual
|
4
|
+
module Write
|
5
|
+
class Clear < Base
|
6
|
+
VALID_KEYS = [
|
7
|
+
:table, :user,
|
8
|
+
:factual_id, :fields,
|
9
|
+
:comment, :reference
|
10
|
+
]
|
11
|
+
|
12
|
+
def initialize(api, params)
|
13
|
+
validate_params(params)
|
14
|
+
super(api, params)
|
15
|
+
end
|
16
|
+
|
17
|
+
VALID_KEYS.each do |key|
|
18
|
+
define_method(key) do |*args|
|
19
|
+
Clear.new(@api, @params.merge(key => form_value(args)))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def path
|
24
|
+
"/t/#{@params[:table]}/#{@params[:factual_id]}/clear"
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def validate_params(params)
|
30
|
+
params.keys.each do |key|
|
31
|
+
raise "Invalid submit option: #{key}" unless VALID_KEYS.include?(key)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'factual/write/base'
|
2
|
+
|
3
|
+
class Factual
|
4
|
+
module Write
|
5
|
+
class Insert < Base
|
6
|
+
VALID_KEYS = [
|
7
|
+
:table, :user,
|
8
|
+
:values,
|
9
|
+
:comment, :reference
|
10
|
+
]
|
11
|
+
|
12
|
+
def initialize(api, params)
|
13
|
+
validate_params(params)
|
14
|
+
super(api, params)
|
15
|
+
end
|
16
|
+
|
17
|
+
VALID_KEYS.each do |key|
|
18
|
+
define_method(key) do |*args|
|
19
|
+
Insert.new(@api, @params.merge(key => form_value(args)))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def path
|
24
|
+
"/t/#{@params[:table]}/insert"
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def validate_params(params)
|
30
|
+
params.keys.each do |key|
|
31
|
+
raise "Invalid insert option: #{key}" unless VALID_KEYS.include?(key)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: factual-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.3.
|
5
|
+
version: 1.3.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Rudiger Lippert
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2012-08
|
14
|
+
date: 2012-11-08 00:00:00 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: oauth
|
@@ -68,7 +68,9 @@ files:
|
|
68
68
|
- lib/factual/query/resolve.rb
|
69
69
|
- lib/factual/query/table.rb
|
70
70
|
- lib/factual/write/base.rb
|
71
|
+
- lib/factual/write/clear.rb
|
71
72
|
- lib/factual/write/flag.rb
|
73
|
+
- lib/factual/write/insert.rb
|
72
74
|
- lib/factual/write/submit.rb
|
73
75
|
- lib/factual.rb
|
74
76
|
- README.md
|