Class: MetaGraph::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/meta_graph/client.rb

Overview

Graph API Client class.

To get a user data, photo data, album data, and so on from Facebook’s Graph API. First, create this client and call the get method, then you can get a instance of Node class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ Client

Create and initialize Graph API Client.

Argument

access_token

access token to read a data from Graph API. Please set to oauth’s access_token.



19
20
21
# File 'lib/meta_graph/client.rb', line 19

def initialize(access_token)
  @access_token = access_token
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



10
11
12
# File 'lib/meta_graph/client.rb', line 10

def access_token
  @access_token
end

Instance Method Details

#fetch(path) ⇒ Object

Get a data from Graph API.

Argument

path

ID you want or full URL.



29
30
31
32
33
34
35
36
37
# File 'lib/meta_graph/client.rb', line 29

def fetch(path)
  resource = Resource.new(@access_token, path.to_s)

  if resource.data && resource.data.is_a?(Array)
    Collection.new(@access_token, resource.data)
  else
    Node.new(@access_token, resource)
  end
end

#meObject

Get a your User data from Graph API. It equals to fetch(‘me’).



42
43
44
# File 'lib/meta_graph/client.rb', line 42

def me
  fetch(:me)
end