Permalink
Browse files

Initial commit for documentation

  • Loading branch information...
1 parent 5ab978e commit e32695ddd035f0a36d4f3a79dbbea98f345eb4de Shreya Bhatia committed Oct 7, 2011
Showing with 8 additions and 24 deletions.
  1. +8 −24 README.md
View
@@ -1,6 +1,7 @@
## Sample Usage
A block of code is worth a thousand words.
+Supports Factual API v3 beta
require 'rubygems'
gem 'ruby-factual'
@@ -9,34 +10,17 @@ A block of code is worth a thousand words.
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
+ # table metadata: name, description, title, geo_enabled etc
+ table = api.get_table("places")
+ puts table.name, table.title
# read rows after filtering and sorting
- table.filter(:two_letter_abbrev => "CA").sort(:state => -1).page(1, :size => 5).each_row do |state_info|
+ table.filter(:name => "CA").sort(:name => 'asc').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
+ fact = state_info["region"]
+ puts fact.value, fact.subject_keys
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
+ puts row["region"]

0 comments on commit e32695d

Please sign in to comment.