dmm 0.0.3 → 0.0.4

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.
File without changes
data/.gitignore CHANGED
@@ -15,4 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
- config/
18
+ config/
19
+ *.DS_Store
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.8.7"
4
+ - "1.9.2"
5
+ - "1.9.3"
6
+ - "2.0.0"
7
+ matrix:
8
+ allow_failures:
9
+ - rvm: 1.8.7
data/Gemfile CHANGED
@@ -1,4 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'rake'
4
+ gem 'json', '~> 1.7.7'
5
+ gem 'coveralls', require:false
6
+
3
7
  # Specify your gem's dependencies in dmm.gemspec
4
8
  gemspec
data/Rakefile CHANGED
@@ -3,4 +3,4 @@ require "bundler/gem_tasks"
3
3
  require "rspec/core/rake_task"
4
4
 
5
5
  RSpec::Core::RakeTask.new('spec')
6
- task :default => :spec
6
+ task :default => :spec
@@ -21,5 +21,6 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency 'faraday_middleware', '~> 0.8'
22
22
  gem.add_dependency 'nokogiri', '~> 1.5.6'
23
23
  gem.add_development_dependency 'rspec'
24
+ gem.add_development_dependency 'webmock', '1.10.1'
24
25
  gem.add_development_dependency 'simplecov'
25
- end
26
+ end
@@ -25,6 +25,7 @@ module Dmm
25
25
  OPTIONS.each do |id|
26
26
  send("#{id}=", options[id])
27
27
  end
28
+ @time = Time.now.to_s
28
29
  end
29
30
 
30
31
  # Perform an HTTP GET request
@@ -62,8 +63,8 @@ module Dmm
62
63
  :affiliate_id => @affiliate_id,
63
64
  :operation => 'ItemList',
64
65
  :version => API_VERSION,
65
- :timestamp => Time.now.to_s,
66
- :site => 'DMM.co.jp',
66
+ :timestamp => @time,
67
+ :site => Dmm::R18,
67
68
  }
68
69
  options.each_value {|val| val.encode! 'euc-jp' if val.kind_of? String}
69
70
  params.merge!(options)
@@ -4,5 +4,8 @@ module Dmm
4
4
  class Unauthorized < Error; end # 401
5
5
  class Forbidden < Error; end # 403
6
6
  class NotFound < Error; end # 404
7
+ class NotAcceptable < Error; end # 406
8
+ class UnprocessableEntity < Error; end # 422
7
9
  class InternalServerError < Error; end # 500
10
+ class ServiceUnavailable < Error; end # 503
8
11
  end
@@ -2,7 +2,7 @@ require 'dmm/base'
2
2
 
3
3
  module Dmm
4
4
  class Iteminfo < Dmm::Base
5
- def method_missing(method)
5
+ def method_missing(method, *args)
6
6
  if method.to_s =~ /^(series|maker|label)$/
7
7
  return nil unless @attrs[method.to_sym]
8
8
  @attrs[method.to_sym][:name]
@@ -27,7 +27,7 @@ module Dmm
27
27
  @delivery_types
28
28
  end
29
29
 
30
- def method_missing(method)
30
+ def method_missing(method, *args)
31
31
  if method.to_s =~ /^price_(\w+)$/
32
32
  array = deliveries.select{ |hash| hash[:type] == $1 }
33
33
  array.first[:price].to_i unless array.empty?
@@ -1,3 +1,3 @@
1
1
  module Dmm
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -26,6 +26,7 @@ module Faraday
26
26
  private
27
27
 
28
28
  def error_message(response)
29
+ return 'Response body not exists.' if response[:body].nil?
29
30
  message = response[:body]['error']
30
31
  return message unless message.empty?
31
32
  "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}"
@@ -0,0 +1,49 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Dmm::API::Items do
5
+ context 'request with wrong affiliate id' do
6
+ before do
7
+ @client = wrong_client(
8
+ :api_id => 'API_ID',
9
+ :affiliate_id => 'WRONG_AFFILIATE_ID',
10
+ :fixture => 'request_with_wrong_affiliate_id.xml')
11
+ end
12
+
13
+ subject { @client }
14
+
15
+ it "should raise Dmm::Error with error message 'RequestError: Parameter not found (affiliate_id)'" do
16
+ error_msg = 'RequestError: Parameter not found (affiliate_id)'
17
+ lambda { subject.item_list(:keyword => '巨乳') }.should raise_error(Dmm::Error, error_msg)
18
+ end
19
+ end
20
+
21
+ context 'request with wrong api id' do
22
+ before do
23
+ @client = wrong_client(
24
+ :api_id => 'WRONG_API_ID',
25
+ :affiliate_id => 'AFFILIATE_ID',
26
+ :fixture => 'request_with_wrong_api_id.xml')
27
+ end
28
+
29
+ subject { @client }
30
+
31
+ it "should raise Dmm::Error with error message 'LoginError: No existing account (login)'" do
32
+ error_msg = 'LoginError: No existing account (login)'
33
+ lambda { subject.item_list(:keyword => '巨乳') }.should raise_error(Dmm::Error, error_msg)
34
+ end
35
+ end
36
+
37
+ context 'request with illegal parameter' do
38
+ before do
39
+ @client = client_with_illegal_param
40
+ end
41
+
42
+ subject { @client }
43
+
44
+ it "should raise Dmm::Error 'RequestError: Parameter illegal (site)'" do
45
+ error_msg = 'RequestError: Parameter illegal (site)'
46
+ lambda { subject.item_list(:site => 'illegalparameter') }.should raise_error(Dmm::Error, error_msg)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,100 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Dmm::Error do
5
+ context 'with response status code is 400' do
6
+ before do
7
+ @client = response_with_error([400, "Bad Request"])
8
+ end
9
+
10
+ subject { @client }
11
+
12
+ it 'should raise Dmm::InternalServerError' do
13
+ lambda { subject.item_list(:keyword => '巨乳') }.should raise_error Dmm::BadRequest
14
+ end
15
+ end
16
+
17
+ context 'with response status code is 401' do
18
+ before do
19
+ @client = response_with_error([401, "Unauthorized"])
20
+ end
21
+
22
+ subject { @client }
23
+
24
+ it 'should raise Dmm::InternalServerError' do
25
+ lambda { subject.item_list(:keyword => '巨乳') }.should raise_error Dmm::Unauthorized
26
+ end
27
+ end
28
+
29
+ context 'with response status code is 403' do
30
+ before do
31
+ @client = response_with_error([403, "Frobidden"])
32
+ end
33
+
34
+ subject { @client }
35
+
36
+ it 'should raise Dmm::InternalServerError' do
37
+ lambda { subject.item_list(:keyword => '巨乳') }.should raise_error Dmm::Forbidden
38
+ end
39
+ end
40
+
41
+ context 'with response status code is 404' do
42
+ before do
43
+ @client = response_with_error([404, "Not Found"])
44
+ end
45
+
46
+ subject { @client }
47
+
48
+ it 'should raise Dmm::InternalServerError' do
49
+ lambda { subject.item_list(:keyword => '巨乳') }.should raise_error Dmm::NotFound
50
+ end
51
+ end
52
+
53
+ context 'with response status code is 406' do
54
+ before do
55
+ @client = response_with_error([406, "Not Acceptable"])
56
+ end
57
+
58
+ subject { @client }
59
+
60
+ it 'should raise Dmm::InternalServerError' do
61
+ lambda { subject.item_list(:keyword => '巨乳') }.should raise_error Dmm::NotAcceptable
62
+ end
63
+ end
64
+
65
+ context 'with response status code is 422' do
66
+ before do
67
+ @client = response_with_error([422, "Unprocessable Entity"])
68
+ end
69
+
70
+ subject { @client }
71
+
72
+ it 'should raise Dmm::InternalServerError' do
73
+ lambda { subject.item_list(:keyword => '巨乳') }.should raise_error Dmm::UnprocessableEntity
74
+ end
75
+ end
76
+
77
+ context 'with response status code is 500' do
78
+ before do
79
+ @client = response_with_error([500, "Internal Server Error"])
80
+ end
81
+
82
+ subject { @client }
83
+
84
+ it 'should raise Dmm::InternalServerError' do
85
+ lambda { subject.item_list(:keyword => '巨乳') }.should raise_error Dmm::InternalServerError
86
+ end
87
+ end
88
+
89
+ context 'with response status code is 503' do
90
+ before do
91
+ @client = response_with_error([503, "Service Unavailable"])
92
+ end
93
+
94
+ subject { @client }
95
+
96
+ it 'should raise Dmm::InternalServerError' do
97
+ lambda { subject.item_list(:keyword => '巨乳') }.should raise_error Dmm::ServiceUnavailable
98
+ end
99
+ end
100
+ end
@@ -2,86 +2,37 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Dmm::Item do
5
+ context 'with valid response' do
6
+ before(:all) do
7
+ @items = sample_response.items
8
+ end
5
9
 
6
- subject do
7
- Dmm::Item.new({:service_name=>"動画",
8
- :floor_name=>"ビデオ",
9
- :category_name=>"ビデオ (動画)",
10
- :content_id=>"118mas00093",
11
- :product_id=>"118mas00093",
12
- :title=>"絶対的美少女、お貸しします。 ACT.25",
13
- :URL=>
14
- "http://www.dmm.co.jp/digital/videoa/-/detail/=/cid=118mas00093/",
15
- :affiliateURL=>
16
- "http://www.dmm.co.jp/digital/videoa/-/detail/=/cid=118mas00093/#{ENV['AFFILIATE_ID']}",
17
- :imageURL=>
18
- {:list=>
19
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093pt.jpg",
20
- :small=>
21
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093ps.jpg",
22
- :large=>
23
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093pl.jpg"},
24
- :sampleImageURL=>
25
- {:sample_s=>
26
- {:image=>
27
- ["http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-1.jpg",
28
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-2.jpg",
29
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-3.jpg",
30
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-4.jpg",
31
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-5.jpg",
32
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-6.jpg",
33
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-7.jpg",
34
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-8.jpg",
35
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-9.jpg",
36
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-10.jpg"]}},
37
- :prices=>
38
- {:price=>"1980~",
39
- :deliveries=>
40
- {:delivery=>
41
- [{:type=>"stream", :price=>"1980"},
42
- {:type=>"download", :price=>"1980"}]}},
43
- :date=>"2013-01-12 10:01:00",
44
- :iteminfo=>
45
- {:keyword=>
46
- [{:name=>"顔射", :id=>"5023"},
47
- {:name=>"単体作品", :id=>"4025"},
48
- {:name=>"美少女", :id=>"1027"}],
49
- :series=>{:name=>"絶対的美少女、お貸しします。", :id=>"79983"},
50
- :maker=>{:name=>"プレステージ", :id=>"40136"},
51
- :actress=>
52
- [{:name=>"あやみ旬果", :id=>"1016835"},
53
- {:name=>"あやみしゅんか", :id=>"1016835_ruby"},
54
- {:name=>"av", :id=>"1016835_classify"}],
55
- :label=>{:name=>"ます。", :id=>"20940"}}})
56
- end
10
+ context 'with first item' do
11
+ subject { @items.first }
12
+
13
+ its(:service_name) { should eq '動画' }
14
+ its(:floor_name) { should eq 'ビデオ' }
15
+ its(:category_name) { should eq 'ビデオ (動画)' }
16
+ its(:content_id) { should eq 'club00025' }
17
+ its(:product_id) { should eq 'club00025' }
18
+ its(:title) { should eq '東京都港区白金セレブ人妻ナンパエステ' }
19
+ its(:url) { should eq 'http://www.dmm.co.jp/digital/videoa/-/detail/=/cid=club00025/' }
20
+ its(:affiliate_url) { should eq 'http://www.dmm.co.jp/digital/videoa/-/detail/=/cid=club00025/AFFILIATE_ID' }
21
+ its(:image_url) { should eq Hash[:list=>"http://pics.dmm.co.jp/digital/video/club00025/club00025pt.jpg", :small=>"http://pics.dmm.co.jp/digital/video/club00025/club00025ps.jpg", :large=>"http://pics.dmm.co.jp/digital/video/club00025/club00025pl.jpg"] }
22
+ its(:sample_image_url) { should eq ["http://pics.dmm.co.jp/digital/video/club00025/club00025-1.jpg", "http://pics.dmm.co.jp/digital/video/club00025/club00025-2.jpg", "http://pics.dmm.co.jp/digital/video/club00025/club00025-3.jpg"] }
23
+ its(:date) { should eq '2013-01-26 10:00:11'}
24
+ its(:prices) { should be_kind_of Dmm::Price }
25
+ its(:iteminfo) { should be_kind_of Dmm::Iteminfo }
57
26
 
58
- its(:service_name) { should eq '動画' }
59
- its(:floor_name) { should eq 'ビデオ' }
60
- its(:category_name) { should eq 'ビデオ (動画)' }
61
- its(:content_id) { should eq '118mas00093' }
62
- its(:product_id) { should eq '118mas00093' }
63
- its(:title) { should eq '絶対的美少女、お貸しします。 ACT.25' }
64
- its(:url) { should eq 'http://www.dmm.co.jp/digital/videoa/-/detail/=/cid=118mas00093/' }
65
- its(:affiliateURL) { should eq "http://www.dmm.co.jp/digital/videoa/-/detail/=/cid=118mas00093/#{ENV['AFFILIATE_ID']}" }
66
- its(:sample_image_url) { should eq ["http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-1.jpg",
67
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-2.jpg",
68
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-3.jpg",
69
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-4.jpg",
70
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-5.jpg",
71
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-6.jpg",
72
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-7.jpg",
73
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-8.jpg",
74
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-9.jpg",
75
- "http://pics.dmm.co.jp/digital/video/118mas00093/118mas00093-10.jpg"] }
76
- its(:prices) { should be_a_kind_of Dmm::Price }
77
- its(:iteminfo) { should be_a_kind_of Dmm::Iteminfo }
27
+ describe 'method_missing' do
28
+ it 'delegates to Dmm::Price' do
29
+ subject.min_price.should eq 500
30
+ end
78
31
 
79
- its(:keyword) { should eq ['顔射', '単体作品', '美少女'] }
80
- its(:price) { should eq '1980~' }
81
- its(:min_price) { should eq 1980 }
82
- its(:price_stream) { should eq 1980 }
83
- its(:price_download) { should eq 1980 }
84
- its(:price_androiddl) { should be_nil }
85
- its(:deliveries) { should eq [{:type=>"stream", :price=>"1980"},{:type=>"download", :price=>"1980"}] }
86
- its(:delivery_types) { should eq ['stream', 'download'] }
32
+ it 'delegates to Dmm::Iteminfo' do
33
+ subject.maker.should eq '変態紳士倶楽部'
34
+ end
35
+ end
36
+ end
37
+ end
87
38
  end
@@ -1,57 +1,26 @@
1
- #encoding: utf-8
2
-
1
+ # -*- encoding: utf-8 -*-
3
2
  require 'spec_helper'
4
3
 
5
4
  describe Dmm::Iteminfo do
6
-
7
- describe '#method_missing' do
8
- subject { Dmm::Iteminfo.new({:keyword =>[{:name => "顔射", :id => "5023"},{:name =>"単体作品", :id =>"4025"},{:name =>"美少女", :id =>"1027"}],:series => {:name => "絶対的美少女、お貸しします。", :id => "79983"},:maker => {:name => "プレステージ", :id => "40136"},:actress =>[{:name => "あやみ旬果", :id => "1016835"},{:name => "あやみしゅんか", :id => "1016835_ruby"},{:name => "av", :id => "1016835_classify"}],:label => {:name => "ます。", :id => "20940"}})}
9
-
10
- context 'with argument :keyword' do
11
- its(:keyword) { should eq ['顔射', '単体作品', '美少女']}
12
- end
13
-
14
- context 'with argument :series' do
15
- its(:series) { should eq '絶対的美少女、お貸しします。' }
5
+ context 'with valid response' do
6
+ before(:all) do
7
+ @items = sample_response.items
16
8
  end
17
9
 
18
- context 'with argument :maker' do
19
- its(:maker) { should eq 'プレステージ' }
20
- end
21
-
22
- context 'with argument :actress' do
23
- its(:actress) { should eq ['あやみ旬果'] }
24
- end
25
-
26
- context 'with argument :director' do
27
- its(:director) { should be_nil }
28
- end
10
+ context 'with first item' do
11
+ subject { @items.first.iteminfo }
29
12
 
30
- context 'with argument :label' do
31
- its(:label) { should eq 'ます。' }
32
- end
33
-
34
- context 'with argument :undefined_method' do
35
- it { proc{ subject.undefined_method }.should raise_error NoMethodError }
36
- end
37
- end
38
-
39
- describe '#keyword' do
40
- context 'has one keyword' do
41
- subject { Dmm::Iteminfo.new(:keyword => {:name => "顔射"}) }
42
-
43
- its(:keyword) { should eq ['顔射'] }
44
- end
45
- context 'has no keyword' do
46
- subject { Dmm::Iteminfo.new }
47
- its(:keyword) { should be_nil }
48
- end
49
- end
13
+ its(:keyword) { should eq ['エステ', 'ナンパ', '人妻', '痴女', '巨乳', '独占配信', 'ハイビジョン'] }
14
+ its(:maker) { should eq '変態紳士倶楽部' }
15
+ its(:label) { should eq '変態紳士倶楽部' }
50
16
 
51
- describe '#respond_to?' do
52
- subject { Dmm::Iteminfo.new }
53
- it 'return true with argument :keyword' do
54
- subject.respond_to?(:keyword).should be_true
17
+ describe 'respond_to?' do
18
+ %w(series maker label keyword actress director author).each do |method|
19
+ it "should be ture with argument #{method.to_sym}" do
20
+ subject.respond_to?(method.to_sym).should be_true
21
+ end
22
+ end
23
+ end
55
24
  end
56
25
  end
57
26
  end