ruboty-yo 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f1229a7a132c43198319d28ff2510e9cc2aa41a1
4
+ data.tar.gz: 558f679275f5a90b69a113980ce5b1f4ae4883f8
5
+ SHA512:
6
+ metadata.gz: b30d9d1f9c9e29f423be585ca8c40c70c41297be04e5c1b88ff2030f24646267cef0f7d5e8bd712a05852e988d2a861de12c43eac9a7b050f6f7cdf7efd9c811
7
+ data.tar.gz: 339ad6e5fc4f63451b787223d5c30c5825d956e0ac141dd0b708425c8d93504372ff9e95105ae255199313d7cb30c25cafe5cc879a06b08f9fc55b0cc08c9e38
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ vendor/bundle
16
+ .env
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-yo.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 block_given?
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.
@@ -0,0 +1,42 @@
1
+ # Ruboty::Yo
2
+
3
+ ruboty plugin for yo.
4
+
5
+ ![screenshot](screenshot.png)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ruboty-yo'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ruboty-yo
22
+
23
+ ## Usage
24
+
25
+ ### Send Yo
26
+
27
+ > すきだよ johndoe
28
+ > 元気にしてるかyo johndoe
29
+ > yo johndoe
30
+
31
+ ### Something wrong
32
+
33
+ > 存在しないユーザにyo ななしのごんべえ
34
+ 伝わらなかったよ
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( https://github.com/blockgiven/ruboty-yo/fork )
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create a new Pull Request
@@ -0,0 +1,50 @@
1
+ require "bundler/gem_tasks"
2
+ begin
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec) do |c|
5
+ c.pattern = [*c.pattern, 'spec/**{,/*/**}/*.feature']
6
+ c.rspec_opts = [*c.rspec_opts, '-r turnip/rspec']
7
+ end
8
+ task default: :spec
9
+ rescue LoadError
10
+ end
11
+
12
+ desc 'make test yo data'
13
+ task :test_yo do
14
+ require 'net/http'
15
+ require 'securerandom'
16
+ require 'vcr'
17
+ require 'webmock'
18
+
19
+ WebMock.allow_net_connect!
20
+ VCR.configure do |c|
21
+ c.cassette_library_dir = 'spec/fixtures'
22
+ c.hook_into :webmock
23
+ end
24
+
25
+ yo_endpoint_url = URI.parse('https://api.justyo.co/yo/')
26
+
27
+ exists_username = 'JOE'
28
+ missing_username = SecureRandom.uuid.gsub(/-/, '')
29
+
30
+ VCR.use_cassette('yo_ok') do
31
+ params = {api_token: ENV['YO_API_TOKEN'], username: exists_username}
32
+ p Net::HTTP.post_form(yo_endpoint_url, params)
33
+ end
34
+ VCR.use_cassette('yo_ng') do
35
+ params = {api_token: ENV['YO_API_TOKEN'], username: missing_username}
36
+ p Net::HTTP.post_form(yo_endpoint_url, params)
37
+ end
38
+
39
+ %w(ok ng).each do |status|
40
+ yo_filename = "spec/fixtures/yo_#{status}.yml"
41
+ yo = File.read(yo_filename)
42
+
43
+ fake_api_token = SecureRandom.uuid
44
+ yo.gsub!(ENV['YO_API_TOKEN'], fake_api_token)
45
+ yo.gsub!(exists_username, 'johndoe')
46
+ yo.gsub!(missing_username, 'janedoe')
47
+
48
+ File.write(yo_filename, yo)
49
+ end
50
+ end
@@ -0,0 +1,15 @@
1
+ require "ruboty/yo/actions/yo"
2
+
3
+ module Ruboty
4
+ module Handlers
5
+ class Yo < Base
6
+ env :YO_API_TOKEN, 'yo api token'
7
+
8
+ on /.*(yo|よ) (?<to>.*)$/, name: 'yo', description: 'send yo', all: true
9
+
10
+ def yo(message)
11
+ Ruboty::Yo::Actions::Yo.new(message).call
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ require "ruboty"
2
+ require "ruboty/yo/version"
3
+ require "ruboty/handlers/yo"
4
+
5
+ module Ruboty
6
+ module Yo
7
+ ENDPOINT_URL = URI.parse('https://api.justyo.co/yo/')
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ module Ruboty
2
+ module Yo
3
+ module Actions
4
+ class Yo < Ruboty::Actions::Base
5
+ def call
6
+ params = {api_token: ENV['YO_API_TOKEN'], username: message[:to]}
7
+ res = Net::HTTP.post_form(::Ruboty::Yo::ENDPOINT_URL, params)
8
+
9
+ unless res.is_a?(Net::HTTPOK)
10
+ message.reply("伝わらなかったよ")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Yo
3
+ VERSION = "1.0.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/yo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-yo"
8
+ spec.version = Ruboty::Yo::VERSION
9
+ spec.authors = ["block_given?"]
10
+ spec.email = ["block_given@outlook.com"]
11
+ spec.summary = %q{ruboty plugin for yo.}
12
+ spec.homepage = "https://github.com/blockgiven/ruboty-yo"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
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.add_runtime_dependency "ruboty"
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "pry"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "turnip"
26
+ spec.add_development_dependency "vcr"
27
+ spec.add_development_dependency "webmock"
28
+ end
Binary file
@@ -0,0 +1,23 @@
1
+ # language: ja
2
+
3
+ フィーチャ: どんな思いもRubotyは受け止めるよ
4
+
5
+ 好きよ君
6
+ ぼっとほうけて
7
+ 冬隣
8
+
9
+ 背景:
10
+ 前提 テスト用のRubotyがいる
11
+ かつ johndoeはyoを使っている
12
+ かつ janedoeはyoを使うのをやめた
13
+
14
+ @yo_ok
15
+ シナリオ: 「好きよ」と伝えられず、呆けたロボットとぼーっと遊びほうけていたら、もう冬が間近にせまっていた。気持ち全然伝わらないよ。
16
+ もし "君が好きだよ johndoe"と私が言った
17
+ ならば Rubotyはjohndoeにyoと伝えた
18
+
19
+ @yo_ng
20
+ シナリオ: 「好きよ」ともっと早くに伝えればよかった。
21
+ もし "君が好きだよ janedoe"と私が言った
22
+ ならば Rubotyはjanedoeにyoと伝えられなかった
23
+ かつ Rubotyは"伝わらなかったよ"と言った
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.justyo.co/yo/
6
+ body:
7
+ encoding: US-ASCII
8
+ string: api_token=3f020510-5961-4ef9-864a-aa8b6d63ed95&username=janedoe
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - api.justyo.co
18
+ Content-Type:
19
+ - application/x-www-form-urlencoded
20
+ response:
21
+ status:
22
+ code: 400
23
+ message: BAD REQUEST
24
+ headers:
25
+ Connection:
26
+ - keep-alive
27
+ Server:
28
+ - gunicorn/18.0
29
+ Date:
30
+ - Fri, 31 Oct 2014 19:04:10 GMT
31
+ Transfer-Encoding:
32
+ - chunked
33
+ Vary:
34
+ - Accept, Cookie
35
+ Allow:
36
+ - POST, OPTIONS
37
+ X-Frame-Options:
38
+ - SAMEORIGIN
39
+ Content-Type:
40
+ - application/json
41
+ Via:
42
+ - 1.1 vegur
43
+ body:
44
+ encoding: UTF-8
45
+ string: '{"code": 141, "error": "NO SUCH USER"}'
46
+ http_version:
47
+ recorded_at: Fri, 31 Oct 2014 19:04:10 GMT
48
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.justyo.co/yo/
6
+ body:
7
+ encoding: US-ASCII
8
+ string: api_token=0ba3144a-5cb4-4eb3-92f1-42fa65345aaf&username=johndoe
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - api.justyo.co
18
+ Content-Type:
19
+ - application/x-www-form-urlencoded
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Connection:
26
+ - keep-alive
27
+ Server:
28
+ - gunicorn/18.0
29
+ Date:
30
+ - Fri, 31 Oct 2014 19:04:09 GMT
31
+ Transfer-Encoding:
32
+ - chunked
33
+ Content-Type:
34
+ - application/json
35
+ Vary:
36
+ - Accept, Cookie
37
+ Allow:
38
+ - POST, OPTIONS
39
+ X-Frame-Options:
40
+ - SAMEORIGIN
41
+ Via:
42
+ - 1.1 vegur
43
+ body:
44
+ encoding: UTF-8
45
+ string: '{"result": "OK"}'
46
+ http_version:
47
+ recorded_at: Fri, 31 Oct 2014 19:04:09 GMT
48
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,5 @@
1
+ require 'pry'
2
+ require 'ruboty/yo'
3
+
4
+ Dir['spec/support/**/*.rb'].each {|f| load f }
5
+ Dir['spec/steps/**/*_steps.rb'].each {|f| load f }
File without changes
@@ -0,0 +1,31 @@
1
+ step 'テスト用のRubotyがいる' do
2
+ @ruboty = ::Ruboty::Robot.new
3
+ @ruboty.run
4
+ end
5
+
6
+ step ':nameはyoを使っている' do |name|
7
+ @yo_users ||= []
8
+ @yo_users << name
9
+ end
10
+
11
+ step ':nameはyoを使うのをやめた' do |name|
12
+ @yo_users -= [name]
13
+ end
14
+
15
+ step ':bodyと私が言った' do |body|
16
+ @ruboty.receive(body: body)
17
+ end
18
+
19
+ step 'Rubotyは:nameにyoと伝えた' do |name|
20
+ expect(@yo_users).to include name
21
+ expect(WebMock).to have_requested(:post, 'https://api.justyo.co/yo/').with {|req| req.body.include? "username=#{name}" }
22
+ end
23
+
24
+ step 'Rubotyは:nameにyoと伝えられなかった' do |name|
25
+ expect(@yo_users).not_to include name
26
+ expect(WebMock).to have_requested(:post, 'https://api.justyo.co/yo/').with {|req| req.body.include? "username=#{name}" }
27
+ end
28
+
29
+ step 'Rubotyは:bodyと言った' do |body|
30
+ expect(@ruboty).to be_said body
31
+ end
File without changes
@@ -0,0 +1 @@
1
+ ENV['YO_API_TOKEN'] = 'b516003c-3643-477c-9c8c-1d5039068ed3'
@@ -0,0 +1,28 @@
1
+ module Ruboty
2
+ module Adapters
3
+ class MockAdapter < Base
4
+ def run
5
+ end
6
+
7
+ def say(message)
8
+ said_messages << message
9
+ end
10
+
11
+ def said_messages
12
+ @said_messages ||= []
13
+ end
14
+
15
+ def said?(body)
16
+ said_messages.any? {|m| m[:body] == body }
17
+ end
18
+ end
19
+ end
20
+
21
+ module Testable
22
+ def said?(body)
23
+ adapter.said?(body)
24
+ end
25
+ end
26
+
27
+ Robot.prepend(Testable)
28
+ end
@@ -0,0 +1,7 @@
1
+ RSpec.shared_context 'yo ng', :yo_ng do
2
+ around do |example|
3
+ VCR.use_cassette('yo_ng') do
4
+ example.run
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ RSpec.shared_context 'yo ok', :yo_ok do
2
+ around do |example|
3
+ VCR.use_cassette('yo_ok') do
4
+ example.run
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ require 'vcr'
2
+ require 'webmock/rspec'
3
+
4
+ WebMock.allow_net_connect!
5
+ VCR.configure do |c|
6
+ c.cassette_library_dir = 'spec/fixtures'
7
+ c.hook_into :webmock
8
+ end
metadata ADDED
@@ -0,0 +1,192 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-yo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - block_given?
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
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: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
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: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
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
+ - !ruby/object:Gem::Dependency
84
+ name: turnip
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email:
127
+ - block_given@outlook.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - Gemfile
134
+ - LICENSE.txt
135
+ - README.md
136
+ - Rakefile
137
+ - lib/ruboty/handlers/yo.rb
138
+ - lib/ruboty/yo.rb
139
+ - lib/ruboty/yo/actions/yo.rb
140
+ - lib/ruboty/yo/version.rb
141
+ - ruboty-yo.gemspec
142
+ - screenshot.png
143
+ - spec/acceptance/yo.feature
144
+ - spec/fixtures/yo_ng.yml
145
+ - spec/fixtures/yo_ok.yml
146
+ - spec/spec_helper.rb
147
+ - spec/steps/.keep
148
+ - spec/steps/yo_steps.rb
149
+ - spec/support/.keep
150
+ - spec/support/env.rb
151
+ - spec/support/ruboty-mock_adapter.rb
152
+ - spec/support/shared_contexts/yo_ng.rb
153
+ - spec/support/shared_contexts/yo_ok.rb
154
+ - spec/support/stub_test_yo_data.rb
155
+ homepage: https://github.com/blockgiven/ruboty-yo
156
+ licenses:
157
+ - MIT
158
+ metadata: {}
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 2.2.2
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: ruboty plugin for yo.
179
+ test_files:
180
+ - spec/acceptance/yo.feature
181
+ - spec/fixtures/yo_ng.yml
182
+ - spec/fixtures/yo_ok.yml
183
+ - spec/spec_helper.rb
184
+ - spec/steps/.keep
185
+ - spec/steps/yo_steps.rb
186
+ - spec/support/.keep
187
+ - spec/support/env.rb
188
+ - spec/support/ruboty-mock_adapter.rb
189
+ - spec/support/shared_contexts/yo_ng.rb
190
+ - spec/support/shared_contexts/yo_ok.rb
191
+ - spec/support/stub_test_yo_data.rb
192
+ has_rdoc: