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.
- data/.coveralls.yml +0 -0
- data/.gitignore +2 -1
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -1
- data/dmm.gemspec +2 -1
- data/lib/dmm/client.rb +3 -2
- data/lib/dmm/error.rb +3 -0
- data/lib/dmm/iteminfo.rb +1 -1
- data/lib/dmm/price.rb +1 -1
- data/lib/dmm/version.rb +1 -1
- data/lib/faraday/response/raise_dmm_error.rb +1 -0
- data/spec/dmm/api/items_spec.rb +49 -0
- data/spec/dmm/error_spec.rb +100 -0
- data/spec/dmm/item_spec.rb +30 -79
- data/spec/dmm/iteminfo_spec.rb +16 -47
- data/spec/dmm/price_spec.rb +36 -0
- data/spec/dmm/result_spec.rb +8 -41
- data/spec/fixtures/request_with_illegal_parameter.xml +22 -0
- data/spec/fixtures/request_with_wrong_affiliate_id.xml +22 -0
- data/spec/fixtures/request_with_wrong_api_id.xml +22 -0
- data/spec/fixtures/sample2.xml +2588 -0
- data/spec/request_helper.rb +77 -0
- data/spec/spec_helper.rb +15 -2
- metadata +36 -8
- data/spec/dmm/client_spec.rb +0 -84
- data/spec/dmm/response_spec.rb +0 -36
- data/spec/dmm_spec.rb +0 -25
data/.coveralls.yml
ADDED
File without changes
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/dmm.gemspec
CHANGED
@@ -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
|
data/lib/dmm/client.rb
CHANGED
@@ -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 =>
|
66
|
-
:site =>
|
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)
|
data/lib/dmm/error.rb
CHANGED
@@ -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
|
data/lib/dmm/iteminfo.rb
CHANGED
data/lib/dmm/price.rb
CHANGED
data/lib/dmm/version.rb
CHANGED
@@ -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
|
data/spec/dmm/item_spec.rb
CHANGED
@@ -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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
data/spec/dmm/iteminfo_spec.rb
CHANGED
@@ -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
|
-
|
8
|
-
|
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
|
19
|
-
|
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
|
-
|
31
|
-
its(:
|
32
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|