ruby-factual 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/factual.rb +35 -2
  2. metadata +4 -4
data/lib/factual.rb CHANGED
@@ -10,7 +10,7 @@
10
10
  require 'rubygems'
11
11
  require 'net/http'
12
12
  require 'json'
13
- require 'uri'
13
+ require 'cgi'
14
14
 
15
15
  module Factual
16
16
  # The start point of using Factual API
@@ -41,6 +41,11 @@ module Factual
41
41
  def get_table(table_key)
42
42
  Table.new(table_key, @adapter)
43
43
  end
44
+
45
+ # Get the token of a {shadow account}[http://wiki.developer.factual.com/f/shadow_input.png], it is a partner-only feature.
46
+ def get_token(unique_id)
47
+ return @adapter.get_token(unique_id)
48
+ end
44
49
  end
45
50
 
46
51
  # This class holds the metadata of a Factual table. The filter and sort methods are to filter and/or sort
@@ -189,6 +194,25 @@ module Factual
189
194
  return ret
190
195
  end
191
196
 
197
+ # Suggest values for a row with a token, it is similar to input, but merely for shadow accounts input, it is a parter-only feature.
198
+ #
199
+ # Parameters:
200
+ # * +token+
201
+ # * +values_hash+
202
+ # * +opts+
203
+ #
204
+ # Returns:
205
+ # { "subjectKey" => <subject_key>, "exists" => <true|false> }
206
+ # subjectKey: a Factual::Row object can be initialized by a subjectKey, e.g. Factual::Row.new(@table, subject_key)
207
+ # exists: if "exists" is true, it means an existing row is edited, otherwise, a new row added
208
+ #
209
+ # Sample:
210
+ # table.input "8kTXTBWBpNFLybFiDmApS9pnQyw2YkM4qImH2XpbC6AG1ixkZFCKKbx2Jk0cGl8Z", :two_letter_abbrev => 'NE', :state => 'Nebraska'
211
+ # table.input("8kTXTBWBpNFLybFiDmApS9pnQyw2YkM4qImH2XpbC6AG1ixkZFCKKbx2Jk0cGl8Z", {:two_letter_abbrev => 'NE', :state => 'Nebraska'}, {:source => 'http://website.com', :comments => 'cornhusker!'})
212
+ def input_with_token(token, values_hash, opts={})
213
+ return input(values_hash, opts.merge({ :token => token }))
214
+ end
215
+
192
216
  private
193
217
 
194
218
  def camelize(str)
@@ -378,10 +402,19 @@ module Factual
378
402
  return resp["response"]
379
403
  end
380
404
 
405
+ def get_token(unique_id)
406
+ url = "/sessions/get_token?uniqueId=#{unique_id}"
407
+ resp = api_call(url)
408
+
409
+ return resp["string"]
410
+ end
411
+
381
412
  def input(table_key, params)
382
- query_string = params.to_a.collect{ |k,v| URI.escape(k.to_s) + '=' + URI.escape(v.to_json) }.join('&')
413
+ token = params.delete(:token)
414
+ query_string = params.to_a.collect{ |k,v| CGI.escape(k.to_s) + '=' + CGI.escape(v.to_json) }.join('&')
383
415
 
384
416
  url = "/tables/#{table_key}/input.js?" + query_string
417
+ url += "&token=" + token if token
385
418
  resp = api_call(url)
386
419
 
387
420
  return resp['response']
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-factual
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Forrest Cao
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-15 00:00:00 +08:00
18
+ date: 2011-03-29 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency