ruby-dmm 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +0 -57
  3. data/.rubocop_todo.yml +59 -24
  4. data/.travis.yml +4 -2
  5. data/Guardfile +1 -1
  6. data/README.md +30 -28
  7. data/lib/ruby-dmm.rb +3 -18
  8. data/lib/ruby-dmm/client.rb +42 -59
  9. data/lib/ruby-dmm/response.rb +18 -32
  10. data/lib/ruby-dmm/version.rb +1 -1
  11. data/ruby-dmm.gemspec +7 -11
  12. data/spec/spec_helper.rb +63 -49
  13. metadata +39 -151
  14. data/lib/faraday/response/raise_dmm_error.rb +0 -26
  15. data/lib/faraday_middleware/response/dmm_rashify.rb +0 -34
  16. data/lib/multi_xml_tweaks.rb +0 -27
  17. data/lib/ruby-dmm/client/item_list.rb +0 -45
  18. data/lib/ruby-dmm/configuration.rb +0 -41
  19. data/lib/ruby-dmm/error.rb +0 -14
  20. data/lib/ruby-dmm/response/item.rb +0 -70
  21. data/lib/ruby-dmm/response/item_info.rb +0 -55
  22. data/spec/client_spec.rb +0 -32
  23. data/spec/fixtures/com.xml +0 -5987
  24. data/spec/fixtures/com_digital.xml +0 -1115
  25. data/spec/fixtures/com_digital_book.xml +0 -3407
  26. data/spec/fixtures/com_iroiro.xml +0 -1711
  27. data/spec/fixtures/com_lod.xml +0 -125
  28. data/spec/fixtures/com_mono.xml +0 -3723
  29. data/spec/fixtures/com_monthly.xml +0 -2075
  30. data/spec/fixtures/com_pcsoft.xml +0 -729
  31. data/spec/fixtures/com_rental.xml +0 -2691
  32. data/spec/fixtures/r18.xml +0 -4203
  33. data/spec/fixtures/r18_book.xml +0 -4965
  34. data/spec/fixtures/r18_digital.xml +0 -26987
  35. data/spec/fixtures/r18_doujin.xml +0 -2741
  36. data/spec/fixtures/r18_mono.xml +0 -3723
  37. data/spec/fixtures/r18_monthly.xml +0 -3515
  38. data/spec/fixtures/r18_pcgame.xml +0 -3373
  39. data/spec/fixtures/r18_ppm.xml +0 -2883
  40. data/spec/fixtures/r18_rental.xml +0 -12371
  41. data/spec/fixtures/request_error.xml +0 -24
  42. data/spec/fixtures/zero_items.xml +0 -37
  43. data/spec/response/item_info_spec.rb +0 -89
  44. data/spec/response/item_spec.rb +0 -67
  45. data/spec/response_spec.rb +0 -77
@@ -1,24 +0,0 @@
1
- <?xml version="1.0" encoding="euc-jp"?>
2
- <response>
3
- <request>
4
- <parameters>
5
- <parameter name="api_id" value="XXXXXXXXXXXXXXXXXXXX" />
6
- <parameter name="affiliate_id" value="xxxxx-990" />
7
- <parameter name="operation" value="ItemList" />
8
- <parameter name="version" value="2.00" />
9
- <parameter name="timestamp" value="2013-01-01 00:00:00 +0900" />
10
- <parameter name="site" value="DMM.co.jp" />
11
- <parameter name="keyword" value="key" />
12
- <parameter name="sort" value="unknown" />
13
- </parameters>
14
- </request>
15
- <result>
16
- <message>REQUEST ERROR</message>
17
- <errors>
18
- <error>
19
- <name>sort</name>
20
- <value>PARAMETER ILLEGAL</value>
21
- </error>
22
- </errors>
23
- </result>
24
- </response>
@@ -1,37 +0,0 @@
1
- <?xml version="1.0" encoding="euc-jp"?>
2
-
3
- <response>
4
-
5
- <request>
6
-
7
- <parameters>
8
-
9
- <parameter name="api_id" value="apiaccount" />
10
-
11
- <parameter name="affiliate_id" value="affiliate-999" />
12
-
13
- <parameter name="operation" value="ItemList" />
14
-
15
- <parameter name="version" value="2.00" />
16
-
17
- <parameter name="timestamp" value="2012-12-01 00:00:00" />
18
-
19
- <parameter name="site" value="DMM.com" />
20
-
21
- <parameter name="keyword" value="item_not_found" />
22
-
23
- </parameters>
24
-
25
- </request>
26
-
27
- <result>
28
-
29
- <result_count>0</result_count>
30
-
31
- <total_count>0</total_count>
32
-
33
- <first_position>0</first_position>
34
-
35
- </result>
36
-
37
- </response>
@@ -1,89 +0,0 @@
1
- # vim: ts=2 sts=2 et sw=2 ft=ruby fileencoding=utf-8
2
- require 'spec_helper'
3
-
4
- describe DMM::Response::ItemInfo do
5
-
6
- def complex_hash
7
- {
8
- 'actor' => [
9
- { 'name' => 'ダニエル・ラドクリフ', 'id' => '60257' },
10
- { 'name' => 'だにえるらどくりふ', 'id' => '60257_ruby' },
11
- { 'name' => 'メガネ君', 'id' => '60257_classify' },
12
- { 'name' => 'ルパート・グリント', 'id' => '60458' },
13
- { 'name' => 'るぱーとぐりんと', 'id' => '60458_ruby' },
14
- { 'name' => 'リチャード・ハリス', 'id' => '61833' },
15
- { 'name' => 'りちゃーどはりす', 'id' => '61833_ruby' },
16
- { 'name' => 'エマ・ワトソン', 'id' => '60074' },
17
- { 'name' => 'えまわとそん', 'id' => '60074_ruby' },
18
- ],
19
- }
20
- end
21
-
22
- def simple_hash
23
- {
24
- 'label' => { 'name' => 'ワーナー・ホーム・ビデオ', 'id' => '60016' },
25
- 'genre' => { 'name' => 'ファンタジー', 'id' => '71009' },
26
- 'series' => { 'name' => 'ハリー・ポッター', 'id' => '60029' },
27
- 'maker' => { 'name' => 'ワーナー・ホーム・ビデオ', 'id' => '45578' },
28
- }
29
- end
30
-
31
- describe '.integrate' do
32
- context 'simple_hash' do
33
- subject { DMM::Response::ItemInfo.integrate(complex_hash['actor']) }
34
- it 'integrates name and ruby and more (classify etc...) by id' do
35
- actor = subject.find { |a| a['id'] == '60257' }
36
- expect(actor['name']).to eq('ダニエル・ラドクリフ')
37
- expect(actor['ruby']).to eq('だにえるらどくりふ')
38
- expect(actor['classify']).to eq('メガネ君')
39
- end
40
- end
41
-
42
- context 'simple_hash' do
43
- subject { DMM::Response::ItemInfo.integrate(simple_hash['label']) }
44
- it 'runs collectry' do
45
- label = subject.first
46
- expect(label['id']).to eq('60016')
47
- expect(label['name']).to eq('ワーナー・ホーム・ビデオ')
48
- end
49
- end
50
- end
51
-
52
- describe 'define method for any keys' do
53
- context 'complex_hash' do
54
- subject { DMM::Response::ItemInfo.new(complex_hash) }
55
-
56
- describe '#actors' do
57
- subject { super().actors }
58
- it { is_expected.not_to be_empty }
59
- end
60
- describe 'actors' do
61
- it 'integrates name and ruby by id' do
62
- actor = subject.actors.find { |a| a['id'] == '60257' }
63
- expect(actor['name']).to eq('ダニエル・ラドクリフ')
64
- expect(actor['ruby']).to eq('だにえるらどくりふ')
65
- expect(actor['classify']).to eq('メガネ君')
66
-
67
- actor = subject.actors.find { |a| a['id'] == '60074' }
68
- expect(actor['name']).to eq('エマ・ワトソン')
69
- expect(actor['ruby']).to eq('えまわとそん')
70
- end
71
- end
72
- end
73
-
74
- context 'simple_hash' do
75
- subject do
76
- DMM::Response::ItemInfo.new(simple_hash)
77
- end
78
- it { is_expected.to be }
79
-
80
- describe 'director' do
81
- it 'respond to given keys' do
82
- simple_hash.keys.each do |key|
83
- expect(subject).to respond_to(key)
84
- end
85
- end
86
- end
87
- end
88
- end
89
- end
@@ -1,67 +0,0 @@
1
- # vim: ts=2 sts=2 et sw=2 ft=ruby fileencoding=utf-8
2
- require 'spec_helper'
3
-
4
- describe DMM::Response::Item do
5
- before :all do
6
- stub_get.to_return(xml_response('com.xml'))
7
- @item = DMM.new.item_list.result.items.first
8
- end
9
-
10
- describe '#images' do
11
- subject { @item.images }
12
- it { is_expected.to be }
13
-
14
- describe '[:list]' do
15
- subject { super()[:list] }
16
- it { is_expected.to eq('http://pics.dmm.com/mono/movie/n_616dlr22659/n_616dlr22659pt.jpg') }
17
- end
18
-
19
- describe '[:small]' do
20
- subject { super()[:small] }
21
- it { is_expected.to eq('http://pics.dmm.com/mono/movie/n_616dlr22659/n_616dlr22659ps.jpg') }
22
- end
23
-
24
- describe '[:large]' do
25
- subject { super()[:large] }
26
- it { is_expected.to eq('http://pics.dmm.com/mono/movie/n_616dlr22659/n_616dlr22659pl.jpg') }
27
- end
28
- end
29
-
30
- describe 'define alias methods' do
31
- subject do
32
- item = DMM::Response::Item::ALIAS_METHOD_MAP.keys.inject({}) { |h, key| h.merge(key => 1) }
33
- DMM::Response::Item.new(item)
34
- end
35
- DMM::Response::Item::ALIAS_METHOD_MAP.values.each do |name|
36
- it { is_expected.to respond_to(name) }
37
- end
38
- end
39
-
40
- describe '#large_images' do
41
- subject do
42
- item = {
43
- :sample_image_url => {
44
- :sample_s => {
45
- :image => ['http://pics.dmm.co.jp/digital/video/aaa00000/aaa00000-9.jpg'],
46
- },
47
- }
48
- }
49
- DMM::Response::Item.new(item)
50
- end
51
-
52
- describe '#large_images' do
53
- subject { super().large_images }
54
- it { is_expected.to eq(['http://pics.dmm.co.jp/digital/video/aaa00000/aaa00000jp-9.jpg']) }
55
- end
56
- end
57
-
58
- describe 'define method for any keys' do
59
- subject do
60
- item = {
61
- :not_defined_key => true,
62
- }
63
- DMM::Response::Item.new(item)
64
- end
65
- it { is_expected.to respond_to(:not_defined_key) }
66
- end
67
- end
@@ -1,77 +0,0 @@
1
- # vim: ts=2 sts=2 et sw=2 ft=ruby fileencoding=utf-8
2
- require 'spec_helper'
3
-
4
- describe DMM::Response do
5
- before :all do
6
- stub_get.to_return(xml_response('com.xml'))
7
- @response = DMM.new.item_list
8
- end
9
-
10
- describe 'Response' do
11
- subject { @response }
12
- it { is_expected.to respond_to(:request) }
13
- it { is_expected.to respond_to(:result) }
14
-
15
- describe '#request' do
16
- subject { super().request }
17
- it { is_expected.to be_a(Hash) }
18
- end
19
-
20
- describe '#result' do
21
- subject { super().result }
22
- it { is_expected.to be_a(DMM::Response::Result) }
23
- end
24
- end
25
- end
26
-
27
- describe DMM::Response::Result do
28
- before :each do
29
- stub_get.to_return(xml_response('com.xml'))
30
- @result = DMM.new.item_list.result
31
- end
32
-
33
- describe '#items' do
34
- context 'items.size > 0' do
35
- subject { @result }
36
-
37
- describe '#items' do
38
- subject { super().items }
39
- it { is_expected.to be_an(Array) }
40
- end
41
- specify do
42
- subject.items.each do |item|
43
- expect(item).to be_a(DMM::Response::Item)
44
- end
45
- end
46
- end
47
-
48
- context 'items.size == 0' do
49
- before do
50
- stub_get.to_return(xml_response('zero_items.xml'))
51
- @result = DMM.new.item_list.result
52
- end
53
-
54
- subject { @result }
55
-
56
- describe '#items' do
57
- subject { super().items }
58
- it { is_expected.to be_an(Array) }
59
- end
60
- specify do
61
- expect(subject.items.size).to eq(0)
62
- end
63
- end
64
- end
65
-
66
- describe 'instance methods' do
67
- subject { @result }
68
- (DMM::Response::Result::RESULT_KEYS - [:items]).each do |key|
69
- it { is_expected.to respond_to(key) }
70
-
71
- describe key do
72
- subject { super().send(key) }
73
- it { is_expected.to be_a(Integer) }
74
- end
75
- end
76
- end
77
- end