t_chatter 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/bin/setup_t_chatter +30 -14
- data/bin/t_chatter +2 -10
- data/lib/t_chatter/chat.rb +39 -6
- data/lib/t_chatter/entry.rb +111 -0
- data/lib/t_chatter/version.rb +1 -1
- data/lib/t_chatter.rb +2 -0
- data/t_chatter-0.1.0.gem +0 -0
- data/t_chatter.gemspec +22 -7
- metadata +29 -19
- data/lib/t_chatter/start.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20d112a39dc3f70adc1aba142d9e3ce0e13cb899
|
4
|
+
data.tar.gz: f5d6b2e9e9bd72337e48e9a57f2c291d9fcd217f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5291a053fa7f109fb8856ddba828d02c33787efea9d256e13e8b38671d56b3a59eb600e258125544623e61620b8888786d5283266a1228190740dfb3ce09507d
|
7
|
+
data.tar.gz: 39c87ee99bb7ad6dce34fcd6e4011d4a97bff1467b708fe9fd0cb639785497606f78ca3502056de31566faa702825b61557073ea64224e44a7319a9b768224ad
|
data/.gitignore
CHANGED
data/bin/setup_t_chatter
CHANGED
@@ -25,48 +25,64 @@ end
|
|
25
25
|
|
26
26
|
config = Hash.new(nil)
|
27
27
|
|
28
|
+
true_false_cmd = {
|
29
|
+
'true' => true,
|
30
|
+
'yes' => true,
|
31
|
+
'y' => true,
|
32
|
+
't' => true,
|
33
|
+
'' => true,
|
34
|
+
'false' => false,
|
35
|
+
'no' => false,
|
36
|
+
'n' => false,
|
37
|
+
'f' => false
|
38
|
+
}
|
39
|
+
|
40
|
+
tfc_short = true_false_cmd.keys.reject{ |k, v| k == '' }.join(', ')
|
41
|
+
|
28
42
|
print "What is your name?(optional) : "
|
29
43
|
config[:user] = gets.chomp.strip
|
30
44
|
|
31
45
|
puts ""
|
32
46
|
|
33
|
-
print "Would you like to
|
47
|
+
print "Would you like to send messages?(optional) #enter (#{tfc_short}) : "
|
34
48
|
config[:send] = gets.chomp.strip
|
35
49
|
|
36
50
|
puts ""
|
37
51
|
|
38
|
-
print "Would you like to receive messages?(optional) : "
|
52
|
+
print "Would you like to receive messages?(optional) #enter (#{tfc_short}) : "
|
39
53
|
config[:receive] = gets.chomp.strip
|
40
54
|
|
41
55
|
print "Enter your URL for the Server?(optional) : "
|
42
56
|
config[:host] = gets.chomp.strip
|
43
57
|
|
44
|
-
true_cmd = {
|
45
|
-
'true' => true,
|
46
|
-
'yes' => true,
|
47
|
-
'y' => true,
|
48
|
-
'' => true,
|
49
|
-
'false' => false,
|
50
|
-
'no' => false,
|
51
|
-
'n' => false
|
52
|
-
}
|
53
58
|
|
54
59
|
real_config = Hash.new(nil)
|
55
60
|
config.each{ |x, y|
|
56
61
|
if [:send, :receive].include? x
|
57
|
-
real_config[x] =
|
58
|
-
real_config[x] = true unless
|
62
|
+
real_config[x] = true_false_cmd[y]
|
63
|
+
real_config[x] = true unless true_false_cmd.keys.include? y
|
59
64
|
else
|
60
65
|
real_config[x] = y if !y.blank?
|
61
66
|
end
|
62
67
|
}
|
63
68
|
|
64
69
|
real_config[:host] = TChatter::DEFAULT_URL unless real_config[:host]
|
70
|
+
real_config[:user_id] = TChatter::UNIQUE_ID
|
65
71
|
|
66
72
|
File.open(file_location, 'w') do |f|
|
67
73
|
::YAML.dump real_config, f
|
68
74
|
end
|
69
75
|
|
76
|
+
applications_to_be_supported = %w[ Slack HipChat ].join(', ')
|
77
|
+
|
70
78
|
puts <<-EOS
|
71
|
-
Congratulations you have completed the basic setup. The file can be found at:
|
79
|
+
Congratulations you have completed the basic setup. The file can be found at:
|
80
|
+
#{file_location}
|
81
|
+
|
82
|
+
To connect to TChatter
|
83
|
+
run `t_chatter` from your terminal and watch the messages stream in
|
84
|
+
|
85
|
+
|
86
|
+
Note: As part of the future plans, you would be able to connect TChatter to
|
87
|
+
your #{applications_to_be_supported} application so you never miss a chat
|
72
88
|
EOS
|
data/bin/t_chatter
CHANGED
@@ -3,13 +3,5 @@
|
|
3
3
|
require "bundler/setup"
|
4
4
|
require "t_chatter"
|
5
5
|
|
6
|
-
|
7
|
-
|
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
|
15
|
-
TChatter::Start.chat
|
6
|
+
chat = TChatter::Entry.new
|
7
|
+
chat.start_chat
|
data/lib/t_chatter/chat.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
module TChatter
|
2
2
|
class Chat
|
3
|
-
attr_reader :connection, :messages, :response, :last_message_id, :user, :config
|
3
|
+
attr_reader :connection, :messages, :response, :last_message_id, :user, :user_id, :config, :url, :all_users
|
4
4
|
# attr_accessor :url
|
5
5
|
|
6
6
|
def initialize(username, config_class)
|
7
7
|
@user = username
|
8
8
|
@messages = []
|
9
9
|
@last_message_id = 0
|
10
|
+
@all_users = []
|
10
11
|
@config = config_class.configuration
|
12
|
+
@user_id = config[:user_id] || UNIQUE_ID
|
11
13
|
set_url
|
12
14
|
connect
|
15
|
+
subscribe_user
|
16
|
+
end
|
17
|
+
|
18
|
+
def subscribe_user
|
19
|
+
connection.post('/new_user', {user_id: user_id , user: user})
|
13
20
|
end
|
14
21
|
|
15
22
|
def set_url
|
@@ -22,7 +29,7 @@ module TChatter
|
|
22
29
|
used everytime you try to connect. However you are now being connected
|
23
30
|
to the global chatter stream
|
24
31
|
EOS
|
25
|
-
@url = URI.parse(
|
32
|
+
@url = URI.parse(DEFAULT_URL)
|
26
33
|
end
|
27
34
|
end
|
28
35
|
|
@@ -37,8 +44,9 @@ module TChatter
|
|
37
44
|
|
38
45
|
def send_message(message)
|
39
46
|
response = connection.post('/send', {message: message, user: user})
|
40
|
-
response = JSON.parse(response.body)
|
41
|
-
@last_message_id = response["last_message_id"]
|
47
|
+
@response = JSON.parse(response.body)
|
48
|
+
@last_message_id = @response["last_message_id"]
|
49
|
+
@messages << message
|
42
50
|
@last_message = message
|
43
51
|
end
|
44
52
|
|
@@ -49,10 +57,35 @@ module TChatter
|
|
49
57
|
last_id = @response["last_message_id"]
|
50
58
|
unless last_id == last_message_id
|
51
59
|
message = @response["message"]
|
52
|
-
@last_message_id = @response["last_message_id"]
|
53
|
-
@messages << message if message
|
54
60
|
puts message
|
61
|
+
@last_message_id = last_id
|
62
|
+
update_messages(message) unless message.blank?
|
55
63
|
end
|
64
|
+
get_subscribed_users if all_users.size < @response["total_users"].to_i
|
65
|
+
end
|
66
|
+
|
67
|
+
def update_messages(message)
|
68
|
+
message = message.split("\n")
|
69
|
+
@last_message = message.last
|
70
|
+
@messages += message
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_subscribed_users
|
74
|
+
response = connection.get('/all_users')
|
75
|
+
response = JSON.parse(response.body)
|
76
|
+
@all_users = response["users"]
|
77
|
+
end
|
78
|
+
|
79
|
+
def each_user
|
80
|
+
@all_users.map{ |y| y['name'] }.join(', ')
|
81
|
+
end
|
82
|
+
|
83
|
+
def show_all_users
|
84
|
+
puts @all_users.map{ |y| "#{y['name']} joined at #{y['joined']}"}.join("\n")
|
85
|
+
end
|
86
|
+
|
87
|
+
def quit
|
88
|
+
connection.get('/quit', {user_id: user_id})
|
56
89
|
end
|
57
90
|
end
|
58
91
|
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module TChatter
|
2
|
+
class Entry
|
3
|
+
attr_reader :user, :config, :chat, :threads
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@config = ConfigSetup.instance
|
7
|
+
setup_user
|
8
|
+
@chat = Chat.new(@user, @config)
|
9
|
+
@threads = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def start_chat
|
13
|
+
setup_threads
|
14
|
+
control_exit_strategy
|
15
|
+
start_threads
|
16
|
+
end
|
17
|
+
|
18
|
+
def want_to_send?
|
19
|
+
@config.configuration.blank? ? true : @config.configuration[:send]
|
20
|
+
end
|
21
|
+
|
22
|
+
def want_to_receive?
|
23
|
+
@config.configuration.blank? ? true : @config.configuration[:receive]
|
24
|
+
end
|
25
|
+
|
26
|
+
def setup_user
|
27
|
+
@user = config.configuration[:user]
|
28
|
+
unless @user
|
29
|
+
print 'Would you mind telling me your name? : '
|
30
|
+
@user = gets.chomp
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def stream_messages
|
35
|
+
Thread.new do
|
36
|
+
loop do
|
37
|
+
chat.receive_message
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def variables_subs
|
43
|
+
{ '@my_name' => chat.user.to_s, '@last_message' => chat.messages.last.to_s, '@each_user' => chat.each_user }
|
44
|
+
end
|
45
|
+
|
46
|
+
def substitute_variables(message)
|
47
|
+
variables_subs.each do |var, val|
|
48
|
+
message = message.gsub(var, val)
|
49
|
+
end
|
50
|
+
message
|
51
|
+
end
|
52
|
+
|
53
|
+
def peep
|
54
|
+
chat.show_all_users
|
55
|
+
end
|
56
|
+
|
57
|
+
def help
|
58
|
+
var_help = variables_subs.keys.join(', ')
|
59
|
+
command_help = commands.keys.join(', ')
|
60
|
+
puts <<-EOS
|
61
|
+
Use the following variables in any message to refer to its inferred
|
62
|
+
meaning in any message: #{var_help}
|
63
|
+
You can use any of these commands to also call the inferred action
|
64
|
+
#{command_help}
|
65
|
+
EOS
|
66
|
+
end
|
67
|
+
|
68
|
+
def quit
|
69
|
+
puts "Gracefully shutting down the chat"
|
70
|
+
chat.quit
|
71
|
+
@threads.each(&:exit)
|
72
|
+
end
|
73
|
+
|
74
|
+
def commands
|
75
|
+
{
|
76
|
+
'#all_users' => :peep,
|
77
|
+
'#help' => :help,
|
78
|
+
'#quit' => :quit
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
def send_messages
|
83
|
+
Thread.new do
|
84
|
+
loop do
|
85
|
+
message = gets.chomp.strip
|
86
|
+
unless commands.keys.include? message
|
87
|
+
message = substitute_variables(message) if message.match(/@\w+/)
|
88
|
+
chat.send_message(message) unless message.blank?
|
89
|
+
else
|
90
|
+
send(commands[message])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def control_exit_strategy
|
97
|
+
trap('INT') do
|
98
|
+
quit
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def setup_threads
|
103
|
+
@threads << stream_messages if want_to_receive?
|
104
|
+
@threads << send_messages if want_to_send?
|
105
|
+
end
|
106
|
+
|
107
|
+
def start_threads
|
108
|
+
@threads.each(&:join)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/lib/t_chatter/version.rb
CHANGED
data/lib/t_chatter.rb
CHANGED
data/t_chatter-0.1.0.gem
ADDED
Binary file
|
data/t_chatter.gemspec
CHANGED
@@ -9,21 +9,36 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Oreoluwa Akinniranye"]
|
10
10
|
spec.email = ["oreoluwa.akinniranye@andela.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{Allows you to chat on your terminal}
|
13
|
-
spec.
|
14
|
-
|
15
|
-
spec.
|
12
|
+
spec.summary = %q{Allows you to chat on your terminal|command line}
|
13
|
+
spec.homepage = "https://github.com/andela-oakinniranye/t_chatter"
|
14
|
+
|
15
|
+
spec.description = <<-EOS
|
16
|
+
TChatter allows you to chat with your friends on your
|
17
|
+
terminal.
|
18
|
+
You can extend it further though to chat with your
|
19
|
+
friends on Slack and other applications."
|
20
|
+
Visit <a href='#{spec.homepage}'>TChatter's Homepage</a>
|
21
|
+
to read more on the application.
|
22
|
+
EOS
|
16
23
|
|
24
|
+
spec.license = "MIT"
|
17
25
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
26
|
spec.bindir = "bin"
|
19
27
|
spec.executables = ['t_chatter', 'setup_t_chatter']
|
20
28
|
spec.require_paths = ["lib"]
|
21
29
|
|
22
|
-
spec.add_dependency "faraday"
|
23
|
-
spec.add_dependency "json"
|
30
|
+
spec.add_dependency "faraday", "~> 0.9"
|
31
|
+
spec.add_dependency "json", "~> 1.8"
|
32
|
+
|
33
|
+
spec.post_install_message = <<-EOS
|
24
34
|
|
25
|
-
|
35
|
+
Thanks for trying out my interesting gem.
|
36
|
+
To complete the installation, run `setup_t_chatter` to
|
37
|
+
create a .chatter.yml configuration file.
|
38
|
+
This allows you to use your own url and set defaults
|
39
|
+
for your version of TChatter
|
26
40
|
|
41
|
+
EOS
|
27
42
|
|
28
43
|
spec.add_development_dependency "bundler", "~> 1.10"
|
29
44
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: t_chatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oreoluwa Akinniranye
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '0.9'
|
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: '0'
|
26
|
+
version: '0.9'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.8'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '1.8'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,8 +66,13 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '10.0'
|
69
|
-
description:
|
70
|
-
|
69
|
+
description: |2
|
70
|
+
TChatter allows you to chat with your friends on your
|
71
|
+
terminal.
|
72
|
+
You can extend it further though to chat with your
|
73
|
+
friends on Slack and other applications."
|
74
|
+
Visit <a href='https://github.com/andela-oakinniranye/t_chatter'>TChatter's Homepage</a>
|
75
|
+
to read more on the application.
|
71
76
|
email:
|
72
77
|
- oreoluwa.akinniranye@andela.com
|
73
78
|
executables:
|
@@ -90,17 +95,22 @@ files:
|
|
90
95
|
- lib/t_chatter.rb
|
91
96
|
- lib/t_chatter/chat.rb
|
92
97
|
- lib/t_chatter/config_setup.rb
|
93
|
-
- lib/t_chatter/
|
98
|
+
- lib/t_chatter/entry.rb
|
94
99
|
- lib/t_chatter/version.rb
|
100
|
+
- t_chatter-0.1.0.gem
|
95
101
|
- t_chatter.gemspec
|
96
|
-
homepage:
|
102
|
+
homepage: https://github.com/andela-oakinniranye/t_chatter
|
97
103
|
licenses:
|
98
104
|
- MIT
|
99
105
|
metadata: {}
|
100
|
-
post_install_message:
|
101
|
-
|
102
|
-
|
103
|
-
|
106
|
+
post_install_message: |2+
|
107
|
+
|
108
|
+
Thanks for trying out my interesting gem.
|
109
|
+
To complete the installation, run `setup_t_chatter` to
|
110
|
+
create a .chatter.yml configuration file.
|
111
|
+
This allows you to use your own url and set defaults
|
112
|
+
for your version of TChatter
|
113
|
+
|
104
114
|
rdoc_options: []
|
105
115
|
require_paths:
|
106
116
|
- lib
|
@@ -119,5 +129,5 @@ rubyforge_project:
|
|
119
129
|
rubygems_version: 2.4.8
|
120
130
|
signing_key:
|
121
131
|
specification_version: 4
|
122
|
-
summary: Allows you to chat on your terminal
|
132
|
+
summary: Allows you to chat on your terminal|command line
|
123
133
|
test_files: []
|
data/lib/t_chatter/start.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module TChatter
|
2
|
-
class Start
|
3
|
-
|
4
|
-
def self.chat
|
5
|
-
config = ConfigSetup.instance
|
6
|
-
user = config.configuration[:user]
|
7
|
-
|
8
|
-
# host = config[:host]
|
9
|
-
unless user
|
10
|
-
print "Would you mind telling me your name? > "
|
11
|
-
user = gets.chomp
|
12
|
-
end
|
13
|
-
|
14
|
-
chat = Chat.new(user, config)
|
15
|
-
|
16
|
-
want_to_receive = config.configuration.blank? ? true : config.configuration[:receive]
|
17
|
-
want_to_send = config.configuration.blank? ? true : config.configuration[:send]
|
18
|
-
|
19
|
-
threads = []
|
20
|
-
|
21
|
-
|
22
|
-
if want_to_receive
|
23
|
-
#response object
|
24
|
-
threads << Thread.new do
|
25
|
-
loop{
|
26
|
-
chat.receive_message
|
27
|
-
}
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
if want_to_send
|
32
|
-
#request object
|
33
|
-
threads << Thread.new do
|
34
|
-
loop{
|
35
|
-
message = gets.chomp
|
36
|
-
chat.send_message(message) if message
|
37
|
-
}
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
trap("INT") {
|
42
|
-
puts "Exiting the chat"
|
43
|
-
threads.each{|t|
|
44
|
-
t.exit
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
threads.each{ |thread|
|
49
|
-
thread.join
|
50
|
-
}
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|