net-irc-mala 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 kimoto
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,2 @@
1
+ = net-irc-mala
2
+
@@ -0,0 +1,61 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "net-irc-mala"
8
+ gem.summary = %Q{mala following API IRC Gateway}
9
+ gem.description = %Q{mala following API IRC Gateway}
10
+ gem.email = "sub+peerler@gmail.com"
11
+ gem.homepage = "http://github.com/kimoto/net-irc-mala"
12
+ gem.authors = ["kimoto"]
13
+ gem.add_development_dependency "thoughtbot-shoulda"
14
+
15
+ gem.add_dependency 'net-irc'
16
+ gem.add_dependency 'em-eventsource'
17
+ gem.add_dependency 'json'
18
+
19
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
+ end
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
23
+ end
24
+
25
+ require 'rake/testtask'
26
+ Rake::TestTask.new(:test) do |test|
27
+ test.libs << 'lib' << 'test'
28
+ test.pattern = 'test/**/*_test.rb'
29
+ test.verbose = true
30
+ end
31
+
32
+ begin
33
+ require 'rcov/rcovtask'
34
+ Rcov::RcovTask.new do |test|
35
+ test.libs << 'test'
36
+ test.pattern = 'test/**/*_test.rb'
37
+ test.verbose = true
38
+ end
39
+ rescue LoadError
40
+ task :rcov do
41
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
42
+ end
43
+ end
44
+
45
+ task :test => :check_dependencies
46
+
47
+ task :default => :test
48
+
49
+ require 'rake/rdoctask'
50
+ Rake::RDocTask.new do |rdoc|
51
+ if File.exist?('VERSION')
52
+ version = File.read('VERSION')
53
+ else
54
+ version = ""
55
+ end
56
+
57
+ rdoc.rdoc_dir = 'rdoc'
58
+ rdoc.title = "net-irc-mala #{version}"
59
+ rdoc.rdoc_files.include('README*')
60
+ rdoc.rdoc_files.include('lib/**/*.rb')
61
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ require 'net/irc/mala'
4
+ Net::IRC::CLI.run(Net::IRC::Mala, ARGV)
5
+
@@ -0,0 +1,6 @@
1
+ #!/bin/env ruby
2
+ # encoding: utf-8
3
+ # Author: kimoto
4
+ require 'net/irc/mala'
5
+ Net::IRC::CLI.run(Net::IRC::MalaFav, ARGV)
6
+
@@ -0,0 +1,73 @@
1
+ module Net::IRC::CLI
2
+ def self.daemonize(foreground=false)
3
+ trap("SIGINT") { exit! 0 }
4
+ trap("SIGTERM") { exit! 0 }
5
+ trap("SIGHUP") { exit! 0 }
6
+ return yield if $DEBUG || foreground
7
+ Process.fork do
8
+ Process.setsid
9
+ Dir.chdir "/"
10
+ File.open("/dev/null") {|f|
11
+ STDIN.reopen f
12
+ STDOUT.reopen f
13
+ STDERR.reopen f
14
+ }
15
+ yield
16
+ end
17
+ exit! 0
18
+ end
19
+
20
+ def self.run(server_session_klass, argv)
21
+ opts = {
22
+ :port => 16701,
23
+ :host => "localhost",
24
+ :log => nil,
25
+ :debug => false,
26
+ :foreground => false,
27
+ }
28
+
29
+ OptionParser.new do |parser|
30
+ parser.instance_eval do
31
+ self.banner = <<-EOB.gsub(/^\t+/, "")
32
+ Usage: #{$0} [opts]
33
+
34
+ EOB
35
+
36
+ separator ""
37
+
38
+ separator "Options:"
39
+ on("-p", "--port [PORT=#{opts[:port]}]", "port number to listen") do |port|
40
+ opts[:port] = port
41
+ end
42
+
43
+ on("-h", "--host [HOST=#{opts[:host]}]", "host name or IP address to listen") do |host|
44
+ opts[:host] = host
45
+ end
46
+
47
+ on("-l", "--log LOG", "log file") do |log|
48
+ opts[:log] = log
49
+ end
50
+
51
+ on("--debug", "Enable debug mode") do |debug|
52
+ opts[:log] = $stdout
53
+ opts[:debug] = true
54
+ end
55
+
56
+ on("-f", "--foreground", "run foreground") do |foreground|
57
+ opts[:log] = $stdout
58
+ opts[:foreground] = true
59
+ end
60
+
61
+ parse!(argv)
62
+ end
63
+ end
64
+
65
+ opts[:logger] = Logger.new(opts[:log], "daily")
66
+ opts[:logger].level = opts[:debug] ? Logger::DEBUG : Logger::INFO
67
+
68
+ daemonize(opts[:debug] || opts[:foreground]) do
69
+ Net::IRC::Server.new(opts[:host], opts[:port], server_session_klass, opts).start
70
+ end
71
+ end
72
+ end
73
+
@@ -0,0 +1,91 @@
1
+ require 'net/irc'
2
+ require 'net/irc/cli'
3
+ require 'net/irc/mala'
4
+ require "em-eventsource"
5
+ require 'json'
6
+ require "optparse"
7
+
8
+ class Net::IRC::AsyncSession < Net::IRC::Server::Session
9
+ def initialize(*args)
10
+ super
11
+ end
12
+
13
+ def on_user(m)
14
+ super
15
+
16
+ post server_name, MODE, @nick, "+o"
17
+ post @prefix, JOIN, main_channel
18
+ post server_name, MODE, main_channel, "+mto", @nick
19
+ post server_name, MODE, main_channel, "+q", @nick
20
+
21
+ @streaming_thread = Thread.start do
22
+ on_new_thread
23
+ end
24
+ end
25
+
26
+ def on_disconnected
27
+ @streaming_thread.kill rescue nil
28
+ end
29
+
30
+ def on_new_thread
31
+ raise "not implemented error"
32
+ end
33
+ end
34
+
35
+ class Net::IRC::Mala < Net::IRC::AsyncSession
36
+ def server_name
37
+ "malastream"
38
+ end
39
+
40
+ def main_channel
41
+ "#malastream"
42
+ end
43
+
44
+ def on_new_thread
45
+ EM.run do
46
+ api = "http://api.ma.la/home_timeline/stream"
47
+ source = EventMachine::EventSource.new(api)
48
+ source.message do |message|
49
+ begin
50
+ status = JSON.parse(message)
51
+ tweet = status["text"]
52
+ screen_name = status['user']['screen_name']
53
+ post screen_name, PRIVMSG, main_channel, tweet
54
+ rescue => ex
55
+ STDERR.puts "error: #{ex.inspect}"
56
+ next
57
+ end
58
+ end
59
+ source.start # Start listening
60
+ end
61
+ end
62
+ end
63
+
64
+ class Net::IRC::MalaFav < Net::IRC::AsyncSession
65
+ def server_name
66
+ "malastream"
67
+ end
68
+
69
+ def main_channel
70
+ "#malastream"
71
+ end
72
+
73
+ def on_new_thread
74
+ EM.run do
75
+ api = "http://api.ma.la/home_timeline/stream/event"
76
+ source = EventMachine::EventSource.new(api)
77
+ source.message do |message|
78
+ begin
79
+ status = JSON.parse(message)
80
+ tweet = status["text"]
81
+ screen_name = status['user']['screen_name']
82
+ post screen_name, PRIVMSG, main_channel, tweet
83
+ rescue => ex
84
+ STDERR.puts "error: #{ex.inspect}"
85
+ next
86
+ end
87
+ end
88
+ source.start # Start listening
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,60 @@
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 = "net-irc-mala"
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["kimoto"]
12
+ s.date = "2012-02-21"
13
+ s.description = "mala following API IRC Gateway"
14
+ s.email = "sub+peerler@gmail.com"
15
+ s.executables = ["mig.rb", "mig_fav.rb"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "bin/mig.rb",
27
+ "bin/mig_fav.rb",
28
+ "lib/net/irc/cli.rb",
29
+ "lib/net/irc/mala.rb",
30
+ "net-irc-mala.gemspec",
31
+ "test/net-irc-mala_test.rb",
32
+ "test/test_helper.rb"
33
+ ]
34
+ s.homepage = "http://github.com/kimoto/net-irc-mala"
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = "1.8.11"
37
+ s.summary = "mala following API IRC Gateway"
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
44
+ s.add_runtime_dependency(%q<net-irc>, [">= 0"])
45
+ s.add_runtime_dependency(%q<em-eventsource>, [">= 0"])
46
+ s.add_runtime_dependency(%q<json>, [">= 0"])
47
+ else
48
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
49
+ s.add_dependency(%q<net-irc>, [">= 0"])
50
+ s.add_dependency(%q<em-eventsource>, [">= 0"])
51
+ s.add_dependency(%q<json>, [">= 0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
55
+ s.add_dependency(%q<net-irc>, [">= 0"])
56
+ s.add_dependency(%q<em-eventsource>, [">= 0"])
57
+ s.add_dependency(%q<json>, [">= 0"])
58
+ end
59
+ end
60
+
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class NetIrcMalaTest < Test::Unit::TestCase
4
+ should "always true" do
5
+ true
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'net-irc-mala'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: net-irc-mala
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - kimoto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thoughtbot-shoulda
16
+ requirement: &68957320 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *68957320
25
+ - !ruby/object:Gem::Dependency
26
+ name: net-irc
27
+ requirement: &68952840 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *68952840
36
+ - !ruby/object:Gem::Dependency
37
+ name: em-eventsource
38
+ requirement: &68948040 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *68948040
47
+ - !ruby/object:Gem::Dependency
48
+ name: json
49
+ requirement: &68945580 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *68945580
58
+ description: mala following API IRC Gateway
59
+ email: sub+peerler@gmail.com
60
+ executables:
61
+ - mig.rb
62
+ - mig_fav.rb
63
+ extensions: []
64
+ extra_rdoc_files:
65
+ - LICENSE
66
+ - README.rdoc
67
+ files:
68
+ - .document
69
+ - LICENSE
70
+ - README.rdoc
71
+ - Rakefile
72
+ - VERSION
73
+ - bin/mig.rb
74
+ - bin/mig_fav.rb
75
+ - lib/net/irc/cli.rb
76
+ - lib/net/irc/mala.rb
77
+ - net-irc-mala.gemspec
78
+ - test/net-irc-mala_test.rb
79
+ - test/test_helper.rb
80
+ homepage: http://github.com/kimoto/net-irc-mala
81
+ licenses: []
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.11
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: mala following API IRC Gateway
104
+ test_files: []