Class: SocialFeedAgregator::GoogleplusReader
- Inherits:
-
BaseReader
- Object
- BaseReader
- SocialFeedAgregator::GoogleplusReader
- Defined in:
- lib/social_feed_agregator/googleplus_reader.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Instance Method Summary collapse
- #get_feeds(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ GoogleplusReader
constructor
A new instance of GoogleplusReader.
Constructor Details
#initialize(options = {}) ⇒ GoogleplusReader
Returns a new instance of GoogleplusReader.
9 10 11 12 13 14 15 |
# File 'lib/social_feed_agregator/googleplus_reader.rb', line 9 def initialize(={}) super() .replace(SFA..merge()) @user_id = [:googleplus_user_id] @api_key = [:googleplus_api_key] end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/social_feed_agregator/googleplus_reader.rb', line 7 def api_key @api_key end |
#user_id ⇒ Object
Returns the value of attribute user_id.
7 8 9 |
# File 'lib/social_feed_agregator/googleplus_reader.rb', line 7 def user_id @user_id end |
Instance Method Details
#get_feeds(options = {}) ⇒ Object
17 18 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 53 54 |
# File 'lib/social_feed_agregator/googleplus_reader.rb', line 17 def get_feeds(={}) super() @user_id = [:user_id] if [:user_id] count = [:count] || 25 from_date = [:from_date] || DateTime.new(1970,1,1) feeds, i, count_per_request, items = [], 0, 100, 0 opts = {count: count < count_per_request ? count : count_per_request} parts = (count.to_f / count_per_request).ceil url = "https://www.googleapis.com/plus/v1/people/#{@user_id}/activities/public?key=#{@api_key}&maxResults=#{opts[:count]}" begin i+=1 next_query = "" data = JSON.parse( RestClient.get("#{url}#{next_query}") ) data['items'].each do |post| items+=1 break if items > count # Break if the date is less if DateTime.parse(post["published"]) <= from_date i = parts break end feed = fill_feed post block_given? ? yield(feed) : feeds << feed end next_query = "&pageToken=#{data['nextPageToken']}" end while (data['items'].count > 0 ) && (i < parts) end |