Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 52877768f876e73306abbc7e19677eb3db364914 @jch committed Feb 11, 2012
@@ -0,0 +1,18 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
+.DS_Store
1 .rspec
@@ -0,0 +1 @@
+--color
1 .rvmrc
@@ -0,0 +1 @@
+rvm use 1.9.3
@@ -0,0 +1,10 @@
+rvm:
+ - 1.9.2
+ - 1.9.3
+bundler_args: --without darwin
+gemfile:
+ - Gemfile
+before_script:
+ - "sudo apt-get install ngircd"
+ - "cd spec/config && ngircd -f ngircd-unencrypted.conf && ngircd -f ngircd-encrypted.conf"
+script: "rake spec"
@@ -0,0 +1 @@
+--no-private --protected - LICENSE
21 Gemfile
@@ -0,0 +1,21 @@
+source 'http://rubygems.org'
+
+# Specify your gem's dependencies in em-irc.gemspec
+gemspec
+
+group :development, :test do
+ gem 'rake'
+ gem 'rspec', "~> 2"
+ gem 'pry'
+ gem 'yard'
+ gem 'redcarpet'
+
+ gem 'guard'
+ gem 'guard-rspec'
+ gem 'guard-bundler'
+end
+
+group :darwin do
+ gem 'rb-fsevent'
+ gem 'growl'
+end
@@ -0,0 +1,13 @@
+# A sample Guardfile
+# More info at https://github.com/guard/guard#readme
+
+guard 'bundler' do
+ watch('Gemfile')
+end
+
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('lib/em-irc.rb') { "spec" }
+ watch('spec/spec_helper.rb') { "spec" }
+end
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2012 Jerry Cheung.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,96 @@
+# EventMachine IRC Client
+
+[![CI Build Status](https://secure.travis-ci.org/jch/em-irc.png?branch=master)]
+
+em-irc is an IRC client that uses EventMachine to handle connections to servers.
+
+## Basic Usage
+
+````ruby
+require 'em-irc'
+
+client = EventMachine::IRC::Client.new do |c|
+ c.host = 'irc.freenode.net'
+ c.port = '6667'
+ c.nick = 'jch'
+
+ c.on(:connect) do
+ join('#general')
+ join('#private', 'key')
+ end
+
+ c.on(:join) do |channel| # called after joining a channel
+ message(channel, "howdy all")
+ end
+
+ c.on(:message) do |source, target, message| # called when being messaged
+ puts "<#{source}> -> <#{target}>: #{message}"
+ end
+
+ # callback for all messages sent from IRC server
+ c.on(:raw) do |hash|
+ puts "#{hash[:prefix]} #{hash[:command]} #{hash[:params].join(' ')}"
+ end
+end
+
+client.run! # start EventMachine loop
+````
+
+## Examples
+
+In the examples folder, there are runnable examples.
+
+* cli.rb - takes input from keyboard, outputs to stdout
+* websocket.rb -
+* echo.rb - bot that echos everything
+* callback.rb - demonstrate how callbacks work
+
+## References
+
+* [RFC 1459 - Internet Relay Chat Protocol](http://tools.ietf.org/html/rfc1459) overview of IRC architecture
+* [RFC 2812 - Internet Relay Chat: Client Protocol](http://tools.ietf.org/html/rfc2812) specifics of client protocol
+* [RFC 2813 - Internet Relay Chat: Server Protocol](http://tools.ietf.org/html/rfc2813) specifics of server protocol
+
+## Development
+
+To run integration specs, you'll need to run a ssl and a non-ssl irc server locally.
+On OSX, you can install a server via [Homebrew](http://mxcl.github.com/homebrew/) with:
+
+```
+bundle
+brew install ngircd
+cd spec/config
+ngircd -f ngircd-unencrypted.conf
+ngircd -f ngircd-encrypted.conf
+rake # or guard
+```
+
+## <a name="license"></a>License
+
+Copyright (c) 2012 Jerry Cheung.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+## TODO
+
+* can we skip using Dispatcher connection handler class?
+* extract :on, :trigger callback gem that works on instances. [hook](https://github.com/apotonick/hooks), but works with instances
+* would prefer the interface to look synchronous, but work async
+* ssl dispatcher testing
+* speed up integration specs
@@ -0,0 +1,6 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
+Bundler::GemHelper.install_tasks
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:spec)
+task :default => :spec
@@ -0,0 +1,20 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/em-irc/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Jerry Cheung"]
+ gem.email = ["jch@whatcodecraves.com"]
+ gem.description = %q{em-irc is an IRC client that uses EventMachine to handle connections to servers}
+ gem.summary = %q{em-irc is an IRC client that uses EventMachine to handle connections to servers}
+ gem.homepage = "http://github.com/jch/em-irc"
+
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.name = "em-irc"
+ gem.require_paths = ["lib"]
+ gem.version = EventMachine::IRC::VERSION
+
+ gem.add_runtime_dependency 'eventmachine'
+ gem.add_runtime_dependency 'activesupport'
+end
@@ -0,0 +1,24 @@
+require File.expand_path '../../lib/em-irc', __FILE__
+require 'logger'
+
+client = EventMachine::IRC::Client.new do
+ host '127.0.0.1'
+ port '6667'
+ # logger Logger.new(STDOUT)
+
+ on :connect do
+ puts 'client connected'
+ join("#general")
+ end
+
+ on :message do |source, target, message|
+ puts "#{target} <#{source}> #{message}"
+ end
+
+ # on :raw do |m|
+ # # puts "raw message: #{m.inspect}"
+ # end
+end
+
+# puts client.callbacks
+client.run!
@@ -0,0 +1,18 @@
+require 'bundler'
+Bundler.setup :default
+
+require 'active_support/core_ext/hash/keys'
+require 'active_support/core_ext/object/blank'
+require 'active_support/callbacks'
+require 'eventmachine'
+require 'forwardable'
+require 'set'
+
+$:.unshift File.expand_path '..', __FILE__
+
+module EventMachine
+ module IRC
+ autoload :Client, 'em-irc/client'
+ autoload :Dispatcher, 'em-irc/dispatcher'
+ end
+end
Oops, something went wrong.

0 comments on commit 5287776

Please sign in to comment.