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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e505b94b8376f49d0f95673a28555ef61233591c
4
- data.tar.gz: c6aab02be506d8cfe8eb7939fa26e1ed9c0da765
3
+ metadata.gz: 5150e290a2ec496a47f2abaa933c2512ae86bd27
4
+ data.tar.gz: '096a75eb137ea573087b41f361a4378d210694bf'
5
5
  SHA512:
6
- metadata.gz: 30f6cb11d2f90a7382359d7b937fd573e36d41794fb56d64d4561564ca8d9f146b9cae0607a1d14a177a4a80b92c28beff3380ff2efa731700043b9423ba2a81
7
- data.tar.gz: 968096c59894deb746e33af93b85c058e83ae91b67fe533873eda98fd0d00e5ff6bb3dc82a62e49da15a7b3a2130d8dc670970bb2952628a6eeaed6fecb0fe6b
6
+ metadata.gz: 0b79707ccbfc4661df22b36d617188a278740fa02746e4e692bd8db0d039c429fb51e290d8777f062f046b2eb8f3a5993a5ae1cf715476f9c1207ce1db245447
7
+ data.tar.gz: ac92ae594fa3dc6d17c8c60640da7f6e65377824e66ae3b99bfb052446774198a235fa6ab46f1d3ac7d2ea8c1725ffa179bf7c7eccf17d4478e8e25732e354bd
@@ -1,8 +1,10 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
+ - ruby-2.2.2
5
+ - ruby-2.3.0
4
6
  - ruby-2.4.0
5
- - 2.3.0
7
+ - ruby-2.4.1
6
8
 
7
9
  before_install:
8
10
  - gem install bundler
@@ -1,3 +1,7 @@
1
+ # v0.0.5
2
+ - Add Ruby versions to `.travis.yml`.
3
+ - Replace owned crawler with dmm-crawler gem.
4
+
1
5
  # v0.0.4
2
6
  - Fix a sentence `"#{term}の本日のランキングです。"` -> `"#{term}のランキングです。"`.
3
7
  - Add periods to at the end of the sentence.
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruboty-dmm (0.0.4)
5
- mechanize
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.2)
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
- domain_name (0.5.20170223)
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.0)
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.1)
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.0.1)
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.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.2)
90
+ unf_ext (0.0.7.4)
89
91
  unicode-display_width (1.1.3)
90
92
  webrobots (0.1.2)
91
93
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## Ruboty DMMとは
6
6
  Ruboty DMMはDMM.R18のランキングをSlackに通知するためのボットです。
7
- 現在は同人誌のみになっています。
7
+ 現在は同人のみになっています。
8
8
 
9
9
  ## インストール
10
10
  使っているボットのGemfileに以下を追記してください。
@@ -1,6 +1,5 @@
1
- require 'mechanize'
1
+ require 'dmm-crawler'
2
2
 
3
- require 'ruboty/dmm/agent'
4
3
  require 'ruboty/dmm/ranking'
5
4
  require 'ruboty/dmm/actions/messenger'
6
5
  require 'ruboty/dmm/version'
@@ -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(submedia: message.match_data[:submedia], term: message.match_data[:term]).books
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
@@ -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
- def initialize(arguments)
8
- @term = discriminate_term(arguments[:term])
9
- @submedia = discriminate_submedia(arguments[:submedia])
10
- @url = "#{BASE_URL}/dc/doujin/-/ranking-all/=/sort=popular/submedia=#{@submedia}/term=#{@term}"
11
- @agent = Agent.new.agent
12
- end
6
+ def initialize(arguments)
7
+ @submedia = arguments[:submedia]
8
+ @term = arguments[:term]
9
+ end
13
10
 
14
- def books
15
- books = page.search('.rank-rankListItem.fn-setPurchaseChange').map do |element|
16
- [
17
- element.search('.rank-name').first.text.strip,
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
- private
16
+ private
26
17
 
27
- def credentials
28
- {
29
- api_id: ENV['API_ID'],
30
- affiliate_id: ENV['AFFILIATE_ID']
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
- def page
35
- @agent.get(@url)
36
- end
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
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module DMM
3
- VERSION = '0.0.4'.freeze
3
+ VERSION = '0.0.5'.freeze
4
4
  end
5
5
  end
@@ -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, 24, weeks, months"
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 'mechanize'
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).books }
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 '#books' do
8
- context 'with 24 argument' do
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 argument' do
17
+ context 'with not registered term' do
18
18
  subject { -> { attachments } }
19
19
 
20
- let(:term) { 'hoge' }
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
@@ -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
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-04-09 00:00:00.000000000 Z
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: mechanize
28
+ name: dmm-crawler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
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: '0'
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, 24, weeks, months
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.11
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
@@ -1,13 +0,0 @@
1
- module Ruboty
2
- module DMM
3
- class Agent
4
- attr_accessor :agent
5
-
6
- def initialize
7
- @agent = ::Mechanize.new
8
- @agent.request_headers = { 'Accept-Encoding' => '' }
9
- @agent.ignore_bad_chunking = true
10
- end
11
- end
12
- end
13
- end