class FBGraph::Base
Attributes
connection_type[R]
fields[R]
last_result[R]
logger[R]
objects[R]
Public Class Methods
new(client)
click to toggle source
# File lib/fbgraph/base.rb, line 7 def initialize(client) @client = client @fields = [] @params = {} end
Public Instance Methods
connection(connection_type)
click to toggle source
# File lib/fbgraph/base.rb, line 18 def connection(connection_type) @connection_type = connection_type return self end
debug=(att)
click to toggle source
# File lib/fbgraph/base.rb, line 92 def debug=(att) @debug= att end
delete!(parsed = true, &block)
click to toggle source
# File lib/fbgraph/base.rb, line 73 def delete!(parsed = true, &block) self.instance_eval(&block) if block_given? @path = build_open_graph_path(@objects , nil) @params.merge!(:access_token => @client.access_token) if (@client.access_token) @params.merge!(:method => :delete) show_log('DELETE' , @path, @params) if @debug result = @client.consumer[@path].post(@params) @last_result = ::FBGraph::Result.new(result, @params) end
find(objects)
click to toggle source
# File lib/fbgraph/base.rb, line 13 def find(objects) @objects = objects return self end
info!(parsed = true, &block)
click to toggle source
# File lib/fbgraph/base.rb, line 44 def info!(parsed = true, &block) self.instance_eval(&block) if block_given? @params.merge!(:fields => sanitized_fields.join(',')) unless sanitized_fields.blank? @params.merge!(:access_token => @client.access_token) unless @client.access_token.nil? if @objects.is_a? Array @params.merge!({:ids => @objects.join(',')}) path = build_open_graph_path(nil,nil, @params) elsif @objects.is_a? String path = build_open_graph_path(@objects , @connection_type, @params) else raise "No Facebook objects were recognized as selected; unable to build fb graph path." end show_log('GET' , path, @params) if @debug result = @client.consumer[path].get @last_result = ::FBGraph::Result.new(result, @params) end
param(pm)
click to toggle source
# File lib/fbgraph/base.rb, line 32 def param(pm) @params.merge!(pm) return self end
params()
click to toggle source
# File lib/fbgraph/base.rb, line 28 def params @params end
params=(ps)
click to toggle source
# File lib/fbgraph/base.rb, line 23 def params=(ps) @params = ps return self end
publish!(data = {},parsed = true, &block)
click to toggle source
# File lib/fbgraph/base.rb, line 62 def publish!(data = {},parsed = true, &block) @params.merge!(data) self.instance_eval(&block) if block_given? @params.merge!(:fields => sanitized_fields.join(',')) unless sanitized_fields.blank? @params.merge!(:access_token => @client.access_token) if (@client.access_token) @path = build_open_graph_path(@objects , @connection_type) show_log('POST' , @path, @params) if @debug result = @client.consumer[@path].post(@params) @last_result = ::FBGraph::Result.new(result, @params) end
with_fields(*new_fields)
click to toggle source
# File lib/fbgraph/base.rb, line 37 def with_fields(*new_fields) @fields.concat(new_fields) if !(new_fields.blank? rescue true) @fields = sanitized_fields self end
Also aliased as: fields
Private Instance Methods
build_open_graph_path(objects, connection_type = nil , params = {})
click to toggle source
# File lib/fbgraph/base.rb, line 102 def build_open_graph_path(objects, connection_type = nil , params = {}) request = [objects , connection_type].compact.join('/') request += "?"+params.to_a.map{|p| p.join('=')}.join('&') unless params.empty? URI.encode(request) end
sanitized_fields()
click to toggle source
# File lib/fbgraph/base.rb, line 98 def sanitized_fields @fields.flatten.map(&:to_s).compact end
show_log(ver, path, params)
click to toggle source
# File lib/fbgraph/base.rb, line 108 def show_log(ver, path, params) client.logger.info "FBGRAPH [#{verb}]: #{path}" client.logger.info "PARAMS: #{params.to_a.map{|p| p.join('=')}.join('&')}" end