Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
THIS PROJECT IS DEPRECATED. Please use https://github.com/Factual/factual-ruby-driver. Ruby gem to access Factual API v2. Since the Factual API v2 will be deprecated in Q2 2012, and we are moving forward to API v3, there is new ruby gem for V3 accessing, which is at https://github.com/Factual/factual-ruby-driver.
Ruby
Branch: master

README.md

THIS PROJECT IS DEPRECATED. Please use https://github.com/Factual/factual-ruby-driver.

Important Notes

Factual is deprecating the v2 APIs. We have released a new ruby gem for the new API (v3), and you can find it here: https://github.com/Factual/factual-ruby-driver. If you do not have a v3 API Key, please go applying one at: http://www.factual.com/devtools/beta.

Sample Usage

A block of code is worth a thousand words.

require 'rubygems'
gem 'ruby-factual'
require 'factual'

api = Factual::Api.new(:api_key => "<YOUR_FACTUAL_API_KEY>")

# get table and its metadata
# table metadata: name, description, rating, source, creator, created_at,
#                 updated_at, total_row_count, geo_enabled, downloadable, 
#                 fields (array of hash)
table = api.get_table("g9R1u2")
puts table.name, table.creator

# read rows after filtering and sorting
table.filter(:two_letter_abbrev => "CA").sort(:state => -1).page(1, :size => 5).each_row do |state_info|

  # read facts
  # fact attributes: value, subject_key, field_ref, field (hash)
  fact = state_info["state"]
  puts fact.value, fact.subject_key

  # write facts
  if fact.input("Kalifornia", :source => "source", :comment => "comment")
    puts "inputted"
  end
end

# you can also get rows by search
row = table.search("hawaii").find_one
puts row["state"]

# add a row
ret = table.input(:state => "Nebraska", :two_letter_abbrev => "NE")

# get a row object from resp
subject_key = ret["subjectKey"]
row = Factual::Row.new(table, subject_key)
puts row["state"].value

THIS PROJECT IS DEPRECATED. Please use https://github.com/Factual/factual-ruby-driver.

Something went wrong with that request. Please try again.