Class: FbGraphApi::Profile

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

Overview

This module provides API requests to get facebook profile details and profile picture

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token = nil) ⇒ Profile

Intialize connection Reverses the contents of a String or IO object.

Parameters:

  • token (String) (defaults to: nil)


13
14
15
16
# File 'lib/fb_graph_api/profile.rb', line 13

def initialize(token = nil)
  client = FbGraphApi::Client.new(token)
  @connection = client.connection
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/fb_graph_api/profile.rb', line 8

def id
  @id
end

Instance Method Details

#infoObject

Retrieve profile details

Returns:

  • Object of facebook profile details



20
21
22
23
24
# File 'lib/fb_graph_api/profile.rb', line 20

def info
  response = @connection.get 'me'
  self.id =  response.body["id"].to_i
  OpenStruct.new(response.body)
end

#picture(size = 'large') ⇒ Object

Retrieve facebook picture

Parameters:

  • size (String) (defaults to: 'large')

Returns:

  • Object of facebook picture



30
31
32
33
34
# File 'lib/fb_graph_api/profile.rb', line 30

def picture(size = 'large')
  info unless id
  response = @connection.get "#{@id}/picture", {type: size}
  OpenStruct.new(response.env.response_headers)
end