Class: Funky::Page
- Inherits:
-
GraphRootNode
- Object
- GraphRootNode
- Funky::Page
- Defined in:
- lib/funky/page.rb
Instance Attribute Summary
Attributes inherited from GraphRootNode
Class Method Summary collapse
-
.find(page_id) ⇒ Funky::Page
Fetches the data from Facebook Graph API and returns a Funky::Page object.
-
.where(id:) ⇒ Array<Funky::Page>
Fetches the data from Facebook’s APIs and instantiates the data into an Array of Funky::Page objects.
Instance Method Summary collapse
-
#city ⇒ String?
The city of the Facebook Page if it is present.
-
#country ⇒ String?
The country of the Facebook Page if it is present.
-
#fan_count ⇒ Integer
The number of people who likes the Facebook page.
-
#has_featured_video? ⇒ Boolean
If the Facebook page has featured_video.
-
#latitude ⇒ Fixnum?
The latitude of the Facebook Page if it is present.
-
#location ⇒ Hash
The location of the Facebook Page if it is present.
-
#longitude ⇒ Fixnum?
The longitude of the Facebook Page if it is present.
-
#name ⇒ String
The name of the Facebook Page.
-
#posts(options = {}) ⇒ Array<Funky::Post>
Fetches data from Facebook Graph API and returns an array of Funky::Post objects belong to the caller page.
-
#state ⇒ String?
The state of the Facebook Page if it is present.
-
#street ⇒ String?
The street of the Facebook Page if it is present.
-
#username ⇒ String
The alias of the Facebook Page.
-
#videos(options = {}) ⇒ Array<Funky::Video>
Fetches data from Facebook Graph API and returns an array of Funky::Video objects belong to the caller page.
-
#zip ⇒ String
The zip code of the Facebook Page if it is present.
Methods inherited from GraphRootNode
Constructor Details
This class inherits a constructor from Funky::GraphRootNode
Class Method Details
.find(page_id) ⇒ Funky::Page
Fetches the data from Facebook Graph API and returns a Funky::Page object. It accepts a page ID.
13 14 15 16 17 18 19 20 |
# 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:) ⇒ Array<Funky::Page>
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.
152 153 154 155 |
# File 'lib/funky/page.rb', line 152 def self.where(id:) return nil unless id instantiate_collection(fetch_and_parse_data Array(id)) end |
Instance Method Details
#city ⇒ String?
Returns the city of the Facebook Page if it is present.
99 100 101 |
# File 'lib/funky/page.rb', line 99 def city location[:city] end |
#country ⇒ String?
Returns the country of the Facebook Page if it is present.
117 118 119 |
# File 'lib/funky/page.rb', line 117 def country location[:country] end |
#fan_count ⇒ Integer
Returns the number of people who likes the Facebook page.
79 80 81 |
# File 'lib/funky/page.rb', line 79 def fan_count data[:fan_count] end |
#has_featured_video? ⇒ Boolean
Returns if the Facebook page has featured_video.
84 85 86 |
# File 'lib/funky/page.rb', line 84 def has_featured_video? !data[:featured_video].nil? end |
#latitude ⇒ Fixnum?
Returns the latitude of the Facebook Page if it is present.
129 130 131 |
# File 'lib/funky/page.rb', line 129 def latitude location[:latitude] end |
#location ⇒ Hash
location is a Hash that contains more specific properties such as city, state, zip, etc.
Returns the location of the Facebook Page if it is present.
93 94 95 |
# File 'lib/funky/page.rb', line 93 def location data.fetch(:location, {}) end |
#longitude ⇒ Fixnum?
Returns the longitude of the Facebook Page if it is present.
135 136 137 |
# File 'lib/funky/page.rb', line 135 def longitude location[:longitude] end |
#name ⇒ String
For example, for www.facebook.com/platform the name is ‘Facebook For Developers’.
Returns the name of the Facebook Page.
74 75 76 |
# File 'lib/funky/page.rb', line 74 def name data[:name] end |
#posts(options = {}) ⇒ Array<Funky::Post>
Fetches data from Facebook Graph API and returns an array of Funky::Post objects belong to the caller page.
54 55 56 57 58 59 |
# File 'lib/funky/page.rb', line 54 def posts( = {}) path_query = "#{id}/posts?fields=type,created_time" path_query << "&since=#{[:since]}" if [:since] posts = Funky::Connection::API.fetch_all(path_query) posts.map {|post| Post.new(post)} end |
#state ⇒ String?
Returns the state of the Facebook Page if it is present.
111 112 113 |
# File 'lib/funky/page.rb', line 111 def state location[:state] end |
#street ⇒ String?
Returns the street of the Facebook Page if it is present.
105 106 107 |
# File 'lib/funky/page.rb', line 105 def street location[:street] end |
#username ⇒ String
For example, for www.facebook.com/platform the username is ‘platform’.
Returns the alias of the Facebook Page.
65 66 67 |
# File 'lib/funky/page.rb', line 65 def username data[:username] end |
#videos(options = {}) ⇒ Array<Funky::Video>
Fetches data from Facebook Graph API and returns an array of Funky::Video objects belong to the caller page.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/funky/page.rb', line 32 def videos( = {}) 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 [:since] path_query << "&since=#{[: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 ⇒ String
Returns the zip code of the Facebook Page if it is present.
123 124 125 |
# File 'lib/funky/page.rb', line 123 def zip location[:zip] end |