ruboty-dmm 0.0.1

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: c68febe22711f064807924d51f16f24d97cad87d
4
+ data.tar.gz: 7232934e8e2acd9d22610c4d7c92e9763ca1f81d
5
+ SHA512:
6
+ metadata.gz: 7df0bc5b27bad579e016c9fbc44439b21ddf2a5008337e65d81172b561df6c82552010de6998a2c45d22a4f5c294fe18df9ee146d96de68db7bd07aa96770a7f
7
+ data.tar.gz: ac28f52a803bd2c39dff72436ed56f20c6fa5ce2d00ffc473dc825072059cd91b8b757157251588b7f65c5d45cf3777013af8eadf8569aed8454634786a44868
@@ -0,0 +1 @@
1
+ /vendor
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,17 @@
1
+ LineLength:
2
+ Enabled: false
3
+
4
+ Metrics/AbcSize:
5
+ Enabled: false
6
+
7
+ CyclomaticComplexity:
8
+ Enabled: false
9
+
10
+ Metrics/ClassLength:
11
+ Enabled: false
12
+
13
+ Metrics/MethodLength:
14
+ Max: 12
15
+
16
+ Style/Documentation:
17
+ Enabled: false
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - ruby-2.4.0
5
+ - 2.3.0
6
+
7
+ before_install:
8
+ - gem install bundler
9
+
10
+ script: 'bundle exec rake spec'
11
+
12
+ notifications:
13
+ slack: sachin21dev:J8sIAeYdBknOGbFHtrphiobX
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,104 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruboty-dmm (0.0.1)
5
+ mechanize
6
+ ruboty
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.0.1)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (~> 0.7)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ ast (2.3.0)
17
+ coderay (1.1.1)
18
+ concurrent-ruby (1.0.4)
19
+ diff-lcs (1.3)
20
+ domain_name (0.5.20161129)
21
+ unf (>= 0.0.5, < 1.0.0)
22
+ dotenv (2.2.0)
23
+ http-cookie (1.0.3)
24
+ domain_name (~> 0.5)
25
+ i18n (0.8.0)
26
+ mechanize (2.7.5)
27
+ domain_name (~> 0.5, >= 0.5.1)
28
+ http-cookie (~> 1.0)
29
+ mime-types (>= 1.17.2)
30
+ net-http-digest_auth (~> 1.1, >= 1.1.1)
31
+ net-http-persistent (~> 2.5, >= 2.5.2)
32
+ nokogiri (~> 1.6)
33
+ ntlm-http (~> 0.1, >= 0.1.1)
34
+ webrobots (>= 0.0.9, < 0.2)
35
+ mem (0.1.5)
36
+ method_source (0.8.2)
37
+ mime-types (3.1)
38
+ mime-types-data (~> 3.2015)
39
+ mime-types-data (3.2016.0521)
40
+ mini_portile2 (2.1.0)
41
+ minitest (5.10.1)
42
+ net-http-digest_auth (1.4.1)
43
+ net-http-persistent (2.9.4)
44
+ nokogiri (1.7.0.1)
45
+ mini_portile2 (~> 2.1.0)
46
+ ntlm-http (0.1.1)
47
+ parser (2.4.0.0)
48
+ ast (~> 2.2)
49
+ powerpack (0.1.1)
50
+ pry (0.10.4)
51
+ coderay (~> 1.1.0)
52
+ method_source (~> 0.8.1)
53
+ slop (~> 3.4)
54
+ rainbow (2.2.1)
55
+ rake (10.5.0)
56
+ rspec (3.5.0)
57
+ rspec-core (~> 3.5.0)
58
+ rspec-expectations (~> 3.5.0)
59
+ rspec-mocks (~> 3.5.0)
60
+ rspec-core (3.5.4)
61
+ rspec-support (~> 3.5.0)
62
+ rspec-expectations (3.5.0)
63
+ diff-lcs (>= 1.2.0, < 2.0)
64
+ rspec-support (~> 3.5.0)
65
+ rspec-mocks (3.5.0)
66
+ diff-lcs (>= 1.2.0, < 2.0)
67
+ rspec-support (~> 3.5.0)
68
+ rspec-support (3.5.0)
69
+ rubocop (0.47.1)
70
+ parser (>= 2.3.3.1, < 3.0)
71
+ powerpack (~> 0.1)
72
+ rainbow (>= 1.99.1, < 3.0)
73
+ ruby-progressbar (~> 1.7)
74
+ unicode-display_width (~> 1.0, >= 1.0.1)
75
+ ruboty (1.3.0)
76
+ activesupport
77
+ bundler
78
+ dotenv
79
+ mem
80
+ slop
81
+ ruby-progressbar (1.8.1)
82
+ slop (3.6.0)
83
+ thread_safe (0.3.5)
84
+ tzinfo (1.2.2)
85
+ thread_safe (~> 0.1)
86
+ unf (0.1.4)
87
+ unf_ext
88
+ unf_ext (0.0.7.2)
89
+ unicode-display_width (1.1.3)
90
+ webrobots (0.1.2)
91
+
92
+ PLATFORMS
93
+ ruby
94
+
95
+ DEPENDENCIES
96
+ bundler (~> 1.14)
97
+ pry (= 0.10.4)
98
+ rake (~> 10.0)
99
+ rspec (= 3.5.0)
100
+ rubocop (~> 0.47)
101
+ ruboty-dmm!
102
+
103
+ BUNDLED WITH
104
+ 1.14.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Satoshi Ohmori
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.
@@ -0,0 +1,55 @@
1
+ :us: [:jp:](./doc/ja/README.md) [![Build Status](https://travis-ci.org/sachin21/ruboty-dmm.svg?branch=master)](https://travis-ci.org/sachin21/ruboty-dmm)
2
+
3
+ # Ruboty DMM
4
+
5
+ ## What is Ruboty DMM
6
+ Ruboty DMM is a notifying rankings for DMM.R18's Japanese doujin CG.
7
+
8
+ ## Installation
9
+ On your gemfile:
10
+
11
+ ```
12
+ gem 'ruboty-dmm'
13
+ ```
14
+
15
+ ## Usage
16
+ From the bot in invited Slack's room:
17
+
18
+ ### 1. Show the 24's ranking
19
+
20
+ ```
21
+ @ruboty dmm ranking 24
22
+ --- output ---
23
+ ```
24
+
25
+ The command can be putting the argument for 24, weekly, monthly, total.
26
+
27
+ ### 2. Register a job by ruboty-cron
28
+ Add ruboty-cron to your bot's Gemfile.
29
+
30
+ ```
31
+ gem 'ruboty-cron'
32
+ ```
33
+
34
+ Deployed after, register a task.
35
+
36
+ ```
37
+ @ruboty add job "* 21 * * *" @ruboty dmm ranking 24
38
+ ```
39
+
40
+ Notify the 24-hour ranking at every 9 pm.
41
+
42
+
43
+ ## Thanks
44
+ Thanks for creating awesome gems
45
+
46
+ - [r7kamura/ruboty](https://github.com/r7kamura/ruboty)
47
+ - [r7kamura/ruboty-cron](https://github.com/r7kamura/ruboty-cron)
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ gem_helper = Bundler::GemHelper.new
9
+
10
+ desc "Create tag #{gem_helper.send(:version_tag)}"
11
+ task :tag do
12
+ gem_helper.send(:tag_version) unless gem_helper.send(:already_tagged?)
13
+ end
@@ -0,0 +1,60 @@
1
+ :jp: [![Build Status](https://travis-ci.org/sachin21/ruboty-dmm.svg?branch=master)](https://travis-ci.org/sachin21/ruboty-dmm)
2
+
3
+ # Ruboty DMM
4
+
5
+ ## Ruboty DMMとは
6
+ Ruboty DMMはDMM.R18のランキングを通知するためのボットです。
7
+ 現在は同人誌のみになっています。
8
+
9
+ ## インストール
10
+ 使っているボットのGemfileに以下を追記してください。
11
+
12
+ ```
13
+ gem 'ruboty-dmm'
14
+ ```
15
+
16
+ ## 使い方
17
+ ボットを招待しているSlackの部屋にて
18
+
19
+ ### 1. 24時間ランキングの表示の仕方
20
+
21
+ ```
22
+ @ruboty dmm ranking 24
23
+ --- output ---
24
+ ```
25
+
26
+ このコマンドは以下の4種類の引数を投げることが可能です。
27
+
28
+ - 24
29
+ - weekly
30
+ - monthly
31
+ - total
32
+
33
+ ### 2. ruboty-cronを使い、特定の時間に通知する
34
+ ruboty-cronを追加します。
35
+
36
+ ```
37
+ gem 'ruboty-cron'
38
+ ```
39
+
40
+ deploy後タスクを登録します。
41
+
42
+ ```
43
+ @ruboty add job "* 21 * * *" @ruboty dmm ranking 24
44
+ ```
45
+
46
+ ruboty-cronを使って毎日9時に通知することが出来ます。
47
+
48
+ ## 謝辞
49
+ ruboty, ruboty-cronを作ってくれた[r7kamura氏](https://github.com/r7kamura)に感謝
50
+
51
+ - [r7kamura/ruboty](https://github.com/r7kamura/ruboty)
52
+ - [r7kamura/ruboty-cron](https://github.com/r7kamura/ruboty-cron)
53
+
54
+ ## コントリビューション
55
+
56
+ 1. フォークする
57
+ 2. 新しくブランチを切る (`git checkout -b my-new-feature`)
58
+ 3. 変更をコミットする (`git commit -am 'Add some feature'`)
59
+ 4. 変更をプッシュする (`git push origin my-new-feature`)
60
+ 5. プルリクエストを投げる :+1:
@@ -0,0 +1,7 @@
1
+ require 'mechanize'
2
+
3
+ require 'ruboty/dmm/agent'
4
+ require 'ruboty/dmm/ranking'
5
+ require 'ruboty/dmm/actions/messenger'
6
+ require 'ruboty/dmm/version'
7
+ require 'ruboty/handlers/dmm'
@@ -0,0 +1,14 @@
1
+ module Ruboty
2
+ module DMM
3
+ module Actions
4
+ class Messenger < Ruboty::Actions::Base
5
+ def call
6
+ ranking = Ruboty::DMM::Ranking.new(message.body).call
7
+ message.reply(ranking)
8
+ rescue => exception
9
+ message.reply("Failed by #{exception.class}")
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module Ruboty
2
+ module DMM
3
+ class Agent
4
+ attr_accessor :agent
5
+
6
+ def initialize
7
+ @agent = ::Mechanize.new
8
+ @agent.user_agent_alias = 'Mac Safari'
9
+ @agent.ignore_bad_chunking = true
10
+ @agent.request_headers = { 'Accept-Encoding' => '' }
11
+ @agent.ignore_bad_chunking = true
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,55 @@
1
+ module Ruboty
2
+ module DMM
3
+ class Ranking
4
+ BASE_URL = 'http://www.dmm.co.jp'.freeze
5
+ RANKING_URL = '/dc/doujin/-/ranking-all/=/sort=popular/submedia=cg/term='.freeze
6
+
7
+ def initialize(body)
8
+ @type = discriminate_argument(body)
9
+ @agent = Agent.new.agent
10
+ end
11
+
12
+ def call
13
+ books = page.search('.rank-rankListItem.fn-setPurchaseChange').map do |element|
14
+ [
15
+ element.search('.rank-name').first.text.strip,
16
+ "#{BASE_URL}#{element.search('.rank-name').first.search('a').first.attributes.first[1].value}"
17
+ ]
18
+ end
19
+ ranking = books.take(10).map.with_index(1) { |book, index| "#{index}位\nタイトル: #{book.first}\nURL: #{book.last}" }
20
+ ranking.join("\n\n")
21
+ end
22
+
23
+ private
24
+
25
+ def client
26
+ @client ||= Rdmm::Client.new(credentials)
27
+ end
28
+
29
+ def credentials
30
+ {
31
+ api_id: ENV['API_ID'],
32
+ affiliate_id: ENV['AFFILIATE_ID']
33
+ }
34
+ end
35
+
36
+ def page
37
+ @agent.get("#{BASE_URL}#{RANKING_URL}#{@type.upcase}")
38
+ end
39
+
40
+ def discriminate_argument(body)
41
+ if body =~ /24/
42
+ '24'
43
+ elsif body =~ /weekly/
44
+ 'weekly'
45
+ elsif body =~ /monthly/
46
+ 'monthly'
47
+ elsif body =~ /total/
48
+ 'total'
49
+ else
50
+ raise TypeError
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module DMM
3
+ VERSION = '0.0.1'.freeze
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ module Ruboty
2
+ module Handlers
3
+ class RubotyDMM < Base
4
+ DESCRIPTION = 'Fetch rankings for DMM R18 only searchable for 24, weekly, monthly, total'.freeze
5
+
6
+ on(
7
+ /dmm ranking (?<type>.*?)\z/,
8
+ name: 'messenger',
9
+ description: DESCRIPTION
10
+ )
11
+
12
+ def messenger(message)
13
+ Ruboty::DMM::Actions::Messenger.new(message).call
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'ruboty/dmm/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'ruboty-dmm'
10
+ spec.version = Ruboty::DMM::VERSION
11
+ spec.authors = ['Satoshi Ohmori']
12
+ spec.email = ['sachin21dev@gmail.com']
13
+
14
+ spec.summary = "A bot for DMM R18's rankings"
15
+ spec.description = "A bot for DMM R18's rankings, 24, weeks, months"
16
+ spec.homepage = 'https://github.com/sachin21/ruboty-dmm'
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0")
20
+
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_runtime_dependency 'ruboty'
24
+ spec.add_runtime_dependency 'mechanize'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.14'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rubocop', '~> 0.47'
29
+ spec.add_development_dependency 'pry', '0.10.4'
30
+ spec.add_development_dependency 'rspec', '3.5.0'
31
+ end
@@ -0,0 +1,21 @@
1
+ describe Ruboty::DMM::Ranking do
2
+ let(:instance) { described_class.new(command).call }
3
+
4
+ describe '#call' do
5
+ context 'with 24 argument' do
6
+ subject { instance }
7
+
8
+ let(:command) { '@ruboty dmm ranking 24' }
9
+
10
+ it { is_expected.not_to be_empty }
11
+ end
12
+
13
+ context 'with not registered argument' do
14
+ subject { -> { instance.size } }
15
+
16
+ let(:command) { '@ruboty dmm ranking hoge' }
17
+
18
+ it { is_expected.to raise_error(TypeError) }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'ruboty'
5
+ require 'ruboty/dmm'
6
+
7
+ RSpec.configure do |config|
8
+ config.order = 'random'
9
+ config.expect_with :rspec do |rspec|
10
+ rspec.syntax = :expect
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-dmm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Satoshi Ohmori
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-24 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: mechanize
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.14'
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: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.47'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.47'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.10.4
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.10.4
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 3.5.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 3.5.0
111
+ description: A bot for DMM R18's rankings, 24, weeks, months
112
+ email:
113
+ - sachin21dev@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".rubocop.yml"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - doc/ja/README.md
128
+ - lib/ruboty/dmm.rb
129
+ - lib/ruboty/dmm/actions/messenger.rb
130
+ - lib/ruboty/dmm/agent.rb
131
+ - lib/ruboty/dmm/ranking.rb
132
+ - lib/ruboty/dmm/version.rb
133
+ - lib/ruboty/handlers/dmm.rb
134
+ - ruboty-dmm.gemspec
135
+ - spec/ruboty/dmm/ranking_spec.rb
136
+ - spec/spec_helper.rb
137
+ homepage: https://github.com/sachin21/ruboty-dmm
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.6.10
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: A bot for DMM R18's rankings
161
+ test_files: []