Class: SocialFeedAgregator::FacebookReader
- Inherits:
-
BaseReader
- Object
- BaseReader
- SocialFeedAgregator::FacebookReader
- Defined in:
- lib/social_feed_agregator/facebook_reader.rb
Instance Attribute Summary collapse
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#app_secret ⇒ Object
Returns the value of attribute app_secret.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #get_feeds(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ FacebookReader
constructor
A new instance of FacebookReader.
Constructor Details
#initialize(options = {}) ⇒ FacebookReader
Returns a new instance of FacebookReader.
10 11 12 13 14 15 16 17 |
# File 'lib/social_feed_agregator/facebook_reader.rb', line 10 def initialize(={}) super() .replace(SFA..merge()) @name = [:facebook_user_name] @app_id = [:facebook_app_id] @app_secret = [:facebook_app_secret] end |
Instance Attribute Details
#app_id ⇒ Object
Returns the value of attribute app_id.
8 9 10 |
# File 'lib/social_feed_agregator/facebook_reader.rb', line 8 def app_id @app_id end |
#app_secret ⇒ Object
Returns the value of attribute app_secret.
8 9 10 |
# File 'lib/social_feed_agregator/facebook_reader.rb', line 8 def app_secret @app_secret end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/social_feed_agregator/facebook_reader.rb', line 8 def name @name end |
Instance Method Details
#get_feeds(options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/social_feed_agregator/facebook_reader.rb', line 19 def get_feeds(={}) super() @name = [:name] if [:name] count = [:count] || 25 from_date = [:from_date] || DateTime.new(1970,1,1) feeds, i, count_per_request, items = [], 0, 25, 0 parts = (count.to_f / count_per_request).ceil oauth = Koala::Facebook::OAuth.new(@app_id, @app_secret) graph = Koala::Facebook::API.new oauth.get_app_access_token posts = graph.get_connections(@name, "posts") begin i+=1 posts.each do |post| items+=1 break if items > count # Break if the date is less if DateTime.parse(post['created_time']) <= from_date i = parts break end feed = fill_feed post block_given? ? yield(feed) : feeds << feed end end while (posts = posts.next_page) && (i < parts) feeds end |