Class: Factual

Inherits:
Object
  • 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/geocode.rb,
lib/factual/query/resolve.rb,
lib/factual/query/geopulse.rb

Defined Under Namespace

Modules: Query, Write Classes: API, Multi

Instance Method Summary collapse

Constructor Details

#initialize(key, secret, options = {}) ⇒ Factual

Returns a new instance of Factual.



27
28
29
30
31
32
# File 'lib/factual.rb', line 27

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

#apply_header(key, value) ⇒ Object



34
35
36
# File 'lib/factual.rb', line 34

def apply_header(key, value)
  @api.apply_header(key, value)
end

#boost(table, user, factual_id, q) ⇒ Object



103
104
105
106
107
108
109
110
111
# File 'lib/factual.rb', line 103

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



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/factual.rb', line 89

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



80
81
82
# File 'lib/factual.rb', line 80

def diffs(view, params = {})
  @api.diffs(view, params)
end

#facets(table_id_or_alias) ⇒ Object



42
43
44
# File 'lib/factual.rb', line 42

def facets(table_id_or_alias)
  Query::Facets.new(@api, "t/#{table_id_or_alias}")
end

#flag(table, user, factual_id, problem, opts = {}) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/factual.rb', line 113

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

#geocode(lat, lng) ⇒ Object



64
65
66
# File 'lib/factual.rb', line 64

def geocode(lat, lng)
  Query::Geocode.new(@api, lat, lng)
end

#geopulse(lat, lng) ⇒ Object



68
69
70
# File 'lib/factual.rb', line 68

def geopulse(lat, lng)
  Query::Geopulse.new(@api, lat, lng)
end

#get(path, query = {}) ⇒ Object



72
73
74
# File 'lib/factual.rb', line 72

def get(path, query={})
  @api.raw_get(path, query)
end

#insert(*params) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/factual.rb', line 142

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



46
47
48
49
50
51
52
53
# File 'lib/factual.rb', line 46

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



84
85
86
87
# File 'lib/factual.rb', line 84

def multi(queries)
  multi = Multi.new(@api, queries)
  multi.send
end

#post(path, body = {}) ⇒ Object



76
77
78
# File 'lib/factual.rb', line 76

def post(path, body={})
  @api.raw_post(path, body)
end

#resolve(*args) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/factual.rb', line 55

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

#submit(*params) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/factual.rb', line 129

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



38
39
40
# File 'lib/factual.rb', line 38

def table(table_id_or_alias)
  Query::Table.new(@api, "t/#{table_id_or_alias}")
end