class Factual
Public Class Methods
new(key, secret, options = {})
click to toggle source
# 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
Public Instance Methods
apply_header(key, value)
click to toggle source
# File lib/factual.rb, line 32 def apply_header(key, value) @api.apply_header(key, value) end
boost(table, user, factual_id, q)
click to toggle source
# 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)
click to toggle source
# 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 = {})
click to toggle source
# File lib/factual.rb, line 79 def diffs(view, params = {}) @api.diffs(view, params) end
facets(table_id_or_alias)
click to toggle source
# 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={})
click to toggle source
# 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={})
click to toggle source
# File lib/factual.rb, line 71 def get(path, query={}) @api.raw_get(path, query) end
insert(*params)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/factual.rb, line 83 def multi(queries) multi = Multi.new(@api, queries) multi.send end
post(path, body={})
click to toggle source
# File lib/factual.rb, line 75 def post(path, body={}) @api.raw_post(path, body) end
resolve(*args)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/factual.rb, line 36 def table(table_id_or_alias) Query::Table.new(@api, "t/#{table_id_or_alias}") end
Private Instance Methods
generate_token(key, secret)
click to toggle source
# File lib/factual.rb, line 155 def generate_token(key, secret) OAuth::AccessToken.new(OAuth::Consumer.new(key, secret)) end