rakuten_web_service 1.9.0 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +0 -3
  3. data/CHANGELOG.md +7 -0
  4. data/lib/rakuten_web_service.rb +2 -0
  5. data/lib/rakuten_web_service/all_proxy.rb +2 -0
  6. data/lib/rakuten_web_service/books.rb +2 -0
  7. data/lib/rakuten_web_service/books/book.rb +2 -0
  8. data/lib/rakuten_web_service/books/cd.rb +2 -0
  9. data/lib/rakuten_web_service/books/dvd.rb +2 -0
  10. data/lib/rakuten_web_service/books/foreign_book.rb +2 -0
  11. data/lib/rakuten_web_service/books/game.rb +2 -0
  12. data/lib/rakuten_web_service/books/genre.rb +5 -3
  13. data/lib/rakuten_web_service/books/magazine.rb +2 -0
  14. data/lib/rakuten_web_service/books/resource.rb +7 -3
  15. data/lib/rakuten_web_service/books/software.rb +2 -0
  16. data/lib/rakuten_web_service/books/total.rb +2 -0
  17. data/lib/rakuten_web_service/client.rb +4 -2
  18. data/lib/rakuten_web_service/configuration.rb +10 -9
  19. data/lib/rakuten_web_service/error.rb +2 -0
  20. data/lib/rakuten_web_service/genre.rb +15 -19
  21. data/lib/rakuten_web_service/genre_information.rb +2 -0
  22. data/lib/rakuten_web_service/gora.rb +2 -0
  23. data/lib/rakuten_web_service/gora/course.rb +3 -1
  24. data/lib/rakuten_web_service/gora/course_detail.rb +6 -4
  25. data/lib/rakuten_web_service/gora/plan.rb +4 -2
  26. data/lib/rakuten_web_service/ichiba.rb +2 -0
  27. data/lib/rakuten_web_service/ichiba/genre.rb +6 -4
  28. data/lib/rakuten_web_service/ichiba/item.rb +9 -7
  29. data/lib/rakuten_web_service/ichiba/product.rb +3 -1
  30. data/lib/rakuten_web_service/ichiba/ranking.rb +2 -0
  31. data/lib/rakuten_web_service/ichiba/shop.rb +4 -2
  32. data/lib/rakuten_web_service/kobo.rb +2 -0
  33. data/lib/rakuten_web_service/kobo/ebook.rb +4 -2
  34. data/lib/rakuten_web_service/kobo/genre.rb +4 -2
  35. data/lib/rakuten_web_service/recipe.rb +4 -2
  36. data/lib/rakuten_web_service/recipe/category.rb +9 -8
  37. data/lib/rakuten_web_service/resource.rb +18 -21
  38. data/lib/rakuten_web_service/response.rb +2 -0
  39. data/lib/rakuten_web_service/search_result.rb +14 -21
  40. data/lib/rakuten_web_service/version.rb +3 -1
  41. data/rakuten_web_service.gemspec +1 -1
  42. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c4169e0d70507985294102d0f0db8bed893ba62f
4
- data.tar.gz: ba7ef71f07923fc35b68f0dbad9395027604fc6b
2
+ SHA256:
3
+ metadata.gz: fd60bf746130b97cac7b59e6a529457183b6eae42f3eb595b64c4aa820b2bbcd
4
+ data.tar.gz: e773d058c29619d931bda28e656f7fe7cea63816905c56e20fa55c7a84662d49
5
5
  SHA512:
6
- metadata.gz: c0207c56e46c0be2d36dcf352d210774cb0e809362b723e6ea974c318477013780efd6d6c00c678bfc522b8a8f7d1151d6235f7590b8eb8f7356a678f5dc8426
7
- data.tar.gz: 99c58dea96689887906f615a08d01198c03b5a3ce212d671971d47be0dbea57296d73983724cbd591b4340a99eafe91f328ff57eb519c73c5725aaa0b0f28af5
6
+ metadata.gz: a68b23e18568d9e7cc60213b2fc881d02085966f809f7dd7e3e503e8c7404096ee46ea5120b2740ad896f4699a915cd57cf53af892ee17cb47aafc7944bb8031
7
+ data.tar.gz: ce2b779f0eddebd1c9246dc041bc277b84a3047e3428f7150ccfd2c60ecc204fa73b89817f31380e80d5c393e09a382cbf765569871912387f2153e2ba6cbf95
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.9
4
3
  - 2.3.6
5
4
  - 2.4.3
6
5
  - 2.5.0
@@ -27,8 +26,6 @@ matrix:
27
26
  allow_failures:
28
27
  - rvm: ruby-head
29
28
  exclude:
30
- - rvm: 2.2.9
31
- env: INTEGRATION=yes
32
29
  - rvm: 2.3.6
33
30
  env: INTEGRATION=yes
34
31
  - rvm: 2.4.3
@@ -1,3 +1,10 @@
1
+ # v1.9.1 (2018/03/30)
2
+
3
+ ## Improvements
4
+
5
+ * Use the magic comment to frozen all string literals.[#93](https://github.com/rakuten-ws/rws-ruby-sdk/pull/93)
6
+ * Drop ruby 2.2 from supported ruby versions since it goes to the EOL. [#95](https://github.com/rakuten-ws/rws-ruby-sdk/pull/95)
7
+
1
8
  # v1.9.0 (2018/01/04)
2
9
 
3
10
  ## Enhancements
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakutenWebService; end
2
4
  RWS = RakutenWebService
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakutenWebService
2
4
  class AllProxy
3
5
  include Enumerable
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/version'
2
4
  require 'rakuten_web_service/configuration'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/books/resource'
2
4
 
3
5
  module RakutenWebService
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/books/resource'
2
4
 
3
5
  module RakutenWebService
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/books/resource'
2
4
 
3
5
  module RakutenWebService
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/resource'
2
4
 
3
5
  module RakutenWebService
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/books/resource'
2
4
 
3
5
  module RakutenWebService
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/genre'
2
4
 
3
5
  module RakutenWebService
@@ -11,9 +13,9 @@ module RakutenWebService
11
13
 
12
14
  root_id '000'
13
15
 
14
- def search(params={})
15
- params = params.merge(booksGenreId: self.id)
16
- resource = Books::Resource.find_resource_by_genre_id(self.id)
16
+ def search(params = {})
17
+ params = params.merge(booksGenreId: id)
18
+ resource = Books::Resource.find_resource_by_genre_id(id)
17
19
  resource.search(params)
18
20
  end
19
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/books/resource'
2
4
 
3
5
  module RakutenWebService
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/resource'
2
4
  require 'rakuten_web_service/books/genre'
3
5
 
@@ -5,7 +7,7 @@ module RakutenWebService
5
7
  module Books
6
8
  class Resource < RakutenWebService::Resource
7
9
  set_parser do |response|
8
- response['Items'].map { |item| self.new(item) }
10
+ response['Items'].map { |item| new(item) }
9
11
  end
10
12
 
11
13
  def self.find_resource_by_genre_id(genre_id)
@@ -25,7 +27,7 @@ module RakutenWebService
25
27
  end
26
28
 
27
29
  def genre
28
- @genre ||= self.books_genre_id.split('/').map do |id|
30
+ @genre ||= books_genre_id.split('/').map do |id|
29
31
  Books::Genre.new(id)
30
32
  end
31
33
  end
@@ -34,10 +36,11 @@ module RakutenWebService
34
36
  def get_attribute(name)
35
37
  name = name.to_s
36
38
  update_params unless @params[name]
37
- @params[name]
39
+ @params[name]
38
40
  end
39
41
 
40
42
  private
43
+
41
44
  def update_params
42
45
  item = self.class.search(update_key => self[update_key]).first
43
46
  @params = item.params
@@ -48,6 +51,7 @@ module RakutenWebService
48
51
  end
49
52
 
50
53
  protected
54
+
51
55
  def params
52
56
  @params.dup
53
57
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/books/resource'
2
4
 
3
5
  module RakutenWebService
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/books/resource'
2
4
 
3
5
  module RakutenWebService
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
  require 'net/http'
3
5
  require 'cgi'
@@ -21,12 +23,12 @@ module RakutenWebService
21
23
 
22
24
  if Net::HTTPSuccess === response
23
25
  return RakutenWebService::Response.new(@resource_class, body)
24
- else
25
- raise RakutenWebService::Error.repository[response.code.to_i], body['error_description']
26
26
  end
27
+ raise RakutenWebService::Error.repository[response.code.to_i], body['error_description']
27
28
  end
28
29
 
29
30
  private
31
+
30
32
  def request(path, params)
31
33
  http = Net::HTTP.new(@url.host, @url.port)
32
34
  http.use_ssl = true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakutenWebService
2
4
  class Configuration
3
5
  attr_accessor :application_id, :affiliate_id, :max_retries, :debug
@@ -13,7 +15,7 @@ module RakutenWebService
13
15
  end
14
16
 
15
17
  def default_parameters
16
- raise "Application ID is not defined" unless has_required_options?
18
+ raise 'Application ID is not defined' unless has_required_options?
17
19
  { application_id: application_id, affiliate_id: affiliate_id, format_version: '2' }
18
20
  end
19
21
 
@@ -22,10 +24,11 @@ module RakutenWebService
22
24
  end
23
25
 
24
26
  def debug_mode?
25
- ENV.has_key?('RWS_SDK_DEBUG') || debug
27
+ ENV.key?('RWS_SDK_DEBUG') || debug
26
28
  end
27
29
 
28
30
  private
31
+
29
32
  def convert_snake_key_to_camel_key(params)
30
33
  params.inject({}) do |h, (k, v)|
31
34
  k = k.to_s.gsub(/([a-z]{1})_([a-z]{1})/) { "#{$1}#{$2.capitalize}" }
@@ -38,17 +41,15 @@ module RakutenWebService
38
41
  def configure(&block)
39
42
  @configuration ||= Configuration.new
40
43
  if block
41
- if block.arity != 1
42
- raise ArgumentError, 'Block is required to have one argument'
43
- end
44
- block.call(@configuration)
44
+ raise ArgumentError, 'Block is required to have one argument' if block.arity != 1
45
+ yield @configuration
45
46
  end
46
- return @configuration
47
+ @configuration
47
48
  end
48
49
 
49
50
  def configuration(&block)
50
- $stderr.puts "Warning: RakutenWebService.configuration is deprecated. Use RakutenWebService.configure." if block_given?
51
- self.configure(&block)
51
+ warn 'Warning: RakutenWebService.configuration is deprecated. Use RakutenWebService.configure.' if block_given?
52
+ configure(&block)
52
53
  end
53
54
 
54
55
  module_function :configure, :configuration
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakutenWebService
2
4
  class Error < StandardError
3
5
  def self.register(status_code, error)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/resource'
2
4
 
3
5
  module RakutenWebService
@@ -5,13 +7,10 @@ module RakutenWebService
5
7
  def self.inherited(klass)
6
8
  klass.set_parser do |response|
7
9
  current = response['current']
8
- children = Array(response['children']).map { |child| klass.new(child) }
9
- current.merge!('children' => children)
10
- parents = Array(response['parents']).map { |parent| klass.new(parent) }
11
- current.merge!('parents' => parents)
12
- brothers = Array(response['brothers']).map { |brother| klass.new(brother) }
13
- current.merge!('brothers' => brothers)
14
-
10
+ %w[children parents brothers].each do |type|
11
+ elements = Array(response[type]).map { |e| klass.new(e) }
12
+ current.merge!(type => elements)
13
+ end
15
14
  genre = klass.new(current)
16
15
  [genre]
17
16
  end
@@ -20,11 +19,8 @@ module RakutenWebService
20
19
  def self.new(params)
21
20
  case params
22
21
  when Integer, String
23
- unless repository[params.to_s].nil?
24
- self.new(repository[params.to_s])
25
- else
26
- search(genre_id_key => params.to_s).first
27
- end
22
+ return new(repository[params.to_s]) unless repository[params.to_s].nil?
23
+ search(genre_id_key => params.to_s).first
28
24
  when Hash
29
25
  super
30
26
  end
@@ -34,16 +30,16 @@ module RakutenWebService
34
30
  :"#{resource_name}_id"
35
31
  end
36
32
 
37
- def self.root_id(id=nil)
33
+ def self.root_id(id = nil)
38
34
  @root_id = id || @root_id
39
35
  end
40
36
 
41
37
  def self.root
42
- self.new(root_id)
38
+ new(root_id)
43
39
  end
44
40
 
45
41
  def self.[](id)
46
- self.new(repository[id.to_s] || id)
42
+ new(repository[id.to_s] || id)
47
43
  end
48
44
 
49
45
  def self.[]=(id, genre)
@@ -56,19 +52,19 @@ module RakutenWebService
56
52
 
57
53
  def initialize(params)
58
54
  super
59
- self.class[self.id.to_s] = @params.reject { |k, _| k == 'itemCount' }
55
+ self.class[id.to_s] = @params.reject { |k, _| k == 'itemCount' }
60
56
  end
61
57
 
62
58
  def children
63
- @params['children'] ||= self.class.search(self.class.genre_id_key => self.id).first.children
59
+ @params['children'] ||= self.class.search(self.class.genre_id_key => id).first.children
64
60
  end
65
61
 
66
62
  def brothers
67
- @params['brothers'] ||= self.class.search(self.class.genre_id_key => self.id).first.brothers
63
+ @params['brothers'] ||= self.class.search(self.class.genre_id_key => id).first.brothers
68
64
  end
69
65
 
70
66
  def parents
71
- @params['parents'] ||= self.class.search(self.class.genre_id_key => self.id).first.parents
67
+ @params['parents'] ||= self.class.search(self.class.genre_id_key => id).first.parents
72
68
  end
73
69
  end
74
70
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakutenWebService
2
4
  class GenreInformation
3
5
  attr_reader :parent, :current, :children
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/gora/course'
2
4
  require 'rakuten_web_service/gora/course_detail'
3
5
  require 'rakuten_web_service/gora/plan'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/resource'
2
4
 
3
5
  module RakutenWebService
@@ -6,7 +8,7 @@ module RakutenWebService
6
8
  endpoint 'https://app.rakuten.co.jp/services/api/Gora/GoraGolfCourseSearch/20170623'
7
9
 
8
10
  set_parser do |response|
9
- response['Items'].map { |item| self.new(item) }
11
+ response['Items'].map { |item| new(item) }
10
12
  end
11
13
 
12
14
  attribute :golfCourseId, :golfCourseName, :golfCourseAbbr, :golfCourseNameKana, :golfCourseCaption,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/resource'
2
4
 
3
5
  module RakutenWebService
@@ -5,14 +7,14 @@ module RakutenWebService
5
7
  class CourseDetail < Resource
6
8
  class << self
7
9
  def find(golf_course_id)
8
- search({golfCourseId: golf_course_id}).first
10
+ search(golfCourseId: golf_course_id).first
9
11
  end
10
12
  end
11
13
 
12
14
  endpoint 'https://app.rakuten.co.jp/services/api/Gora/GoraGolfCourseDetail/20170623'
13
15
 
14
16
  set_parser do |response|
15
- [self.new(response['Item'])]
17
+ [new(response['Item'])]
16
18
  end
17
19
 
18
20
  attribute :carrier, :golfCourseId, :golfCourseName, :golfCourseAbbr, :golfCourseNameKana, :golfCourseCaption,
@@ -25,11 +27,11 @@ module RakutenWebService
25
27
  :meal, :course, :costperformance, :distance, :fairway, :reserveCalUrl, :voiceUrl, :layoutUrl, :routeMapUrl
26
28
 
27
29
  def ratings
28
- get_attribute('ratings').map {|rating| Rating.new(rating)}
30
+ get_attribute('ratings').map { |rating| Rating.new(rating) }
29
31
  end
30
32
 
31
33
  def new_plans
32
- get_attribute('newPlans').map {|plan| Plan.new(plan)}
34
+ get_attribute('newPlans').map { |plan| Plan.new(plan) }
33
35
  end
34
36
 
35
37
  class Rating < Resource
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/resource'
2
4
 
3
5
  module RakutenWebService
@@ -6,7 +8,7 @@ module RakutenWebService
6
8
  endpoint 'https://app.rakuten.co.jp/services/api/Gora/GoraPlanSearch/20170623'
7
9
 
8
10
  set_parser do |response|
9
- response['Items'].map { |item| self.new(item) }
11
+ response['Items'].map { |item| new(item) }
10
12
  end
11
13
 
12
14
  attribute :golfCourseId, :golfCourseName, :golfCourseAbbr, :golfCourseNameKana, :golfCourseCaption,
@@ -14,7 +16,7 @@ module RakutenWebService
14
16
  :golfCourseImageUrl, :evaluation
15
17
 
16
18
  def plan_info
17
- get_attribute('planInfo').map {|plan| PlanInfo.new(plan['plan'])}
19
+ get_attribute('planInfo').map { |plan| PlanInfo.new(plan['plan']) }
18
20
  end
19
21
 
20
22
  class PlanInfo < Resource
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/version'
2
4
  require 'rakuten_web_service/configuration'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/genre'
2
4
  require 'rakuten_web_service/ichiba/ranking'
3
5
  require 'rakuten_web_service/ichiba/product'
@@ -11,13 +13,13 @@ module RakutenWebService
11
13
 
12
14
  root_id 0
13
15
 
14
- def ranking(options={})
15
- options = options.merge(genre_id: self.id)
16
+ def ranking(options = {})
17
+ options = options.merge(genre_id: id)
16
18
  RakutenWebService::Ichiba::RankingItem.search(options)
17
19
  end
18
20
 
19
- def products(options={})
20
- options = options.merge(genre_id: self.id)
21
+ def products(options = {})
22
+ options = options.merge(genre_id: id)
21
23
  RakutenWebService::Ichiba::Product.search(options)
22
24
  end
23
25
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/resource'
2
4
 
3
5
  module RakutenWebService
@@ -35,16 +37,16 @@ module RakutenWebService
35
37
  :genreId
36
38
 
37
39
  def genre
38
- Genre.new(self.genre_id)
40
+ Genre.new(genre_id)
39
41
  end
40
42
 
41
43
  def shop
42
- Shop.new({
43
- 'shopName' => self.shop_name,
44
- 'shopCode' => self.shop_code,
45
- 'shopUrl' => self.shop_url,
46
- 'shopAffiliateUrl' => self.shop_affiliate_url
47
- })
44
+ Shop.new(
45
+ 'shopName' => shop_name,
46
+ 'shopCode' => shop_code,
47
+ 'shopUrl' => shop_url,
48
+ 'shopAffiliateUrl' => shop_affiliate_url
49
+ )
48
50
  end
49
51
  end
50
52
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/resource'
2
4
  require 'rakuten_web_service/ichiba/genre'
3
5
 
@@ -27,7 +29,7 @@ module RakutenWebService
27
29
  :ProductDetails
28
30
 
29
31
  def genre
30
- RakutenWebService::Ichiba::Genre.new(self.genre_id)
32
+ RakutenWebService::Ichiba::Genre.new(genre_id)
31
33
  end
32
34
  end
33
35
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/ichiba/item'
2
4
 
3
5
  module RakutenWebService
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/resource'
2
4
  require 'rakuten_web_service/ichiba/item'
3
5
 
@@ -6,8 +8,8 @@ module RakutenWebService
6
8
  class Shop < Resource
7
9
  attribute :shopName, :shopCode, :shopUrl, :shopAffiliateUrl
8
10
 
9
- def items(options={})
10
- options = options.merge(shop_code: self.code)
11
+ def items(options = {})
12
+ options = options.merge(shop_code: code)
11
13
  RakutenWebService::Ichiba::Item.search(options)
12
14
  end
13
15
  end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/kobo/ebook'
2
4
  require 'rakuten_web_service/kobo/genre'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/resource'
2
4
 
3
5
  module RakutenWebService
@@ -15,7 +17,7 @@ module RakutenWebService
15
17
  :koboGenreId
16
18
 
17
19
  set_parser do |response|
18
- response['Items'].map { |i| self.new(i) }
20
+ response['Items'].map { |i| new(i) }
19
21
  end
20
22
 
21
23
  def self.genre_class
@@ -23,7 +25,7 @@ module RakutenWebService
23
25
  end
24
26
 
25
27
  def genre
26
- Kobo::Genre.new(self.kobo_genre_id)
28
+ Kobo::Genre.new(kobo_genre_id)
27
29
  end
28
30
  end
29
31
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/genre'
2
4
 
3
5
  module RakutenWebService
@@ -11,8 +13,8 @@ module RakutenWebService
11
13
 
12
14
  attribute :koboGenreId, :koboGenreName, :genreLevel, :itemCount
13
15
 
14
- def search(options={})
15
- options = options.merge(self.class.genre_id_key => self.id)
16
+ def search(options = {})
17
+ options = options.merge(self.class.genre_id_key => id)
16
18
  RWS::Kobo::Ebook.search(options)
17
19
  end
18
20
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/configuration'
2
4
 
3
5
  require 'rakuten_web_service/recipe/category'
@@ -19,8 +21,8 @@ module RakutenWebService
19
21
 
20
22
  def self.ranking(category_id = nil)
21
23
  params = {}
22
- params.merge!(category_id: category_id) unless category_id.nil?
23
- self.search(params)
24
+ params = params.merge(category_id: category_id) unless category_id.nil?
25
+ search(params)
24
26
  end
25
27
 
26
28
  class << self
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakutenWebService
2
4
  class Recipe < Resource
3
5
 
@@ -35,7 +37,7 @@ module RakutenWebService
35
37
 
36
38
  def parent_category
37
39
  return nil if parent_category_type.nil?
38
- Recipe.categories(parent_category_type).find { |c| c.id.to_i === parent_category_id.to_i }
40
+ Recipe.categories(parent_category_type).find { |c| c.id.to_i == parent_category_id.to_i }
39
41
  end
40
42
 
41
43
  def absolute_category_id
@@ -47,14 +49,13 @@ module RakutenWebService
47
49
  end
48
50
 
49
51
  private
50
- def parent_category_type
51
- case type
52
- when 'small' then 'medium'
53
- when 'medium' then 'large'
54
- else
55
- nil
56
- end
52
+
53
+ def parent_category_type
54
+ case type
55
+ when 'small' then 'medium'
56
+ when 'medium' then 'large'
57
57
  end
58
+ end
58
59
  end
59
60
  end
60
61
  end
@@ -1,25 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/client'
2
4
  require 'rakuten_web_service/search_result'
3
5
 
4
6
  module RakutenWebService
5
7
  class Resource
8
+ attr_reader :params
9
+
6
10
  class << self
7
11
  def attribute(*attributes)
8
12
  attributes.each do |attribute|
9
- method_name = attribute.to_s.gsub(/([a-z]+)([A-Z]{1})/) do |_|
10
- "#{$1}_#{$2}"
11
- end.downcase
12
- method_name = method_name.sub(/^#{resource_name}_(\w+)$/) { $1 }
13
+ method_name = attribute.to_s.gsub(/([a-z]+)([A-Z]{1})/, '\1_\2').downcase
14
+ method_name = method_name.sub(/^#{resource_name}_(\w+)$/, '\1')
13
15
  instance_eval do
14
16
  define_method method_name do
15
17
  get_attribute(attribute.to_s)
16
18
  end
17
19
  end
18
- if method_name =~ /(.+)_flag$/
19
- instance_eval do
20
- define_method "#{$1}?" do
21
- get_attribute(attribute.to_s) == 1
22
- end
20
+ next if method_name !~ /(.+)_flag$/
21
+ instance_eval do
22
+ define_method "#{$1}?" do
23
+ get_attribute(attribute.to_s) == 1
23
24
  end
24
25
  end
25
26
  end
@@ -38,14 +39,14 @@ module RakutenWebService
38
39
  end
39
40
 
40
41
  def resource_name
41
- @resource_name ||= self.name.split('::').last.downcase
42
+ @resource_name ||= name.split('::').last.downcase
42
43
  end
43
44
 
44
45
  def set_resource_name(name)
45
46
  @resource_name = name
46
47
  end
47
48
 
48
- def endpoint(url=nil)
49
+ def endpoint(url = nil)
49
50
  @endpoint = url || @endpoint
50
51
  end
51
52
 
@@ -66,7 +67,8 @@ module RakutenWebService
66
67
  end
67
68
 
68
69
  def [](key)
69
- camel_key = key.gsub(/([a-z]+)_(\w{1})/) { "#{$1}#{$2.capitalize}" }
70
+ camel_key = key.split('_').map(&:capitalize).join
71
+ camel_key[0] = camel_key[0].downcase
70
72
  @params[key] || @params[camel_key]
71
73
  end
72
74
 
@@ -78,17 +80,12 @@ module RakutenWebService
78
80
  params.keys
79
81
  end
80
82
 
81
- def ==(genre)
82
- raise ArgumentError unless genre.is_a?(RakutenWebService::Resource)
83
+ def ==(other)
84
+ raise ArgumentError unless other.is_a?(RakutenWebService::Resource)
83
85
 
84
- self.params.keys.all? do |k|
85
- @params[k] == genre.params[k]
86
+ params.keys.all? do |k|
87
+ @params[k] == other.params[k]
86
88
  end
87
89
  end
88
-
89
- protected
90
- def params
91
- @params
92
- end
93
90
  end
94
91
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakutenWebService
2
4
  class Response
3
5
  include Enumerable
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rakuten_web_service/all_proxy'
2
4
  require 'rakuten_web_service/genre_information'
3
5
 
@@ -24,11 +26,8 @@ module RakutenWebService
24
26
 
25
27
  def all(&block)
26
28
  proxy = AllProxy.new(self)
27
- if block
28
- proxy.each(&block)
29
- else
30
- return proxy
31
- end
29
+ proxy.each(&block) if block
30
+ proxy
32
31
  end
33
32
 
34
33
  def params
@@ -38,7 +37,7 @@ module RakutenWebService
38
37
  def order(options)
39
38
  new_params = params.dup
40
39
  if options.is_a? Hash
41
- key, sort_order = *(options.to_a.last)
40
+ key, sort_order = *options.to_a.last
42
41
  key = camelize(key.to_s)
43
42
  new_params[:sort] = case sort_order.to_s.downcase
44
43
  when 'desc'
@@ -88,25 +87,19 @@ module RakutenWebService
88
87
  end
89
88
 
90
89
  private
91
- def ensure_retries(max_retries=RakutenWebService.configuration.max_retries)
92
- begin
93
- yield
94
- rescue RWS::TooManyRequests => e
95
- if max_retries > 0
96
- max_retries -= 1
97
- sleep 1
98
- retry
99
- else
100
- raise e
101
- end
102
- end
90
+
91
+ def ensure_retries(max_retries = RakutenWebService.configuration.max_retries)
92
+ yield
93
+ rescue RWS::TooManyRequests => e
94
+ raise e if max_retries <= 0
95
+ max_retries -= 1
96
+ sleep 1
97
+ retry
103
98
  end
104
99
 
105
100
  def camelize(str)
106
101
  str = str.downcase
107
- str = str.gsub(/([a-z]+)_([a-z]+)/) do
108
- "#{$1.capitalize}#{$2.capitalize}"
109
- end
102
+ str = str.split('_').map(&:capitalize).join
110
103
  str[0] = str[0].downcase
111
104
  str
112
105
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakutenWebService
2
- VERSION = '1.9.0'.freeze
4
+ VERSION = '1.9.1'.freeze
3
5
  end
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.files = `git ls-files`.split($/)
16
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
17
  spec.require_paths = ['lib']
18
- spec.required_ruby_version = '>= 2.2.0'
18
+ spec.required_ruby_version = '>= 2.3.0'
19
19
 
20
20
  spec.add_development_dependency 'bundler', '~> 1.3'
21
21
  spec.add_development_dependency 'rake', '~> 12.3.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rakuten_web_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tatsuya Sato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-04 00:00:00.000000000 Z
11
+ date: 2018-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -206,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
206
206
  requirements:
207
207
  - - ">="
208
208
  - !ruby/object:Gem::Version
209
- version: 2.2.0
209
+ version: 2.3.0
210
210
  required_rubygems_version: !ruby/object:Gem::Requirement
211
211
  requirements:
212
212
  - - ">="
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  version: '0'
215
215
  requirements: []
216
216
  rubyforge_project:
217
- rubygems_version: 2.5.2
217
+ rubygems_version: 2.7.3
218
218
  signing_key:
219
219
  specification_version: 4
220
220
  summary: Ruby Client for Rakuten Web Service