ruby-dmm 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79cc74c7709505fc6927020e46facf6b3e220ac7
4
- data.tar.gz: 0869a4633cb3da9608f81290a514ba958e57a0a6
3
+ metadata.gz: ac99893fcfd318b40594e20186d9c3e4a1b88c78
4
+ data.tar.gz: 85a2cab6e07afc8f84ccf3cd69d852c29369bba5
5
5
  SHA512:
6
- metadata.gz: 84d6e48892644274e3728a5a1ab2dd23064f75cf6f3aacd429cbd7d20113a3d82614be035a769fe94acf3e88d424650a8215353a30f1b9cc6b9624c5065334fb
7
- data.tar.gz: 5c5e95763c5017e44177a19aade42d7b94cf65b7944a82b420edc0f56c2d29b6cb61f04daf68f6c5f214cd5cf8fdf368c098bf465224bd26226ca531d8bdb2d4
6
+ metadata.gz: 498bbb08f6f7cc5c66e5b298be23f6fe443796508bef4bbc69a8263be04d551081d074d045f219a2c6fac1ed0587a77b14ef123ca867307d977c36106f2d8e42
7
+ data.tar.gz: 07c25a5cbf5230f7fea56c90756ce6263bad73b2ca45541866bc76eb8f4fbc5e73c9d0bde8caa69879a7375e179db4b17a427b2f62dbafc885104aff82acf2a1
@@ -0,0 +1,58 @@
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
+ inherit_from: .rubocop_todo.yml
@@ -0,0 +1,41 @@
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.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 1
9
+ Style/CyclomaticComplexity:
10
+ Max: 11
11
+
12
+ # Offense count: 14
13
+ Style/Documentation:
14
+ Enabled: false
15
+
16
+ # Offense count: 1
17
+ Style/DoubleNegation:
18
+ Enabled: false
19
+
20
+ # Offense count: 1
21
+ Style/EachWithObject:
22
+ Enabled: false
23
+
24
+ # Offense count: 12
25
+ # Configuration parameters: AllowURI.
26
+ Style/LineLength:
27
+ Max: 141
28
+
29
+ # Offense count: 7
30
+ # Configuration parameters: CountComments.
31
+ Style/MethodLength:
32
+ Max: 23
33
+
34
+ # Offense count: 1
35
+ # Configuration parameters: SupportedStyles.
36
+ Style/RaiseArgs:
37
+ EnforcedStyle: compact
38
+
39
+ # Offense count: 2
40
+ Style/RegexpLiteral:
41
+ MaxSlashes: 0
@@ -1,5 +1,6 @@
1
- bundler_args: --without development
2
1
  language: ruby
2
+ script: rake ci
3
3
  rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
+ - 2.1.0
data/Gemfile CHANGED
@@ -1,17 +1,2 @@
1
1
  source 'https://rubygems.org'
2
-
3
- group :development, :test do
4
- gem 'rake'
5
- gem 'rspec', '>= 2.11'
6
- gem 'webmock'
7
- gem 'pry'
8
- gem 'guard-rspec'
9
- gem 'ox'
10
- end
11
-
12
- group :test do
13
- gem 'coveralls', :require => false
14
- gem 'simplecov', :require => false
15
- end
16
-
17
2
  gemspec
data/Guardfile CHANGED
@@ -4,7 +4,7 @@ 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$})
7
- watch(%r{lib/(.+)\.rb$}) {|m| "spec/#{m[1]}_spec.rb"}
8
- watch(%r{lib/(.+)/.+\.rb$}) {|m| "spec/#{m[1]}/#{m[2]}_spec.rb"}
7
+ watch(%r{lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
8
+ watch(%r{lib/(.+)/(.+)\.rb$}) { |m| "spec/#{m[1]}/#{m[2]}_spec.rb" }
9
+ watch(%r{lib/ruby-dmm/(.+)/(.+)\.rb$}) { |m| "spec/#{m[1]}/#{m[2]}_spec.rb" }
9
10
  end
10
-
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # ruby-dmm
2
- [![Gem Version](https://badge.fury.io/rb/ruby-dmm.png)](http://badge.fury.io/rb/ruby-dmm) [![Build Status](https://travis-ci.org/meganemura/ruby-dmm.png?branch=master)](https://travis-ci.org/meganemura/ruby-dmm) [![Coverage Status](https://coveralls.io/repos/meganemura/ruby-dmm/badge.png?branch=master)](https://coveralls.io/r/meganemura/ruby-dmm?branch=master) [![Code Climate](https://codeclimate.com/github/meganemura/ruby-dmm.png)](https://codeclimate.com/github/meganemura/ruby-dmm) [![Dependency Status](https://gemnasium.com/meganemura/ruby-dmm.png)](https://gemnasium.com/meganemura/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)
3
7
 
4
8
  Client for the DMM Web Service API 2.0.
5
9
 
data/Rakefile CHANGED
@@ -1,9 +1,17 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # encoding: utf-8
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+ require 'coveralls/rake/task'
5
+ require 'rubocop/rake_task'
3
6
 
4
7
  RSpec::Core::RakeTask.new(:rspec) do |spec|
5
8
  spec.pattern = 'spec/**/*_spec.rb'
6
9
  spec.rspec_opts = ['-cfd --backtrace']
7
10
  end
8
11
 
9
- task :default => :rspec
12
+ RuboCop::RakeTask.new(:style)
13
+
14
+ Coveralls::RakeTask.new
15
+
16
+ task :default => %w(rspec style)
17
+ task :ci => %w(rspec style coveralls:push)
@@ -2,23 +2,25 @@
2
2
  require 'faraday'
3
3
 
4
4
  module Faraday
5
- class Response::RaiseDMMError < Response::Middleware
6
- ERROR_MAP = {
7
- 400 => DMM::BadRequest,
8
- 401 => DMM::Unauthorized,
9
- 403 => DMM::Forbidden,
10
- 404 => DMM::NotFound,
11
- 406 => DMM::NotAcceptable,
12
- 422 => DMM::UnprocessableEntity,
13
- 500 => DMM::InternalServerError,
14
- 501 => DMM::NotImplemented,
15
- 502 => DMM::BadGateway,
16
- 503 => DMM::ServiceUnavailable
17
- }
5
+ class Response
6
+ class RaiseDMMError < Middleware
7
+ ERROR_MAP = {
8
+ 400 => DMM::BadRequest,
9
+ 401 => DMM::Unauthorized,
10
+ 403 => DMM::Forbidden,
11
+ 404 => DMM::NotFound,
12
+ 406 => DMM::NotAcceptable,
13
+ 422 => DMM::UnprocessableEntity,
14
+ 500 => DMM::InternalServerError,
15
+ 501 => DMM::NotImplemented,
16
+ 502 => DMM::BadGateway,
17
+ 503 => DMM::ServiceUnavailable
18
+ }
18
19
 
19
- def on_complete(response)
20
- key = response[:status].to_i
21
- raise ERROR_MAP[key].new(response) if ERROR_MAP.has_key? key
20
+ def on_complete(response)
21
+ key = response[:status].to_i
22
+ raise ERROR_MAP[key].new(response) if ERROR_MAP.key? key
23
+ end
22
24
  end
23
25
  end
24
26
  end
@@ -5,16 +5,17 @@ require 'rash'
5
5
  module DMM
6
6
  class Rash < ::Hashie::Rash
7
7
  protected
8
+
8
9
  def underscore_string(str)
9
- str.to_s.strip.
10
- gsub(' ', '_').
11
- gsub(/::/, '/').
12
- gsub(/(URL)([a-z])/, '\1_\2').
13
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
14
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
15
- tr("-", "_").
16
- squeeze("_").
17
- downcase
10
+ str.to_s.strip
11
+ .gsub(' ', '_')
12
+ .gsub(/::/, '/')
13
+ .gsub(/(URL)([a-z])/, '\1_\2')
14
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
15
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
16
+ .tr('-', '_')
17
+ .squeeze('_')
18
+ .downcase
18
19
  end
19
20
  end
20
21
  end
@@ -3,8 +3,7 @@ require 'multi_xml'
3
3
 
4
4
  module MultiXml
5
5
  class << self
6
-
7
- def encoding_values(params, encoding=Encoding::UTF_8)
6
+ def encoding_values(params, encoding = Encoding::UTF_8)
8
7
  case params
9
8
  when Hash
10
9
  params.inject({}) do |result, (key, value)|
@@ -13,17 +12,16 @@ module MultiXml
13
12
  when String
14
13
  params.encode(encoding)
15
14
  when Array
16
- params.map {|v| encoding_values(v) }
15
+ params.map { |v| encoding_values(v) }
17
16
  else
18
17
  params
19
18
  end
20
19
  end
21
20
 
22
- alias :original_parse :parse
23
- def parse(xml, options={})
21
+ alias_method :original_parse, :parse
22
+ def parse(xml, options = {})
24
23
  hash = original_parse(xml, options)
25
- return encoding_values(hash)
24
+ encoding_values(hash)
26
25
  end
27
-
28
26
  end
29
27
  end
@@ -1,13 +1,13 @@
1
1
  # encoding: utf-8
2
- require "ruby-dmm/configuration"
2
+ require 'ruby-dmm/configuration'
3
3
  require 'ruby-dmm/error'
4
- require "ruby-dmm/client"
4
+ require 'ruby-dmm/client'
5
5
 
6
6
  module DMM
7
7
  extend Configuration
8
8
 
9
9
  class << self
10
- def new(options={})
10
+ def new(options = {})
11
11
  DMM::Client.new(options)
12
12
  end
13
13
 
@@ -17,7 +17,7 @@ module DMM
17
17
  new.send(method, *args, &block)
18
18
  end
19
19
 
20
- def respond_to?(method, include_private=false)
20
+ def respond_to?(method, include_private = false)
21
21
  new.respond_to?(method, include_private) || super(method, include_private)
22
22
  end
23
23
  end
@@ -8,20 +8,19 @@ require 'ruby-dmm/response'
8
8
  require 'ruby-dmm/client/item_list'
9
9
 
10
10
  module DMM
11
-
12
11
  DEFAULT_API_VERSION = '2.00'.freeze
13
12
  SITE_DMM_CO_JP = 'DMM.co.jp'.freeze
14
13
  SITE_DMM_COM = 'DMM.com'.freeze
15
14
  DEFAULT_SITE = SITE_DMM_CO_JP
16
15
 
17
16
  class Client
18
-
19
17
  include DMM::Client::ItemList
20
18
 
21
- attr_accessor *Configuration::VALID_OPTIONS_KEYS
19
+ attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
22
20
  attr_accessor :params
21
+ attr_reader :last_response
23
22
 
24
- def initialize(params={})
23
+ def initialize(params = {})
25
24
  DMM.options.each do |key, value|
26
25
  # fall back to `DMM::Configuration` module defaults
27
26
  send("#{key}=", params[key] || value)
@@ -32,14 +31,14 @@ module DMM
32
31
  hash.merge(key.to_sym => value)
33
32
  end
34
33
 
34
+ @result_only = !!params.delete(:result_only) # Set true to get response.result only.
35
35
  @params = {
36
36
  :api_id => ENV['DMM_API_ID'] || params[:api_id], # your own api_id
37
37
  :affiliate_id => ENV['DMM_AFFILIATE_ID'] || params[:affiliate_id], # your own affiliate_id
38
38
  :operation => nil,
39
39
  :version => DEFAULT_API_VERSION,
40
- :timestamp => Time.now.strftime("%F %T"),
40
+ :timestamp => Time.now.strftime('%F %T'),
41
41
  :site => DEFAULT_SITE,
42
- :result_only => false, # Set true to get response.result only.
43
42
  }.merge(params)
44
43
  end
45
44
 
@@ -51,24 +50,20 @@ module DMM
51
50
  @params[:operation] ? get('/', @params) : nil
52
51
  end
53
52
 
54
- def last_response
55
- @last_response
56
- end
57
-
58
53
  private
59
54
 
60
- def get(path, options={})
55
+ def get(_path, options = {})
61
56
  encode_params!
62
57
  @last_response = connection.get('/', options)
63
58
  @last_response.body
64
59
  end
65
60
 
66
- def connection(options={})
61
+ def connection(options = {})
67
62
  # TODO: not to create on every request.
68
63
  connection = Faraday.new(api_endpoint, options) do |faraday|
69
64
  faraday.adapter(adapter)
70
65
  faraday.request(:url_encoded)
71
- faraday.response(:xml, :content_type => "text/xml; charset=euc-jp")
66
+ faraday.response(:xml, :content_type => 'text/xml; charset=euc-jp')
72
67
  faraday.use(FaradayMiddleware::DMMRashify)
73
68
  faraday.use(FaradayMiddleware::ParseXml)
74
69
  faraday.use(Faraday::Response::RaiseDMMError)
@@ -78,7 +73,7 @@ module DMM
78
73
  end
79
74
 
80
75
  def encode_params!
81
- @params.each do |key, value|
76
+ @params.each do |_key, value|
82
77
  value.encode!(Encoding::EUC_JP) if value.is_a?(String) && !value.frozen?
83
78
  end
84
79
  end
@@ -1,19 +1,22 @@
1
1
  # encoding: utf-8
2
2
  module DMM
3
-
4
- OPERATION_ITEM_LIST = 'ItemList'
3
+ OPERATION_ITEM_LIST = 'ItemList'.freeze
5
4
 
6
5
  class Client
7
6
  module ItemList
8
-
9
- def item_list(keyword="", options={})
7
+ def item_list(keyword = '', options = {})
10
8
  @params = @params.merge(:keyword => keyword).merge(options)
11
9
  @params[:operation] = OPERATION_ITEM_LIST
12
10
  response = get('/', @params)
13
11
  item_list = DMM::Response.new(response[:response])
14
- @params[:result_only] ? item_list.result : item_list
12
+
13
+ if @result_only
14
+ item_list.result
15
+ else
16
+ item_list
17
+ end
15
18
  end
16
- alias :items :item_list
19
+ alias_method :items, :item_list
17
20
 
18
21
  ITEM_LIST_PARAMETERS = [
19
22
  :floor,
@@ -34,10 +37,9 @@ module DMM
34
37
  end
35
38
  end
36
39
 
37
- alias :limit :hits
38
- alias :order :sort
39
- alias :stock :mono_stock
40
+ alias_method :limit, :hits
41
+ alias_method :order, :sort
42
+ alias_method :stock, :mono_stock
40
43
  end
41
-
42
44
  end
43
45
  end
@@ -1,9 +1,8 @@
1
1
  # encoding: utf-8
2
2
  require 'faraday'
3
- require "ruby-dmm/version"
3
+ require 'ruby-dmm/version'
4
4
 
5
5
  module DMM
6
-
7
6
  module Configuration
8
7
  VALID_OPTIONS_KEYS = [
9
8
  :adapter,
@@ -15,7 +14,7 @@ module DMM
15
14
  DEFAULT_USER_AGENT = "ruby-dmm gem #{DMM::VERSION}".freeze
16
15
  DEFAULT_API_ENDPOINT = ENV['DMM_API_ENDPOINT'] || 'http://affiliate-api.dmm.com'.freeze
17
16
 
18
- attr_accessor *VALID_OPTIONS_KEYS
17
+ attr_accessor(*VALID_OPTIONS_KEYS)
19
18
 
20
19
  def self.extended(base)
21
20
  base.reset
@@ -26,11 +25,11 @@ module DMM
26
25
  end
27
26
 
28
27
  def options
29
- VALID_OPTIONS_KEYS.inject({}) {|h, k| h.merge(k => send(k)) };
28
+ VALID_OPTIONS_KEYS.inject({}) { |h, k| h.merge(k => send(k)) }
30
29
  end
31
30
 
32
31
  def api_endpoint=(value)
33
- @api_endpoint = File.join(value, "")
32
+ @api_endpoint = File.join(value, '')
34
33
  end
35
34
 
36
35
  def reset
@@ -6,7 +6,7 @@ module DMM
6
6
  attr_reader :request, :result
7
7
 
8
8
  def initialize(response)
9
- @request = response[:request][:parameters][:parameter].inject({}) {|hash, params| hash.merge(params[:name].to_sym => params[:value]) }
9
+ @request = response[:request][:parameters][:parameter].inject({}) { |hash, params| hash.merge(params[:name].to_sym => params[:value]) }
10
10
  if response[:result][:message] && response[:result][:errors]
11
11
  @result = response[:result]
12
12
  else
@@ -21,7 +21,9 @@ module DMM
21
21
  :result_count,
22
22
  :total_count,
23
23
  ]
24
- attr_reader *RESULT_KEYS
24
+ attr_reader(*RESULT_KEYS)
25
+ alias_method :offset, :first_position
26
+ alias_method :per_result, :result_count
25
27
 
26
28
  def initialize(result)
27
29
  RESULT_KEYS.each do |key|
@@ -4,7 +4,6 @@ require 'ruby-dmm/response/item_info'
4
4
  module DMM
5
5
  class Response
6
6
  class Item
7
-
8
7
  PREDEFINED_KEYS = [
9
8
  :date,
10
9
  :iteminfo,
@@ -14,7 +13,7 @@ module DMM
14
13
  :prices,
15
14
  :small_images,
16
15
  ]
17
- attr_reader *PREDEFINED_KEYS
16
+ attr_reader(*PREDEFINED_KEYS)
18
17
  alias_method :item_info, :iteminfo
19
18
  alias_method :info, :iteminfo
20
19
 
@@ -40,7 +39,7 @@ module DMM
40
39
  self.class.class_eval do
41
40
  unless method_defined?(key)
42
41
  attr_reader key
43
- if name = ALIAS_METHOD_MAP[key.to_sym]
42
+ if (name = ALIAS_METHOD_MAP[key.to_sym])
44
43
  alias_method name, key.to_sym
45
44
  end
46
45
  end
@@ -2,7 +2,6 @@
2
2
  module DMM
3
3
  class Response
4
4
  class ItemInfo
5
-
6
5
  # for defining
7
6
  # alias_method :actors, :actor
8
7
  PLURAL_MAP = {
@@ -26,7 +25,7 @@ module DMM
26
25
  self.class.class_eval do
27
26
  unless method_defined?(key)
28
27
  attr_reader key
29
- if plural = PLURAL_MAP[key.to_sym]
28
+ if (plural = PLURAL_MAP[key.to_sym])
30
29
  alias_method plural, key.to_sym
31
30
  end
32
31
  end
@@ -36,16 +35,20 @@ module DMM
36
35
  end
37
36
 
38
37
  def self.integrate(h)
39
- h && [h].flatten.inject({}) {|hash, params|
40
- id, key = params["id"].split('_')
41
- hash[id] ||= {"id" => id}
38
+ return nil unless h
39
+
40
+ hashes = [h].flatten.inject({}) do |hash, params|
41
+ id, key = params['id'].split('_')
42
+ hash[id] ||= { 'id' => id }
42
43
  if key
43
- hash[id].merge!(key => params["name"])
44
+ hash[id].merge!(key => params['name'])
44
45
  else
45
- hash[id].merge!("name" => params["name"])
46
+ hash[id].merge!('name' => params['name'])
46
47
  end
47
48
  hash
48
- }.values
49
+ end
50
+
51
+ hashes.values
49
52
  end
50
53
  end
51
54
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module DMM
3
- VERSION = "0.1.3"
3
+ VERSION = '0.1.4'
4
4
  end
@@ -4,23 +4,33 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'ruby-dmm/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "ruby-dmm"
7
+ gem.name = 'ruby-dmm'
8
8
  gem.version = DMM::VERSION
9
- gem.authors = ["meganemura"]
10
- gem.email = ["mura2megane@gmail.com"]
11
- gem.description = %q{Client for the DMM Web Service API 2.0.}
12
- gem.summary = %q{Client for the DMM Web Service API 2.0.}
13
- gem.homepage = ""
9
+ gem.authors = ['meganemura']
10
+ gem.email = ['mura2megane@gmail.com']
11
+ gem.description = 'Client for the DMM Web Service API 2.0.'
12
+ gem.summary = 'Client for the DMM Web Service API 2.0.'
13
+ gem.homepage = ''
14
14
 
15
- gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.files = `git ls-files -z`.split("\x0")
16
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
19
- gem.licenses = ["MIT"]
18
+ gem.require_paths = ['lib']
19
+ gem.licenses = ['MIT']
20
20
  gem.homepage = 'https://github.com/meganemura/ruby-dmm'
21
21
 
22
- gem.add_dependency('faraday', '~> 0.8')
23
- gem.add_dependency('faraday_middleware')
24
- gem.add_dependency('multi_xml')
25
- gem.add_dependency('rash')
22
+ gem.add_dependency 'faraday', '~> 0.8'
23
+ gem.add_dependency 'faraday_middleware'
24
+ gem.add_dependency 'multi_xml'
25
+ gem.add_dependency 'rash'
26
+
27
+ gem.add_development_dependency 'rake'
28
+ gem.add_development_dependency 'rspec'
29
+ gem.add_development_dependency 'webmock'
30
+ gem.add_development_dependency 'pry'
31
+ gem.add_development_dependency 'guard-rspec'
32
+ gem.add_development_dependency 'ox'
33
+ gem.add_development_dependency 'rubocop'
34
+ gem.add_development_dependency 'coveralls'
35
+ gem.add_development_dependency 'simplecov'
26
36
  end
@@ -1,26 +1,32 @@
1
1
  # vim: ts=2 sts=2 et sw=2 ft=ruby fileencoding=utf-8
2
- require "spec_helper"
2
+ require 'spec_helper'
3
3
 
4
4
  describe DMM::Client do
5
- describe ".item_list" do
5
+ describe '.item_list' do
6
6
  fixtures.each do |fixture|
7
7
  it "returns response for #{fixture.split('.').first}" do
8
8
  stub_get.to_return(xml_response(fixture))
9
9
  @item_list = DMM::Client.new.item_list
10
- @item_list.should_not be_nil
10
+ expect(@item_list).not_to be_nil
11
11
  end
12
12
  end
13
13
  end
14
14
 
15
- describe "#last_response" do
15
+ describe '#last_response' do
16
16
  before do
17
17
  stub_get.to_return(xml_response(random_fixture))
18
18
  @client = DMM::Client.new(:result_only => false)
19
19
  @item_list = @client.item_list
20
20
  end
21
21
 
22
- it "returns last response" do
23
- @client.last_response.should_not be_nil
22
+ it 'returns last response' do
23
+ expect(@client.last_response).not_to be_nil
24
24
  end
25
+
26
+ describe 'request params' do
27
+ subject { @client.params }
28
+ it { is_expected.not_to have_key(:result_only) }
29
+ end
30
+
25
31
  end
26
32
  end
@@ -1,69 +1,72 @@
1
1
  # vim: ts=2 sts=2 et sw=2 ft=ruby fileencoding=utf-8
2
- require "spec_helper"
2
+ require 'spec_helper'
3
3
 
4
4
  describe DMM::Response::ItemInfo do
5
5
 
6
6
  def complex_hash
7
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"},
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
18
  ],
19
19
  }
20
20
  end
21
21
 
22
22
  def simple_hash
23
23
  {
24
- "label" => {"name" => "ワーナー・ホーム・ビデオ", "id" => "60016"},
25
- "genre" => {"name" => "ファンタジー", "id" => "71009"},
26
- "series" => {"name" => "ハリー・ポッター", "id" => "60029"},
27
- "maker" => {"name" => "ワーナー・ホーム・ビデオ", "id" => "45578"},
24
+ 'label' => { 'name' => 'ワーナー・ホーム・ビデオ', 'id' => '60016' },
25
+ 'genre' => { 'name' => 'ファンタジー', 'id' => '71009' },
26
+ 'series' => { 'name' => 'ハリー・ポッター', 'id' => '60029' },
27
+ 'maker' => { 'name' => 'ワーナー・ホーム・ビデオ', 'id' => '45578' },
28
28
  }
29
29
  end
30
30
 
31
31
  describe '.integrate' do
32
32
  context 'simple_hash' do
33
- subject { DMM::Response::ItemInfo.integrate(complex_hash["actor"]) }
33
+ subject { DMM::Response::ItemInfo.integrate(complex_hash['actor']) }
34
34
  it 'integrates name and ruby and more (classify etc...) by id' do
35
- actor = subject.find {|actor| actor["id"] == "60257" }
36
- actor["name"].should == "ダニエル・ラドクリフ"
37
- actor["ruby"].should == "だにえるらどくりふ"
38
- actor["classify"].should == "メガネ君"
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
39
  end
40
40
  end
41
41
 
42
42
  context 'simple_hash' do
43
- subject { DMM::Response::ItemInfo.integrate(simple_hash["label"]) }
43
+ subject { DMM::Response::ItemInfo.integrate(simple_hash['label']) }
44
44
  it 'runs collectry' do
45
45
  label = subject.first
46
- label["id"].should == "60016"
47
- label["name"].should == "ワーナー・ホーム・ビデオ"
46
+ expect(label['id']).to eq('60016')
47
+ expect(label['name']).to eq('ワーナー・ホーム・ビデオ')
48
48
  end
49
49
  end
50
50
  end
51
51
 
52
-
53
52
  describe 'define method for any keys' do
54
53
  context 'complex_hash' do
55
54
  subject { DMM::Response::ItemInfo.new(complex_hash) }
56
- its(:actors) { should_not be_empty }
55
+
56
+ describe '#actors' do
57
+ subject { super().actors }
58
+ it { is_expected.not_to be_empty }
59
+ end
57
60
  describe 'actors' do
58
61
  it 'integrates name and ruby by id' do
59
- actor = subject.actors.find {|actor| actor["id"] == "60257" }
60
- actor["name"].should == "ダニエル・ラドクリフ"
61
- actor["ruby"].should == "だにえるらどくりふ"
62
- actor["classify"].should == "メガネ君"
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('メガネ君')
63
66
 
64
- actor = subject.actors.find {|actor| actor["id"] == "60074" }
65
- actor["name"].should == "エマ・ワトソン"
66
- actor["ruby"].should == "えまわとそん"
67
+ actor = subject.actors.find { |a| a['id'] == '60074' }
68
+ expect(actor['name']).to eq('エマ・ワトソン')
69
+ expect(actor['ruby']).to eq('えまわとそん')
67
70
  end
68
71
  end
69
72
  end
@@ -72,12 +75,12 @@ describe DMM::Response::ItemInfo do
72
75
  subject do
73
76
  DMM::Response::ItemInfo.new(simple_hash)
74
77
  end
75
- it { should be }
78
+ it { is_expected.to be }
76
79
 
77
80
  describe 'director' do
78
81
  it 'respond to given keys' do
79
82
  simple_hash.keys.each do |key|
80
- subject.should respond_to(key)
83
+ expect(subject).to respond_to(key)
81
84
  end
82
85
  end
83
86
  end
@@ -1,27 +1,39 @@
1
1
  # vim: ts=2 sts=2 et sw=2 ft=ruby fileencoding=utf-8
2
- require "spec_helper"
2
+ require 'spec_helper'
3
3
 
4
4
  describe DMM::Response::Item do
5
5
  before :all do
6
- stub_get.to_return(xml_response("com.xml"))
7
- @item = DMM::new.item_list.result.items.first
6
+ stub_get.to_return(xml_response('com.xml'))
7
+ @item = DMM.new.item_list.result.items.first
8
8
  end
9
9
 
10
10
  describe '#images' do
11
11
  subject { @item.images }
12
- it { should be }
13
- its([:list]) { should == 'http://pics.dmm.com/mono/movie/n_616dlr22659/n_616dlr22659pt.jpg' }
14
- its([:small]) { should == 'http://pics.dmm.com/mono/movie/n_616dlr22659/n_616dlr22659ps.jpg' }
15
- its([:large]) { should == 'http://pics.dmm.com/mono/movie/n_616dlr22659/n_616dlr22659pl.jpg' }
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
16
28
  end
17
29
 
18
30
  describe 'define alias methods' do
19
31
  subject do
20
- item = DMM::Response::Item::ALIAS_METHOD_MAP.keys.inject({}) {|h, key| h.merge(key => 1) }
32
+ item = DMM::Response::Item::ALIAS_METHOD_MAP.keys.inject({}) { |h, key| h.merge(key => 1) }
21
33
  DMM::Response::Item.new(item)
22
34
  end
23
35
  DMM::Response::Item::ALIAS_METHOD_MAP.values.each do |name|
24
- it { should respond_to(name) }
36
+ it { is_expected.to respond_to(name) }
25
37
  end
26
38
  end
27
39
 
@@ -30,13 +42,17 @@ describe DMM::Response::Item do
30
42
  item = {
31
43
  :sample_image_url => {
32
44
  :sample_s => {
33
- :image => ["http://pics.dmm.co.jp/digital/video/aaa00000/aaa00000-9.jpg"],
45
+ :image => ['http://pics.dmm.co.jp/digital/video/aaa00000/aaa00000-9.jpg'],
34
46
  },
35
47
  }
36
48
  }
37
49
  DMM::Response::Item.new(item)
38
50
  end
39
- its(:large_images) { should == ["http://pics.dmm.co.jp/digital/video/aaa00000/aaa00000jp-9.jpg"] }
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
40
56
  end
41
57
 
42
58
  describe 'define method for any keys' do
@@ -46,6 +62,6 @@ describe DMM::Response::Item do
46
62
  }
47
63
  DMM::Response::Item.new(item)
48
64
  end
49
- it { should respond_to(:not_defined_key) }
65
+ it { is_expected.to respond_to(:not_defined_key) }
50
66
  end
51
67
  end
@@ -1,48 +1,64 @@
1
1
  # vim: ts=2 sts=2 et sw=2 ft=ruby fileencoding=utf-8
2
- require "spec_helper"
2
+ require 'spec_helper'
3
3
 
4
4
  describe DMM::Response do
5
5
  before :all do
6
- stub_get.to_return(xml_response("com.xml"))
7
- @response = DMM::new.item_list
6
+ stub_get.to_return(xml_response('com.xml'))
7
+ @response = DMM.new.item_list
8
8
  end
9
9
 
10
- describe "Response" do
10
+ describe 'Response' do
11
11
  subject { @response }
12
- it { should respond_to(:request) }
13
- it { should respond_to(:result) }
14
- its(:request) { should be_a(Hash) }
15
- its(:result) { should be_a(DMM::Response::Result) }
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
16
24
  end
17
25
  end
18
26
 
19
27
  describe DMM::Response::Result do
20
28
  before :each do
21
- stub_get.to_return(xml_response("com.xml"))
22
- @result = DMM::new.item_list.result
29
+ stub_get.to_return(xml_response('com.xml'))
30
+ @result = DMM.new.item_list.result
23
31
  end
24
32
 
25
33
  describe '#items' do
26
- context "items.size > 0" do
34
+ context 'items.size > 0' do
27
35
  subject { @result }
28
- its(:items) { should be_an(Array) }
36
+
37
+ describe '#items' do
38
+ subject { super().items }
39
+ it { is_expected.to be_an(Array) }
40
+ end
29
41
  specify do
30
42
  subject.items.each do |item|
31
- item.should be_a(DMM::Response::Item)
43
+ expect(item).to be_a(DMM::Response::Item)
32
44
  end
33
45
  end
34
46
  end
35
47
 
36
- context "items.size == 0" do
48
+ context 'items.size == 0' do
37
49
  before do
38
- stub_get.to_return(xml_response("zero_items.xml"))
39
- @result = DMM::new.item_list.result
50
+ stub_get.to_return(xml_response('zero_items.xml'))
51
+ @result = DMM.new.item_list.result
40
52
  end
41
53
 
42
54
  subject { @result }
43
- its(:items) { should be_an(Array) }
55
+
56
+ describe '#items' do
57
+ subject { super().items }
58
+ it { is_expected.to be_an(Array) }
59
+ end
44
60
  specify do
45
- subject.items.size.should == 0
61
+ expect(subject.items.size).to eq(0)
46
62
  end
47
63
  end
48
64
  end
@@ -50,8 +66,12 @@ describe DMM::Response::Result do
50
66
  describe 'instance methods' do
51
67
  subject { @result }
52
68
  (DMM::Response::Result::RESULT_KEYS - [:items]).each do |key|
53
- it { should respond_to(key) }
54
- its(key) { should be_a(Integer) }
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
55
75
  end
56
76
  end
57
77
  end
@@ -1,5 +1,6 @@
1
- require "ruby-dmm"
2
- require "webmock/rspec"
1
+ # encoding: utf-8
2
+ require 'ruby-dmm'
3
+ require 'webmock/rspec'
3
4
 
4
5
  require 'coveralls'
5
6
  Coveralls.wear!
@@ -11,7 +12,6 @@ Coveralls.wear!
11
12
  #
12
13
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
13
14
  RSpec.configure do |config|
14
- config.treat_symbols_as_metadata_keys_with_true_values = true
15
15
  config.run_all_when_everything_filtered = true
16
16
  config.filter_run :focus
17
17
 
@@ -23,15 +23,15 @@ RSpec.configure do |config|
23
23
  end
24
24
 
25
25
  def fixture_path
26
- File.expand_path(File.dirname(__FILE__) + "/fixtures/")
26
+ File.expand_path(File.dirname(__FILE__) + '/fixtures/')
27
27
  end
28
28
 
29
29
  def fixture(file)
30
- File.new(fixture_path + '/' + file, "rb")
30
+ File.new(fixture_path + '/' + file, 'rb')
31
31
  end
32
32
 
33
33
  def all_fixtures
34
- Dir.glob(fixture_path + '/' + "*.xml").map {|x| File.basename(x) }.sort
34
+ Dir.glob(fixture_path + '/' + '*.xml').map { |x| File.basename(x) }.sort
35
35
  end
36
36
 
37
37
  def fixtures
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-dmm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - meganemura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-30 00:00:00.000000000 Z
11
+ date: 2014-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -66,6 +66,132 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: ox
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: coveralls
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: simplecov
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
69
195
  description: Client for the DMM Web Service API 2.0.
70
196
  email:
71
197
  - mura2megane@gmail.com
@@ -75,6 +201,8 @@ extra_rdoc_files: []
75
201
  files:
76
202
  - .gitignore
77
203
  - .rspec
204
+ - .rubocop.yml
205
+ - .rubocop_todo.yml
78
206
  - .travis.yml
79
207
  - Gemfile
80
208
  - Guardfile