tweeter-bachue 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.yml
19
+ lost/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tweeter.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Bachue Zhou
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,66 @@
1
+ # Tweeter
2
+
3
+ This is a gem to tweet in command line.
4
+
5
+ It can also connect proxy by SSH to do it if the connection to twitter is not available.
6
+
7
+ And it can log the tweet if all proxies are failed.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'tweeter-bachue'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install tweeter-bachue
22
+
23
+ Then try run:
24
+
25
+ $ tweet
26
+
27
+ If there's no any error message, it means you installed it successfully.
28
+
29
+ ## Usage
30
+
31
+ After install `tweeter-bachue`, please go to the config directory:
32
+
33
+ If you use rvm, you can just run:
34
+
35
+ $ cd `rvm gemdir`/gems/tweeter-bachue-*/config
36
+
37
+ Then you could see 2 example config files, `key.yml.example` and `proxies.yml.example`:
38
+
39
+ $ mv key.yml.example key.yml
40
+ $ mv proxies.yml.example proxies.yml
41
+
42
+ Then please edit them:
43
+
44
+ 1. Edit `config/key.yml`
45
+ 2. Replace with your consumer key/secret, oauth token, oauth token secret (google if you need help)
46
+ 3. Then edit `config/proxies.yml`
47
+ 4. Add all your proxies info into this file. in this file, host, port and user are related to the ssh account, and gemset and path is related to `tweet` command
48
+ 5. Don't forget to install and config `tweeter-bachue` in all your proxies in the same way
49
+ 6. You'd better delete `proxies.yml` if you haven't any proxy
50
+
51
+ After all, try:
52
+
53
+ $ tweet "This is my 'hello world', sent from `tweet-bachue` gem"
54
+
55
+ `tweeter-bachue` will try to tweet it by itself. if it failed for 3 times, will try the same command on each of your proxies by ssh one by one, until anyone of them puts "Succeed". when the `tweeter-bachue` in your proxies failed for 3 times, it will also do the same thing, try its proxies.
56
+
57
+ If all tries are failed, `tweeter-bachue` will write the tweet in a file which is in the `lost/` directory and the name is the current timestamp, you won't lost any of your tweet. but remember, proxy won't do this because it's not necessary.
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it from <https://gitcafe.com/bachue/tweeter.git>
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create new Pull Request
66
+ 6. Any Pull Request is Welcome
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'twitter'
5
+ require 'yaml'
6
+ require 'socket'
7
+ require 'active_support/all'
8
+
9
+ def lost_file_name(path)
10
+ name = Time.now.to_f.to_s.sub('.', '') + '.tweet'
11
+ File.join(path, name)
12
+ end
13
+
14
+ if ARGV.first.downcase == 'proxy'
15
+ is_proxy = true
16
+ ARGV.shift
17
+ end
18
+
19
+ tweet = ARGV.join(' ')
20
+
21
+ exit if tweet.blank?
22
+
23
+ root_dir = File.expand_path File.join(File.dirname(__FILE__), '..')
24
+ config_dir = File.join(root_dir, 'config')
25
+ lost_dir = File.join(root_dir, 'lost')
26
+ client_info = YAML.load_file(File.join(config_dir, 'key.yml')).symbolize_keys
27
+ proxies_info = YAML.load_file(File.join(config_dir, 'proxies.yml')).map(&:symbolize_keys) rescue []
28
+
29
+ @client = Twitter::Client.new(client_info)
30
+ retry_count = 0
31
+ begin
32
+ retry_count += 1
33
+ @client.update(tweet)
34
+ puts 'Succeed'
35
+ rescue
36
+ retry if retry_count < 3
37
+ puts "Failed to tweet by #{Socket.gethostname}, ask the proxies"
38
+ proxies_info = proxies_info.map { |proxy| [proxy[:host], proxy[:port], proxy[:user], proxy[:path], proxy[:gemset]] }
39
+ catch(:succ) {
40
+ proxies_info.each { |host, port, user, path, gemset|
41
+ puts input = "ssh #{"#{user}@" if user.present?}#{host} #{"-p #{port}" if port.present?} \"#{"rvm use #{gemset} &&" if gemset.present?} #{path.present? ? path : 'tweet' } proxy '#{tweet}'\""
42
+ puts output = system(input) rescue next
43
+ throw :succ if output =~ /Succeed/
44
+ }
45
+ File.open(lost_file_name(lost_dir), 'w') { |f| f << tweet } unless is_proxy
46
+ }
47
+ end
@@ -0,0 +1,5 @@
1
+ ---
2
+ consumer_key: COMSUMER_KEY
3
+ consumer_secret: CONSUMER_SECRET
4
+ oauth_token: OAUTH_TOKEN
5
+ oauth_token_secret: OAUTH_TOKEN_SECRET
@@ -0,0 +1,7 @@
1
+ ---
2
+ - host: localhost
3
+ port:
4
+ user: root
5
+ gemset:
6
+ path:
7
+
@@ -0,0 +1,3 @@
1
+ module Tweeter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tweeter/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'tweeter-bachue'
8
+ gem.version = Tweeter::VERSION
9
+ gem.authors = ['Bachue Zhou']
10
+ gem.email = ['bachue.shu@gmail.com']
11
+ gem.description = %q{This is a gem to tweet in command line. It can also connect proxy by SSH to do it if the connection to twitter is not available}
12
+ gem.summary = gem.description
13
+ gem.homepage = 'https://gitcafe.com/bachue/tweeter'
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+
19
+ gem.add_dependency 'twitter'
20
+ gem.add_dependency 'activesupport', '>= 3.0.0'
21
+ gem.add_dependency 'rake'
22
+ gem.add_development_dependency 'pry'
23
+ gem.add_development_dependency 'pry-doc'
24
+ gem.add_development_dependency 'pry-nav'
25
+ gem.add_development_dependency 'pry-stack_explorer'
26
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tweeter-bachue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bachue Zhou
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: twitter
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 3.0.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry-doc
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: pry-nav
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: pry-stack_explorer
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: This is a gem to tweet in command line. It can also connect proxy by
127
+ SSH to do it if the connection to twitter is not available
128
+ email:
129
+ - bachue.shu@gmail.com
130
+ executables:
131
+ - tweet
132
+ extensions: []
133
+ extra_rdoc_files: []
134
+ files:
135
+ - .gitignore
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - bin/tweet
141
+ - config/key.yml.example
142
+ - config/proxies.yml.example
143
+ - lib/tweeter/version.rb
144
+ - lost/.git-keep
145
+ - tweeter-bachue.gemspec
146
+ homepage: https://gitcafe.com/bachue/tweeter
147
+ licenses: []
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ segments:
159
+ - 0
160
+ hash: -2088777374129425809
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ segments:
168
+ - 0
169
+ hash: -2088777374129425809
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 1.8.24
173
+ signing_key:
174
+ specification_version: 3
175
+ summary: This is a gem to tweet in command line. It can also connect proxy by SSH
176
+ to do it if the connection to twitter is not available
177
+ test_files: []
178
+ has_rdoc: