Class: SocialFeedAgregator::PinterestReader

Inherits:
BaseReader
  • Object
show all
Defined in:
lib/social_feed_agregator/pinterest_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PinterestReader

Returns a new instance of PinterestReader.



9
10
11
12
13
# File 'lib/social_feed_agregator/pinterest_reader.rb', line 9

def initialize(options={})
  super(options)
  options.replace(SFA.default_options.merge(options))
  @name = options[:pinterest_user_name]      
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/social_feed_agregator/pinterest_reader.rb', line 7

def name
  @name
end

Instance Method Details

#get_feeds(options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/social_feed_agregator/pinterest_reader.rb', line 15

def get_feeds(options={})
  super(options)
  @name = options[:name]  if options[:name]
  count = options[:count] || 25
  from_date = options[:from_date] || DateTime.new(1970,1,1) 

  feeds = []
  items = 0

  doc = Nokogiri::XML( RestClient.get("http://pinterest.com/#{@name}/feed.rss") )

  doc.xpath('//item').each do |item|
    items += 1
    break if items > count

    # Break if the date is less
    if DateTime.parse(item.xpath('pubDate').inner_text) <= from_date
      break
    end

    feed = fill_feed item
    
    block_given? ? yield(feed) : feeds << feed
  end
  feeds
end