ruboty-line 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 077b976bdc23c573e7f97c719cb313b8b35c3532
4
+ data.tar.gz: 3f325a187c660d9a35ec2d8fb71169c392a9e681
5
+ SHA512:
6
+ metadata.gz: eba29af7cbaea7dc4b217ddc7473fa0999cce467970becd3c9e6534fabebf6619f3cb37f1ab04830c584dc39e7f3f8edd4ac400eaaf2bbaed0f72c240480321b
7
+ data.tar.gz: 8face0e1c6fe19b1a83b199c7c829d7626f4eca08f3d3e6c05830cb861c095d61a68a6c54e47c873f186d2a99f9e626bdcb6e7936cd293d6e33c6bee903a677d
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-line.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Ruboty::Line
2
+
3
+ LINE adapter for Ruboty.
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ # Gemfile
9
+ gem "ruboty-line"
10
+ ```
11
+
12
+ ## ENV
13
+
14
+ ```
15
+ RUBOTY_LINE_CHANNEL_ID - YOUR LINE BOT Channel ID.
16
+ RUBOTY_LINE_CHANNEL_SECRET - YOUR LINE BOT Channel Secret.
17
+ RUBOTY_LINE_CHANNEL_MID - YOUR LINE BOT MID'
18
+ RUBOTY_LINE_ENDPOINT - LINE bot endpoint(Callback URL). (e.g. '/ruboty/line'
19
+ RUBOTY_FIXIE_URL - Proxy URL.
20
+ LOG_LEVEL - Use Ruboty logger. If LOG_LEVEL=0, output debug log.
21
+ ```
22
+
23
+ ## Contributing
24
+
25
+ Bug reports and pull requests are welcome on GitHub at https://github.com/osyo-manga/gem-ruboty-line.
26
+
27
+ ## Release note
28
+
29
+ #### 0.1.0
30
+
31
+ * Release!
32
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruboty/line"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,98 @@
1
+ require "rack"
2
+ require 'line/bot'
3
+ require 'rest-client'
4
+
5
+ module Line
6
+ module Bot
7
+ class HTTPClient
8
+ def post(url, payload, header = {})
9
+ Ruboty.logger.debug "======= HTTPClient#post ======="
10
+ Ruboty.logger.debug "payload #{payload}"
11
+ Ruboty.logger.debug "FIXIT_URL #{ENV["RUBOTY_FIXIE_URL"]}"
12
+ RestClient.proxy = ENV["RUBOTY_FIXIE_URL"] if ENV["RUBOTY_FIXIE_URL"]
13
+ RestClient.post(url, payload, header)
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+
20
+ module Ruboty module Adapters
21
+ class LINE < Base
22
+ env :RUBOTY_LINE_CHANNEL_ID, "YOUR LINE BOT Channel ID"
23
+ env :RUBOTY_LINE_CHANNEL_SECRET, "YOUR LINE BOT Channel Secret"
24
+ env :RUBOTY_LINE_CHANNEL_MID, "YOUR LINE BOT MID"
25
+ env :RUBOTY_LINE_ENDPOINT, "LINE bot endpoint(Callback URL). (e.g. '/ruboty/line'"
26
+ def run
27
+ Ruboty.logger.info "======= LINE#run ======="
28
+ start_server
29
+ end
30
+
31
+ def say msg
32
+ Ruboty.logger.info "======= LINE#say ======="
33
+
34
+ text = msg[:body]
35
+ to = msg[:to]
36
+
37
+ Ruboty.logger.info "text : #{text}"
38
+ Ruboty.logger.debug "to : #{to}"
39
+
40
+ client.send_text(
41
+ to_mid: to,
42
+ text: text
43
+ )
44
+ end
45
+
46
+ private
47
+ def start_server
48
+ Rack::Handler::Thin.run(Proc.new{ |env|
49
+ Ruboty.logger.info "======= LINE access ======="
50
+ Ruboty.logger.debug "env : #{env}"
51
+
52
+ request = ::Line::Bot::Receive::Request.new(env)
53
+ result = on_post request
54
+
55
+ [200, {"Content-Type" => "text/plain"}, [result]]
56
+ }, { Port: ENV["PORT"] || "8080" })
57
+ end
58
+
59
+ def on_post req
60
+ Ruboty.logger.info "======= LINE#on_post ======="
61
+ Ruboty.logger.debug "request : #{req}"
62
+
63
+ return "OK" unless req.post? && req.fullpath == ENV["RUBOTY_LINE_ENDPOINT"]
64
+
65
+ Ruboty.logger.debug "request.body : #{req.data}"
66
+
67
+ req.data.each { |message|
68
+ case message.content
69
+ when ::Line::Bot::Message::Text
70
+ on_message message
71
+ end
72
+ }
73
+
74
+ return ""
75
+ end
76
+
77
+ def on_message msg
78
+ Ruboty.logger.info "======= LINE#on_message ======="
79
+ Ruboty.logger.debug "content : #{msg.content}"
80
+
81
+ Thread.start {
82
+ robot.receive(
83
+ body: msg.content[:text],
84
+ from: msg.from_mid,
85
+ to: msg.from_mid,
86
+ message: msg)
87
+ }
88
+ end
89
+
90
+ def client
91
+ @client ||= ::Line::Bot::Client.new { |config|
92
+ config.channel_id = ENV["RUBOTY_LINE_CHANNEL_ID"]
93
+ config.channel_secret = ENV["RUBOTY_LINE_CHANNEL_SECRET"]
94
+ config.channel_mid = ENV["RUBOTY_LINE_CHANNEL_MID"]
95
+ }
96
+ end
97
+ end
98
+ end end
@@ -0,0 +1,2 @@
1
+ require "ruboty/line/version"
2
+ require_relative "./adapters/line"
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Line
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/line/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-line"
8
+ spec.version = Ruboty::Line::VERSION
9
+ spec.authors = ["manga_osyo"]
10
+ spec.email = ["manga.osyo@gmail.com"]
11
+
12
+ spec.summary = %q{LINE adapter for Ruboty.}
13
+ spec.description = %q{LINE adapter for Ruboty.}
14
+ spec.homepage = "https://github.com/osyo-manga/gem-ruboty-line"
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_dependency "rack"
22
+ spec.add_dependency "thin"
23
+ spec.add_dependency "rest-client"
24
+ spec.add_dependency "line-bot-api"
25
+ spec.add_development_dependency "bundler", "~> 1.12"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-line
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - manga_osyo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
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: thin
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: line-bot-api
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description: LINE adapter for Ruboty.
112
+ email:
113
+ - manga.osyo@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - README.md
123
+ - Rakefile
124
+ - bin/console
125
+ - bin/setup
126
+ - lib/ruboty/adapters/line.rb
127
+ - lib/ruboty/line.rb
128
+ - lib/ruboty/line/version.rb
129
+ - ruboty-line.gemspec
130
+ homepage: https://github.com/osyo-manga/gem-ruboty-line
131
+ licenses: []
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.4.5.1
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: LINE adapter for Ruboty.
153
+ test_files: []