Skip to content
Browse files

Added debug mode

  • Loading branch information...
1 parent 59bfa4d commit 19447c3c816dc56823ed573983219e15292c212e @rudyl313 rudyl313 committed Mar 29, 2012
Showing with 15 additions and 3 deletions.
  1. +10 −0 README.md
  2. +2 −2 lib/factual.rb
  3. +3 −1 lib/factual/api.rb
View
10 README.md
@@ -413,5 +413,15 @@ forward-slash) and the request will be made using your OAuth token:
factual.read('/t/restaurants-us?filters={"name":{"$bw":"Star"}}&include_count=true')
````
+# Debug Mode
+To see the query paths generated by the driver you can use it in debug mode by passing true as
+the third argument of the Factual constructor. Here is an example in irb:
+
+````ruby
+> factual = Factual.new(key, secret, true)
+> factual.table("places").filters("name" => {"$bw" => "starbucks"})
+Request: http://api.v3.factual.com/t/places?filters=%7B%22name%22%3A%7B%22%24bw%22%3A%22starbucks%22%7D%7D
+ => [{"address"=>"11290 Donner Pass Rd", "category"=>"Food & Beverage > Cafes, Coffee Houses & Tea Houses", ...
+````
View
4 lib/factual.rb
@@ -5,8 +5,8 @@
require 'factual/query/crosswalk'
class Factual
- def initialize(key, secret)
- @api = API.new(generate_token(key, secret))
+ def initialize(key, secret, debug_mode = false)
+ @api = API.new(generate_token(key, secret), debug_mode)
end
def table(table_id_or_alias)
View
4 lib/factual/api.rb
@@ -7,8 +7,9 @@ class API
DRIVER_VERSION_TAG = "factual-ruby-driver-1.0"
PARAM_ALIASES = { :search => :q, :sort_asc => :sort }
- def initialize(access_token)
+ def initialize(access_token, debug_mode = false)
@access_token = access_token
+ @debug_mode = debug_mode
end
def execute(query, other_params={})
@@ -29,6 +30,7 @@ def raw_read(path)
def handle_request(action, path, params)
url = "#{API_V3_HOST}/#{path}?#{query_string(params)}"
+ puts "Request: #{url}" if @debug_mode
payload = JSON.parse(make_request(url).body)
handle_payload(payload)
end

0 comments on commit 19447c3

Please sign in to comment.
Something went wrong with that request. Please try again.