dmm-crawler 0.3.3 → 0.3.4

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
  SHA256:
3
- metadata.gz: b6449f249355693b543ef568f92525a4a7748c4d0639085d98950f2d463ba987
4
- data.tar.gz: 11628215e86cbf6e7c4b2b6758755ca4549ba822dc4881f7269f981601d2af9e
3
+ metadata.gz: ba00ec149d0da09749dc8ec8816ec3ddf8622f4e480c61eceadff8debebbcda8
4
+ data.tar.gz: 214724b5d29f1f1f6d8ba1de2352a237f9912bfd268a08c773b72fbdc103642b
5
5
  SHA512:
6
- metadata.gz: 71e135dc337bfc1055db8f5c8cccf4af60ad8915e242c81a577dd7f2b0e42d4295bad870b27d6c170038fada22e3ee1338bf6163b682993a8a5f83ac8649afb0
7
- data.tar.gz: 1d270e6c3af7d334e6ed0303728387eb446b1119153c936e0026305c46d03f40074a8005b011870b71f118f026721dd925dbf4e7e9c556a305a111a823e6750f
6
+ metadata.gz: bd1d972aba0af499834e7749e5a5e55d3ee790761000a4a33f62045c6e30e8bf3c8046509acac7d77bcbb991f7e3f95a37534f5244c2aa8594bb6305cf4f2389
7
+ data.tar.gz: db9c7320934c9883568b129882d66fd355ddc2c348074dbc0949598f0f044bb325d84346a1650e2be0bfd0f5182990d11130a727fb87fd61c5af4a8c26acb767
@@ -1,10 +1,10 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - ruby-2.2.2
5
- - ruby-2.3.0
6
- - ruby-2.4.0
7
- - ruby-2.4.1
4
+ - ruby-2.2.9
5
+ - ruby-2.3.7
6
+ - ruby-2.4.4
7
+ - ruby-2.5.1
8
8
 
9
9
  before_install:
10
10
  - gem install bundler
@@ -1,5 +1,9 @@
1
1
  # Change logs
2
2
 
3
+ ## 0.3.4
4
+ - Support Ruby `2.5.1`.
5
+ - Implement the function to detect excluded arts for affiliating.
6
+
3
7
  ## 0.3.3
4
8
  - Fetch first img element from art page.
5
9
 
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
17
17
 
18
18
  spec.require_paths = ['lib']
19
19
 
20
+ spec.add_runtime_dependency 'rdmm'
20
21
  spec.add_runtime_dependency 'mechanize'
21
22
 
22
23
  spec.add_development_dependency 'bundler'
@@ -1,3 +1,4 @@
1
+ require 'rdmm'
1
2
  require 'mechanize'
2
3
 
3
4
  module DMMCrawler
@@ -1,7 +1,10 @@
1
1
  module DMMCrawler
2
2
  class Attributes
3
+ HTTP_STATUS_CODE_OF_SUCCESS = 200
4
+
3
5
  def initialize(url, agent: Agent.instance.agent)
4
6
  @page = agent.get(url)
7
+ @r_client = Rdmm::Client.new(affiliate_id: ENV['DMM_AFFILIATE_ID'], api_id: ENV['DMM_API_ID'])
5
8
  end
6
9
 
7
10
  def to_a
@@ -13,10 +16,15 @@ module DMMCrawler
13
16
  author,
14
17
  informations,
15
18
  price,
19
+ affiliateable?,
16
20
  tags
17
21
  ]
18
22
  end
19
23
 
24
+ def affiliateable?
25
+ @r_client.list_items(site: 'DMM.R18', keyword: title).body['result']['status'] == HTTP_STATUS_CODE_OF_SUCCESS
26
+ end
27
+
20
28
  private
21
29
 
22
30
  def title
@@ -15,5 +15,9 @@ module DMMCrawler
15
15
  def get_attributes(url)
16
16
  Attributes.new(url, agent: @agent).to_a
17
17
  end
18
+
19
+ def affiliateable?(url)
20
+ Attributes.new(url, agent: @agent).affiliateable?
21
+ end
18
22
  end
19
23
  end
@@ -15,7 +15,7 @@ module DMMCrawler
15
15
  end
16
16
  end
17
17
 
18
- arts.map.with_index(1) do |(title, title_link, image_url, submedia, author, informations, price, tags), rank|
18
+ arts.map.with_index(1) do |(title, title_link, image_url, submedia, author, informations, price, affiliateable, tags), rank|
19
19
  {
20
20
  title: title,
21
21
  title_link: title_link,
@@ -25,6 +25,7 @@ module DMMCrawler
25
25
  informations: informations,
26
26
  rank: rank,
27
27
  price: price,
28
+ affiliateable: affiliateable,
28
29
  tags: tags
29
30
  }
30
31
  end
@@ -1,3 +1,3 @@
1
1
  module DMMCrawler
2
- VERSION = '0.3.3'.freeze
2
+ VERSION = '0.3.4'.freeze
3
3
  end
@@ -1,33 +1,30 @@
1
1
  describe DMMCrawler::Ranking do
2
- let(:attachments) { described_class.new(arguments).arts }
3
-
4
2
  let(:agent) { DMMCrawler::Agent.instance.agent }
5
3
  let(:submedia) { 'cg' }
6
4
  let(:arguments) { { submedia: submedia, term: term, agent: agent } }
7
5
 
8
6
  describe '#arts' do
7
+ subject { attachments }
8
+
9
9
  after { sleep 2 }
10
10
 
11
11
  context 'with length' do
12
- subject { attachments.length }
13
-
12
+ let(:attachments) { described_class.new(arguments).arts.length }
14
13
  let(:term) { '24' }
15
14
 
16
15
  it { is_expected.to be 10 }
17
16
  end
18
17
 
19
18
  context 'with 24 argument' do
20
- subject { attachments }
21
-
19
+ let(:attachments) { described_class.new(arguments).arts }
22
20
  let(:term) { '24' }
23
21
 
24
- it { is_expected.to all(include(:title, :title_link, :image_url, :submedia, :author, :informations, :rank, :price, :tags)) }
22
+ it { is_expected.to all(include(:title, :title_link, :image_url, :submedia, :author, :informations, :rank, :price, :affiliateable, :tags)) }
25
23
  it { is_expected.to all(satisfy { |art| art.all? { |_k, v| v != '' } }) }
26
24
  end
27
25
 
28
26
  context 'with not registered argument' do
29
- subject { -> { attachments } }
30
-
27
+ let(:attachments) { -> { described_class.new(arguments).arts } }
31
28
  let(:term) { nil }
32
29
 
33
30
  it { is_expected.to raise_error(TypeError) }
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dmm-crawler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Satoshi Ohmori
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-26 00:00:00.000000000 Z
11
+ date: 2018-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdmm
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'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: mechanize
15
29
  requirement: !ruby/object:Gem::Requirement