Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions lib/fb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ def initialize(options = {})

def owned_pages
@owned_pages ||= begin
params = { access_token: @access_token, fields: "category,name" }
params = { access_token: @access_token, fields: "category,name,access_token" }
request = HTTPRequest.new path: "/#{@id}/owned_pages", params: params
request.run.body['data'].map do |page_data|
unless page_data.key?("access_token")
page_data.merge! access_token: @access_token
end
# unless page_data.key?("access_token")
# page_data.merge! access_token: @access_token
# end
Page.new symbolize_keys(page_data)
end
end
end

def client_pages
@client_pages ||= begin
params = { access_token: @access_token, fields: "category,name" }
params = { access_token: @access_token, fields: "category,name,access_token" }
request = HTTPRequest.new path: "/#{@id}/client_pages", params: params
request.run.body['data'].map do |page_data|
unless page_data.key?("access_token")
page_data.merge! access_token: @access_token
end
# unless page_data.key?("access_token")
# page_data.merge! access_token: @access_token
# end
Page.new symbolize_keys(page_data)
end
end
Expand All @@ -50,7 +50,7 @@ def client_pages

def symbolize_keys(hash)
{}.tap do |new_hash|
hash.each_key{|key| new_hash[key.to_sym] = hash[key]}
hash.each_key {|key| new_hash[key.to_sym] = hash[key] }
end
end
end
Expand Down Expand Up @@ -78,7 +78,7 @@ def revoke_permissions

def pages
@pages ||= begin
params = { access_token: @access_token }
params = { access_token: @access_token, fields: "category,name,access_token" }
request = HTTPRequest.new path: '/me/accounts', params: params
request.run.body['data'].map do |page_data|
# unless page_data.key?("access_token")
Expand All @@ -91,7 +91,7 @@ def pages

def businesses
@businesses ||= begin
params = { access_token: @access_token }
params = { access_token: @access_token, fields: "name,access_token" }
request = HTTPRequest.new path: '/me/businesses', params: params
request.run.body['data'].map do |business_data|
unless business_data.key?("access_token")
Expand All @@ -106,7 +106,7 @@ def businesses

def symbolize_keys(hash)
{}.tap do |new_hash|
hash.each_key{|key| new_hash[key.to_sym] = hash[key]}
hash.each_key {|key| new_hash[key.to_sym] = hash[key] }
end
end
end
Expand All @@ -125,6 +125,13 @@ def thumbnail_url
"https://graph.facebook.com/#{@id}/picture?width=240&height=240"
end

# # For test the page token - temporary code
# def feed
# params = { access_token: @access_token }
# request = HTTPRequest.new(path: "/#{@id}/feed", params: params)
# request.run.body['data']
# end

# Either link or message must be supplied.
# https://developers.facebook.com/docs/graph-api/reference/v21.0/page/feed#publish
def publish(options = {})
Expand Down