Created
August 10, 2014 15:37
-
-
Save shunirr/8aed0fcd797136db6b2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Name:: Automatic::Plugin::Publish::Fastladder | |
# Author:: shunirr <http://s5r.jp> | |
# Created:: Aug 8, 2014 | |
# Updated:: Aug 8, 2014 | |
# Copyright:: Copyright (c) 2012-2014 Automatic Ruby Developers. | |
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. | |
module Automatic::Plugin | |
class PublishFastladder | |
def initialize(config, pipeline=[]) | |
@pipeline = pipeline | |
@base_url = config['base_url'] | |
@api_key = config['api_key'] | |
end | |
def run | |
@pipeline.each do |feeds| | |
next if feeds.nil? | |
items = [] | |
feeds.items.each do |feed| | |
if feeds.is_a? RSS::Atom::Feed | |
items << { | |
"feedlink"=> feeds.link, | |
"feedtitle"=> feeds.title || 'NO TITLE', | |
"feeddescription"=> feeds.subtitle || '', | |
"link"=> feed.link, | |
"body"=> feed.content || feed.summary, | |
"title"=> feed.title, | |
} | |
else | |
items << { | |
"feedlink"=> feeds.channel.link, | |
"feedtitle"=> feeds.channel.title || 'NO TITLE', | |
"feeddescription"=> feeds.channel.description || '', | |
"link"=> feed.link, | |
"body"=> feed.content_encoded || feed.description, | |
"title"=> feed.title, | |
} | |
end | |
end | |
Net::HTTP.post_form URI("#{@base_url}/rpc/update_feeds"), { | |
"api_key"=> @api_key, | |
"feeds"=> JSON.dump(items) | |
} | |
end | |
end | |
@pipeline | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment