Module: BuzzFeed::Client
- Defined in:
- lib/buzz_feed/client.rb
Class Method Summary collapse
-
.read(service_name) ⇒ Object
Returns data of a service.
-
.service_names ⇒ Object
Lists all defined services.
-
.update(service_name) ⇒ Object
Updates the Buzz model with fresh links from the service.
-
.update_all ⇒ Object
Updates the Buzz model with fresh links from all available services.
Class Method Details
.read(service_name) ⇒ Object
Returns data of a service.
16 17 18 |
# File 'lib/buzz_feed/client.rb', line 16 def self.read(service_name) read_blogspot(BuzzFeed.config['service'][service_name]['url']) end |
.service_names ⇒ Object
Lists all defined services.
8 9 10 11 12 13 |
# File 'lib/buzz_feed/client.rb', line 8 def self.service_names list = [] service = BuzzFeed.config['service'].keys.each do |name| list << name end end |
.update(service_name) ⇒ Object
Updates the Buzz model with fresh links from the service.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/buzz_feed/client.rb', line 21 def self.update(service_name) fresh_data = self.read(service_name) fresh_ids = fresh_data.map{|b| b[:id]} old_ids = Buzz.select('service_item_id').where('service_name=?', service_name).where('service_item_id in (?)', fresh_ids).all.map(&:service_item_id) new_ids = fresh_data.map{|b| b[:id]} - old_ids fresh_data.each do |buzz| Buzz.create(:title => buzz[:title], :service_name => service_name, :service_item_id => buzz[:id], :url => buzz[:url], :created_at => buzz[:created_at]) unless new_ids.rindex(buzz[:id]).nil? end true end |
.update_all ⇒ Object
Updates the Buzz model with fresh links from all available services.
35 36 37 38 39 40 |
# File 'lib/buzz_feed/client.rb', line 35 def self.update_all self.service_names.each do |name| self.update(name) end true end |