Class: FacebookClient::Graph

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fb, access_token, expires = nil) ⇒ Graph

Returns a new instance of Graph.



11
12
13
14
15
16
# File 'lib/graph.rb', line 11

def initialize(fb, access_token, expires = nil)
  @fb           = fb
  @access_token = access_token
  expires       = 0 if expires.nil?
  expires       = expires.to_i
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



9
10
11
# File 'lib/graph.rb', line 9

def access_token
  @access_token
end

Instance Method Details

#connectionObject



37
38
39
40
41
42
# File 'lib/graph.rb', line 37

def connection
  @connection ||= Faraday::Connection.new(:url => Base::GRAPH_URL) do |builder|
    builder.adapter :net_http
    builder.response :yajl
  end
end

#get(path, params = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/graph.rb', line 18

def get(path, params = {})
  params = params.stringify_keys
  params['access_token'] = @access_token
  response = connection.run_request(:get, path, nil, {}) do |request|
    request.params.update(params)
  end
  response = parse_response(response)
  return response
end

#parse_response(response) ⇒ Object

processing access token.”, “type”=>“OAuthException”}



29
30
31
32
33
34
35
# File 'lib/graph.rb', line 29

def parse_response(response)
  body = response.body
  if body.is_a?(Hash) and body.has_key?('error')
    raise ResponseError, "#{body['error']['message']}"
  end
  return body
end