campline 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "tinder"
4
+ gem "rb-readline"
5
+ gem "cli-colorize"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "pry"
11
+ gem "rspec", "~> 2.8.0"
12
+ gem "bundler"
13
+ gem "jeweler", "~> 1.8.4"
14
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Herval
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ = campline
2
+
3
+ A tiny Campfire client.
4
+
5
+ Usage: campline <domain> <room> <username>
6
+
7
+ The client will prompt for your password and that's it - you're in!
8
+
9
+ == Contributing to campline
10
+
11
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
12
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
13
+ * Fork the project.
14
+ * Start a feature/bugfix branch.
15
+ * Commit and push until you are happy with your contribution.
16
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
17
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
18
+
19
+ == Copyright
20
+
21
+ Partially based on campfire-cli, by Petyo Ivanov
22
+
23
+ Copyleft (c) 2012 Herval. See LICENSE.txt for further details.
24
+
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "campline"
18
+ gem.homepage = "http://github.com/herval/campline"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A tiny Campfire client}
21
+ gem.description = %Q{A tiny Campfire client for command line}
22
+ gem.email = "hervalfreire@gmail.com"
23
+ gem.authors = ["Herval Freire"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "campline #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require "campline"
4
+
5
+ if ARGV.size != 3
6
+ puts "Usage: campline <domain> <room> <username>"
7
+ exit 1
8
+ end
9
+
10
+ domain, room, username = *ARGV
11
+
12
+ puts "Type in your password:"
13
+ password = $stdin.gets.strip
14
+
15
+ Campline::Client.new(domain, room, username, password).listen!
@@ -0,0 +1,70 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "campline"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Herval Freire"]
12
+ s.date = "2012-07-02"
13
+ s.description = "A tiny Campfire client for command line"
14
+ s.email = "hervalfreire@gmail.com"
15
+ s.executables = ["campline"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/campline",
29
+ "campline.gemspec",
30
+ "lib/campline.rb",
31
+ "spec/campline_spec.rb",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = "http://github.com/herval/campline"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "1.8.24"
38
+ s.summary = "A tiny Campfire client"
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<tinder>, [">= 0"])
45
+ s.add_runtime_dependency(%q<rb-readline>, [">= 0"])
46
+ s.add_runtime_dependency(%q<cli-colorize>, [">= 0"])
47
+ s.add_development_dependency(%q<pry>, [">= 0"])
48
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
49
+ s.add_development_dependency(%q<bundler>, [">= 0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
51
+ else
52
+ s.add_dependency(%q<tinder>, [">= 0"])
53
+ s.add_dependency(%q<rb-readline>, [">= 0"])
54
+ s.add_dependency(%q<cli-colorize>, [">= 0"])
55
+ s.add_dependency(%q<pry>, [">= 0"])
56
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
57
+ s.add_dependency(%q<bundler>, [">= 0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<tinder>, [">= 0"])
62
+ s.add_dependency(%q<rb-readline>, [">= 0"])
63
+ s.add_dependency(%q<cli-colorize>, [">= 0"])
64
+ s.add_dependency(%q<pry>, [">= 0"])
65
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
66
+ s.add_dependency(%q<bundler>, [">= 0"])
67
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
68
+ end
69
+ end
70
+
@@ -0,0 +1,113 @@
1
+ require 'rubygems'
2
+ require 'readline'
3
+ require 'tinder'
4
+ require 'yaml'
5
+ require 'cli-colorize'
6
+
7
+ module Campline
8
+
9
+ class Client
10
+ include Tinder
11
+ include CLIColorize
12
+
13
+ def initialize(domain, room, username, password)
14
+ @domain = domain
15
+ @room = room
16
+ @username = username
17
+ @password = password
18
+ @user_id = nil
19
+ @room_users = []
20
+ end
21
+
22
+ def print_message(msg)
23
+ next if msg[:user] && msg[:user][:id] == @user_id
24
+ case msg[:type]
25
+ when "SoundMessage" then
26
+ puts "#{green(msg[:user][:name])} played some annoying sound"
27
+ when "PasteMessage" then
28
+ puts "#{green(msg[:user][:name])}: #{msg[:body]}"
29
+ when "TextMessage" then
30
+ puts "#{green(msg[:user][:name])}: #{msg[:body]}"
31
+ end
32
+ end
33
+
34
+ def commands
35
+ {
36
+ "/help" => lambda { puts "Available commands: /users (list users on the room), /exit (quit!)"},
37
+ "/exit" => lambda { @campfire_room.leave; exit; },
38
+ "/users" => lambda { list_users }
39
+ }
40
+ end
41
+
42
+ def list_users
43
+ puts white("In the room right now: #{@room_users.join(', ')}")
44
+ end
45
+
46
+ def update_user_list
47
+ new_list = @campfire_room.users.collect(&:name)
48
+ @room_users = new_list if @room_users.empty?
49
+
50
+ new_guys = new_list - @room_users
51
+ new_guys.each { |n| puts "#{n} joined the room" }
52
+
53
+ dead_guys = @room_users - new_list
54
+ dead_guys.each { |n| puts "#{n} left the room" }
55
+ @room_users = new_list
56
+ end
57
+
58
+ def blue(str)
59
+ colorize(str, :foreground => :blue)
60
+ end
61
+
62
+ def green(str)
63
+ colorize(str, :foreground => :green)
64
+ end
65
+
66
+ def white(str)
67
+ colorize(str, :foreground => :white)
68
+ end
69
+
70
+ def highlight(str)
71
+ colorize(str, :background => :red)
72
+ end
73
+
74
+ def listen!
75
+ puts "Logging in..."
76
+ campfire = Campfire.new @domain, :username => @username, :password => @password, :ssl => true
77
+ @user_id = campfire.me.id
78
+
79
+ puts "Joining #{@room}..."
80
+ @campfire_room = campfire.find_room_by_name @room
81
+ @campfire_room.join
82
+
83
+ update_user_list
84
+
85
+ puts "You're up! For a list of available commands, type #{highlight('/help')}"
86
+
87
+ Thread.new(@campfire_room) do |listener|
88
+ while true
89
+ listener.listen do |msg|
90
+ print_message msg
91
+ end
92
+ end
93
+ end
94
+
95
+ Thread.new do
96
+ while true
97
+ sleep(10)
98
+ update_user_list
99
+ end
100
+ end
101
+
102
+ while msg = Readline.readline('', true)
103
+ next if msg.strip.blank?
104
+ if commands[msg]
105
+ commands[msg].call
106
+ else
107
+ @campfire_room.speak msg
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Campline" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'campline'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: campline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Herval Freire
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: tinder
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: rb-readline
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '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: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: cli-colorize
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: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 2.8.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: 2.8.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: bundler
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: jeweler
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 1.8.4
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: 1.8.4
126
+ description: A tiny Campfire client for command line
127
+ email: hervalfreire@gmail.com
128
+ executables:
129
+ - campline
130
+ extensions: []
131
+ extra_rdoc_files:
132
+ - LICENSE.txt
133
+ - README.rdoc
134
+ files:
135
+ - .document
136
+ - .rspec
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.rdoc
140
+ - Rakefile
141
+ - VERSION
142
+ - bin/campline
143
+ - campline.gemspec
144
+ - lib/campline.rb
145
+ - spec/campline_spec.rb
146
+ - spec/spec_helper.rb
147
+ homepage: http://github.com/herval/campline
148
+ licenses:
149
+ - MIT
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ segments:
161
+ - 0
162
+ hash: 813841254707109310
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ none: false
165
+ requirements:
166
+ - - ! '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 1.8.24
172
+ signing_key:
173
+ specification_version: 3
174
+ summary: A tiny Campfire client
175
+ test_files: []