twitter2fleep 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +39 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +49 -0
- data/Rakefile +2 -0
- data/bin/twitter2fleep +2 -53
- data/config.yml.example +15 -0
- data/lib/twitter2fleep.rb +6 -0
- data/lib/twitter2fleep/bot.rb +48 -0
- data/lib/twitter2fleep/cli.rb +53 -0
- data/lib/twitter2fleep/version.rb +3 -0
- data/twitter2fleep.gemspec +24 -0
- metadata +30 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67deea3e777d5ab3a72969cdb05601478d007863
|
4
|
+
data.tar.gz: 4b23f1c08d04be09dcce9f1b558d60030e57bfa0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a05f8c5c0600c0c1609f6b7fc428dc3392fb0b607353de27e5aae816afe4d42ed3fa5733d879545943d7959432e01eb8425b53ca5b263de9c76b4926ef3ce38e
|
7
|
+
data.tar.gz: 50fef436084640a7bcfd64a5b1f1dafac95680af8abc6e967fde56634b52e676e2d15eacf60ff97be141de5b4b8232fee056471ac9a3a2ffdad9c8f60164a8e1
|
data/.gitignore
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
/vendor/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
Gemfile.lock
|
31
|
+
# .ruby-version
|
32
|
+
# .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
36
|
+
|
37
|
+
# config of Twitter2Fleep
|
38
|
+
/config.yml
|
39
|
+
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# twitter2fleep
|
2
|
+
|
3
|
+
A simple tool forwards tweets to Fleep.io conversation.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's `Gemfile`:
|
9
|
+
|
10
|
+
gem 'twitter2fleep'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install twitter2fleep
|
19
|
+
|
20
|
+
|
21
|
+
## Config
|
22
|
+
|
23
|
+
Please create the config file `~/.twitter2fleep/config.yml`.
|
24
|
+
|
25
|
+
There is the [example][Config Example].
|
26
|
+
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Just run the script:
|
31
|
+
|
32
|
+
twitter2fleep
|
33
|
+
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new Pull Request
|
42
|
+
|
43
|
+
## Copyright
|
44
|
+
|
45
|
+
Copyright (c) 2014 Chun-Wen Wang. See [LICENSE][] for details.
|
46
|
+
|
47
|
+
[Config Example]: config.yml.example
|
48
|
+
[LICENSE]: LICENSE
|
49
|
+
|
data/Rakefile
ADDED
data/bin/twitter2fleep
CHANGED
@@ -1,56 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'twitter2fleep/cli'
|
4
4
|
|
5
|
-
|
6
|
-
require 'http'
|
7
|
-
require 'yaml'
|
8
|
-
|
9
|
-
begin
|
10
|
-
config_file = "#{Dir.home}/.twitter2fleep/config.yml"
|
11
|
-
t2f_config = YAML::load_file(config_file)
|
12
|
-
rescue Errno::ENOENT => exception
|
13
|
-
puts "You need to create the config file ~/.twitter2fleep/config.yml"
|
14
|
-
puts "See example at https://github.com/wancw/twitter2fleep/blob/master/config.yml.example"
|
15
|
-
exit(-1)
|
16
|
-
end
|
17
|
-
|
18
|
-
client = Twitter::Streaming::Client.new do |client_config|
|
19
|
-
client_config.consumer_key = t2f_config[:client][:consumer_key]
|
20
|
-
client_config.consumer_secret = t2f_config[:client][:consumer_secret]
|
21
|
-
client_config.access_token = t2f_config[:client][:access_token]
|
22
|
-
client_config.access_token_secret = t2f_config[:client][:access_token_secret]
|
23
|
-
end
|
24
|
-
|
25
|
-
$selected_user_ids = t2f_config[:selected_user_ids]
|
26
|
-
|
27
|
-
fleep_hook_url = t2f_config[:fleep_hook_url]
|
28
|
-
|
29
|
-
def should_post?(tweet)
|
30
|
-
$selected_user_ids.nil? or (
|
31
|
-
$selected_user_ids.include?(tweet.user.id) and (
|
32
|
-
not tweet.reply? or $selected_user_ids.include?(tweet.in_reply_to_user_id)
|
33
|
-
)
|
34
|
-
)
|
35
|
-
end
|
36
|
-
|
37
|
-
client.user do |object|
|
38
|
-
case object
|
39
|
-
when Twitter::Tweet
|
40
|
-
tweet = object
|
41
|
-
author = tweet.user
|
42
|
-
if should_post?(tweet)
|
43
|
-
message = "@#{author.screen_name}:\n#{tweet.text}"
|
44
|
-
|
45
|
-
response = HTTP.post(
|
46
|
-
"#{fleep_hook_url}/#{author.screen_name}",
|
47
|
-
:form => {:message => message}
|
48
|
-
).response
|
49
|
-
|
50
|
-
puts message
|
51
|
-
puts "----> #{response.status_code}"
|
52
|
-
end
|
53
|
-
when Twitter::Streaming::StallWarning
|
54
|
-
warn "Falling behind!"
|
55
|
-
end
|
56
|
-
end
|
5
|
+
Twitter2Fleep::CLI.start(ARGV)
|
data/config.yml.example
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
:twitter:
|
3
|
+
:consumer_key: "YOUR_CONSUMER_KEY"
|
4
|
+
:consumer_secret: "YOUR_CONSUMER_SECRET"
|
5
|
+
:access_token: "YOUR_ACCESS_TOKEN"
|
6
|
+
:access_token_secret: "YOUR_ACCESS_SECRET"
|
7
|
+
|
8
|
+
# Array of Twitter user ids, or remove it to forward all tweets.
|
9
|
+
:selected_user_ids:
|
10
|
+
- 1 # first ID
|
11
|
+
- 2 # second ID
|
12
|
+
- 3 # third ID
|
13
|
+
# and so on...
|
14
|
+
|
15
|
+
:fleep_hook_url: "YOUR_FLEEP_HOOK_URL"
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'twitter'
|
2
|
+
require 'http'
|
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
|
10
|
+
|
11
|
+
def start
|
12
|
+
@twitter_client.user do |object|
|
13
|
+
case object
|
14
|
+
when Twitter::Tweet
|
15
|
+
tweet = object
|
16
|
+
author = tweet.user
|
17
|
+
|
18
|
+
if should_post?(tweet)
|
19
|
+
message = "@#{author.screen_name}: #{tweet.text}"
|
20
|
+
|
21
|
+
response = post_to_fleep(author.screen_name, message)
|
22
|
+
|
23
|
+
puts message
|
24
|
+
puts "----> #{response.status_code}"
|
25
|
+
end
|
26
|
+
when Twitter::Streaming::StallWarning
|
27
|
+
warn "Falling behind!"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
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)
|
38
|
+
)
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def post_to_fleep(display_name, message)
|
43
|
+
HTTP.post(
|
44
|
+
"#{@fleep_hook_url}/#{display_name}",
|
45
|
+
:form => {:message => message}
|
46
|
+
).response
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'twitter2fleep/bot'
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'yaml'
|
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)
|
19
|
+
end
|
20
|
+
bot = Twitter2Fleep::Bot.new(config)
|
21
|
+
bot.start
|
22
|
+
end
|
23
|
+
|
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
|
37
|
+
|
38
|
+
def load_config_file(filename)
|
39
|
+
config_file = options[:config_file]
|
40
|
+
|
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
|
48
|
+
|
49
|
+
return config
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'twitter2fleep/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'twitter2fleep'
|
7
|
+
spec.version = Twitter2Fleep::VERSION
|
8
|
+
spec.license = 'MIT'
|
9
|
+
|
10
|
+
spec.summary = 'Twitter to Fleep'
|
11
|
+
spec.description = 'Forward tweets to Fleep.io conversation.'
|
12
|
+
|
13
|
+
spec.homepage = 'http://github.com/wancw/twitter2fleep'
|
14
|
+
|
15
|
+
spec.author = 'WanCW'
|
16
|
+
spec.email = 'wancw.wang@gmail.com'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency 'twitter', '~> 5.8.0'
|
23
|
+
spec.add_dependency 'thor', '~> 0.19.1'
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter2fleep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- WanCW
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twitter
|
@@ -16,14 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.8.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 5.8.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.19.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.19.1
|
27
41
|
description: Forward tweets to Fleep.io conversation.
|
28
42
|
email: wancw.wang@gmail.com
|
29
43
|
executables:
|
@@ -31,7 +45,18 @@ executables:
|
|
31
45
|
extensions: []
|
32
46
|
extra_rdoc_files: []
|
33
47
|
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
34
53
|
- bin/twitter2fleep
|
54
|
+
- config.yml.example
|
55
|
+
- lib/twitter2fleep.rb
|
56
|
+
- lib/twitter2fleep/bot.rb
|
57
|
+
- lib/twitter2fleep/cli.rb
|
58
|
+
- lib/twitter2fleep/version.rb
|
59
|
+
- twitter2fleep.gemspec
|
35
60
|
homepage: http://github.com/wancw/twitter2fleep
|
36
61
|
licenses:
|
37
62
|
- MIT
|
@@ -52,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
77
|
version: '0'
|
53
78
|
requirements: []
|
54
79
|
rubyforge_project:
|
55
|
-
rubygems_version: 2.2.
|
80
|
+
rubygems_version: 2.2.2
|
56
81
|
signing_key:
|
57
82
|
specification_version: 4
|
58
83
|
summary: Twitter to Fleep
|