Class: MiniFB::GraphObject
- Inherits:
-
Object
- Object
- MiniFB::GraphObject
show all
- Defined in:
- lib/mini_fb.rb
Overview
Wraps a graph object for easily accessing its connections
Instance Method Summary
collapse
Constructor Details
#initialize(session_or_token, id) ⇒ GraphObject
Creates a GraphObject using an OAuthSession or access_token
367
368
369
370
371
372
373
374
375
376
|
# File 'lib/mini_fb.rb', line 367
def initialize(session_or_token, id)
@oauth_session = if session_or_token.is_a?(MiniFB::OAuthSession)
session_or_token
else
MiniFB::OAuthSession.new(session_or_token)
end
@id = id
@object = @oauth_session.get(id, :metadata => true)
@connections_cache = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
406
407
408
409
410
411
412
413
414
415
416
417
|
# File 'lib/mini_fb.rb', line 406
def method_missing(method, *args, &block)
key = method.to_s
if @object.keys.include?(key)
@object[key]
elsif @connections_cache.has_key?(key)
@connections_cache[key]
elsif connections.include?(key)
@connections_cache[key] = @oauth_session.get(@id, :type => key)
else
super
end
end
|
Instance Method Details
#[](key) ⇒ Object
402
403
404
|
# File 'lib/mini_fb.rb', line 402
def [](key)
@object[key]
end
|
#connections ⇒ Object
382
383
384
|
# File 'lib/mini_fb.rb', line 382
def connections
@object.metadata.connections.keys
end
|
#inspect ⇒ Object
378
379
380
|
# File 'lib/mini_fb.rb', line 378
def inspect
"<##{self.class.name} #{@object.inspect}>"
end
|
#keys ⇒ Object
398
399
400
|
# File 'lib/mini_fb.rb', line 398
def keys
@object.keys
end
|
#methods ⇒ Object
390
391
392
|
# File 'lib/mini_fb.rb', line 390
def methods
super + @object.keys.include?(key) + connections.include?(key)
end
|
#respond_to?(method) ⇒ Boolean
394
395
396
|
# File 'lib/mini_fb.rb', line 394
def respond_to?(method)
@object.keys.include?(key) || connections.include?(key) || super
end
|