Created
December 17, 2013 11:24
-
-
Save st63jun/8003480 to your computer and use it in GitHub Desktop.
Automatic::Plugin::Publish::ChatWork
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::ChatWork | |
# Author:: Jun Saito <http://github.com/st63jun> | |
# Created:: Dec 17, 2013 | |
# Updated:: Dec 17, 2013 | |
# Copyright:: Copyright (c) 2013 Jun Saito. | |
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. | |
module Automatic::Plugin | |
require 'chatwork' | |
class PublishChatWork | |
def initialize(config, pipeline=[]) | |
@config = config | |
@pipeline = pipeline | |
# @client = ChatWork::Client.new(@config['api_token'], 'https://api.chatwork.com/', '/v1') | |
ChatWork.api_key = @config['api_key'] | |
end | |
def run | |
@pipeline.each {|feeds| | |
unless feeds.nil? | |
feeds.items.each {|feed| | |
retries = 0 | |
begin | |
ChatWork.client.post('/rooms/' + @config['room_id'].to_s + '/messages', {body: feed.title + ' ' + feed.link + ' '}\ | |
) | |
Automatic::Log.puts("info", "post: #{feed.description.gsub(/[\r\n]/,'')[0..50]}...") rescue nil | |
rescue => e | |
retries += 1 | |
Automatic::Log.puts("error", "ErrorCount: #{retries}, #{e.message}") | |
sleep @config['interval'].to_i unless @config['interval'].nil? | |
retry if retries <= @config['retry'].to_i unless @config['retry'].nil? | |
end | |
sleep @config['interval'].to_i unless @config['interval'].nil? | |
} | |
end | |
} | |
@pipeline | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
動かすには事前に
chatwork
がインストールされている必要があります。https://github.com/asonas/chatwork-ruby