ruboty-lingr 0.1.0

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: 9cde2b82a87e2fe6a78f1b11c8b4e5eb1f709fec
4
+ data.tar.gz: a9196347b7cf21d0e696402657216c1c4458a86c
5
+ SHA512:
6
+ metadata.gz: 9ed9c79c1babd96039679426e2836670ac4796cb3a889cb75bdd2f99f7d9128fc585ccf681577a1f5529689a05e2ae6aaa718edc70901617abecaa1c0ac34f28
7
+ data.tar.gz: 8861c64babc79e9d0a584f013f38a5bc72ca9e180f2a06a7a4fb7a7a2c08c49f3e2380b0e748240d3e6f378e7cc966e3d1c3cdff64687450d3a89083e08f561f
@@ -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
@@ -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.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-lingr.gemspec
4
+ gemspec
5
+
6
+ gem "rack"
@@ -0,0 +1,25 @@
1
+ # Ruboty::Lingr
2
+
3
+ Lingr adapter for Ruboty.
4
+
5
+
6
+ ## Usage
7
+
8
+ ```ruby
9
+ # Gemfile
10
+ gem "ruboty-lingr"
11
+ ```
12
+
13
+ ## ENV
14
+
15
+ ```
16
+ RUBOTY_LINGR_BOT_KEY - Lingr bot key.
17
+ RUBOTY_LINGR_BOT_NAME - Lingr bot name.
18
+ RUBOTY_LINGR_ENDPOINT - Lingr bot endpoint(Callback URL). (e.g. '/ruboty/lingr'
19
+ LOG_LEVEL - Use Ruboty logger. If LOG_LEVEL=0, output debug log.
20
+ ```
21
+
22
+ ## Contributing
23
+
24
+ Bug reports and pull requests are welcome on GitHub at https://github.com/osyo-manga/gem-ruboty-lingr.
25
+
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruboty/lingr"
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
@@ -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,102 @@
1
+ require "rack"
2
+ require 'open-uri'
3
+ require "json"
4
+
5
+
6
+ module Ruboty module Lingr
7
+ class Client
8
+ attr_accessor :bot_name, :bot_key
9
+
10
+ def initialize options = {}
11
+ options.each do |key, value|
12
+ instance_variable_set("@#{key}", value)
13
+ end
14
+ yield(self) if block_given?
15
+ end
16
+
17
+ def post room, text
18
+ param = {
19
+ room: room,
20
+ bot: bot_name,
21
+ text: text,
22
+ bot_verifier: bot_key
23
+ }.tap {|p| p[:bot_verifier] = Digest::SHA1.hexdigest(p[:bot] + p[:bot_verifier]) }
24
+
25
+ query_string = param.map {|e|
26
+ e.map {|s| ERB::Util.url_encode s.to_s }.join '='
27
+ }.join '&'
28
+ open "http://lingr.com/api/room/say?#{query_string}"
29
+ end
30
+ end
31
+ end end
32
+
33
+
34
+ module Ruboty module Adapters
35
+ class Lingr < Base
36
+ env :RUBOTY_LINGR_BOT_KEY, "Lingr bot key."
37
+ env :RUBOTY_LINGR_BOT_NAME, "Lingr bot name."
38
+ env :RUBOTY_LINGR_ENDPOINT, "Lingr bot endpoint(Callback URL). (e.g. '/ruboty/lingr'"
39
+
40
+ def run
41
+ Ruboty.logger.info "======= Lingr#run ======="
42
+ start_server
43
+ end
44
+
45
+ def say msg
46
+ Ruboty.logger.info "======= Lingr#say ======="
47
+ room = msg[:original][:room]
48
+ text = msg[:body]
49
+ Ruboty.logger.info "room : #{room}"
50
+ Ruboty.logger.info "text : #{text}"
51
+
52
+ Ruboty.logger.debug "msg : #{msg}"
53
+
54
+ client.post(room, text)
55
+ end
56
+
57
+ private
58
+ def start_server
59
+ Rack::Handler::WEBrick.run(Proc.new{ |env|
60
+ Ruboty.logger.info "======= Lingr access ======="
61
+ Ruboty.logger.debug "env : #{env}"
62
+
63
+ request = Rack::Request.new(env)
64
+ result = on_post request
65
+ [200, {"Content-Type" => "text/plain"}, [result]]
66
+ }, { Port: ENV["PORT"] || "8080" })
67
+ end
68
+
69
+ def on_post req
70
+ Ruboty.logger.info "======= Lingr#on_post ======="
71
+ Ruboty.logger.debug "request : #{req}"
72
+
73
+ return "OK" unless req.post? && req.fullpath == ENV["RUBOTY_LINGR_ENDPOINT"]
74
+
75
+ params = JSON.parse req.body.read
76
+ Ruboty.logger.debug "POST params : #{params}"
77
+
78
+ return "" unless params.has_key?("events") && params["events"].kind_of?(Array)
79
+
80
+ params["events"].select {|e| e['message'] }.map {|e|
81
+ on_message e["message"]
82
+ }
83
+ return ""
84
+ end
85
+
86
+ def on_message msg
87
+ Ruboty.logger.info "======= Lingr#on_message ======="
88
+ Ruboty.logger.debug "message : #{msg}"
89
+
90
+ Thread.start {
91
+ robot.receive(body: msg["text"], room: msg["room"], message: msg)
92
+ }
93
+ end
94
+
95
+ def client
96
+ @client ||= ::Ruboty::Lingr::Client.new({
97
+ bot_name: ::ENV["RUBOTY_LINGR_BOT_NAME"],
98
+ bot_key: ::ENV["RUBOTY_LINGR_BOT_KEY"],
99
+ })
100
+ end
101
+ end
102
+ end end
@@ -0,0 +1,2 @@
1
+ require "ruboty/adapters/lingr"
2
+ require "ruboty/lingr/version"
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Lingr
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/lingr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-lingr"
8
+ spec.version = Ruboty::Lingr::VERSION
9
+ spec.authors = ["manga_osyo"]
10
+ spec.email = ["manga.osyo@gmail.com"]
11
+
12
+ spec.summary = %q{Lingr adapter for Ruboty.}
13
+ spec.description = %q{Lingr adapter for Ruboty.}
14
+ spec.homepage = "https://github.com/osyo-manga/gem-ruboty-lingr"
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
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-lingr
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-03 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
+ description: Lingr adapter for Ruboty.
56
+ email:
57
+ - manga.osyo@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - lib/ruboty/adapters/lingr.rb
71
+ - lib/ruboty/lingr.rb
72
+ - lib/ruboty/lingr/version.rb
73
+ - ruboty-lingr.gemspec
74
+ homepage: https://github.com/osyo-manga/gem-ruboty-lingr
75
+ licenses: []
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: '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.4.5.1
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Lingr adapter for Ruboty.
97
+ test_files: []