Class: FBGraph::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/fbgraph/base.rb

Direct Known Subclasses

FQL, Realtime, Search, Selection, Timeline

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Base

Returns a new instance of Base



7
8
9
10
11
# File 'lib/fbgraph/base.rb', line 7

def initialize(client)
  @client = client
  @fields = []
  @params = {}
end

Instance Attribute Details

#connection_typeObject (readonly)

Returns the value of attribute connection_type



5
6
7
# File 'lib/fbgraph/base.rb', line 5

def connection_type
  @connection_type
end

#last_resultObject (readonly)

Returns the value of attribute last_result



5
6
7
# File 'lib/fbgraph/base.rb', line 5

def last_result
  @last_result
end

#loggerObject (readonly)

Returns the value of attribute logger



5
6
7
# File 'lib/fbgraph/base.rb', line 5

def logger
  @logger
end

#objectsObject (readonly)

Returns the value of attribute objects



5
6
7
# File 'lib/fbgraph/base.rb', line 5

def objects
  @objects
end

Instance Method Details

#connection(connection_type) ⇒ Object



18
19
20
21
# File 'lib/fbgraph/base.rb', line 18

def connection(connection_type)
  @connection_type = connection_type
  return self
end

#debug=(att) ⇒ Object



92
93
94
# File 'lib/fbgraph/base.rb', line 92

def debug=(att)
  @debug= att
end

#delete!(parsed = true, &block) ⇒ Object



73
74
75
76
77
78
79
80
81
# 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) ⇒ Object



13
14
15
16
# File 'lib/fbgraph/base.rb', line 13

def find(objects)
  @objects = objects
  return self
end

#info!(parsed = true, &block) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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) ⇒ Object



32
33
34
35
# File 'lib/fbgraph/base.rb', line 32

def param(pm)
  @params.merge!(pm)
  return self
end

#paramsObject



28
29
30
# File 'lib/fbgraph/base.rb', line 28

def params
  @params
end

#params=(ps) ⇒ Object



23
24
25
26
# File 'lib/fbgraph/base.rb', line 23

def params=(ps)
  @params = ps
  return self
end

#publish!(data = {}, parsed = true, &block) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# 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) ⇒ Object Also known as: fields



37
38
39
40
41
# 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