ruboty-dmm 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +11 -9
- data/doc/ja/README.md +1 -1
- data/lib/ruboty/dmm.rb +1 -2
- data/lib/ruboty/dmm/actions/messenger.rb +4 -2
- data/lib/ruboty/dmm/ranking.rb +17 -37
- data/lib/ruboty/dmm/version.rb +1 -1
- data/ruboty-dmm.gemspec +2 -2
- data/spec/ruboty/dmm/ranking_spec.rb +17 -7
- data/spec/ruboty/handlers/dmm_spec.rb +39 -0
- data/spec/spec_helper.rb +6 -0
- metadata +10 -10
- data/lib/ruboty/dmm/agent.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5150e290a2ec496a47f2abaa933c2512ae86bd27
|
4
|
+
data.tar.gz: '096a75eb137ea573087b41f361a4378d210694bf'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b79707ccbfc4661df22b36d617188a278740fa02746e4e692bd8db0d039c429fb51e290d8777f062f046b2eb8f3a5993a5ae1cf715476f9c1207ce1db245447
|
7
|
+
data.tar.gz: ac92ae594fa3dc6d17c8c60640da7f6e65377824e66ae3b99bfb052446774198a235fa6ab46f1d3ac7d2ea8c1725ffa179bf7c7eccf17d4478e8e25732e354bd
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruboty-dmm (0.0.
|
5
|
-
|
4
|
+
ruboty-dmm (0.0.5)
|
5
|
+
dmm-crawler (= 0.0.4)
|
6
6
|
ruboty
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (5.0
|
11
|
+
activesupport (5.1.0)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
13
|
i18n (~> 0.7)
|
14
14
|
minitest (~> 5.1)
|
@@ -17,9 +17,11 @@ GEM
|
|
17
17
|
coderay (1.1.1)
|
18
18
|
concurrent-ruby (1.0.5)
|
19
19
|
diff-lcs (1.3)
|
20
|
-
|
20
|
+
dmm-crawler (0.0.4)
|
21
|
+
mechanize
|
22
|
+
domain_name (0.5.20170404)
|
21
23
|
unf (>= 0.0.5, < 1.0.0)
|
22
|
-
dotenv (2.2.
|
24
|
+
dotenv (2.2.1)
|
23
25
|
http-cookie (1.0.3)
|
24
26
|
domain_name (~> 0.5)
|
25
27
|
i18n (0.8.1)
|
@@ -38,10 +40,10 @@ GEM
|
|
38
40
|
mime-types-data (~> 3.2015)
|
39
41
|
mime-types-data (3.2016.0521)
|
40
42
|
mini_portile2 (2.1.0)
|
41
|
-
minitest (5.10.
|
43
|
+
minitest (5.10.2)
|
42
44
|
net-http-digest_auth (1.4.1)
|
43
45
|
net-http-persistent (2.9.4)
|
44
|
-
nokogiri (1.7.
|
46
|
+
nokogiri (1.7.2)
|
45
47
|
mini_portile2 (~> 2.1.0)
|
46
48
|
ntlm-http (0.1.1)
|
47
49
|
parser (2.4.0.0)
|
@@ -81,11 +83,11 @@ GEM
|
|
81
83
|
ruby-progressbar (1.8.1)
|
82
84
|
slop (3.6.0)
|
83
85
|
thread_safe (0.3.6)
|
84
|
-
tzinfo (1.2.
|
86
|
+
tzinfo (1.2.3)
|
85
87
|
thread_safe (~> 0.1)
|
86
88
|
unf (0.1.4)
|
87
89
|
unf_ext
|
88
|
-
unf_ext (0.0.7.
|
90
|
+
unf_ext (0.0.7.4)
|
89
91
|
unicode-display_width (1.1.3)
|
90
92
|
webrobots (0.1.2)
|
91
93
|
|
data/doc/ja/README.md
CHANGED
data/lib/ruboty/dmm.rb
CHANGED
@@ -3,9 +3,9 @@ module Ruboty
|
|
3
3
|
module Actions
|
4
4
|
class Messenger < Ruboty::Actions::Base
|
5
5
|
def call
|
6
|
-
attachments = Ruboty::DMM::Ranking.new(
|
6
|
+
attachments = Ruboty::DMM::Ranking.new(message.match_data).arts
|
7
7
|
term = term_converter(message.match_data[:term])
|
8
|
-
message.reply("#{term}のランキングです。", attachments: attachments)
|
8
|
+
message.reply("#{term}のランキングです。", attachments: attachments) # temporary ignoring tags. I have to add interface for tags
|
9
9
|
rescue => exception
|
10
10
|
message.reply("Failed by #{exception.class}")
|
11
11
|
end
|
@@ -22,6 +22,8 @@ module Ruboty
|
|
22
22
|
'月間'
|
23
23
|
when 'total'
|
24
24
|
'全体'
|
25
|
+
else
|
26
|
+
raise TypeError
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
data/lib/ruboty/dmm/ranking.rb
CHANGED
@@ -1,49 +1,29 @@
|
|
1
1
|
module Ruboty
|
2
2
|
module DMM
|
3
3
|
class Ranking
|
4
|
-
BASE_URL = 'http://www.dmm.co.jp'.freeze
|
5
4
|
COLORS = %w(7acc28 9dcc28 cc2828 cc6e28 28a9cc 3428cc cc28b4 c0cc28 2886cc 28cca9).map { |hex| "##{hex}" }.freeze
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@agent = Agent.new.agent
|
12
|
-
end
|
6
|
+
def initialize(arguments)
|
7
|
+
@submedia = arguments[:submedia]
|
8
|
+
@term = arguments[:term]
|
9
|
+
end
|
13
10
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
element.search('img').last.attributes['src'].value,
|
19
|
-
"#{BASE_URL}#{element.search('.rank-name').first.search('a').first.attributes.first[1].value}"
|
20
|
-
]
|
21
|
-
end
|
22
|
-
books.take(10).zip(COLORS).map.with_index(1) { |((title, image, url), color), rank| { title: "#{rank}位: #{title}", title_link: url, image_url: image, color: color } }
|
23
|
-
end
|
11
|
+
def arts
|
12
|
+
arts = DMMCrawler::Ranking.new(submedia: submedia, term: term).arts.take(10)
|
13
|
+
arts.zip(COLORS).map { |art, color| art.merge(color: color) }
|
14
|
+
end
|
24
15
|
|
25
|
-
|
16
|
+
private
|
26
17
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}
|
32
|
-
end
|
18
|
+
def term
|
19
|
+
return @term if %w(24 weekly monthly total).include?(@term)
|
20
|
+
raise TypeError
|
21
|
+
end
|
33
22
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
def discriminate_term(term)
|
39
|
-
return term if %w(24 weekly monthly total).include?(term)
|
40
|
-
raise TypeError
|
41
|
-
end
|
42
|
-
|
43
|
-
def discriminate_submedia(submedia)
|
44
|
-
return submedia if %w(all weekly cg game voice).include?(submedia)
|
45
|
-
raise TypeError
|
46
|
-
end
|
23
|
+
def submedia
|
24
|
+
return @submedia if %w(all comic cg game voice).include?(@submedia)
|
25
|
+
raise TypeError
|
26
|
+
end
|
47
27
|
end
|
48
28
|
end
|
49
29
|
end
|
data/lib/ruboty/dmm/version.rb
CHANGED
data/ruboty-dmm.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.email = ['sachin21dev@gmail.com']
|
13
13
|
|
14
14
|
spec.summary = "A bot for DMM R18's rankings"
|
15
|
-
spec.description = "A bot for DMM R18's rankings
|
15
|
+
spec.description = "A bot for DMM R18's rankings for 24, weeks, months"
|
16
16
|
spec.homepage = 'https://github.com/sachin21/ruboty-dmm'
|
17
17
|
spec.license = 'MIT'
|
18
18
|
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
23
|
spec.add_runtime_dependency 'ruboty'
|
24
|
-
spec.add_runtime_dependency '
|
24
|
+
spec.add_runtime_dependency 'dmm-crawler', '0.0.4'
|
25
25
|
|
26
26
|
spec.add_development_dependency 'bundler', '~> 1.14'
|
27
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
@@ -1,23 +1,33 @@
|
|
1
1
|
describe Ruboty::DMM::Ranking do
|
2
|
-
let(:attachments) { described_class.new(arguments).
|
2
|
+
let(:attachments) { described_class.new(arguments).arts }
|
3
3
|
|
4
|
-
let(:submedia) { 'cg' }
|
5
4
|
let(:arguments) { { submedia: submedia, term: term } }
|
6
5
|
|
7
|
-
describe '#
|
8
|
-
context 'with
|
6
|
+
describe '#arts' do
|
7
|
+
context 'with registered arguments' do
|
9
8
|
subject { attachments }
|
10
9
|
|
11
10
|
let(:term) { '24' }
|
11
|
+
let(:submedia) { 'cg' }
|
12
12
|
|
13
13
|
it { is_expected.not_to be_empty }
|
14
|
-
it { is_expected.to all(include(:title, :title_link, :image_url, :color)) }
|
14
|
+
it { is_expected.to all(include(:title, :title_link, :image_url, :tags, :color)) }
|
15
15
|
end
|
16
16
|
|
17
|
-
context 'with not registered
|
17
|
+
context 'with not registered term' do
|
18
18
|
subject { -> { attachments } }
|
19
19
|
|
20
|
-
let(:term) { '
|
20
|
+
let(:term) { 'foobaz' }
|
21
|
+
let(:submedia) { 'cg' }
|
22
|
+
|
23
|
+
it { is_expected.to raise_error(TypeError) }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with not registered submedia' do
|
27
|
+
subject { -> { attachments } }
|
28
|
+
|
29
|
+
let(:term) { '24' }
|
30
|
+
let(:submedia) { 'foobaz' }
|
21
31
|
|
22
32
|
it { is_expected.to raise_error(TypeError) }
|
23
33
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ruboty::Handlers::RubotyDMM do
|
4
|
+
let(:robot) { Ruboty::Robot.new }
|
5
|
+
|
6
|
+
let(:channel) { '#bot_test' }
|
7
|
+
|
8
|
+
let(:sender) { 'mikoto-sister' }
|
9
|
+
|
10
|
+
let(:body) { %(ruboty dmm #{submedia} #{term}) }
|
11
|
+
|
12
|
+
before { sleep 2 }
|
13
|
+
|
14
|
+
describe '#messenger' do
|
15
|
+
|
16
|
+
subject { -> { robot.receive(body: body, from: sender, to: channel) } }
|
17
|
+
|
18
|
+
context 'with valid arguments' do
|
19
|
+
let(:submedia) { 'cg' }
|
20
|
+
let(:term) { '24' }
|
21
|
+
|
22
|
+
it { is_expected.to output("24時間のランキングです。\n").to_stdout }
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with invalid submedia' do
|
26
|
+
let(:submedia) { 'foobaz' }
|
27
|
+
let(:term) { '24' }
|
28
|
+
|
29
|
+
it { is_expected.to output("Failed by TypeError\n").to_stdout }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with invalid term' do
|
33
|
+
let(:submedia) { 'cg' }
|
34
|
+
let(:term) { 'foobaz' }
|
35
|
+
|
36
|
+
it { is_expected.to output("Failed by TypeError\n").to_stdout }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,8 +4,14 @@
|
|
4
4
|
require 'ruboty'
|
5
5
|
require 'ruboty/dmm'
|
6
6
|
|
7
|
+
require 'pry'
|
8
|
+
|
7
9
|
RSpec.configure do |config|
|
8
10
|
config.order = 'random'
|
11
|
+
|
12
|
+
config.filter_run :focus => true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
|
9
15
|
config.expect_with :rspec do |rspec|
|
10
16
|
rspec.syntax = :expect
|
11
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-dmm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Satoshi Ohmori
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruboty
|
@@ -25,19 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: dmm-crawler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.0.4
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.0.4
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- - '='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 3.5.0
|
111
|
-
description: A bot for DMM R18's rankings
|
111
|
+
description: A bot for DMM R18's rankings for 24, weeks, months
|
112
112
|
email:
|
113
113
|
- sachin21dev@gmail.com
|
114
114
|
executables: []
|
@@ -128,12 +128,12 @@ files:
|
|
128
128
|
- doc/ja/README.md
|
129
129
|
- lib/ruboty/dmm.rb
|
130
130
|
- lib/ruboty/dmm/actions/messenger.rb
|
131
|
-
- lib/ruboty/dmm/agent.rb
|
132
131
|
- lib/ruboty/dmm/ranking.rb
|
133
132
|
- lib/ruboty/dmm/version.rb
|
134
133
|
- lib/ruboty/handlers/dmm.rb
|
135
134
|
- ruboty-dmm.gemspec
|
136
135
|
- spec/ruboty/dmm/ranking_spec.rb
|
136
|
+
- spec/ruboty/handlers/dmm_spec.rb
|
137
137
|
- spec/spec_helper.rb
|
138
138
|
homepage: https://github.com/sachin21/ruboty-dmm
|
139
139
|
licenses:
|
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
155
|
version: '0'
|
156
156
|
requirements: []
|
157
157
|
rubyforge_project:
|
158
|
-
rubygems_version: 2.6.
|
158
|
+
rubygems_version: 2.6.12
|
159
159
|
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: A bot for DMM R18's rankings
|
data/lib/ruboty/dmm/agent.rb
DELETED