Skip to content

Commit

Permalink
Added :logging option to show queries
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Dec 29, 2011
1 parent cf96389 commit 48248ff
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
8 changes: 5 additions & 3 deletions Gemfile.lock
@@ -1,7 +1,8 @@
PATH
remote: .
specs:
fb_graph (2.2.3)
fb_graph (2.2.4)
colorize (~> 0.5.8)
httpclient (>= 2.2.0.2)
rack-oauth2 (>= 0.9.4)

Expand All @@ -28,6 +29,7 @@ GEM
addressable (2.2.6)
attr_required (0.0.3)
builder (3.0.0)
colorize (0.5.8)
configatron (2.8.4)
yamler (>= 0.1.0)
cover_me (1.2.0)
Expand All @@ -38,9 +40,9 @@ GEM
erubis (2.7.0)
hashie (1.2.0)
hike (1.2.1)
httpclient (2.2.3)
httpclient (2.2.4)
i18n (0.6.0)
json (1.6.1)
json (1.6.4)
multi_json (1.0.3)
rack (1.3.5)
rack-cache (1.1)
Expand Down
1 change: 1 addition & 0 deletions fb_graph.gemspec
Expand Up @@ -14,6 +14,7 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.add_runtime_dependency "httpclient", ">= 2.2.0.2"
s.add_runtime_dependency "rack-oauth2", ">= 0.9.4"
s.add_runtime_dependency "colorize", "~> 0.5.8"
s.add_development_dependency "rake", ">= 0.8"
if RUBY_VERSION >= '1.9'
s.add_development_dependency "cover_me", ">= 1.2.0"
Expand Down
7 changes: 6 additions & 1 deletion lib/fb_graph/node.rb
@@ -1,15 +1,17 @@
require 'tempfile'
require 'colorize'

module FbGraph
class Node
include Comparison

attr_accessor :identifier, :endpoint, :access_token
attr_accessor :identifier, :endpoint, :access_token, :logging

def initialize(identifier, options = {})
@identifier = identifier
@endpoint = File.join(ROOT_URL, identifier.to_s)
@access_token = options[:access_token]
@logging = options[:logging]
@cached_collections = {}
end

Expand Down Expand Up @@ -45,18 +47,21 @@ def destroy(options = {})
protected

def get(params = {})
puts "GET #{@identifier}: #{params.inspect}".colorize(:green) if @logging
handle_response do
http_client.get build_endpoint(params), build_params(params)
end
end

def post(params = {})
puts "POST #{@identifier}: #{params.inspect}".colorize(:blue) if @logging
handle_response do
http_client.post build_endpoint(params), build_params(params)
end
end

def delete(params = {})
puts "DELETE #{@identifier}: #{params.inspect}".colorize(:red) if @logging
_endpoint_, _params_ = build_endpoint(params), build_params(params)
_endpoint_ = [_endpoint_, _params_.try(:to_query)].compact.join('?')
handle_response do
Expand Down
3 changes: 2 additions & 1 deletion lib/fb_graph/searchable.rb
@@ -1,10 +1,11 @@
module FbGraph
module Searchable
def self.search(query, options = {})
logging = options.delete(:logging)
klass = options.delete(:class) || Searchable
query_param = klass.search_query_param
collection = Collection.new(
Node.new(:search).send(:get, options.merge(query_param.to_sym => query))
Node.new(:search, :logging => logging).send(:get, options.merge(query_param.to_sym => query))
)
yield collection if block_given?
Searchable::Result.new(query, klass, options.merge(:collection => collection))
Expand Down

0 comments on commit 48248ff

Please sign in to comment.