rakuten_web_service 1.12.0 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +12 -0
- data/.travis.yml +4 -16
- data/CHANGELOG.md +28 -0
- data/Gemfile +3 -3
- data/README.ja.md +118 -48
- data/README.md +30 -6
- data/examples/ichiba_item_search.rb +1 -1
- data/examples/recipe_search.rb +16 -0
- data/lib/rakuten_web_service/all_proxy.rb +2 -1
- data/lib/rakuten_web_service/books/genre.rb +1 -1
- data/lib/rakuten_web_service/books/resource.rb +1 -1
- data/lib/rakuten_web_service/books/total.rb +1 -1
- data/lib/rakuten_web_service/client.rb +9 -9
- data/lib/rakuten_web_service/error.rb +5 -0
- data/lib/rakuten_web_service/genre.rb +1 -1
- data/lib/rakuten_web_service/gora/course.rb +1 -1
- data/lib/rakuten_web_service/gora/course_detail.rb +1 -1
- data/lib/rakuten_web_service/gora/plan.rb +1 -1
- data/lib/rakuten_web_service/ichiba/item.rb +1 -1
- data/lib/rakuten_web_service/ichiba/product.rb +1 -1
- data/lib/rakuten_web_service/ichiba/ranking.rb +1 -1
- data/lib/rakuten_web_service/ichiba/tag.rb +5 -0
- data/lib/rakuten_web_service/ichiba/tag_group.rb +2 -6
- data/lib/rakuten_web_service/kobo/ebook.rb +1 -1
- data/lib/rakuten_web_service/kobo/genre.rb +1 -1
- data/lib/rakuten_web_service/recipe.rb +1 -1
- data/lib/rakuten_web_service/recipe/category.rb +3 -1
- data/lib/rakuten_web_service/resource.rb +29 -20
- data/lib/rakuten_web_service/response.rb +5 -4
- data/lib/rakuten_web_service/search_result.rb +14 -15
- data/lib/rakuten_web_service/travel/area_class.rb +28 -22
- data/lib/rakuten_web_service/travel/hotel.rb +3 -1
- data/lib/rakuten_web_service/travel/search_result.rb +1 -1
- data/lib/rakuten_web_service/version.rb +1 -1
- data/rakuten_web_service.gemspec +6 -4
- data/spec/rakuten_web_service/genre_spec.rb +1 -1
- data/spec/rakuten_web_service/ichiba/tag_spec.rb +17 -0
- data/spec/rakuten_web_service/resource_spec.rb +2 -2
- data/spec/rakuten_web_service/response_spec.rb +7 -7
- data/spec/rakuten_web_service/travel/search_result_spec.rb +4 -4
- metadata +43 -15
- data/spec/integration/integration_spec.rb +0 -81
@@ -5,7 +5,7 @@ require 'rakuten_web_service/genre'
|
|
5
5
|
module RakutenWebService
|
6
6
|
module Books
|
7
7
|
class Genre < RakutenWebService::BaseGenre
|
8
|
-
|
8
|
+
self.resource_name = 'books_genre'
|
9
9
|
|
10
10
|
endpoint 'https://app.rakuten.co.jp/services/api/BooksGenre/Search/20121128'
|
11
11
|
|
@@ -7,7 +7,7 @@ module RakutenWebService
|
|
7
7
|
class Total < Books::Resource
|
8
8
|
endpoint 'https://app.rakuten.co.jp/services/api/BooksTotal/Search/20170404'
|
9
9
|
|
10
|
-
|
10
|
+
parser do |response|
|
11
11
|
response['Items'].map do |item|
|
12
12
|
resource_class = find_resource_by_genre_id(item['booksGenreId'])
|
13
13
|
resource_class.new(item)
|
@@ -9,6 +9,8 @@ require 'rakuten_web_service/error'
|
|
9
9
|
|
10
10
|
module RakutenWebService
|
11
11
|
class Client
|
12
|
+
USER_AGENT = "RakutenWebService SDK for Ruby v#{RWS::VERSION}(ruby-#{RUBY_VERSION} [#{RUBY_PLATFORM}])".freeze
|
13
|
+
|
12
14
|
attr_reader :url
|
13
15
|
|
14
16
|
def initialize(resource_class)
|
@@ -20,25 +22,23 @@ module RakutenWebService
|
|
20
22
|
params = RakutenWebService.configuration.generate_parameters(params)
|
21
23
|
response = request(url.path, params)
|
22
24
|
body = JSON.parse(response.body)
|
23
|
-
|
24
|
-
|
25
|
-
return RakutenWebService::Response.new(@resource_class, body)
|
25
|
+
unless response.is_a?(Net::HTTPSuccess)
|
26
|
+
raise RakutenWebService::Error.for(response)
|
26
27
|
end
|
27
|
-
|
28
|
+
|
29
|
+
RakutenWebService::Response.new(@resource_class, body)
|
28
30
|
end
|
29
31
|
|
30
32
|
private
|
31
33
|
|
32
34
|
def request(path, params)
|
33
|
-
http = Net::HTTP.new(
|
35
|
+
http = Net::HTTP.new(url.host, url.port)
|
34
36
|
http.use_ssl = true
|
35
37
|
if RakutenWebService.configuration.debug_mode?
|
36
38
|
http.set_debug_output($stderr)
|
37
39
|
end
|
38
|
-
path = "#{path}?#{
|
39
|
-
header = {
|
40
|
-
'User-Agent' => "RakutenWebService SDK for Ruby v#{RWS::VERSION}(ruby-#{RUBY_VERSION} [#{RUBY_PLATFORM}])"
|
41
|
-
}
|
40
|
+
path = "#{path}?#{URI.encode_www_form(params)}"
|
41
|
+
header = { 'User-Agent' => USER_AGENT }
|
42
42
|
http.get(path, header)
|
43
43
|
end
|
44
44
|
end
|
@@ -6,6 +6,11 @@ module RakutenWebService
|
|
6
6
|
repository[status_code] = error
|
7
7
|
end
|
8
8
|
|
9
|
+
def self.for(response)
|
10
|
+
error_class = repository[response.code.to_i]
|
11
|
+
error_class.new(JSON.parse(response.body)['error_description'])
|
12
|
+
end
|
13
|
+
|
9
14
|
def self.repository
|
10
15
|
@repository ||= {}
|
11
16
|
end
|
@@ -7,7 +7,7 @@ module RakutenWebService
|
|
7
7
|
def self.inherited(klass)
|
8
8
|
super
|
9
9
|
|
10
|
-
klass.
|
10
|
+
klass.parser do |response|
|
11
11
|
current = response['current']
|
12
12
|
%w[children parents brothers].each do |type|
|
13
13
|
elements = Array(response[type]).map { |e| klass.new(e) }
|
@@ -7,7 +7,7 @@ module RakutenWebService
|
|
7
7
|
class RankingItem < RakutenWebService::Ichiba::Item
|
8
8
|
endpoint 'https://app.rakuten.co.jp/services/api/IchibaItem/Ranking/20170628'
|
9
9
|
|
10
|
-
|
10
|
+
parser do |response|
|
11
11
|
response['Items'].map { |item| RankingItem.new(item) }
|
12
12
|
end
|
13
13
|
|
@@ -7,7 +7,7 @@ module RakutenWebService
|
|
7
7
|
class TagGroup < Resource
|
8
8
|
endpoint 'https://app.rakuten.co.jp/services/api/IchibaTag/Search/20140222'
|
9
9
|
|
10
|
-
|
10
|
+
parser do |response|
|
11
11
|
response['tagGroups'].map { |tag_group| TagGroup.new(tag_group) }
|
12
12
|
end
|
13
13
|
|
@@ -15,11 +15,7 @@ module RakutenWebService
|
|
15
15
|
|
16
16
|
def tags
|
17
17
|
get_attribute('tags').map do |tag|
|
18
|
-
Tag.new(
|
19
|
-
'tagId' => tag['tagId'],
|
20
|
-
'tagName' => tag['tagName'],
|
21
|
-
'parentTagId' => tag['parentTagId']
|
22
|
-
)
|
18
|
+
Tag.new(tag)
|
23
19
|
end
|
24
20
|
end
|
25
21
|
end
|
@@ -37,7 +37,9 @@ module RakutenWebService
|
|
37
37
|
|
38
38
|
def parent_category
|
39
39
|
return nil if parent_category_type.nil?
|
40
|
-
Recipe.categories(parent_category_type).find
|
40
|
+
Recipe.categories(parent_category_type).find do |c|
|
41
|
+
c.id.to_i == parent_category_id.to_i
|
42
|
+
end
|
41
43
|
end
|
42
44
|
|
43
45
|
def absolute_category_id
|
@@ -12,6 +12,8 @@ module RakutenWebService
|
|
12
12
|
using RakutenWebService::StringSupport
|
13
13
|
|
14
14
|
class << self
|
15
|
+
attr_writer :resource_name
|
16
|
+
|
15
17
|
def inherited(subclass)
|
16
18
|
@@subclasses ||= []
|
17
19
|
@@subclasses.push(subclass)
|
@@ -24,20 +26,11 @@ module RakutenWebService
|
|
24
26
|
def attribute(*attribute_names)
|
25
27
|
attribute_names.each do |attribute_name|
|
26
28
|
attribute_name = attribute_name.to_s
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
get_attribute(attribute_name)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
next if method_name !~ /(.+)_flag$/
|
36
|
-
instance_eval do
|
37
|
-
define_method "#{$1}?" do
|
38
|
-
get_attribute(attribute_name) == 1
|
39
|
-
end
|
40
|
-
end
|
29
|
+
|
30
|
+
define_getter_for_attribute(attribute_name)
|
31
|
+
next unless attribute_name.end_with?('Flag')
|
32
|
+
|
33
|
+
define_asking_method_for_attribute(attribute_name)
|
41
34
|
end
|
42
35
|
end
|
43
36
|
|
@@ -57,19 +50,36 @@ module RakutenWebService
|
|
57
50
|
@resource_name ||= name.split('::').last.downcase
|
58
51
|
end
|
59
52
|
|
60
|
-
def set_resource_name(name)
|
61
|
-
@resource_name = name
|
62
|
-
end
|
63
|
-
|
64
53
|
def endpoint(url = nil)
|
65
54
|
@endpoint = url || @endpoint
|
66
55
|
end
|
67
56
|
|
68
|
-
def
|
57
|
+
def parser(&block)
|
69
58
|
instance_eval do
|
70
59
|
define_singleton_method :parse_response, block
|
71
60
|
end
|
72
61
|
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def define_getter_for_attribute(attribute_name)
|
66
|
+
method_name = attribute_name.to_snake
|
67
|
+
method_name.sub!(/^#{resource_name}_(\w+)$/, '\1')
|
68
|
+
|
69
|
+
define_method method_name do
|
70
|
+
get_attribute(attribute_name)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def define_asking_method_for_attribute(attribute_name)
|
75
|
+
method_name = attribute_name.to_snake
|
76
|
+
method_name.sub!(/^#{resource_name}_(\w+)$/, '\1')
|
77
|
+
method_name.sub!(/(.+)_flag$/, '\1')
|
78
|
+
|
79
|
+
define_method "#{method_name}?" do
|
80
|
+
get_attribute(attribute_name) == 1
|
81
|
+
end
|
82
|
+
end
|
73
83
|
end
|
74
84
|
|
75
85
|
def initialize(params)
|
@@ -79,7 +89,6 @@ module RakutenWebService
|
|
79
89
|
|
80
90
|
def [](key)
|
81
91
|
camel_key = key.to_camel
|
82
|
-
# camel_key[0] = camel_key[0].downcase
|
83
92
|
@params[key] || @params[camel_key]
|
84
93
|
end
|
85
94
|
|
@@ -33,6 +33,7 @@ module RakutenWebService
|
|
33
33
|
def genre_information
|
34
34
|
return unless @resource_class.respond_to?(:genre_class)
|
35
35
|
return if self['GenreInformation'].empty?
|
36
|
+
|
36
37
|
RWS::GenreInformation.new(self['GenreInformation'][0], @resource_class.genre_class)
|
37
38
|
end
|
38
39
|
|
@@ -40,12 +41,12 @@ module RakutenWebService
|
|
40
41
|
@resources ||= @resource_class.parse_response(@json)
|
41
42
|
end
|
42
43
|
|
43
|
-
def
|
44
|
-
page &&
|
44
|
+
def next_page?
|
45
|
+
page && !last_page?
|
45
46
|
end
|
46
47
|
|
47
|
-
def
|
48
|
-
page &&
|
48
|
+
def previous_page?
|
49
|
+
page && !first_page?
|
49
50
|
end
|
50
51
|
|
51
52
|
def first_page?
|
@@ -43,20 +43,19 @@ module RakutenWebService
|
|
43
43
|
|
44
44
|
def order(options)
|
45
45
|
new_params = params.dup
|
46
|
-
if options.
|
47
|
-
key, sort_order = *options.to_a.last
|
48
|
-
key = key.to_s.to_camel
|
49
|
-
new_params[:sort] = case sort_order.to_s.downcase
|
50
|
-
when 'desc'
|
51
|
-
"-#{key}"
|
52
|
-
when 'asc'
|
53
|
-
"+#{key}"
|
54
|
-
end
|
55
|
-
elsif options.to_s == 'standard'
|
46
|
+
if options.to_s == 'standard'
|
56
47
|
new_params[:sort] = 'standard'
|
57
|
-
|
48
|
+
return self.class.new(new_params, @resource_class)
|
49
|
+
end
|
50
|
+
unless options.is_a? Hash
|
58
51
|
raise ArgumentError, "Invalid Sort Option: #{options.inspect}"
|
59
52
|
end
|
53
|
+
|
54
|
+
key, sort_order = *options.to_a.last
|
55
|
+
case sort_order.to_s.downcase
|
56
|
+
when 'desc' then new_params[:sort] = "-#{key}".to_camel
|
57
|
+
when 'asc' then new_params[:sort] = "+#{key}".to_camel
|
58
|
+
end
|
60
59
|
self.class.new(new_params, @resource_class)
|
61
60
|
end
|
62
61
|
|
@@ -69,16 +68,16 @@ module RakutenWebService
|
|
69
68
|
@response ||= query
|
70
69
|
end
|
71
70
|
|
72
|
-
def
|
73
|
-
response.
|
71
|
+
def next_page?
|
72
|
+
response.next_page?
|
74
73
|
end
|
75
74
|
|
76
75
|
def next_page
|
77
76
|
search(page: response.page + 1)
|
78
77
|
end
|
79
78
|
|
80
|
-
def
|
81
|
-
response.
|
79
|
+
def previous_page?
|
80
|
+
response.previous_page?
|
82
81
|
end
|
83
82
|
|
84
83
|
def previous_page
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rakuten_web_service/travel/resource'
|
2
4
|
|
3
5
|
module RakutenWebService
|
@@ -8,9 +10,9 @@ module RakutenWebService
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def [](class_code)
|
11
|
-
LargeClass[class_code]
|
12
|
-
MiddleClass[class_code]
|
13
|
-
SmallClass[class_code]
|
13
|
+
LargeClass[class_code] ||
|
14
|
+
MiddleClass[class_code] ||
|
15
|
+
SmallClass[class_code] ||
|
14
16
|
DetailClass[class_code]
|
15
17
|
end
|
16
18
|
module_function :search, :[]
|
@@ -18,7 +20,7 @@ module RakutenWebService
|
|
18
20
|
class Base < RakutenWebService::Travel::Resource
|
19
21
|
endpoint 'https://app.rakuten.co.jp/services/api/Travel/GetAreaClass/20131024'
|
20
22
|
|
21
|
-
|
23
|
+
parser do |response|
|
22
24
|
response['areaClasses']['largeClasses'].map do |data|
|
23
25
|
LargeClass.new(data)
|
24
26
|
end
|
@@ -60,26 +62,17 @@ module RakutenWebService
|
|
60
62
|
|
61
63
|
attr_reader :parent, :children
|
62
64
|
|
63
|
-
def initialize(
|
65
|
+
def initialize(class_data, parent = nil)
|
64
66
|
@parent = parent
|
65
|
-
class_data
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
if !children.nil? && !children.empty?
|
74
|
-
children_class = children.keys.first[/\A(\w*)Classes\Z/, 1]
|
75
|
-
class_name = "#{children_class}Classes"
|
76
|
-
@params[class_name] = children[class_name].map do |child_data|
|
77
|
-
Base.area_classes[children_class].new(child_data["#{children_class}Class"], self)
|
78
|
-
end
|
79
|
-
@children = @params[class_name]
|
80
|
-
else
|
81
|
-
@children = []
|
67
|
+
case class_data
|
68
|
+
when Array
|
69
|
+
@params = class_data.shift
|
70
|
+
@children = class_data.shift
|
71
|
+
when Hash
|
72
|
+
@params = class_data
|
73
|
+
@children = nil
|
82
74
|
end
|
75
|
+
parse_children_attributes
|
83
76
|
end
|
84
77
|
|
85
78
|
def area_level
|
@@ -105,6 +98,19 @@ module RakutenWebService
|
|
105
98
|
|
106
99
|
Hotel.search(params)
|
107
100
|
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def parse_children_attributes
|
105
|
+
return @children = [] if children.nil? || children.empty?
|
106
|
+
|
107
|
+
children_class = children.keys.first[/\A(\w*)Classes\Z/, 1]
|
108
|
+
class_name = "#{children_class}Classes"
|
109
|
+
params[class_name] = children[class_name].map do |child_data|
|
110
|
+
Base.area_classes[children_class].new(child_data["#{children_class}Class"], self)
|
111
|
+
end
|
112
|
+
@children = params[class_name]
|
113
|
+
end
|
108
114
|
end
|
109
115
|
|
110
116
|
class LargeClass < Base
|