redchick 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a92b8efa4b47577ac49ac378d383ce0d50cd761c
4
+ data.tar.gz: 791db8945b2833b1fe039c527390e10f2617ef20
5
+ SHA512:
6
+ metadata.gz: bf87a5384ed711d3c84070406d5000c1cc7b6c78c100b63f755ca4f6021d5f4d4409b65260e227d294c6acccd8b9fd489a22692a60ed089b1e893efc68cedf34
7
+ data.tar.gz: 53748e81d09a08b70aacc1951a6babbc6f610749cd444c8cb44787d23a731d317a3289c20555f600ed3f6fbf7b52cacb731d370c1c0c762476b1b5c9de6b4e9f
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /*.gem
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in redchick.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 saki
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Redchick
2
+ [![Build Status](https://travis-ci.org/sakihet/redchick.svg?branch=master)](https://travis-ci.org/sakihet/redchick)
3
+
4
+ Twitter client on terminal.
5
+
6
+ ## Installation
7
+
8
+ $ gem install redchick
9
+
10
+ ## Usage
11
+
12
+ TODO: Write usage instructions here
13
+
14
+ ## Development
15
+
16
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec redchick` to use the gem in this directory, ignoring other installed copies of this gem.
17
+
18
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
19
+
20
+ ## Contributing
21
+
22
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sakihet/redchick.
23
+
24
+
25
+ ## License
26
+
27
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
28
+
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rubocop/rake_task'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'test'
7
+ t.libs << 'lib'
8
+ t.test_files = FileList['test/**/*_test.rb']
9
+ end
10
+
11
+ task default: :test
12
+
13
+ RuboCop::RakeTask.new
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'redchick'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/redchick ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'redchick'
4
+
5
+ Redchick.start
data/lib/redchick.rb ADDED
@@ -0,0 +1,261 @@
1
+ require 'redchick/version'
2
+ require 'redchick/layout'
3
+ require 'readline'
4
+ require 'yaml'
5
+ require 'oauth'
6
+ require 'twitter'
7
+ require 'pry'
8
+ require 'colorize'
9
+
10
+ module Redchick
11
+ CONSUMER_KEY = '6vSPn8nvt62lIXlmQ0f6JSI7O'
12
+ CONSUMER_SECRET = 'PYZQYeIm0ca6Jc6DMdlrMx0hfDyPKZPsksA1WvMWKtgzjeihSO'
13
+ CONFIG_FILE = '.redchick.yml'
14
+
15
+ class Cli
16
+ @client = nil
17
+
18
+ def initialize(config)
19
+ @config = config
20
+ current_user = @config[:current_user]
21
+ token = @config[:users][current_user.to_sym][:oauth_token]
22
+ secret = @config[:users][current_user.to_sym][:oauth_token_secret]
23
+
24
+ @client = Twitter::REST::Client.new do |conf|
25
+ conf.consumer_key = CONSUMER_KEY
26
+ conf.consumer_secret = CONSUMER_SECRET
27
+ conf.access_token = token
28
+ conf.access_token_secret = secret
29
+ end
30
+
31
+ @timeline_opts = {
32
+ count: @config[:count]
33
+ }
34
+ end
35
+
36
+ def start
37
+ puts "redchick version: #{Redchick::VERSION::STRING}"
38
+ client_methods = Redchick::Cli.instance_methods(false)
39
+ commands = client_methods.map(&:to_s)
40
+ comp = proc { |s| commands.grep(/^#{Regexp.escape(s)}/) }
41
+ Readline.completion_proc = comp
42
+ while buf = Readline.readline("\e[31m>\e[0m ", true)
43
+ begin
44
+ cmd, *vals = buf.split(' ')
45
+ if cmd
46
+ cmd = cmd.to_sym
47
+ if client_methods.include?(cmd)
48
+ if vals.empty?
49
+ send(cmd)
50
+ else
51
+ send(cmd, vals)
52
+ end
53
+ else
54
+ puts 'no command'
55
+ puts 'please use help'
56
+ end
57
+ end
58
+ rescue
59
+ puts 'error'
60
+ end
61
+ end
62
+ end
63
+
64
+ def exit
65
+ exit!
66
+ end
67
+ alias_method :quit, :exit
68
+
69
+ def config
70
+ puts @config
71
+ end
72
+
73
+ def layout
74
+ puts @config[:layout]
75
+ end
76
+
77
+ def version
78
+ puts Redchick::VERSION::STRING
79
+ end
80
+
81
+ def help
82
+ help_text = <<-'EOS'
83
+ explore commands:
84
+ home
85
+ mentions
86
+ likes
87
+ view <screen name>
88
+ whois <screen name>
89
+ search <query>
90
+ tweet commands:
91
+ tweet
92
+ reply <tweet id>
93
+ delete <tweet id>
94
+ like <tweet id>
95
+ retweet <tweet id>
96
+ open <tweet id>
97
+ friends and followers commands:
98
+ ls fl,fr
99
+ follow <screen name>
100
+ unfollow <screen name>
101
+ list commands:
102
+ lists
103
+ list <list name>
104
+ EOS
105
+ puts help_text
106
+ end
107
+ alias_method :h, :help
108
+
109
+ def tweet(vals)
110
+ @client.update(vals.join(' '))
111
+ end
112
+ alias_method :t, :tweet
113
+
114
+ def reply(id_and_str)
115
+ id = id_and_str[0]
116
+ str = id_and_str[1]
117
+ target = @client.status(id)
118
+ @client.update("@#{target.user.screen_name} #{str}", in_reply_to_status: target)
119
+ end
120
+ alias_method :rep, :reply
121
+
122
+ def delete(ids)
123
+ ids.each { |id| @client.destroy_status id }
124
+ end
125
+ alias_method :del, :delete
126
+
127
+ def like(ids)
128
+ ids.each { |i| @client.favorite i }
129
+ end
130
+
131
+ def retweet(ids)
132
+ ids.each { |i| @client.retweet i }
133
+ end
134
+
135
+ def open(ids)
136
+ ids.each { |id| system "open #{@client.status(id).uri}" }
137
+ end
138
+ alias_method :o, :open
139
+
140
+ def home
141
+ @client.home_timeline(@timeline_opts).each do |t|
142
+ show_tweet(t)
143
+ end
144
+ end
145
+
146
+ def mentions
147
+ @client.mentions_timeline(@timeline_opts).each do |t|
148
+ show_tweet(t)
149
+ end
150
+ end
151
+
152
+ def likes
153
+ @client.favorites(count: @config[:count]).each do |t|
154
+ show_tweet(t)
155
+ end
156
+ end
157
+
158
+ def view(username)
159
+ @client.user_timeline(username, @timeline_opts).each do |t|
160
+ show_tweet(t)
161
+ end
162
+ end
163
+
164
+ def whois(username)
165
+ user = @client.user(username)
166
+ puts "name: #{user.name}"
167
+ puts "description: #{user.description}"
168
+ puts "tweets: #{user.statuses_count}"
169
+ puts "followers: #{user.followers_count}"
170
+ puts "friends: #{user.friends_count}"
171
+ puts "location: #{user.location}"
172
+ end
173
+
174
+ def search(query)
175
+ @client.search("#{query}").take(@config[:count]).each do |t|
176
+ show_tweet(t)
177
+ end
178
+ end
179
+ alias_method :s, :search
180
+
181
+ def ls(arg)
182
+ case arg[0]
183
+ when 'fl'
184
+ @client.followers.each { |user| puts user.screen_name }
185
+ when 'fr'
186
+ @client.friends.each { |user| puts user.screen_name }
187
+ else
188
+ puts 'error'
189
+ end
190
+ end
191
+
192
+ def follow(users)
193
+ users.each { |u| @client.follow u }
194
+ end
195
+ alias_method :f, :follow
196
+
197
+ def unfollow(users)
198
+ users.each { |u| @client.unfollow u }
199
+ end
200
+ alias_method :uf, :unfollow
201
+
202
+ def block(users)
203
+ users.each { |u| @client.block u }
204
+ end
205
+ alias_method :bl, :block
206
+
207
+ def lists
208
+ @client.owned_lists.each do |l|
209
+ puts l.name
210
+ end
211
+ end
212
+
213
+ def list(arg)
214
+ @client.list_timeline(arg[0]).each do |t|
215
+ show_tweet(t)
216
+ end
217
+ end
218
+
219
+ def show_tweet(t)
220
+ puts Redchick::Layout.send(@config[:layout], t)
221
+ end
222
+ end
223
+
224
+ def self.start
225
+ generate_config_file unless File.exist? File.join(Dir.home, CONFIG_FILE)
226
+ config = YAML.load_file(File.join(Dir.home, CONFIG_FILE))
227
+ cli = Redchick::Cli.new(config)
228
+ cli.start
229
+ end
230
+
231
+ def self.get_access_token
232
+ consumer = OAuth::Consumer.new(
233
+ CONSUMER_KEY,
234
+ CONSUMER_SECRET,
235
+ site: 'https://api.twitter.com'
236
+ )
237
+ request_token = consumer.get_request_token
238
+ puts 'open following url and authorize it', request_token.authorize_url
239
+ puts 'enter PIN: '
240
+ pin = STDIN.gets.chomp
241
+ access_token = request_token.get_access_token(oauth_verifier: pin)
242
+ end
243
+
244
+ def self.generate_config_file
245
+ access_token = get_access_token
246
+ screen_name = access_token.params[:screen_name]
247
+ config = {
248
+ current_user: screen_name,
249
+ layout: 'basic',
250
+ count: 15,
251
+ users: {
252
+ "#{screen_name}": {
253
+ oauth_token: access_token.token,
254
+ oauth_token_secret: access_token.secret
255
+ }
256
+ }
257
+ }
258
+ f = File.new(File.join(Dir.home, CONFIG_FILE), 'w')
259
+ f.write config.to_yaml
260
+ end
261
+ end
@@ -0,0 +1,15 @@
1
+ module Redchick
2
+ module Layout
3
+ @colors = [:red, :green, :yellow, :blue, :magenta, :cyan]
4
+ def self.simple(t)
5
+ "#{t.user.screen_name.rjust(15)}: #{t.text}"
6
+ end
7
+
8
+ def self.basic(t)
9
+ "#{t.user.name} @#{t.user.screen_name} #{t.created_at}\n"\
10
+ "#{t.text}\n"\
11
+ "rt: #{t.retweet_count}, like: #{t.favorite_count}, id: #{t.id}\n"\
12
+ '--'.colorize(@colors[t.user.screen_name.sum % @colors.size])
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module Redchick
2
+ module VERSION
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ PATCH = 5
6
+
7
+ STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
+ end
9
+ end
data/redchick.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'redchick/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'redchick'
8
+ spec.version = Redchick::VERSION::STRING
9
+ spec.authors = ['saki']
10
+ spec.email = ['sakihet@gmail.com']
11
+
12
+ spec.summary = 'twitter client'
13
+ spec.description = 'twitter client'
14
+ spec.homepage = ''
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_runtime_dependency 'oauth', '~> 0.4.7'
23
+ spec.add_runtime_dependency 'twitter', '~> 5.15'
24
+ spec.add_runtime_dependency 'colorize', '~> 0.7.7'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.10'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'minitest'
29
+ spec.add_development_dependency 'pry', '~> 0.10.3'
30
+ spec.add_development_dependency 'rubocop', '~> 0.35.1'
31
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redchick
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - saki
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.4.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: twitter
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.15'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.7.7
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.7.7
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.10.3
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.10.3
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.35.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.35.1
125
+ description: twitter client
126
+ email:
127
+ - sakihet@gmail.com
128
+ executables:
129
+ - redchick
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - exe/redchick
142
+ - lib/redchick.rb
143
+ - lib/redchick/layout.rb
144
+ - lib/redchick/version.rb
145
+ - redchick.gemspec
146
+ homepage: ''
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.5.1
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: twitter client
170
+ test_files: []