Class: Factual
- Inherits:
-
Object
show all
- Defined in:
- lib/factual.rb,
lib/factual/api.rb,
lib/factual/multi.rb,
lib/factual/query/base.rb,
lib/factual/write/base.rb,
lib/factual/write/flag.rb,
lib/factual/query/match.rb,
lib/factual/query/table.rb,
lib/factual/write/boost.rb,
lib/factual/write/clear.rb,
lib/factual/query/facets.rb,
lib/factual/write/insert.rb,
lib/factual/write/submit.rb,
lib/factual/query/resolve.rb
Defined Under Namespace
Modules: Query, Write
Classes: API, Multi
Instance Method Summary
collapse
-
#apply_header(key, value) ⇒ Object
-
#boost(table, user, factual_id, q) ⇒ Object
-
#clear(*params) ⇒ Object
-
#diffs(view, params = {}) ⇒ Object
-
#facets(table_id_or_alias) ⇒ Object
-
#flag(table, user, factual_id, problem, opts = {}) ⇒ Object
-
#get(path, query = {}) ⇒ Object
-
#initialize(key, secret, options = {}) ⇒ Factual
constructor
A new instance of Factual.
-
#insert(*params) ⇒ Object
-
#match(*args) ⇒ Object
-
#multi(queries) ⇒ Object
-
#post(path, body = {}) ⇒ Object
-
#resolve(*args) ⇒ Object
-
#resolve_absolute(*args) ⇒ Object
-
#submit(*params) ⇒ Object
-
#table(table_id_or_alias) ⇒ Object
Constructor Details
#initialize(key, secret, options = {}) ⇒ Factual
Returns a new instance of Factual.
25
26
27
28
29
30
|
# File 'lib/factual.rb', line 25
def initialize(key, secret, options = {})
debug_mode = options[:debug].nil? ? false : options[:debug]
host = options[:host]
timeout = options[:timeout]
@api = API.new(generate_token(key, secret), debug_mode, host, timeout)
end
|
Instance Method Details
32
33
34
|
# File 'lib/factual.rb', line 32
def (key, value)
@api.(key, value)
end
|
#boost(table, user, factual_id, q) ⇒ Object
102
103
104
105
106
107
108
109
110
|
# File 'lib/factual.rb', line 102
def boost(table, user, factual_id, q)
boost_params = {
:table => table,
:factual_id => factual_id,
:q => q,
:user => user }
Write::Boost.new(@api, boost_params)
end
|
#clear(*params) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/factual.rb', line 88
def clear(*params)
fields = []
fields = params.pop if params.last.is_a? Array
table, user, factual_id = params
clear_params = {
:table => table,
:factual_id => factual_id,
:fields => fields.join(","),
:user => user }
Write::Clear.new(@api, clear_params)
end
|
#diffs(view, params = {}) ⇒ Object
79
80
81
|
# File 'lib/factual.rb', line 79
def diffs(view, params = {})
@api.diffs(view, params)
end
|
#facets(table_id_or_alias) ⇒ Object
40
41
42
|
# File 'lib/factual.rb', line 40
def facets(table_id_or_alias)
Query::Facets.new(@api, "t/#{table_id_or_alias}")
end
|
#flag(table, user, factual_id, problem, opts = {}) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/factual.rb', line 112
def flag(table, user, factual_id, problem, opts={})
flag_params = {
:table => table,
:factual_id => factual_id,
:problem => problem,
:user => user }
data = opts[:data] || opts["data"]
flag_params[:data] = data if data
fields = opts[:fields] || opts["fields"]
flag_params[:fields] = fields if fields
Write::Flag.new(@api, flag_params)
end
|
#get(path, query = {}) ⇒ Object
71
72
73
|
# File 'lib/factual.rb', line 71
def get(path, query={})
@api.raw_get(path, query)
end
|
#insert(*params) ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/factual.rb', line 141
def insert(*params)
values = {}
values = params.pop if params.last.is_a? Hash
table, user = params
insert_params = {
:table => table,
:user => user,
:values => values }
Write::Insert.new(@api, insert_params)
end
|
#match(*args) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/factual.rb', line 44
def match(*args)
table = 'places'
values = args[-1]
if args.first.is_a?(String)
table = args[0]
end
Query::Match.new(@api, table, :values => values)
end
|
#multi(queries) ⇒ Object
83
84
85
86
|
# File 'lib/factual.rb', line 83
def multi(queries)
multi = Multi.new(@api, queries)
multi.send
end
|
#post(path, body = {}) ⇒ Object
75
76
77
|
# File 'lib/factual.rb', line 75
def post(path, body={})
@api.raw_post(path, body)
end
|
#resolve(*args) ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'lib/factual.rb', line 53
def resolve(*args)
table = 'places'
values = args[-1]
if args.first.is_a?(String)
table = args[0]
end
Query::Resolve.new(@api, table, :values => values)
end
|
#resolve_absolute(*args) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/factual.rb', line 62
def resolve_absolute(*args)
table = 'places'
values = args[-1]
if args.first.is_a?(String)
table = args[0]
end
Query::ResolveAbsolute.new(@api, table, :values => values)
end
|
#submit(*params) ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/factual.rb', line 128
def submit(*params)
values = {}
values = params.pop if params.last.is_a? Hash
table, user, factual_id = params
submit_params = {
:table => table,
:user => user,
:factual_id => factual_id,
:values => values }
Write::Submit.new(@api, submit_params)
end
|
#table(table_id_or_alias) ⇒ Object
36
37
38
|
# File 'lib/factual.rb', line 36
def table(table_id_or_alias)
Query::Table.new(@api, "t/#{table_id_or_alias}")
end
|