Skip to content

Commit 414eb64

Browse files
committed
Add fb pages
1 parent ee86f92 commit 414eb64

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lib/fb.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ def email
2626
request.run.body['email']
2727
end
2828
end
29+
30+
def pages
31+
@pages ||= begin
32+
params = { access_token: @access_token }
33+
request = HTTPRequest.new path: '/me/accounts', params: params
34+
request.run.body['data'].map do |page_data|
35+
Page.new symbolize_keys(page_data.merge access_token: @access_token)
36+
end
37+
end
38+
end
39+
40+
private
41+
42+
def symbolize_keys(hash)
43+
{}.tap do |new_hash|
44+
hash.each_key{|key| new_hash[key.to_sym] = hash[key]}
45+
end
46+
end
2947
end
3048

3149
module Config
@@ -154,4 +172,15 @@ def error_message
154172
JSON(response.body)['error']['message']
155173
end
156174
end
175+
176+
class Page
177+
attr_reader :id, :name, :category
178+
179+
def initialize(options = {})
180+
@id = options[:id]
181+
@name = options[:name]
182+
@category = options[:category]
183+
@access_token = options[:access_token]
184+
end
185+
end
157186
end

0 commit comments

Comments
 (0)