class Fb::Page
Fb::Page
reprensents a Facebook page. Provides methods to get/set a page's name and id.
Attributes
id[R]
@return [String] the unique id of the page.
name[R]
@return [String] the name of the page.
Public Class Methods
new(options = {})
click to toggle source
@param [Hash] options the options to initialize an instance of Fb::Page
. @option [String] :name The name of the page. @option [String] :id The unique id of the page.
# File lib/fb/page.rb, line 16 def initialize(options = {}) @name = options["name"] @id = options["id"] @user = options["user"] end
Public Instance Methods
insights(options = {})
click to toggle source
@param [Hash] options to customize the insights returned from the API. @option [String] :since The lower bound of the time range to consider. @option [String] :period The aggregation period (must be available to all
given metrics).
@option [Array<String, Symbol>] :metric A list of metrics. @return [Hash] a collection of metrics with metric name as key
and metric object as value.
@example
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>,..}
# 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_s()
click to toggle source
@return [String] the representation of the page.
# File lib/fb/page.rb, line 43 def to_s "#<#{self.class.name} id=#{@id}, name=#{@name}>" end
Private Instance Methods
fetch_insights(options)
click to toggle source
# File lib/fb/page.rb, line 49 def fetch_insights(options) unless options[:metric] raise Fb::Error, 'Missing required parameter: metric' end insights_params = options.merge(metric: options[:metric].join(","), access_token: @user.send(:access_token)) Fb::Request.new( path: "/v2.9/#{@id}/insights", params: insights_params ).run end