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
@@ -0,0 +1,77 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'uri/http'
|
3
|
+
|
4
|
+
module RequestHelper
|
5
|
+
def sample_response
|
6
|
+
time = Time.now.to_s.gsub(/\s/, '+')
|
7
|
+
request_url = URI::HTTP.build(
|
8
|
+
:host => 'affiliate-api.dmm.com',
|
9
|
+
:path => '/',
|
10
|
+
:query => 'api_id=API_ID' +
|
11
|
+
'&affiliate_id=AFFILIATE_ID' +
|
12
|
+
'&operation=ItemList' +
|
13
|
+
'&version=2.00' +
|
14
|
+
'×tamp=' + time +
|
15
|
+
'&site=DMM.co.jp' +
|
16
|
+
'&keyword=%B5%F0%C6%FD'
|
17
|
+
)
|
18
|
+
stub_request(:get, request_url.to_s).to_return(:status => 200, :body => fixture('sample2.xml'))
|
19
|
+
client = Dmm.new(:api_id => 'API_ID', :affiliate_id => 'AFFILIATE_ID')
|
20
|
+
client.instance_variable_set(:@time, time)
|
21
|
+
client.item_list(:keyword => '巨乳')
|
22
|
+
end
|
23
|
+
|
24
|
+
def response_with_error(status=[])
|
25
|
+
time = Time.now.to_s.gsub(/\s/, '+')
|
26
|
+
request_url = URI::HTTP.build(
|
27
|
+
:host => 'affiliate-api.dmm.com',
|
28
|
+
:path => '/',
|
29
|
+
:query => 'api_id=API_ID' +
|
30
|
+
'&affiliate_id=AFFILIATE_ID' +
|
31
|
+
'&operation=ItemList' +
|
32
|
+
'&version=2.00' +
|
33
|
+
'×tamp=' + time +
|
34
|
+
'&site=DMM.co.jp' +
|
35
|
+
'&keyword=%B5%F0%C6%FD'
|
36
|
+
)
|
37
|
+
stub_request(:get, request_url.to_s).to_return(:status => status)
|
38
|
+
client = Dmm.new(:api_id => 'API_ID', :affiliate_id => 'AFFILIATE_ID')
|
39
|
+
client.instance_variable_set(:@time, time)
|
40
|
+
return client
|
41
|
+
end
|
42
|
+
|
43
|
+
def wrong_client(options={})
|
44
|
+
time = Time.now.to_s.gsub(/\s/, '+')
|
45
|
+
request_url = URI::HTTP.build(
|
46
|
+
:host => 'affiliate-api.dmm.com',
|
47
|
+
:path => '/',
|
48
|
+
:query => 'api_id=' + options[:api_id] +
|
49
|
+
'&affiliate_id=' + options[:affiliate_id] +
|
50
|
+
'&operation=ItemList' +
|
51
|
+
'&version=2.00'+
|
52
|
+
'×tamp=' + time +
|
53
|
+
'&site=DMM.co.jp' +
|
54
|
+
'&keyword=%B5%F0%C6%FD')
|
55
|
+
stub_request(:get, request_url.to_s).to_return(:status => 200, :body => fixture(options[:fixture]))
|
56
|
+
client = Dmm.new(:api_id => options[:api_id], :affiliate_id => options[:affiliate_id])
|
57
|
+
client.instance_variable_set(:@time, time)
|
58
|
+
return client
|
59
|
+
end
|
60
|
+
|
61
|
+
def client_with_illegal_param
|
62
|
+
time = Time.now.to_s.gsub(/\s/, '+')
|
63
|
+
request_url = URI::HTTP.build(
|
64
|
+
:host => 'affiliate-api.dmm.com',
|
65
|
+
:path => '/',
|
66
|
+
:query => 'api_id=API_ID' +
|
67
|
+
'&affiliate_id=AFFILIATE_ID' +
|
68
|
+
'&operation=ItemList' +
|
69
|
+
'&version=2.00'+
|
70
|
+
'×tamp=' + time +
|
71
|
+
'&site=illegalparameter')
|
72
|
+
stub_request(:get, request_url.to_s).to_return(:status => 200, :body => fixture('request_with_illegal_parameter.xml'))
|
73
|
+
client = Dmm.new(:api_id => 'API_ID', :affiliate_id => 'AFFILIATE_ID')
|
74
|
+
client.instance_variable_set(:@time, time)
|
75
|
+
return client
|
76
|
+
end
|
77
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,7 +6,20 @@ end
|
|
6
6
|
|
7
7
|
require 'bundler/setup'
|
8
8
|
require 'dmm'
|
9
|
-
require '
|
9
|
+
require 'webmock/rspec'
|
10
|
+
require 'request_helper'
|
11
|
+
require 'coveralls'
|
12
|
+
|
13
|
+
Coveralls.wear!
|
10
14
|
|
11
15
|
RSpec.configure do |config|
|
12
|
-
|
16
|
+
config.include RequestHelper
|
17
|
+
end
|
18
|
+
|
19
|
+
def fixture_path
|
20
|
+
File.expand_path('../fixtures', __FILE__)
|
21
|
+
end
|
22
|
+
|
23
|
+
def fixture(file)
|
24
|
+
File.new(fixture_path + '/' + file)
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dmm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: webmock
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - '='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.10.1
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - '='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.10.1
|
78
94
|
- !ruby/object:Gem::Dependency
|
79
95
|
name: simplecov
|
80
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,8 +114,10 @@ executables: []
|
|
98
114
|
extensions: []
|
99
115
|
extra_rdoc_files: []
|
100
116
|
files:
|
117
|
+
- .coveralls.yml
|
101
118
|
- .gitignore
|
102
119
|
- .rspec
|
120
|
+
- .travis.yml
|
103
121
|
- Gemfile
|
104
122
|
- LICENSE.txt
|
105
123
|
- README.md
|
@@ -119,12 +137,17 @@ files:
|
|
119
137
|
- lib/dmm/result.rb
|
120
138
|
- lib/dmm/version.rb
|
121
139
|
- lib/faraday/response/raise_dmm_error.rb
|
122
|
-
- spec/dmm/
|
140
|
+
- spec/dmm/api/items_spec.rb
|
141
|
+
- spec/dmm/error_spec.rb
|
123
142
|
- spec/dmm/item_spec.rb
|
124
143
|
- spec/dmm/iteminfo_spec.rb
|
125
|
-
- spec/dmm/
|
144
|
+
- spec/dmm/price_spec.rb
|
126
145
|
- spec/dmm/result_spec.rb
|
127
|
-
- spec/
|
146
|
+
- spec/fixtures/request_with_illegal_parameter.xml
|
147
|
+
- spec/fixtures/request_with_wrong_affiliate_id.xml
|
148
|
+
- spec/fixtures/request_with_wrong_api_id.xml
|
149
|
+
- spec/fixtures/sample2.xml
|
150
|
+
- spec/request_helper.rb
|
128
151
|
- spec/spec_helper.rb
|
129
152
|
homepage: https://github.com/shunsugai/dmm
|
130
153
|
licenses: []
|
@@ -151,10 +174,15 @@ signing_key:
|
|
151
174
|
specification_version: 3
|
152
175
|
summary: Ruby wrapper for DMM Web Service API ver2
|
153
176
|
test_files:
|
154
|
-
- spec/dmm/
|
177
|
+
- spec/dmm/api/items_spec.rb
|
178
|
+
- spec/dmm/error_spec.rb
|
155
179
|
- spec/dmm/item_spec.rb
|
156
180
|
- spec/dmm/iteminfo_spec.rb
|
157
|
-
- spec/dmm/
|
181
|
+
- spec/dmm/price_spec.rb
|
158
182
|
- spec/dmm/result_spec.rb
|
159
|
-
- spec/
|
183
|
+
- spec/fixtures/request_with_illegal_parameter.xml
|
184
|
+
- spec/fixtures/request_with_wrong_affiliate_id.xml
|
185
|
+
- spec/fixtures/request_with_wrong_api_id.xml
|
186
|
+
- spec/fixtures/sample2.xml
|
187
|
+
- spec/request_helper.rb
|
160
188
|
- spec/spec_helper.rb
|
data/spec/dmm/client_spec.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dmm::Client do
|
4
|
-
|
5
|
-
context 'initialize with correct configuration value' do
|
6
|
-
|
7
|
-
subject do
|
8
|
-
Dmm::Client.new(:api_id => ENV['API_ID'], :affiliate_id => ENV['AFFILIATE_ID'])
|
9
|
-
end
|
10
|
-
|
11
|
-
describe 'initialization' do
|
12
|
-
its(:api_id) { should eq ENV['API_ID'] }
|
13
|
-
its(:affiliate_id) { should eq ENV['AFFILIATE_ID'] }
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '#params' do
|
17
|
-
it 'should return collect params' do
|
18
|
-
params = {
|
19
|
-
:api_id => ENV['API_ID'],
|
20
|
-
:affiliate_id => ENV['AFFILIATE_ID'],
|
21
|
-
:operation => 'ItemList',
|
22
|
-
:version => Dmm::API_VERSION,
|
23
|
-
:timestamp => Time.now.to_s,
|
24
|
-
:site => Dmm::R18,
|
25
|
-
:keyword => 'hogehoge'
|
26
|
-
}
|
27
|
-
subject.send(:params, {:keyword => 'hogehoge'}).should eq params
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'initialize with wrong configuration value' do
|
33
|
-
|
34
|
-
share_examples_for '#item_list with wrong arguments' do
|
35
|
-
it { proc{subject.item_list}.should raise_error Dmm::Error }
|
36
|
-
end
|
37
|
-
|
38
|
-
share_examples_for '#error_message with wrong api_id' do
|
39
|
-
it 'should equal "LoginError: No existing account (login)"' do
|
40
|
-
res = Hash.from_xml(subject.get('/', subject.send(:params)))
|
41
|
-
subject.send(:error_message, res).should eq 'LoginError: No existing account (login)'
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'call API with wrong api_id' do
|
46
|
-
subject { Dmm.new(:api_id => 'foo', :affiliate_id => ENV['AFFILIATE_ID']) }
|
47
|
-
|
48
|
-
describe '#item_list' do
|
49
|
-
it_should_behave_like '#item_list with wrong arguments'
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#error_message' do
|
53
|
-
it_should_behave_like '#error_message with wrong api_id'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'call API with wrong affiliate_id' do
|
58
|
-
subject { Dmm.new(:api_id => ENV['API_ID'], :affiliate_id => 'foo') }
|
59
|
-
|
60
|
-
describe '#item_list' do
|
61
|
-
it_should_behave_like '#item_list with wrong arguments'
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#error_message' do
|
65
|
-
it 'should equal "RequestError: Parameter not found (affiliate_id)"' do
|
66
|
-
res = Hash.from_xml(subject.get('/', subject.send(:params)))
|
67
|
-
subject.send(:error_message, res).should eq 'RequestError: Parameter not found (affiliate_id)'
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context 'call API with wrong api_id and affiliate_id' do
|
73
|
-
subject { Dmm.new(:api_id => 'foo', :affiliate_id => 'bar') }
|
74
|
-
|
75
|
-
describe '#item_list' do
|
76
|
-
it_should_behave_like '#item_list with wrong arguments'
|
77
|
-
end
|
78
|
-
|
79
|
-
describe '#error_message' do
|
80
|
-
it_should_behave_like '#error_message with wrong api_id'
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
data/spec/dmm/response_spec.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dmm::Response do
|
4
|
-
subject { Dmm.new(:api_id => ENV['API_ID'], :affiliate_id => ENV['AFFILIATE_ID']).item_list }
|
5
|
-
|
6
|
-
describe '#respond_to?' do
|
7
|
-
it 'should be true with argument :items' do
|
8
|
-
subject.respond_to?(:items).should be_true
|
9
|
-
end
|
10
|
-
it 'should be true with argument :result_count' do
|
11
|
-
subject.respond_to?(:result_count).should be_true
|
12
|
-
end
|
13
|
-
it 'should be true with argument :total_count' do
|
14
|
-
subject.respond_to?(:total_count).should be_true
|
15
|
-
end
|
16
|
-
it 'should be true with argument :first_position' do
|
17
|
-
subject.respond_to?(:first_position).should be_true
|
18
|
-
end
|
19
|
-
it 'should be true with argument :result' do
|
20
|
-
subject.respond_to?(:result).should be_true
|
21
|
-
end
|
22
|
-
it 'should not be true with argument :hogehoge' do
|
23
|
-
subject.respond_to?(:hogehoge).should_not be_true
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe 'Object#method' do
|
28
|
-
it 'should be return instance of Method' do
|
29
|
-
subject.method(:items).should be_kind_of Method
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should raise NameError argument with undefined method in Dmm::Result' do
|
33
|
-
lambda{subject.method(:fooooo)}.should raise_error NameError
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/spec/dmm_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dmm do
|
4
|
-
it { should respond_to(:new) }
|
5
|
-
|
6
|
-
describe 'new' do
|
7
|
-
it 'returns Dmm::Client instance' do
|
8
|
-
subject.new.should be_a_kind_of Dmm::Client
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe 'const_missing' do
|
13
|
-
it 'should be "DMM.co.jp" when call DMM::R18' do
|
14
|
-
Dmm::R18.should == 'DMM.co.jp'
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should be "DMM.com" when call DMM::COM' do
|
18
|
-
Dmm::COM.should == 'DMM.com'
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should raise NameError when call undefined constant "Foo"' do
|
22
|
-
lambda{Dmm::Foo}.should raise_error NameError
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|