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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 403ce570cb0430ed5a1e0b5bc7412c715a4d0cf5
4
- data.tar.gz: 923c8c937a288036beea2da4d3e7abb24ae0c20f
3
+ metadata.gz: b1f5de77476b1e6e8ed597018fec625d738551d3
4
+ data.tar.gz: be8c16c990d71f2090cc60b28ff14b64c0c8ba28
5
5
  SHA512:
6
- metadata.gz: 662149fa1ae1228108b6f403582db0810709641a20ac02c2fbf2cf7514023bc7af63def56e7b56f91bd845da64038b6f5d3da07c3d4dd372ef5a020422d9f3a2
7
- data.tar.gz: 7b3ff9d7badbb13b54c1426e0bee31a7da03ce5cd89c263d1fa278e33a4662048f88034dfe698dbed7685333e3d1afeee5a5c110acbc3de22fba58470dfb5811
6
+ metadata.gz: 6dc509405bae84c500837f1639408d2e7f49ea9b7e247c82d230c03074012be59e22074f8bad14238b32775652e371e64c75c6edcf5c46a9a054cceeec024e14
7
+ data.tar.gz: 2da0d30029e1e13406576dd0414d1d69ca14444de7251b0aa55e763f20a68e8643a9ee0a5645df850b83e8e9f5a1c1593df301642add03f5738ea322976859aa
@@ -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
@@ -1,41 +1,76 @@
1
- # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2014-07-12 00:25:45 +0900 using RuboCop version 0.24.1.
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
- Style/CyclomaticComplexity:
10
- Max: 11
10
+ # Cop supports --auto-correct.
11
+ Lint/Debugger:
12
+ Exclude:
13
+ - 'test.rb'
11
14
 
12
- # Offense count: 14
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
- Enabled: false
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
- Style/DoubleNegation:
18
- Enabled: false
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
- Style/EachWithObject:
22
- Enabled: false
44
+ # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
45
+ Style/FileName:
46
+ Exclude:
47
+ - 'lib/ruby-dmm.rb'
23
48
 
24
- # Offense count: 12
25
- # Configuration parameters: AllowURI.
26
- Style/LineLength:
27
- Max: 141
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: 7
30
- # Configuration parameters: CountComments.
31
- Style/MethodLength:
32
- Max: 23
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
- # Configuration parameters: SupportedStyles.
36
- Style/RaiseArgs:
37
- EnforcedStyle: compact
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: 2
40
- Style/RegexpLiteral:
41
- MaxSlashes: 0
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'
@@ -1,6 +1,8 @@
1
+ cache: bundler
1
2
  language: ruby
2
- script: rake ci
3
+ script: bundle exec rake ci
4
+ sudo: false
3
5
  rvm:
4
- - 1.9.3
5
6
  - 2.0.0
6
7
  - 2.1.0
8
+ - 2.2.0
data/Guardfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # vim: ts=2 sts=2 et sw=2 ft=ruby
2
2
 
3
- ENV['GUARD_TEST'] = "true"
3
+ ENV['GUARD_TEST'] = 'true'
4
4
 
5
5
  guard 'rspec', :all_after_pass => false, :all_on_start => false do
6
6
  watch(%r{spec/.+_spec\.rb$})
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://travis-ci.org/meganemura/ruby-dmm.svg?branch=master)](https://travis-ci.org/meganemura/ruby-dmm)
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://gemnasium.com/meganemura/ruby-dmm.svg)](https://gemnasium.com/meganemura/ruby-dmm)
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 2.0.
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 => "your_api_id", :affiliate_id => "your_affiliate_id", :result_only => true)
28
- response = client.order("date").limit(5).item_list("妄想")
29
- response.items.map {|item| item.title }
30
- # => ["ココロ@ファンクション!",
31
- # "やらせてっ!てぃーちゃー学園旅行〜やらてぃーが学園を飛び出したァ!?〜(DVDPG)",
32
- # "彫刻ボディ 瀧川花音",
33
- # "目が奪われる瞬間 vol.02",
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
- ### Choose your favorite XML Parser
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
 
@@ -1,24 +1,9 @@
1
1
  # encoding: utf-8
2
- require 'ruby-dmm/configuration'
3
- require 'ruby-dmm/error'
2
+
4
3
  require 'ruby-dmm/client'
5
4
 
6
5
  module DMM
7
- extend Configuration
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
@@ -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/client/item_list'
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
- @result_only = !!params.delete(:result_only) # Set true to get response.result only.
35
- @params = {
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
- @encode_options = params[:encode_options] || {}
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
- def operation(value)
48
- @params.update(:operation => value)
49
- end
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
- def all
52
- @params[:operation] ? get('/', @params) : nil
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 get(_path, options = {})
58
- encode_params!
59
- @last_response = connection.get('/', options)
60
- @last_response.body
38
+ def credentials
39
+ {
40
+ api_id: @api_id,
41
+ affiliate_id: @affiliate_id,
42
+ }
61
43
  end
62
44
 
63
- def connection(options = {})
64
- # TODO: not to create on every request.
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 encode_params!
78
- @params.each do |_key, value|
79
- value.encode!(Encoding::EUC_JP, @encode_options) if value.is_a?(String) && !value.frozen?
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
@@ -1,43 +1,29 @@
1
1
  # encoding: utf-8
2
- require 'ruby-dmm/response/item'
2
+
3
+ require 'active_support/core_ext/hash/keys'
3
4
 
4
5
  module DMM
5
6
  class Response
6
- attr_reader :request, :result
7
+ def initialize(faraday_response)
8
+ @original_response = faraday_response
9
+ end
10
+
11
+ attr_reader :original_response
7
12
 
8
- def initialize(response)
9
- @request = response[:request][:parameters][:parameter].inject({}) { |hash, params| hash.merge(params[:name].to_sym => params[:value]) }
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
- class Result
18
- RESULT_KEYS = [
19
- :first_position,
20
- :items,
21
- :result_count,
22
- :total_count,
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
- def initialize(result)
29
- RESULT_KEYS.each do |key|
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