ruboty-url 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 25733544717f76136fc6c0677fb97bd4c1b2a314
4
+ data.tar.gz: 633d9cced34f92cd04ce8117b158b2c3d615cf9c
5
+ SHA512:
6
+ metadata.gz: 32d7b93275d9faaec3f3c7283a260ca2b110d5899a9f3d7394b4bd073ad72189722ac5ece356e96741672b55b5b6552fac560b8475b8a7d7ee92f7beca8c970f
7
+ data.tar.gz: 8470ee94c848d3533a736c89d070845e6070211a4cf1f29e3e7f91c19e45a75e067ff3ea5a73b1805ad0528b739567dbb209e78c0fb405e073cd5b936e4ed337
data/.gitignore ADDED
@@ -0,0 +1,53 @@
1
+ ### https://raw.github.com/github/gitignore/68ae2ff9f7ce0176696966539b9807525002893b/Rails.gitignore
2
+
3
+ *.rbc
4
+ capybara-*.html
5
+ .rspec
6
+ /log
7
+ /tmp
8
+ /db/*.sqlite3
9
+ /db/*.sqlite3-journal
10
+ /public/system
11
+ /coverage/
12
+ /spec/tmp
13
+ *.orig
14
+ rerun.txt
15
+ pickle-email-*.html
16
+
17
+ # TODO Comment out this rule if you are OK with secrets being uploaded to the repo
18
+ config/initializers/secret_token.rb
19
+
20
+ # Only include if you have production secrets in this file, which is no longer a Rails default
21
+ # config/secrets.yml
22
+
23
+ # dotenv
24
+ # TODO Comment out this rule if environment variables can be committed
25
+ .env
26
+
27
+ ## Environment normalization:
28
+ /.bundle
29
+ /vendor/bundle
30
+
31
+ # these should all be checked in to normalize the environment:
32
+ # Gemfile.lock, .ruby-version, .ruby-gemset
33
+ Gemfile.lock
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
37
+
38
+ # if using bower-rails ignore default bower_components path bower.json files
39
+ /vendor/assets/bower_components
40
+ *.bowerrc
41
+ bower.json
42
+
43
+ # Ignore pow environment settings
44
+ .powenv
45
+
46
+ # Ignore Byebug command history file.
47
+ .byebug_history
48
+
49
+ # Ignore node_modules
50
+ node_modules/
51
+
52
+ /pkg
53
+
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
6
+ notifications:
7
+ slack:
8
+ secure: FaNGHfEjL0lfgQrNGsXz+6knlaGEsiJ3cia3/bcXPEVrvB37poQIzi3ixsYBYmaEDJTpSiFNharYMEQXimlahXLUOwIVMT4hBOFEcqwguU9GOUSms/Qwld0+N1l3xIf5mIM8h6KpVv8rpjTGnBQkQl8mu70wk1omu/P9x4lykhU7ZdttgSgNzsUH81dPmDBCS70CkTNfhmbaWzAtXdrploAcN/eA3mUSRl048v2r2rLLNBeLEbDougL+h8nSg80AF1Ux3X2aXwiTxZO2AqFlza5l0JyR0B5A660XsMmxBOcRY4HSgbL9zSGuIfqDYtZMzWmGcDh1kJxmdeH/xX1dTtLISc3tzwtAzZDePNEsZYVLSrY2QvlocDFlneVnRZ3SPJCYI/LkTMoZwp4Uz0dZnPcvXhGWf3yR6bce4aAMWHgMyUZaQ0PIWEvB7r7GvT7fAtMP4/Y6fwPsOwXUdynfSroHoNAbyZkNwoVxBFO4Qb0n366Lvq98tRPM2Rv+w785zSxnPUrQjPDJCtWBW/YvgxZkuxuW9AhFuMTyXx6WR6LDdhbPnj9B2VkMXfNFY+Nmd2meZVHW93J9BuvrRiR+PHyINrtMi4fwqBFPLqwgR5vjj+2pyNsJ55hMQjezE8e37jLWxF5FhpyZDmoDbTNMIQ9v4IOOmZaSmDg1ltiQ/go=
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ruboty-url.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 zeero
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Ruboty::Url
2
+
3
+ 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/ruboty/url`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ruboty-url'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ruboty-url
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/zeero/ruboty-url.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruboty/url"
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(__FILE__)
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,14 @@
1
+ require 'ruboty/url'
2
+
3
+ module Ruboty
4
+ module Handlers
5
+ # url
6
+ class Url < Base
7
+ on(Regexp.new(ENV['RUBOTY_URL_REGEXP'] || '$^'), name: 'title', description: 'Show html title with specified url.', all: true)
8
+
9
+ def title(message)
10
+ Ruboty::Url::Actions::Title.new(message).call
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ require 'ruboty/url'
2
+
3
+ module Ruboty
4
+ module Url
5
+ module Actions
6
+ # Ruboty::Url::Actions::Title
7
+ class Title < Ruboty::Actions::Base
8
+ def call
9
+ url = message[0]
10
+ title = ''
11
+ open(url) do |f|
12
+ doc = Nokogiri::HTML(f)
13
+ title = doc.xpath('/html/head/title').text
14
+ end
15
+ attachments = [{
16
+ color: '#0099ff',
17
+ title: title,
18
+ title_link: url,
19
+ }]
20
+ message.reply(nil, attachments: attachments) unless title.empty?
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Url
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
data/lib/ruboty/url.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'open-uri'
2
+
3
+ require 'active_support'
4
+ require 'active_support/core_ext'
5
+ require 'nokogiri'
6
+
7
+ module Ruboty
8
+ # Ruboty::Url
9
+ module Url
10
+ class << self
11
+ end
12
+ end
13
+ end
14
+
15
+ Dir[File.expand_path('url', __dir__) << '/**/*.rb'].each { |file| require file }
16
+ require 'ruboty/handlers/url'
17
+
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'ruboty/url/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'ruboty-url'
7
+ spec.version = Ruboty::Url::VERSION
8
+ spec.authors = ['zeero']
9
+ spec.email = ['zeero26@gmail.com']
10
+ spec.summary = 'Show html title with specified URL.'
11
+ spec.description = 'Show html title with specified URL.'
12
+ spec.homepage = ''
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_dependency 'activesupport'
21
+ spec.add_dependency 'nokogiri'
22
+ spec.add_runtime_dependency 'ruboty'
23
+ spec.add_development_dependency 'bundler', '~> 1.16'
24
+ spec.add_development_dependency 'byebug'
25
+ spec.add_development_dependency 'minitest'
26
+ spec.add_development_dependency 'minitest-reporters'
27
+ spec.add_development_dependency 'mocha'
28
+ spec.add_development_dependency 'pry'
29
+ spec.add_development_dependency 'pry-byebug'
30
+ spec.add_development_dependency 'pry-theme'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ end
@@ -0,0 +1,34 @@
1
+ ENV['RUBOTY_URL_REGEXP'] = '(https://0.0.0.0:8888.*|http://1.1.1.1.*)'
2
+
3
+ require 'test_helper'
4
+
5
+ describe Ruboty::Handlers::Url do
6
+ let(:robot) { Ruboty::Robot.new }
7
+
8
+ before do
9
+ end
10
+
11
+ describe '#title' do
12
+ let(:action) { Ruboty::Url::Actions::Title }
13
+ let(:mock_action_call) { mock.tap { |mock| mock.expects(:call).once } }
14
+
15
+ it '環境変数RUBOTY_URL_REGEXPとマッチする文字列に反応する' do
16
+ url = 'http://1.1.1.1/foo'
17
+ action
18
+ .stubs(:new)
19
+ .with do |message|
20
+ p "message: #{message}"
21
+ message[0].must_equal url
22
+ end
23
+ .returns(mock_action_call)
24
+
25
+ robot.receive(body: url, from: 'sender', to: 'channel')
26
+ end
27
+
28
+ it '環境変数RUBOTY_URL_REGEXPとマッチしない文字列に反応しない' do
29
+ url = 'https://0.0.0.0'
30
+ action.any_instance.expects(:call).never
31
+ robot.receive(body: url, from: 'sender', to: 'channel')
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ describe Ruboty::Url::Actions::Title do
4
+ subject { Ruboty::Url::Actions::Title.new(mock_message) }
5
+
6
+ let(:mock_message) { mock }
7
+
8
+ before do
9
+ end
10
+
11
+ describe '#call' do
12
+ let(:url) { 'https://foo/' }
13
+ let(:title) { "foo's title" }
14
+
15
+ it 'should get HTML title' do
16
+ # stub
17
+ mock_message.stubs(:[]).with(0).returns(url)
18
+ OpenURI.stubs(:open_uri).yields(StringIO.new("<html><head><title>#{title}</title></head></html>"))
19
+ # mock
20
+ attachments = [{
21
+ color: '#0099ff',
22
+ title: title,
23
+ title_link: url,
24
+ }]
25
+ mock_message.expects(:reply).with(nil, attachments: attachments).once
26
+ subject.call
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class Ruboty::UrlTest < Minitest::Test
4
+ def test_that_it_has_a_version_number
5
+ refute_nil ::Ruboty::Url::VERSION
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/reporters'
3
+ require 'mocha/mini_test'
4
+
5
+ require 'ruboty'
6
+
7
+ require 'ruboty/url'
8
+
9
+ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
10
+
metadata ADDED
@@ -0,0 +1,235 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-url
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - zeero
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
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: nokogiri
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: ruboty
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: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
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: minitest
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: minitest-reporters
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: mocha
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
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry-byebug
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry-theme
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rake
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '10.0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '10.0'
181
+ description: Show html title with specified URL.
182
+ email:
183
+ - zeero26@gmail.com
184
+ executables:
185
+ - console
186
+ - setup
187
+ extensions: []
188
+ extra_rdoc_files: []
189
+ files:
190
+ - ".gitignore"
191
+ - ".travis.yml"
192
+ - Gemfile
193
+ - LICENSE.txt
194
+ - README.md
195
+ - Rakefile
196
+ - bin/console
197
+ - bin/setup
198
+ - lib/ruboty/handlers/url.rb
199
+ - lib/ruboty/url.rb
200
+ - lib/ruboty/url/actions/title.rb
201
+ - lib/ruboty/url/version.rb
202
+ - ruboty-url.gemspec
203
+ - test/ruboty/handlers/url_test.rb
204
+ - test/ruboty/url/actions/title_test.rb
205
+ - test/ruboty/url_test.rb
206
+ - test/test_helper.rb
207
+ homepage: ''
208
+ licenses:
209
+ - MIT
210
+ metadata: {}
211
+ post_install_message:
212
+ rdoc_options: []
213
+ require_paths:
214
+ - lib
215
+ required_ruby_version: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ version: '0'
220
+ required_rubygems_version: !ruby/object:Gem::Requirement
221
+ requirements:
222
+ - - ">="
223
+ - !ruby/object:Gem::Version
224
+ version: '0'
225
+ requirements: []
226
+ rubyforge_project:
227
+ rubygems_version: 2.5.1
228
+ signing_key:
229
+ specification_version: 4
230
+ summary: Show html title with specified URL.
231
+ test_files:
232
+ - test/ruboty/handlers/url_test.rb
233
+ - test/ruboty/url/actions/title_test.rb
234
+ - test/ruboty/url_test.rb
235
+ - test/test_helper.rb