class Funky::Page

Public Class Methods

find(page_id) click to toggle source

Fetches the data from Facebook Graph API and returns a Funky::Page object. It accepts a page ID.

@example Getting a page object

Funky::Page.find 'FullscreenInc' # or
Funky::Page.find '221406534569729'
# => #<Funky::Page @data={:name=>"Fullscreen", :id=>"221406534569729"}>

@return [Funky::Page] containing the data fetched by Facebook Graph API.

# File lib/funky/page.rb, line 13
def self.find(page_id)
  page = Funky::Connection::API.fetch("#{page_id}?fields=name,username,location,fan_count,featured_video")
  if page[:name].nil?
    raise ContentNotFound, "Page not found with ID #{page_id}"
  else
    new(page)
  end
end
where(id:) click to toggle source

Fetches the data from Facebook's APIs and instantiates the data into an Array of Funky::Page objects. It can accept one page ID or an array of multiple page IDs.

@example Getting one page

id = '10153834590672139'
Funky::Page.where(id: id) # => [#<Funky::Page>]

@example Getting multiple videos

ids = ['10154439119663508', '10153834590672139']
Funky::Page.where(id: ids) # => [#<Funky::Page>, #<Funky::Page>]

@return [Array<Funky::Page>] multiple instances of Funky::Page objects

containing data obtained by Facebook's APIs.
# File lib/funky/page.rb, line 152
def self.where(id:)
  return nil unless id
  instantiate_collection(fetch_and_parse_data Array(id))
end

Private Class Methods

fields() click to toggle source
# File lib/funky/page.rb, line 159
def self.fields
  [
    'name',
    'username',
    'location'
  ]
end

Public Instance Methods

city() click to toggle source

@see developers.facebook.com/docs/graph-api/reference/location/ @return [String, nil] the city of the Facebook Page if it is present

# File lib/funky/page.rb, line 99
def city
  location[:city]
end
country() click to toggle source

@see developers.facebook.com/docs/graph-api/reference/location/ @return [String, nil] the country of the Facebook Page if it is present

# File lib/funky/page.rb, line 117
def country
  location[:country]
end
fan_count() click to toggle source

@return [Integer] the number of people who likes the Facebook page.

# File lib/funky/page.rb, line 79
def fan_count
  data[:fan_count]
end
latitude() click to toggle source

@see developers.facebook.com/docs/graph-api/reference/location/ @return [Fixnum, nil] the latitude of the Facebook Page if it is present

# File lib/funky/page.rb, line 129
def latitude
  location[:latitude]
end
location() click to toggle source

@note

location is a Hash that contains more specific properties such as city,
state, zip, etc.

@see developers.facebook.com/docs/graph-api/reference/page/ @return [Hash] the location of the Facebook Page if it is present

# File lib/funky/page.rb, line 93
def location
  data.fetch(:location, {})
end
longitude() click to toggle source

@see developers.facebook.com/docs/graph-api/reference/location/ @return [Fixnum, nil] the longitude of the Facebook Page if it is present

# File lib/funky/page.rb, line 135
def longitude
  location[:longitude]
end
name() click to toggle source

@note

For example, for www.facebook.com/platform the name is
'Facebook For Developers'.

@see developers.facebook.com/docs/graph-api/reference/page/ @return [String] the name of the Facebook Page.

# File lib/funky/page.rb, line 74
def name
  data[:name]
end
posts(options = {}) click to toggle source

Fetches data from Facebook Graph API and returns an array of Funky::Post objects belong to the caller page.

@example Getting posts under a page

page = Funky::Page.find 'FullscreenInc'
page.posts
# => [#<Funky::Post @data={...}>, #<Funky::Post @data={...}>]

@return [Array<Funky::Post>] multiple Funky::Post objects containing data

fetched by Facebook Graph API.
# File lib/funky/page.rb, line 54
def posts(options = {})
  path_query = "#{id}/posts?fields=type,created_time"
  path_query << "&since=#{options[:since]}" if options[:since]
  posts = Funky::Connection::API.fetch_all(path_query)
  posts.map {|post| Post.new(post)}
end
state() click to toggle source

@see developers.facebook.com/docs/graph-api/reference/location/ @return [String, nil] the state of the Facebook Page if it is present

# File lib/funky/page.rb, line 111
def state
  location[:state]
end
street() click to toggle source

@see developers.facebook.com/docs/graph-api/reference/location/ @return [String, nil] the street of the Facebook Page if it is present

# File lib/funky/page.rb, line 105
def street
  location[:street]
end
username() click to toggle source

@note

For example, for www.facebook.com/platform the username is 'platform'.

@see developers.facebook.com/docs/graph-api/reference/page/ @return [String] the alias of the Facebook Page.

# File lib/funky/page.rb, line 65
def username
  data[:username]
end
videos(options = {}) click to toggle source

Fetches data from Facebook Graph API and returns an array of Funky::Video objects belong to the caller page.

@example Getting videos under a page

page = Funky::Page.find 'FullscreenInc'
page.videos
# => [#<Funky::Video @data={...}>, #<Funky::Video @data={...}>]

@return [Array<Funky::Video>] multiple Funky::Video objects containing data

fetched by Facebook Graph API.
# File lib/funky/page.rb, line 32
def videos(options = {})
  path_query = "#{id}/videos?fields=id,title,description,created_time,length,comments.limit(0).summary(true),likes.limit(0).summary(true),reactions.limit(0).summary(true)"
  videos = []
  if options[:since]
    path_query << "&since=#{options[:since]}"
    videos = Funky::Connection::API.fetch_all(path_query)
  else
    videos = Funky::Connection::API.fetch(path_query, is_array: true)
  end
  videos.map {|video| Video.new(video) }
end
zip() click to toggle source

@see developers.facebook.com/docs/graph-api/reference/location/ @return [String] the zip code of the Facebook Page if it is present

# File lib/funky/page.rb, line 123
def zip
  location[:zip]
end