twitter2fleep 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67deea3e777d5ab3a72969cdb05601478d007863
4
- data.tar.gz: 4b23f1c08d04be09dcce9f1b558d60030e57bfa0
3
+ metadata.gz: 7a9f8a35ba6701ab3d7dd0b394f1f1bc5386062c
4
+ data.tar.gz: fbdfdf4da6b6348e1b347bf7e61792f6e5cc7c69
5
5
  SHA512:
6
- metadata.gz: a05f8c5c0600c0c1609f6b7fc428dc3392fb0b607353de27e5aae816afe4d42ed3fa5733d879545943d7959432e01eb8425b53ca5b263de9c76b4926ef3ce38e
7
- data.tar.gz: 50fef436084640a7bcfd64a5b1f1dafac95680af8abc6e967fde56634b52e676e2d15eacf60ff97be141de5b4b8232fee056471ac9a3a2ffdad9c8f60164a8e1
6
+ metadata.gz: 7b9ee4e9b3501f1e5fad1a9202329fe7fb09eb6653d1025f58589f272eb2504eff73b423cf9cfed59792346331edc8daba16eae1edca66b337956371612d87d8
7
+ data.tar.gz: a05e5da34da8861d2dd3d69351e649a8f78bc5700b125d6c2e0a4185925ce7991455f0cee89e170ce936a75c66ea70c825f4d418ff0c07599f4bfc84dad98eac
@@ -1,48 +1,50 @@
1
1
  require 'twitter'
2
2
  require 'http'
3
3
 
4
- class Twitter2Fleep::Bot
5
- def initialize(config)
6
- @twitter_client = Twitter::Streaming::Client.new(config[:twitter])
7
- @selected_user_ids = config[:selected_user_ids]
8
- @fleep_hook_url = config[:fleep_hook_url]
9
- end
4
+ module Twitter2Fleep
5
+ class Bot
6
+ def initialize(config)
7
+ @twitter_client = Twitter::Streaming::Client.new(config[:twitter])
8
+ @selected_user_ids = config[:selected_user_ids]
9
+ @fleep_hook_url = config[:fleep_hook_url]
10
+ end
10
11
 
11
- def start
12
- @twitter_client.user do |object|
13
- case object
14
- when Twitter::Tweet
15
- tweet = object
16
- author = tweet.user
12
+ def start
13
+ @twitter_client.user do |object|
14
+ case object
15
+ when Twitter::Tweet
16
+ tweet = object
17
+ author = tweet.user
17
18
 
18
- if should_post?(tweet)
19
- message = "@#{author.screen_name}: #{tweet.text}"
19
+ if should_post?(tweet)
20
+ message = "@#{author.screen_name}: #{tweet.text}"
20
21
 
21
- response = post_to_fleep(author.screen_name, message)
22
+ response = post_to_fleep(author.screen_name, message)
22
23
 
23
- puts message
24
- puts "----> #{response.status_code}"
24
+ puts message
25
+ puts "----> #{response.status_code}"
26
+ end
27
+ when Twitter::Streaming::StallWarning
28
+ warn "Falling behind!"
25
29
  end
26
- when Twitter::Streaming::StallWarning
27
- warn "Falling behind!"
28
30
  end
29
31
  end
30
- end
31
32
 
32
- private
33
+ private
33
34
 
34
- def should_post?(tweet)
35
- @selected_user_ids.nil? or (
36
- @selected_user_ids.include?(tweet.user.id) and (
37
- not tweet.reply? or @selected_user_ids.include?(tweet.in_reply_to_user_id)
35
+ def should_post?(tweet)
36
+ @selected_user_ids.nil? or (
37
+ @selected_user_ids.include?(tweet.user.id) and (
38
+ not tweet.reply? or @selected_user_ids.include?(tweet.in_reply_to_user_id)
39
+ )
38
40
  )
39
- )
40
- end
41
+ end
41
42
 
42
- def post_to_fleep(display_name, message)
43
- HTTP.post(
44
- "#{@fleep_hook_url}/#{display_name}",
45
- :form => {:message => message}
46
- ).response
43
+ def post_to_fleep(display_name, message)
44
+ HTTP.post(
45
+ "#{@fleep_hook_url}/#{display_name}",
46
+ :form => {:message => message}
47
+ ).response
48
+ end
47
49
  end
48
50
  end
@@ -3,51 +3,53 @@ require 'twitter2fleep/bot'
3
3
  require 'thor'
4
4
  require 'yaml'
5
5
 
6
- class Twitter2Fleep::CLI < Thor
7
- desc "start", "Start the bot"
8
- option :config_file, :default => "#{Dir.home}/.twitter2fleep/config.yml"
9
- option :env_config, :type => :boolean, :default => false
10
-
11
- def start
12
- if options[:env_config]
13
- puts "Load config from environment variables."
14
- config = load_env_config
15
- else
16
- config_file = options[:config_file]
17
- puts "Load config from \`#{config_file}\`."
18
- config = load_config_file(config_file)
6
+ module Twitter2Fleep
7
+ class CLI < Thor
8
+ desc "start", "Start the bot"
9
+ option :config_file, :default => "#{Dir.home}/.twitter2fleep/config.yml"
10
+ option :env_config, :type => :boolean, :default => false
11
+
12
+ def start
13
+ if options[:env_config]
14
+ puts "Load config from environment variables."
15
+ config = load_env_config
16
+ else
17
+ config_file = options[:config_file]
18
+ puts "Load config from \`#{config_file}\`."
19
+ config = load_config_file(config_file)
20
+ end
21
+ bot = Twitter2Fleep::Bot.new(config)
22
+ bot.start
19
23
  end
20
- bot = Twitter2Fleep::Bot.new(config)
21
- bot.start
22
- end
23
24
 
24
- no_commands do
25
- def load_env_config
26
- {
27
- :twitter => {
28
- :consumer_key => ENV.fetch('TWITTER_CONSUMER_KEY', ''),
29
- :consumer_secret => ENV.fetch('TWITTER_CONSUMER_SECRET', ''),
30
- :access_token => ENV.fetch('TWITTER_ACCESS_TOKEN', ''),
31
- :access_token_secret => ENV.fetch('TWITTER_ACCESS_TOKEN_SECRET', ''),
32
- },
33
- :selected_user_ids => ENV.fetch('SELECTED_USER_IDS', '').split(',').map {|v| v.to_i},
34
- :fleep_hook_url => ENV.fetch('FLEEP_HOOK_URL', '')
35
- }
36
- end
25
+ no_commands do
26
+ def load_env_config
27
+ {
28
+ :twitter => {
29
+ :consumer_key => ENV.fetch('TWITTER_CONSUMER_KEY', ''),
30
+ :consumer_secret => ENV.fetch('TWITTER_CONSUMER_SECRET', ''),
31
+ :access_token => ENV.fetch('TWITTER_ACCESS_TOKEN', ''),
32
+ :access_token_secret => ENV.fetch('TWITTER_ACCESS_TOKEN_SECRET', ''),
33
+ },
34
+ :selected_user_ids => ENV.fetch('SELECTED_USER_IDS', '').split(',').map {|v| v.to_i},
35
+ :fleep_hook_url => ENV.fetch('FLEEP_HOOK_URL', '')
36
+ }
37
+ end
37
38
 
38
- def load_config_file(filename)
39
- config_file = options[:config_file]
39
+ def load_config_file(filename)
40
+ config_file = options[:config_file]
40
41
 
41
- begin
42
- config = YAML::load_file(config_file)
43
- rescue Errno::ENOENT => exception
44
- puts "You need to create the config file \`#{config_file}\`"
45
- puts "See example at https://github.com/wancw/twitter2fleep/blob/master/config.yml.example"
46
- exit(-1)
47
- end
42
+ begin
43
+ config = YAML::load_file(config_file)
44
+ rescue Errno::ENOENT => exception
45
+ puts "You need to create the config file \`#{config_file}\`"
46
+ puts "See example at https://github.com/wancw/twitter2fleep/blob/master/config.yml.example"
47
+ exit(-1)
48
+ end
48
49
 
49
- return config
50
+ return config
51
+ end
50
52
  end
51
- end
52
53
 
53
- end
54
+ end
55
+ end
@@ -1,3 +1,3 @@
1
1
  module Twitter2Fleep
2
- VERSION = '0.4.0'
3
- end
2
+ VERSION = '0.4.1'
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter2fleep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - WanCW