rakuten_web_service 1.9.1 → 1.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Gemfile +1 -1
- data/Rakefile +13 -0
- data/lib/rakuten_web_service/configuration.rb +5 -1
- data/lib/rakuten_web_service/genre.rb +2 -0
- data/lib/rakuten_web_service/resource.rb +16 -3
- data/lib/rakuten_web_service/response.rb +5 -1
- data/lib/rakuten_web_service/search_result.rb +4 -8
- data/lib/rakuten_web_service/string_support.rb +18 -0
- data/lib/rakuten_web_service/version.rb +1 -1
- data/rakuten_web_service.gemspec +2 -1
- data/spec/integration/integration_spec.rb +1 -1
- data/spec/rakuten_web_service/resource_spec.rb +30 -0
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0c08817b3b086ee80a86cf9a6799eb48af3b1ecba03f23d0b6a753d4f363b78
|
4
|
+
data.tar.gz: 310b9971d2c034a51d59f18a7a349b35fac553227ab2ec66508b64b94628c1a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8db55655f6042aa85f5300201933b58031deee31005cf6c1b4b18516c9e3b1d66c2c543ff80ea2e46e89f16729c02a1b7d54dc3573346d543f46de3809f57cf
|
7
|
+
data.tar.gz: 78b44e29c7afa9b975d15003f00781162ed665b97b96fe214c2cf6dcfdec8ce7d608b07e5b9190b383d9f2bd3899927b446d860b345018cf08f7f23667b0335e
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rspec/core/rake_task'
|
3
3
|
|
4
|
+
task :endpoints do
|
5
|
+
require 'rakuten_web_service'
|
6
|
+
require 'terminal-table'
|
7
|
+
|
8
|
+
table = Terminal::Table.new(headings: %w[Resource Endpoint]) do |t|
|
9
|
+
RakutenWebService::Resource.subclasses.each do |resource|
|
10
|
+
t << [resource.name, resource.endpoint] unless resource.endpoint.nil?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
puts table
|
15
|
+
end
|
16
|
+
|
4
17
|
RSpec::Core::RakeTask.new do |t|
|
5
18
|
t.pattern = 'spec/**/*_spec.rb'
|
6
19
|
t.rspec_opts = '-c -fd'
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'rakuten_web_service/string_support'
|
4
|
+
|
3
5
|
module RakutenWebService
|
4
6
|
class Configuration
|
5
7
|
attr_accessor :application_id, :affiliate_id, :max_retries, :debug
|
@@ -29,9 +31,11 @@ module RakutenWebService
|
|
29
31
|
|
30
32
|
private
|
31
33
|
|
34
|
+
using RakutenWebService::StringSupport
|
35
|
+
|
32
36
|
def convert_snake_key_to_camel_key(params)
|
33
37
|
params.inject({}) do |h, (k, v)|
|
34
|
-
k = k.to_s.
|
38
|
+
k = k.to_s.to_camel
|
35
39
|
h[k] = v
|
36
40
|
h
|
37
41
|
end
|
@@ -3,14 +3,27 @@
|
|
3
3
|
require 'rakuten_web_service/client'
|
4
4
|
require 'rakuten_web_service/search_result'
|
5
5
|
|
6
|
+
require 'rakuten_web_service/string_support'
|
7
|
+
|
6
8
|
module RakutenWebService
|
7
9
|
class Resource
|
8
10
|
attr_reader :params
|
9
11
|
|
12
|
+
using RakutenWebService::StringSupport
|
13
|
+
|
10
14
|
class << self
|
15
|
+
def inherited(subclass)
|
16
|
+
@@subclasses ||= []
|
17
|
+
@@subclasses.push(subclass)
|
18
|
+
end
|
19
|
+
|
20
|
+
def subclasses
|
21
|
+
@@subclasses || []
|
22
|
+
end
|
23
|
+
|
11
24
|
def attribute(*attributes)
|
12
25
|
attributes.each do |attribute|
|
13
|
-
method_name = attribute.to_s.
|
26
|
+
method_name = attribute.to_s.to_snake
|
14
27
|
method_name = method_name.sub(/^#{resource_name}_(\w+)$/, '\1')
|
15
28
|
instance_eval do
|
16
29
|
define_method method_name do
|
@@ -67,8 +80,8 @@ module RakutenWebService
|
|
67
80
|
end
|
68
81
|
|
69
82
|
def [](key)
|
70
|
-
camel_key = key.
|
71
|
-
camel_key[0] = camel_key[0].downcase
|
83
|
+
camel_key = key.to_camel
|
84
|
+
# camel_key[0] = camel_key[0].downcase
|
72
85
|
@params[key] || @params[camel_key]
|
73
86
|
end
|
74
87
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'rakuten_web_service/string_support'
|
4
|
+
|
3
5
|
module RakutenWebService
|
4
6
|
class Response
|
5
7
|
include Enumerable
|
@@ -19,8 +21,10 @@ module RakutenWebService
|
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
24
|
+
using RakutenWebService::StringSupport
|
25
|
+
|
22
26
|
%w[count hits page first last carrier pageCount].each do |name|
|
23
|
-
method_name = name.
|
27
|
+
method_name = name.to_snake
|
24
28
|
define_method method_name do
|
25
29
|
self[name]
|
26
30
|
end
|
@@ -2,11 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'rakuten_web_service/all_proxy'
|
4
4
|
require 'rakuten_web_service/genre_information'
|
5
|
+
require 'rakuten_web_service/string_support'
|
5
6
|
|
6
7
|
module RakutenWebService
|
7
8
|
class SearchResult
|
8
9
|
include Enumerable
|
9
10
|
|
11
|
+
using RakutenWebService::StringSupport
|
12
|
+
|
10
13
|
def initialize(params, resource_class)
|
11
14
|
@params = params.dup
|
12
15
|
@resource_class = resource_class
|
@@ -38,7 +41,7 @@ module RakutenWebService
|
|
38
41
|
new_params = params.dup
|
39
42
|
if options.is_a? Hash
|
40
43
|
key, sort_order = *options.to_a.last
|
41
|
-
key =
|
44
|
+
key = key.to_s.to_camel
|
42
45
|
new_params[:sort] = case sort_order.to_s.downcase
|
43
46
|
when 'desc'
|
44
47
|
"-#{key}"
|
@@ -96,12 +99,5 @@ module RakutenWebService
|
|
96
99
|
sleep 1
|
97
100
|
retry
|
98
101
|
end
|
99
|
-
|
100
|
-
def camelize(str)
|
101
|
-
str = str.downcase
|
102
|
-
str = str.split('_').map(&:capitalize).join
|
103
|
-
str[0] = str[0].downcase
|
104
|
-
str
|
105
|
-
end
|
106
102
|
end
|
107
103
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RakutenWebService
|
4
|
+
module StringSupport
|
5
|
+
refine String do
|
6
|
+
def to_snake
|
7
|
+
gsub(/([a-z]+)([A-Z]{1})/, '\1_\2').downcase
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_camel
|
11
|
+
gsub(/([a-z]{1})_([a-z]{1})/) do |matched|
|
12
|
+
matched = matched.split('_')
|
13
|
+
matched[0] + matched[1].capitalize
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/rakuten_web_service.gemspec
CHANGED
@@ -21,5 +21,6 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency 'rake', '~> 12.3.0'
|
22
22
|
spec.add_development_dependency 'rspec', '~> 3.7.0'
|
23
23
|
spec.add_development_dependency 'tapp', '~> 1.5.1'
|
24
|
-
spec.add_development_dependency '
|
24
|
+
spec.add_development_dependency 'terminal-table', '~> 1.8.0'
|
25
|
+
spec.add_development_dependency 'webmock', '~> 3.5.0'
|
25
26
|
end
|
@@ -51,7 +51,7 @@ describe 'Call all APIs', type: 'integration' do
|
|
51
51
|
expect { RWS::Recipe.categories('large') }.not_to raise_error
|
52
52
|
end
|
53
53
|
it do
|
54
|
-
expect { RWS::Recipe.categories('large').first.ranking.first }
|
54
|
+
expect { RWS::Recipe.categories('large').first.ranking.first }.not_to raise_error
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -9,6 +9,36 @@ describe RakutenWebService::Resource do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
describe '.subclasses' do
|
13
|
+
before do
|
14
|
+
resource_class
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { RakutenWebService::Resource.subclasses }
|
18
|
+
|
19
|
+
specify 'returns all sub classes of Resource' do
|
20
|
+
expect(subject).to include(resource_class)
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'When some resources are inherited from other resource' do
|
24
|
+
let(:other_resource_class) do
|
25
|
+
Class.new(resource_class) do
|
26
|
+
set_resource_name 'NestedResource'
|
27
|
+
|
28
|
+
attribute :name, :someOtherAttribute
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
before do
|
33
|
+
other_resource_class
|
34
|
+
end
|
35
|
+
|
36
|
+
specify 'includes nested resources' do
|
37
|
+
expect(subject).to include(resource_class, other_resource_class)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
12
42
|
describe '#attributes' do
|
13
43
|
let(:params) do
|
14
44
|
{
|
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.
|
4
|
+
version: 1.9.2
|
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-
|
11
|
+
date: 2018-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,20 +66,34 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 1.5.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: terminal-table
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.8.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.8.0
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: webmock
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: 3.
|
89
|
+
version: 3.5.0
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: 3.
|
96
|
+
version: 3.5.0
|
83
97
|
description: Ruby Client for Rakuten Web Service
|
84
98
|
email:
|
85
99
|
- tatsuya.b.sato@mail.rakuten.com
|
@@ -141,6 +155,7 @@ files:
|
|
141
155
|
- lib/rakuten_web_service/resource.rb
|
142
156
|
- lib/rakuten_web_service/response.rb
|
143
157
|
- lib/rakuten_web_service/search_result.rb
|
158
|
+
- lib/rakuten_web_service/string_support.rb
|
144
159
|
- lib/rakuten_web_service/version.rb
|
145
160
|
- rakuten_web_service.gemspec
|
146
161
|
- spec/fixtures/books/book_search_with_keyword_Ruby.json
|
@@ -213,8 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
228
|
- !ruby/object:Gem::Version
|
214
229
|
version: '0'
|
215
230
|
requirements: []
|
216
|
-
|
217
|
-
rubygems_version: 2.7.3
|
231
|
+
rubygems_version: 3.0.1
|
218
232
|
signing_key:
|
219
233
|
specification_version: 4
|
220
234
|
summary: Ruby Client for Rakuten Web Service
|