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.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -57
- data/.rubocop_todo.yml +59 -24
- data/.travis.yml +4 -2
- data/Guardfile +1 -1
- data/README.md +30 -28
- data/lib/ruby-dmm.rb +3 -18
- data/lib/ruby-dmm/client.rb +42 -59
- data/lib/ruby-dmm/response.rb +18 -32
- data/lib/ruby-dmm/version.rb +1 -1
- data/ruby-dmm.gemspec +7 -11
- data/spec/spec_helper.rb +63 -49
- metadata +39 -151
- data/lib/faraday/response/raise_dmm_error.rb +0 -26
- data/lib/faraday_middleware/response/dmm_rashify.rb +0 -34
- data/lib/multi_xml_tweaks.rb +0 -27
- data/lib/ruby-dmm/client/item_list.rb +0 -45
- data/lib/ruby-dmm/configuration.rb +0 -41
- data/lib/ruby-dmm/error.rb +0 -14
- data/lib/ruby-dmm/response/item.rb +0 -70
- data/lib/ruby-dmm/response/item_info.rb +0 -55
- data/spec/client_spec.rb +0 -32
- data/spec/fixtures/com.xml +0 -5987
- data/spec/fixtures/com_digital.xml +0 -1115
- data/spec/fixtures/com_digital_book.xml +0 -3407
- data/spec/fixtures/com_iroiro.xml +0 -1711
- data/spec/fixtures/com_lod.xml +0 -125
- data/spec/fixtures/com_mono.xml +0 -3723
- data/spec/fixtures/com_monthly.xml +0 -2075
- data/spec/fixtures/com_pcsoft.xml +0 -729
- data/spec/fixtures/com_rental.xml +0 -2691
- data/spec/fixtures/r18.xml +0 -4203
- data/spec/fixtures/r18_book.xml +0 -4965
- data/spec/fixtures/r18_digital.xml +0 -26987
- data/spec/fixtures/r18_doujin.xml +0 -2741
- data/spec/fixtures/r18_mono.xml +0 -3723
- data/spec/fixtures/r18_monthly.xml +0 -3515
- data/spec/fixtures/r18_pcgame.xml +0 -3373
- data/spec/fixtures/r18_ppm.xml +0 -2883
- data/spec/fixtures/r18_rental.xml +0 -12371
- data/spec/fixtures/request_error.xml +0 -24
- data/spec/fixtures/zero_items.xml +0 -37
- data/spec/response/item_info_spec.rb +0 -89
- data/spec/response/item_spec.rb +0 -67
- data/spec/response_spec.rb +0 -77
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1f5de77476b1e6e8ed597018fec625d738551d3
|
4
|
+
data.tar.gz: be8c16c990d71f2090cc60b28ff14b64c0c8ba28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dc509405bae84c500837f1639408d2e7f49ea9b7e247c82d230c03074012be59e22074f8bad14238b32775652e371e64c75c6edcf5c46a9a054cceeec024e14
|
7
|
+
data.tar.gz: 2da0d30029e1e13406576dd0414d1d69ca14444de7251b0aa55e763f20a68e8643a9ee0a5645df850b83e8e9f5a1c1593df301642add03f5738ea322976859aa
|
data/.rubocop.yml
CHANGED
@@ -1,58 +1 @@
|
|
1
|
-
Style/HashSyntax:
|
2
|
-
EnforcedStyle: hash_rockets
|
3
|
-
|
4
|
-
Lint/AmbiguousOperator:
|
5
|
-
Enabled: true
|
6
|
-
|
7
|
-
Lint/AssignmentInCondition:
|
8
|
-
Enabled: true
|
9
|
-
|
10
|
-
Lint/UnusedBlockArgument:
|
11
|
-
Enabled: true
|
12
|
-
|
13
|
-
Lint/UnusedMethodArgument:
|
14
|
-
Enabled: true
|
15
|
-
|
16
|
-
Style/ClassAndModuleChildren:
|
17
|
-
Enabled: true
|
18
|
-
|
19
|
-
Style/CollectionMethods:
|
20
|
-
Enabled: true
|
21
|
-
PreferredMethods:
|
22
|
-
reduce: 'inject'
|
23
|
-
|
24
|
-
Style/EmptyLinesAroundBody:
|
25
|
-
Enabled: true
|
26
|
-
|
27
|
-
Style/FileName:
|
28
|
-
Enabled: false
|
29
|
-
|
30
|
-
Style/PercentLiteralDelimiters:
|
31
|
-
Enabled: true
|
32
|
-
|
33
|
-
Style/SignalException:
|
34
|
-
Enabled: true
|
35
|
-
EnforcedStyle: only_raise
|
36
|
-
|
37
|
-
Style/SingleLineBlockParams:
|
38
|
-
Enabled: false
|
39
|
-
|
40
|
-
Style/SingleSpaceBeforeFirstArg:
|
41
|
-
Enabled: true
|
42
|
-
|
43
|
-
Style/SpaceInsideHashLiteralBraces:
|
44
|
-
Enabled: true
|
45
|
-
|
46
|
-
Style/SpecialGlobalVars:
|
47
|
-
Enabled: true
|
48
|
-
|
49
|
-
Style/StringLiterals:
|
50
|
-
Enabled: true
|
51
|
-
|
52
|
-
Style/TrailingComma:
|
53
|
-
Enabled: false
|
54
|
-
|
55
|
-
Style/UnneededPercentQ:
|
56
|
-
Enabled: true
|
57
|
-
|
58
1
|
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
CHANGED
@@ -1,41 +1,76 @@
|
|
1
|
-
# This configuration was generated by
|
2
|
-
#
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2016-05-21 21:44:17 +0900 using RuboCop version 0.40.0.
|
3
4
|
# The point is for the user to remove these configuration records
|
4
5
|
# one by one as the offenses are removed from the code base.
|
5
6
|
# Note that changes in the inspected code, or installation of new
|
6
7
|
# versions of RuboCop, may require this file to be generated again.
|
7
8
|
|
8
9
|
# Offense count: 1
|
9
|
-
|
10
|
-
|
10
|
+
# Cop supports --auto-correct.
|
11
|
+
Lint/Debugger:
|
12
|
+
Exclude:
|
13
|
+
- 'test.rb'
|
11
14
|
|
12
|
-
# Offense count:
|
15
|
+
# Offense count: 1
|
16
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
17
|
+
# URISchemes: http, https
|
18
|
+
Metrics/LineLength:
|
19
|
+
Max: 93
|
20
|
+
|
21
|
+
# Offense count: 7
|
22
|
+
Style/AsciiComments:
|
23
|
+
Exclude:
|
24
|
+
- 'lib/ruby-dmm/client.rb'
|
25
|
+
|
26
|
+
# Offense count: 3
|
13
27
|
Style/Documentation:
|
14
|
-
|
28
|
+
Exclude:
|
29
|
+
- 'spec/**/*'
|
30
|
+
- 'test/**/*'
|
31
|
+
- 'lib/ruby-dmm.rb'
|
32
|
+
- 'lib/ruby-dmm/client.rb'
|
33
|
+
- 'lib/ruby-dmm/response.rb'
|
15
34
|
|
16
35
|
# Offense count: 1
|
17
|
-
|
18
|
-
|
36
|
+
# Cop supports --auto-correct.
|
37
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
38
|
+
# SupportedStyles: empty_lines, no_empty_lines
|
39
|
+
Style/EmptyLinesAroundClassBody:
|
40
|
+
Exclude:
|
41
|
+
- 'lib/ruby-dmm/client.rb'
|
19
42
|
|
20
43
|
# Offense count: 1
|
21
|
-
|
22
|
-
|
44
|
+
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
|
45
|
+
Style/FileName:
|
46
|
+
Exclude:
|
47
|
+
- 'lib/ruby-dmm.rb'
|
23
48
|
|
24
|
-
# Offense count:
|
25
|
-
#
|
26
|
-
|
27
|
-
|
49
|
+
# Offense count: 4
|
50
|
+
# Cop supports --auto-correct.
|
51
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
|
52
|
+
# SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets
|
53
|
+
Style/HashSyntax:
|
54
|
+
Enabled: false
|
28
55
|
|
29
|
-
# Offense count:
|
30
|
-
#
|
31
|
-
Style/
|
32
|
-
|
56
|
+
# Offense count: 1
|
57
|
+
# Cop supports --auto-correct.
|
58
|
+
Style/MutableConstant:
|
59
|
+
Exclude:
|
60
|
+
- 'lib/ruby-dmm/version.rb'
|
33
61
|
|
34
62
|
# Offense count: 1
|
35
|
-
#
|
36
|
-
|
37
|
-
|
63
|
+
# Cop supports --auto-correct.
|
64
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
|
65
|
+
# SupportedStyles: single_quotes, double_quotes
|
66
|
+
Style/StringLiterals:
|
67
|
+
Enabled: false
|
38
68
|
|
39
|
-
# Offense count:
|
40
|
-
|
41
|
-
|
69
|
+
# Offense count: 5
|
70
|
+
# Cop supports --auto-correct.
|
71
|
+
# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
|
72
|
+
# SupportedStyles: comma, consistent_comma, no_comma
|
73
|
+
Style/TrailingCommaInLiteral:
|
74
|
+
Exclude:
|
75
|
+
- 'lib/ruby-dmm/client.rb'
|
76
|
+
- 'spec/ruby-dmm/client_spec.rb'
|
data/.travis.yml
CHANGED
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# ruby-dmm
|
2
|
-
[![Gem Version](https://img.shields.io/gem/v/ruby-dmm.svg)](http://badge.fury.io/rb/ruby-dmm)
|
3
|
-
[![Build Status](https://
|
4
|
-
[![Coverage Status](https://img.shields.io/coveralls/meganemura/ruby-dmm.svg)](https://coveralls.io/r/meganemura/ruby-dmm?branch=master)
|
5
|
-
[![Code Climate](https://img.shields.io/codeclimate/github/meganemura/ruby-dmm.svg)](https://codeclimate.com/github/meganemura/ruby-dmm)
|
6
|
-
[![Dependency Status](https://
|
2
|
+
[![Gem Version](https://img.shields.io/gem/v/ruby-dmm.svg?style=flat)](http://badge.fury.io/rb/ruby-dmm)
|
3
|
+
[![Build Status](https://img.shields.io/travis/meganemura/ruby-dmm.svg?style=flat)](https://travis-ci.org/meganemura/ruby-dmm)
|
4
|
+
[![Coverage Status](https://img.shields.io/coveralls/meganemura/ruby-dmm.svg?style=flat)](https://coveralls.io/r/meganemura/ruby-dmm?branch=master)
|
5
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/meganemura/ruby-dmm.svg?style=flat)](https://codeclimate.com/github/meganemura/ruby-dmm)
|
6
|
+
[![Dependency Status](https://img.shields.io/gemnasium/meganemura/ruby-dmm.svg?style=flat)](https://gemnasium.com/meganemura/ruby-dmm)
|
7
7
|
|
8
|
-
Client for the DMM Web Service API
|
8
|
+
Client for the DMM Web Service API v3
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
@@ -24,30 +24,32 @@ Or install it yourself as:
|
|
24
24
|
## Usage
|
25
25
|
|
26
26
|
```ruby
|
27
|
-
client = DMM.new(:api_id => "
|
28
|
-
response =
|
29
|
-
response.items.map {|
|
30
|
-
# => ["
|
31
|
-
# "
|
32
|
-
# "
|
33
|
-
# "
|
34
|
-
# "
|
27
|
+
client = DMM.new(:api_id => "YOUR-API-ID", :affiliate_id => "YOUR-AFFILIATE-ID")
|
28
|
+
response = cli.product(:site => 'DMM.com', :keyword => '超能力', :sort => 'rank')
|
29
|
+
response.result[:items].map {|x| x[:title] }
|
30
|
+
# => ["僕のヒーローアカデミア",
|
31
|
+
# "みんな!エスパーだよ!-欲望だらけのラブ・ウォーズ-",
|
32
|
+
# "血界戦線 Vol.6 (ブルーレイディスク)",
|
33
|
+
# "エルフェンリート",
|
34
|
+
# "学園アリス",
|
35
|
+
# "ストレイヤーズ・クロニクル",
|
36
|
+
# "Honey Bitter",
|
37
|
+
# "MONSTERZ モンスターズ",
|
38
|
+
# "AREA D 異能領域",
|
39
|
+
# "十十虫は夢を見る",
|
40
|
+
# "蝶戦士ピンクフューリーS",
|
41
|
+
# "バビル2世 ザ・リターナー",
|
42
|
+
# "とある科学の超電磁砲",
|
43
|
+
# "裸心の十字架",
|
44
|
+
# "菊池俊輔 作曲50周年 CD-BOX Composer SHUNSUKE KIKUCHI 50th Anniversary",
|
45
|
+
# "アライブ 最終進化的少年",
|
46
|
+
# "恋は光",
|
47
|
+
# "ホムンクルス",
|
48
|
+
# "目隠しの国",
|
49
|
+
# "AKIRA"]
|
35
50
|
```
|
36
51
|
|
37
|
-
|
38
|
-
|
39
|
-
You can use `ox`, `libxml`, `nokogiri` through `multi_xml`.
|
40
|
-
|
41
|
-
Add 'ox' and 'nokogiri' to your Gemfile, then it works below.
|
42
|
-
|
43
|
-
```ruby
|
44
|
-
> require 'ruby-dmm'
|
45
|
-
> MultiXml.parser # => MultiXml::Parsers::Ox
|
46
|
-
> MultiXml.parser = :nokogiri
|
47
|
-
> MultiXml.parser # => MultiXml::Parsers::Nokogiri
|
48
|
-
```
|
49
|
-
|
50
|
-
See [multi_xml documents](http://rdoc.info/gems/multi_xml).
|
52
|
+
DMM::Client interface is very similar to (dmm-js-sdk](https://github.com/DMMcomLabo/dmm-js-sdk).
|
51
53
|
|
52
54
|
## Contributing
|
53
55
|
|
data/lib/ruby-dmm.rb
CHANGED
@@ -1,24 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'ruby-dmm/error'
|
2
|
+
|
4
3
|
require 'ruby-dmm/client'
|
5
4
|
|
6
5
|
module DMM
|
7
|
-
|
8
|
-
|
9
|
-
class << self
|
10
|
-
def new(options = {})
|
11
|
-
DMM::Client.new(options)
|
12
|
-
end
|
13
|
-
|
14
|
-
# Delegate to DMM::Client.new
|
15
|
-
def method_missing(method, *args, &block)
|
16
|
-
return super unless new.respond_to?(method)
|
17
|
-
new.send(method, *args, &block)
|
18
|
-
end
|
19
|
-
|
20
|
-
def respond_to?(method, include_private = false)
|
21
|
-
new.respond_to?(method, include_private) || super(method, include_private)
|
22
|
-
end
|
6
|
+
def self.new(options = {})
|
7
|
+
DMM::Client.new(options)
|
23
8
|
end
|
24
9
|
end
|
data/lib/ruby-dmm/client.rb
CHANGED
@@ -1,83 +1,66 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
|
2
3
|
require 'faraday'
|
3
|
-
require 'faraday/response/raise_dmm_error'
|
4
4
|
require 'faraday_middleware'
|
5
|
-
require 'faraday_middleware/response/dmm_rashify'
|
6
|
-
require 'multi_xml_tweaks'
|
7
5
|
require 'ruby-dmm/response'
|
8
|
-
require 'ruby-dmm/
|
6
|
+
require 'ruby-dmm/version'
|
9
7
|
|
10
8
|
module DMM
|
11
|
-
DEFAULT_API_VERSION = '2.00'.freeze
|
12
|
-
SITE_DMM_CO_JP = 'DMM.co.jp'.freeze
|
13
|
-
SITE_DMM_COM = 'DMM.com'.freeze
|
14
|
-
DEFAULT_SITE = SITE_DMM_CO_JP
|
15
|
-
|
16
9
|
class Client
|
17
|
-
include DMM::Client::ItemList
|
18
|
-
|
19
|
-
attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
|
20
|
-
attr_accessor :params
|
21
|
-
attr_reader :last_response
|
22
|
-
|
23
|
-
def initialize(params = {})
|
24
|
-
DMM.options.each do |key, value|
|
25
|
-
# fall back to `DMM::Configuration` module defaults
|
26
|
-
send("#{key}=", params[key] || value)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Symbolize keys
|
30
|
-
params = params.inject({}) do |hash, (key, value)|
|
31
|
-
hash.merge(key.to_sym => value)
|
32
|
-
end
|
33
10
|
|
34
|
-
|
35
|
-
|
36
|
-
:api_id => ENV['DMM_API_ID'] || params[:api_id], # your own api_id
|
37
|
-
:affiliate_id => ENV['DMM_AFFILIATE_ID'] || params[:affiliate_id], # your own affiliate_id
|
38
|
-
:operation => nil,
|
39
|
-
:version => DEFAULT_API_VERSION,
|
40
|
-
:timestamp => Time.now.strftime('%F %T'),
|
41
|
-
:site => DEFAULT_SITE,
|
42
|
-
}.merge(params)
|
11
|
+
BASE_URL = 'https://api.dmm.com/affiliate/v3/'.freeze
|
12
|
+
DEFAULT_USER_AGENT = "ruby-dmm gem #{DMM::VERSION}".freeze
|
43
13
|
|
44
|
-
|
14
|
+
def initialize(options = {})
|
15
|
+
@api_id = (ENV['DMM_API_ID'] || options[:api_id])
|
16
|
+
@affiliate_id = (ENV['DMM_AFFILIATE_ID'] || options[:affiliate_id])
|
17
|
+
@user_agent = (ENV['DMM_USER_AGENT'] || options[:user_agent] || DEFAULT_USER_AGENT)
|
45
18
|
end
|
46
19
|
|
47
|
-
|
48
|
-
|
49
|
-
|
20
|
+
API_MAP = {
|
21
|
+
product: 'ItemList', # 商品情報
|
22
|
+
floor: 'FloorList', # フロア
|
23
|
+
actress: 'ActressSearch', # 女優検索
|
24
|
+
genre: 'GenreSearch', # ジャンル検索
|
25
|
+
maker: 'MakerSearch', # メーカー検索
|
26
|
+
series: 'SeriesSearch', # シリーズ検索
|
27
|
+
author: 'AuthorSearch', # 作者検索
|
28
|
+
}.freeze
|
50
29
|
|
51
|
-
|
52
|
-
|
30
|
+
API_MAP.each do |method, path|
|
31
|
+
define_method method do |params = {}|
|
32
|
+
get(path, credentials.merge(params))
|
33
|
+
end
|
53
34
|
end
|
54
35
|
|
55
36
|
private
|
56
37
|
|
57
|
-
def
|
58
|
-
|
59
|
-
|
60
|
-
|
38
|
+
def credentials
|
39
|
+
{
|
40
|
+
api_id: @api_id,
|
41
|
+
affiliate_id: @affiliate_id,
|
42
|
+
}
|
61
43
|
end
|
62
44
|
|
63
|
-
def
|
64
|
-
|
65
|
-
connection = Faraday.new(api_endpoint, options) do |faraday|
|
66
|
-
faraday.adapter(adapter)
|
67
|
-
faraday.request(:url_encoded)
|
68
|
-
faraday.response(:xml, :content_type => 'text/xml; charset=euc-jp')
|
69
|
-
faraday.use(FaradayMiddleware::DMMRashify)
|
70
|
-
faraday.use(FaradayMiddleware::ParseXml)
|
71
|
-
faraday.use(Faraday::Response::RaiseDMMError)
|
72
|
-
end
|
73
|
-
connection.headers[:user_agent] = user_agent
|
74
|
-
connection
|
45
|
+
def get(path, options = {})
|
46
|
+
Response.new(connection.get(path, options))
|
75
47
|
end
|
76
48
|
|
77
|
-
def
|
78
|
-
@
|
79
|
-
|
49
|
+
def connection
|
50
|
+
@connection ||= Faraday.new(faraday_options) do |faraday|
|
51
|
+
faraday.adapter Faraday.default_adapter
|
52
|
+
faraday.request :url_encoded
|
53
|
+
faraday.response :json
|
80
54
|
end
|
81
55
|
end
|
56
|
+
|
57
|
+
def faraday_options
|
58
|
+
{
|
59
|
+
url: BASE_URL,
|
60
|
+
headers: {
|
61
|
+
user_agent: @user_agent,
|
62
|
+
},
|
63
|
+
}
|
64
|
+
end
|
82
65
|
end
|
83
66
|
end
|
data/lib/ruby-dmm/response.rb
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
2
|
+
|
3
|
+
require 'active_support/core_ext/hash/keys'
|
3
4
|
|
4
5
|
module DMM
|
5
6
|
class Response
|
6
|
-
|
7
|
+
def initialize(faraday_response)
|
8
|
+
@original_response = faraday_response
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :original_response
|
7
12
|
|
8
|
-
def
|
9
|
-
@
|
10
|
-
if response[:result][:message] && response[:result][:errors]
|
11
|
-
@result = response[:result]
|
12
|
-
else
|
13
|
-
@result = DMM::Response::Result.new(response[:result])
|
14
|
-
end
|
13
|
+
def body
|
14
|
+
@body ||= original_response.body.deep_symbolize_keys
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
attr_reader(*RESULT_KEYS)
|
25
|
-
alias_method :offset, :first_position
|
26
|
-
alias_method :per_result, :result_count
|
17
|
+
def headers
|
18
|
+
original_response.headers
|
19
|
+
end
|
20
|
+
|
21
|
+
def status
|
22
|
+
original_response.status
|
23
|
+
end
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
case key
|
31
|
-
when :items
|
32
|
-
@items = [result[:items][:item]].flatten.map do |item|
|
33
|
-
DMM::Response::Item.new(item)
|
34
|
-
end if result.key?(:items)
|
35
|
-
@items ||= []
|
36
|
-
else
|
37
|
-
instance_variable_set("@#{key}", result[key].to_i)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
25
|
+
def result
|
26
|
+
body[:result]
|
41
27
|
end
|
42
28
|
end
|
43
29
|
end
|