line-bot-lite 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/line/bot.rb +8 -0
- data/lib/line/bot/api.rb +8 -0
- data/lib/line/bot/certentials.rb +56 -0
- data/lib/line/bot/client.rb +27 -0
- data/lib/line/bot/event_type.rb +15 -0
- data/lib/line/bot/http.rb +23 -0
- data/lib/line/bot/request.rb +50 -0
- data/lib/line/bot/version.rb +5 -0
- data/line-bot.gemspec +26 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5c1f8ee3b4159b17a10bdde7c3ab2ea0fa440af3
|
4
|
+
data.tar.gz: e630abf534a9997edc6ebb46983e854442b788c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c9cc316b45cef4ac76ba0c29dbaf74e72d0cb442f4e8db5fd89295e3b762e0bfbbbd5633b2b4ff67dc9a3c2672321aa1bff9710c40b867bd98793906e8a3282f
|
7
|
+
data.tar.gz: e7ee5ac2000ae74e7d47d5b7c4d3a8759ae95a2cd4ef1a28cdcab51bc56513916bbf4b3a03b22955aea28d1b2902320844743ecef1153d22f7629c7f5fc5ba45
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at elct9620@frost.tw. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Line Bot Lite
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/elct9620/line-bot.svg?branch=master)](https://travis-ci.org/elct9620/line-bot)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/elct9620/line-bot/badge.svg?branch=master)](https://coveralls.io/github/elct9620/line-bot?branch=master)
|
5
|
+
|
6
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/line/bot`. To experiment with that code, run `bin/console` for an interactive prompt.
|
7
|
+
|
8
|
+
TODO: Delete this and the text above, and describe your gem
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'line-bot'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install line-bot
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
TODO: Write usage instructions here
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
33
|
+
|
34
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/line-bot. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
39
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "line/bot"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/line/bot.rb
ADDED
data/lib/line/bot/api.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module Line
|
4
|
+
module Bot
|
5
|
+
class Certentials
|
6
|
+
|
7
|
+
attr_accessor :channel_id, :channel_secret, :channel_mid
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
options.each do |key, value|
|
11
|
+
instance_variable_set("@#{key}", value)
|
12
|
+
end
|
13
|
+
|
14
|
+
yield(self) if block_given?
|
15
|
+
end
|
16
|
+
|
17
|
+
def payload
|
18
|
+
{
|
19
|
+
'X-Line-ChannelID' => channel_id,
|
20
|
+
'X-Line-ChannelSecret' => channel_secret,
|
21
|
+
'X-Line-Trusted-User-With-ACL' => channel_mid
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid?
|
26
|
+
payload.values.all?
|
27
|
+
end
|
28
|
+
|
29
|
+
def validate_signature?(body = "", channel_signature)
|
30
|
+
return false unless !channel_signature.nil? && valid?
|
31
|
+
|
32
|
+
hash = OpenSSL::HMAC::digest(OpenSSL::Digest::SHA256.new, channel_secret, body)
|
33
|
+
signature = Base64.strict_encode64(hash)
|
34
|
+
|
35
|
+
variable_secure_compare(channel_signature, signature)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def variable_secure_compare(a, b)
|
41
|
+
secure_compare(::Digest::SHA256.hexdigest(a), ::Digest::SHA256.hexdigest(b))
|
42
|
+
end
|
43
|
+
|
44
|
+
def secure_compare(a, b)
|
45
|
+
return false if a.bytesize != b.bytesize
|
46
|
+
|
47
|
+
l = a.unpack "C#{a.bytesize}"
|
48
|
+
|
49
|
+
res = 0
|
50
|
+
b.each_byte { |byte| res |= byte ^ l.shift }
|
51
|
+
res == 0
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
class Client
|
4
|
+
attr_accessor :certentials
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
@certentials = options if options.is_a?(Certentials)
|
8
|
+
@certentials = Certentials.new(options) if options.is_a?(Hash)
|
9
|
+
yield(self) if block_given?
|
10
|
+
end
|
11
|
+
|
12
|
+
def send_text(to_mid, message)
|
13
|
+
request = Request.new do |config|
|
14
|
+
config.to_mid = to_mid
|
15
|
+
config.certentials = @certentials
|
16
|
+
config.endpoint = API::ENDPOINT
|
17
|
+
config.endpoint_path = "/events"
|
18
|
+
config.message = message
|
19
|
+
config.event_type = Line::Bot::EventType::MESSAGE
|
20
|
+
end
|
21
|
+
|
22
|
+
request.post
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
module EventType
|
4
|
+
MESSAGE = 138311608800106203
|
5
|
+
MULTIPLE_MESSAGE = 140177271400161403
|
6
|
+
end
|
7
|
+
|
8
|
+
module Receive
|
9
|
+
module EventType
|
10
|
+
MESSAGE = 138311609000106303
|
11
|
+
OPERATION = 138311609100106403
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module Line
|
4
|
+
module Bot
|
5
|
+
class HTTP
|
6
|
+
def self.http(uri)
|
7
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
8
|
+
http.use_ssl = true if uri.scheme == "https"
|
9
|
+
http
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.get(url, header = {})
|
13
|
+
uri = URI(url)
|
14
|
+
self.http(uri).get(uri.requrest_uri, header)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.post(url, payload, header = {})
|
18
|
+
uri = URI(url)
|
19
|
+
self.http(uri).post(uri.requrest_uri, payload, header)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
class Request
|
4
|
+
|
5
|
+
attr_accessor :to_mid, :message, :certentials, :endpoint, :endpoint_path, :event_type
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
yield(self) if block_given?
|
9
|
+
end
|
10
|
+
|
11
|
+
def to
|
12
|
+
to_mid.is_a?(String) ? [to_mid] : to_mid
|
13
|
+
end
|
14
|
+
|
15
|
+
def payload
|
16
|
+
{
|
17
|
+
to: to,
|
18
|
+
toChannel: API::MESSAGE_CHANNEL_ID, # Fixed value
|
19
|
+
eventType: event_type.to_s,
|
20
|
+
content: {
|
21
|
+
contentType: 1,
|
22
|
+
toType: 1,
|
23
|
+
text: message
|
24
|
+
}
|
25
|
+
|
26
|
+
}.to_json
|
27
|
+
end
|
28
|
+
|
29
|
+
def header
|
30
|
+
header = {
|
31
|
+
'Content-Type' => 'application/json; charset=UTF-8',
|
32
|
+
'User-Agent' => "Line-Bot-Lite/#{Line::Bot::VERSION}"
|
33
|
+
}
|
34
|
+
return header if certentials.nil?
|
35
|
+
hash = certentials.payload.inject({}) { |h, (k, v)| h[k] = v.to_s; h }
|
36
|
+
|
37
|
+
header.merge(hash)
|
38
|
+
end
|
39
|
+
|
40
|
+
def get
|
41
|
+
HTTP.get(endpoint + endpoint_path, header)
|
42
|
+
end
|
43
|
+
|
44
|
+
def post
|
45
|
+
HTTP.post(endpoint + endpoint_path, payload, header)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/line-bot.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'line/bot/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "line-bot-lite"
|
8
|
+
spec.version = Line::Bot::VERSION
|
9
|
+
spec.authors = ["蒼時弦也"]
|
10
|
+
spec.email = ["contact@frost.tw"]
|
11
|
+
|
12
|
+
spec.summary = %q{ Line Bot API implemented use Ruby builtin library }
|
13
|
+
spec.description = %q{ Line Bot API usuall depend on rack but it cause newer rack cannot working correctly, so I create yet another library for it. }
|
14
|
+
spec.homepage = "https://github.com/elct9620/line-bot"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
spec.add_development_dependency "fuubar", "~> 2.0"
|
25
|
+
spec.add_development_dependency "coveralls", "~> 0.8"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: line-bot-lite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- 蒼時弦也
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fuubar
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: coveralls
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.8'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.8'
|
83
|
+
description: " Line Bot API usuall depend on rack but it cause newer rack cannot working
|
84
|
+
correctly, so I create yet another library for it. "
|
85
|
+
email:
|
86
|
+
- contact@frost.tw
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- lib/line/bot.rb
|
101
|
+
- lib/line/bot/api.rb
|
102
|
+
- lib/line/bot/certentials.rb
|
103
|
+
- lib/line/bot/client.rb
|
104
|
+
- lib/line/bot/event_type.rb
|
105
|
+
- lib/line/bot/http.rb
|
106
|
+
- lib/line/bot/request.rb
|
107
|
+
- lib/line/bot/version.rb
|
108
|
+
- line-bot.gemspec
|
109
|
+
homepage: https://github.com/elct9620/line-bot
|
110
|
+
licenses: []
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.5.1
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Line Bot API implemented use Ruby builtin library
|
132
|
+
test_files: []
|