Class: Fb::Page

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

Overview

Fb::Page reprensents a Facebook page. Provides methods to get/set a page’s name and id.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Page

Returns a new instance of Page.

Parameters:

  • options (Hash) (defaults to: {})

    the options to initialize an instance of Fb::Page.

  • [String] (Hash)

    a customizable set of options



16
17
18
19
20
# File 'lib/fb/page.rb', line 16

def initialize(options = {})
  @name = options["name"]
  @id = options["id"]
  @user = options["user"]
end

Instance Attribute Details

#idString (readonly)

Returns the unique id of the page.

Returns:

  • (String)

    the unique id of the page.



11
12
13
# File 'lib/fb/page.rb', line 11

def id
  @id
end

#nameString (readonly)

Returns the name of the page.

Returns:

  • (String)

    the name of the page.



8
9
10
# File 'lib/fb/page.rb', line 8

def name
  @name
end

Instance Method Details

#insights(options = {}) ⇒ Hash

Returns a collection of metrics with metric name as key and metric object as value.

Examples:

page = Fb::User.new('token').pages.first
page.insights(options)
=> {"page_fan_adds_unique"=>#<Fb::Metric:0x123abc
@name="page_fans", @description="Weekly: The
number of new people who have liked your Page (Unique Users)",
@value=123>,..}

Parameters:

  • options (Hash) (defaults to: {})

    to customize the insights returned from the API.

  • [String] (Hash)

    a customizable set of options

  • [Array<String, (Hash)

    a customizable set of options

Returns:

  • (Hash)

    a collection of metrics with metric name as key and metric object as value.



36
37
38
39
40
# File 'lib/fb/page.rb', line 36

def insights(options = {})
  fetch_insights(options)["data"].map do |metric_data|
    [metric_data["name"], Fb::Metric.new(metric_data)]
  end.to_h
end

#to_sString

Returns the representation of the page.

Returns:

  • (String)

    the representation of the page.



43
44
45
# File 'lib/fb/page.rb', line 43

def to_s
  "#<#{self.class.name} id=#{@id}, name=#{@name}>"
end