ikachan 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d939208a0c35025386846b84a7c6ec52149d34c3
4
+ data.tar.gz: 4b0abdcd11c1ccc3e0bcd2557afb3c0c9d40b2e1
5
+ SHA512:
6
+ metadata.gz: 2c7f9eefd42e90f9e0d3dc80b3b36b787f1774f3fcd8b04af3cd82c848facfa407fed7fa4193db9e03e8d3a6cb3145ae07c611acc65f48795d44a81e5d4454f4
7
+ data.tar.gz: 8f8cda63eeb6c8be55b8174ab8c4bac2681ee5d88cf59b9ae34092955199511cc002ebca17db6b84ffa622f5e541886e0b512199f092c17bb0e693a87b7c1ba4
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1
7
+ - ruby-head
8
+
9
+ script: rake test
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ikachan.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 SHIBATA Hiroshi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # Ikachan
2
+
3
+ Ruby wrapper of Ikachan
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ikachan'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ikachan
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ Ikachan.url = "http://irc.example.com:4649"
23
+ Ikachan.channel = "#example"
24
+ Ikachan.notice 'awesome comment'
25
+ ```
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( https://github.com/[my-github-username]/ikachan/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ t.verbose = true
9
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ikachan/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ikachan"
8
+ spec.version = Ikachan::VERSION
9
+ spec.authors = ["SHIBATA Hiroshi"]
10
+ spec.email = ["shibata.hiroshi@gmail.com"]
11
+ spec.summary = %q{Ruby wrapper of Ikachan}
12
+ spec.description = %q{Ruby wrapper of Ikachan}
13
+ spec.homepage = "https://github.com/paperboy-all/ikachan"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activesupport"
22
+
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "test-unit"
26
+ spec.add_development_dependency "mocha"
27
+ end
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'pathname'
5
+ require 'active_support/all'
6
+
7
+ module Ikachan
8
+ mattr_accessor :url, :channel
9
+
10
+ module_function
11
+
12
+ def join
13
+ request('/join', { 'channel' => @@channel })
14
+ end
15
+
16
+ def notice(message)
17
+ join
18
+ request('/notice', { 'channel' => @@channel, 'message' => message })
19
+ end
20
+
21
+ def uri_for(path = nil)
22
+ uri = URI.parse("#{@@url}/#{path}")
23
+ uri.path = Pathname.new(uri.path).cleanpath.to_s
24
+ uri
25
+ end
26
+
27
+ def request(path, params)
28
+ begin
29
+ uri = uri_for(path)
30
+
31
+ http = Net::HTTP.new(uri.host, uri.port)
32
+ http.open_timeout = http.read_timeout = 10
33
+
34
+ req = Net::HTTP::Post.new(uri.path)
35
+ req.form_data = params
36
+
37
+ http.request(req)
38
+ rescue StandardError, TimeoutError => e
39
+ logger.warn("#{e.class} #{e.message}")
40
+ end
41
+ end
42
+
43
+ def logger
44
+ @@_logger ||= Rails.logger
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Ikachan
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,79 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+ require_relative '../lib/ikachan'
4
+
5
+ class IkachanTest < Test::Unit::TestCase
6
+ def setup
7
+ Ikachan.url = "http://irc.example.com:4649"
8
+ Ikachan.channel = "#example"
9
+ end
10
+
11
+ def test_join
12
+ http = mock('http')
13
+ http.stub_everything
14
+ http.expects(:request)
15
+ Net::HTTP.expects(:new).with('irc.example.com', 4649).returns(http)
16
+
17
+ req = mock('req')
18
+ req.stub_everything
19
+ req.expects(:form_data=).with do |params|
20
+ params['channel'] == '#example'
21
+ end
22
+ Net::HTTP::Post.expects(:new).with('/join').returns(req)
23
+
24
+ Ikachan.join
25
+ assert true
26
+ end
27
+
28
+ def test_notice
29
+ Ikachan.expects(:join)
30
+
31
+ http = mock('http')
32
+ http.stub_everything
33
+ http.expects(:request)
34
+ Net::HTTP.expects(:new).with('irc.example.com', 4649).returns(http)
35
+
36
+ req = mock('req')
37
+ req.stub_everything
38
+ req.expects(:form_data=).with do |params|
39
+ (params['channel'] == '#example') && (params['message'] == 'foo bar buzz')
40
+ end
41
+ Net::HTTP::Post.expects(:new).with('/notice').returns(req)
42
+
43
+ Ikachan.notice('foo bar buzz')
44
+ end
45
+
46
+ def test_rescue_timeout_error
47
+ Ikachan.expects(:join)
48
+
49
+ http = stub('http')
50
+ http.stub_everything
51
+ http.stubs(:request).raises(TimeoutError, 'timeout error!')
52
+ Net::HTTP.expects(:new).with('irc.example.com', 4649).returns(http)
53
+
54
+ req = stub('req')
55
+ req.stub_everything
56
+ Net::HTTP::Post.expects(:new).with('/notice').returns(req)
57
+
58
+ assert_nothing_raised do
59
+ Ikachan.notice('foo bar buzz')
60
+ end
61
+ end
62
+
63
+ def test_rescue_socket_error
64
+ Ikachan.expects(:join)
65
+
66
+ http = stub('http')
67
+ http.stub_everything
68
+ http.stubs(:request).raises(SocketError, 'connection error!')
69
+ Net::HTTP.expects(:new).with('irc.example.com', 4649).returns(http)
70
+
71
+ req = stub('req')
72
+ req.stub_everything
73
+ Net::HTTP::Post.expects(:new).with('/notice').returns(req)
74
+
75
+ assert_nothing_raised do
76
+ Ikachan.notice('foo bar buzz')
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,12 @@
1
+ require 'test/unit'
2
+ require 'mocha/setup'
3
+
4
+ require 'logger'
5
+ require 'tempfile'
6
+
7
+ module Rails
8
+ module_function
9
+ def logger
10
+ @@_logger ||= Logger.new(STDOUT)
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ikachan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - SHIBATA Hiroshi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Ruby wrapper of Ikachan
84
+ email:
85
+ - shibata.hiroshi@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - ikachan.gemspec
97
+ - lib/ikachan.rb
98
+ - lib/ikachan/version.rb
99
+ - test/ikachan_test.rb
100
+ - test/test_helper.rb
101
+ homepage: https://github.com/paperboy-all/ikachan
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.2.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Ruby wrapper of Ikachan
125
+ test_files:
126
+ - test/ikachan_test.rb
127
+ - test/test_helper.rb
128
+ has_rdoc: