takosan 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +9 -0
- data/lib/takosan.rb +41 -0
- data/lib/takosan/version.rb +3 -0
- data/takosan.gemspec +27 -0
- data/test/takosan_test.rb +56 -0
- data/test/test_helper.rb +12 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bf40dcefadc2f20efc648038d9b9cb0f4b556279
|
4
|
+
data.tar.gz: 1ea6f3ff98df4d3678f39d169af434536ccc191b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d5132d58eead08c719385175cbfe7fce8c6446b22c039bde4b2fe8a8dc87399ccfa5dbf62330c3a31e3625e51efe655eb87a3ef65ba938f3653b65550c74cb9d
|
7
|
+
data.tar.gz: 2c88b25f1a84559b525d968deddb4bdb00d00a6ac2b3c680ee3d914161f5d715acee17efe5c5d97fd3f5ded9dddde1ae1f6a9cc385cfe60921a03a5f79e5f8f4
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
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
|
23
|
+
/vendor/bundle
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 GMO Pepabo, Inc.
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Takosan
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/takosan.png)](http://badge.fury.io/rb/takosan)
|
4
|
+
[![Build Status](https://travis-ci.org/pepabo/takosan.png?branch=master)](https://travis-ci.org/pepabo/takosan)
|
5
|
+
|
6
|
+
Ruby wrapper of Takosan
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'takosan'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install takosan
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
Takosan.url = "http://irc.example.com:4649"
|
26
|
+
Takosan.channel = "#example"
|
27
|
+
Takosan.notice 'awesome comment'
|
28
|
+
```
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it ( https://github.com/[my-github-username]/takosan/fork )
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/takosan.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
require 'pathname'
|
5
|
+
require 'active_support/all'
|
6
|
+
|
7
|
+
module Takosan
|
8
|
+
mattr_accessor :url, :channel
|
9
|
+
|
10
|
+
module_function
|
11
|
+
|
12
|
+
def privmsg(message)
|
13
|
+
request('/privmsg', { 'channel' => @@channel, 'message' => message })
|
14
|
+
end
|
15
|
+
|
16
|
+
def uri_for(path = nil)
|
17
|
+
uri = URI.parse("#{@@url}/#{path}")
|
18
|
+
uri.path = Pathname.new(uri.path).cleanpath.to_s
|
19
|
+
uri
|
20
|
+
end
|
21
|
+
|
22
|
+
def request(path, params)
|
23
|
+
begin
|
24
|
+
uri = uri_for(path)
|
25
|
+
|
26
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
27
|
+
http.open_timeout = http.read_timeout = 10
|
28
|
+
|
29
|
+
req = Net::HTTP::Post.new(uri.path)
|
30
|
+
req.form_data = params
|
31
|
+
|
32
|
+
http.request(req)
|
33
|
+
rescue StandardError, TimeoutError => e
|
34
|
+
logger.warn("#{e.class} #{e.message}")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def logger
|
39
|
+
@@_logger ||= Rails.logger
|
40
|
+
end
|
41
|
+
end
|
data/takosan.gemspec
ADDED
@@ -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 'takosan/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "takosan"
|
8
|
+
spec.version = Takosan::VERSION
|
9
|
+
spec.authors = ["OKUMURA Takahiro"]
|
10
|
+
spec.email = ["hfm.garden@gmail.com"]
|
11
|
+
spec.summary = %q{Ruby wrapper of Takosan}
|
12
|
+
spec.description = %q{Ruby wrapper of Takosan}
|
13
|
+
spec.homepage = "https://github.com/pepabo/takosan"
|
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,56 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
require_relative '../lib/takosan'
|
4
|
+
|
5
|
+
class TakosanTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
Takosan.url = "http://irc.example.com:4649"
|
8
|
+
Takosan.channel = "#example"
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_privmsg
|
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') && (params['message'] == 'foo bar buzz')
|
21
|
+
end
|
22
|
+
Net::HTTP::Post.expects(:new).with('/privmsg').returns(req)
|
23
|
+
|
24
|
+
Takosan.privmsg('foo bar buzz')
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_rescue_timeout_error
|
28
|
+
http = stub('http')
|
29
|
+
http.stub_everything
|
30
|
+
http.stubs(:request).raises(TimeoutError, 'timeout error!')
|
31
|
+
Net::HTTP.expects(:new).with('irc.example.com', 4649).returns(http)
|
32
|
+
|
33
|
+
req = stub('req')
|
34
|
+
req.stub_everything
|
35
|
+
Net::HTTP::Post.expects(:new).with('/privmsg').returns(req)
|
36
|
+
|
37
|
+
assert_nothing_raised do
|
38
|
+
Takosan.privmsg('foo bar buzz')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_rescue_socket_error
|
43
|
+
http = stub('http')
|
44
|
+
http.stub_everything
|
45
|
+
http.stubs(:request).raises(SocketError, 'connection error!')
|
46
|
+
Net::HTTP.expects(:new).with('irc.example.com', 4649).returns(http)
|
47
|
+
|
48
|
+
req = stub('req')
|
49
|
+
req.stub_everything
|
50
|
+
Net::HTTP::Post.expects(:new).with('/privmsg').returns(req)
|
51
|
+
|
52
|
+
assert_nothing_raised do
|
53
|
+
Takosan.privmsg('foo bar buzz')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: takosan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- OKUMURA Takahiro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-18 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 Takosan
|
84
|
+
email:
|
85
|
+
- hfm.garden@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/takosan.rb
|
96
|
+
- lib/takosan/version.rb
|
97
|
+
- takosan.gemspec
|
98
|
+
- test/takosan_test.rb
|
99
|
+
- test/test_helper.rb
|
100
|
+
homepage: https://github.com/pepabo/takosan
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.4.5
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: Ruby wrapper of Takosan
|
124
|
+
test_files:
|
125
|
+
- test/takosan_test.rb
|
126
|
+
- test/test_helper.rb
|