ikachan-client 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +79 -0
- data/Rakefile +5 -0
- data/ikachan-client.gemspec +25 -0
- data/lib/ikachan-client.rb +1 -0
- data/lib/ikachan/client.rb +55 -0
- data/spec/ikachan/client_spec.rb +34 -0
- data/spec/spec_helper.rb +4 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e1f312dc2327ce173def96eaad7755b6670b3ead
|
4
|
+
data.tar.gz: e406db70c848062600e2842822cedb1fd6a59b22
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 298e4b713953c222224f809015b1d04b38a370e05b19da48c76137031b50d575d38a03d0170fa64a03ec148e6b45b99c0acd59e220711deec87aa954609eda7f
|
7
|
+
data.tar.gz: 18444e2818997d769122ef2d9ad55d37656dec3cc50b9bd2c4b39086bb2efcf8bb5ff851599adf69061626505ad03848809bac713c380a61f6c8dcaa631843ad
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 studio3104
|
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,79 @@
|
|
1
|
+
# Ikachan::Client [![Build Status](https://travis-ci.org/studio3104/ikachan-client.png)](https://travis-ci.org/studio3104/ikachan-client)
|
2
|
+
|
3
|
+
post message to irc http gateway `ikachan`.
|
4
|
+
|
5
|
+
see: https://metacpan.org/module/ikachan
|
6
|
+
|
7
|
+
see: http://blog.yappo.jp/yappo/archives/000760.html (Japanese)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'ikachan-client'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ikachan-client
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
#### Expamples
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'ikachan/client'
|
29
|
+
|
30
|
+
# ikachan server: http://localhost:4979
|
31
|
+
ikachan = Ikachan::Client.new('localhost')
|
32
|
+
|
33
|
+
# ikachan server: http://localhost
|
34
|
+
ikachan = Ikachan::Client.new('localhost', 80)
|
35
|
+
|
36
|
+
# use https, and not verify certificate
|
37
|
+
ikachan = Ikachan::Client.new('localhost', ssl: true)
|
38
|
+
|
39
|
+
# use https, and verify default certificate
|
40
|
+
ikachan = Ikachan::Client.new('localhost', ssl: true, verify_ssl: true)
|
41
|
+
|
42
|
+
# use https, and verify specified certificate
|
43
|
+
ikachan = Ikachan::Client.new('localhost', ssl: true, verify_ssl: true, ca_file: '/path/to/ca_file')
|
44
|
+
```
|
45
|
+
|
46
|
+
###### send NOTICE
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
ikachan.notice('#channel', 'message')
|
50
|
+
```
|
51
|
+
|
52
|
+
###### send PRIVMSG
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
ikachan.privmsg('#chennel', 'message')
|
56
|
+
```
|
57
|
+
|
58
|
+
###### JOIN
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
ikachan.join('#channel')
|
62
|
+
|
63
|
+
# authenticate with channel password
|
64
|
+
ikachan.join('#channel', channel_keyword: 'channel password')
|
65
|
+
```
|
66
|
+
|
67
|
+
###### LEAVE
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
ikachan.leave('#channel')
|
71
|
+
```
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
1. Fork it ( http://github.com/studio3104/ikachan-client/fork )
|
76
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
77
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
78
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
79
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "ikachan-client"
|
7
|
+
spec.version = '0.1'
|
8
|
+
spec.authors = ['studio3104']
|
9
|
+
spec.email = ['studio3104.com@gmail.com']
|
10
|
+
spec.summary = 'post message to irc http gateway `ikachan`'
|
11
|
+
spec.description = 'post message to irc http gateway `ikachan` (see: https://metacpan.org/module/ikachan)'
|
12
|
+
spec.homepage = 'https://github.com/studio3104/ikachan-client'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.required_ruby_version = '>= 2.0.0'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'webmock'
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'ikachan/client'
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/https'
|
3
|
+
|
4
|
+
module Ikachan
|
5
|
+
class Client
|
6
|
+
def initialize(host, port = 4979, ssl: false, verify_ssl: false, ca_file: nil)
|
7
|
+
@host = host
|
8
|
+
@port = port
|
9
|
+
@ssl = ssl
|
10
|
+
@verify_ssl = verify_ssl
|
11
|
+
@ca_file = ca_file
|
12
|
+
end
|
13
|
+
|
14
|
+
def notice(channel, message)
|
15
|
+
http_post_request('notice', channel: channel, message: message)
|
16
|
+
end
|
17
|
+
|
18
|
+
def privmsg(channel, message)
|
19
|
+
http_post_request('privmsg', channel: channel, message: message)
|
20
|
+
end
|
21
|
+
|
22
|
+
def join(channel, channel_keyword: nil) # channel_keyword: channel password
|
23
|
+
http_post_request('join', channel: channel, channel_keyword: channel_keyword)
|
24
|
+
end
|
25
|
+
|
26
|
+
def leave(channel)
|
27
|
+
http_post_request('leave', channel: channel)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def http
|
33
|
+
http = Net::HTTP.new(@host, @port)
|
34
|
+
|
35
|
+
if @ssl
|
36
|
+
http.use_ssl = true
|
37
|
+
|
38
|
+
if @verify_ssl
|
39
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
40
|
+
http.ca_file = @ca_file if @ca_file
|
41
|
+
else
|
42
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
http
|
47
|
+
end
|
48
|
+
|
49
|
+
def http_post_request(method, params)
|
50
|
+
request = Net::HTTP::Post.new('/' + method)
|
51
|
+
request.set_form_data(params)
|
52
|
+
http.request(request)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ikachan::Client do
|
4
|
+
let(:host) { 'test.ikachan.com' }
|
5
|
+
let(:port) { 80 }
|
6
|
+
let(:base_url) { "http://#{host}:#{port}" }
|
7
|
+
let(:channel) { '#test' }
|
8
|
+
let(:message) { 'test message' }
|
9
|
+
let(:client) { Ikachan::Client.new(host, port) }
|
10
|
+
|
11
|
+
it 'notice' do
|
12
|
+
stub_request(:post, base_url + '/notice').with(body: URI.encode_www_form(channel: channel, message: message))
|
13
|
+
response = client.notice(channel, message)
|
14
|
+
expect(response.code.to_i).to eq(200)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'privmsg' do
|
18
|
+
stub_request(:post, base_url + '/privmsg').with(body: URI.encode_www_form(channel: channel, message: message))
|
19
|
+
response = client.privmsg(channel, message)
|
20
|
+
expect(response.code.to_i).to eq(200)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'join' do
|
24
|
+
stub_request(:post, base_url + '/join').with(body: URI.encode_www_form(channel: channel, channel_keyword: nil))
|
25
|
+
response = client.join(channel)
|
26
|
+
expect(response.code.to_i).to eq(200)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'leave' do
|
30
|
+
stub_request(:post, base_url + '/leave').with(body: URI.encode_www_form(channel: channel))
|
31
|
+
response = client.leave(channel)
|
32
|
+
expect(response.code.to_i).to eq(200)
|
33
|
+
end
|
34
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ikachan-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- studio3104
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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: rspec
|
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: webmock
|
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
|
+
description: 'post message to irc http gateway `ikachan` (see: https://metacpan.org/module/ikachan)'
|
56
|
+
email:
|
57
|
+
- studio3104.com@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- ikachan-client.gemspec
|
69
|
+
- lib/ikachan-client.rb
|
70
|
+
- lib/ikachan/client.rb
|
71
|
+
- spec/ikachan/client_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
homepage: https://github.com/studio3104/ikachan-client
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.0.0
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.2.2
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: post message to irc http gateway `ikachan`
|
97
|
+
test_files:
|
98
|
+
- spec/ikachan/client_spec.rb
|
99
|
+
- spec/spec_helper.rb
|