rms_api_ruby 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +13 -1
- data/README.md +8 -85
- data/docs/inventory_api.md +23 -0
- data/docs/item_api.md +131 -0
- data/docs/order_api.md +57 -0
- data/lib/rms_api_ruby.rb +2 -0
- data/lib/rms_api_ruby/chain.rb +3 -2
- data/lib/rms_api_ruby/chain/http_client.rb +94 -0
- data/lib/rms_api_ruby/chain/soap_client.rb +2 -1
- data/lib/rms_api_ruby/config.rb +1 -0
- data/lib/rms_api_ruby/item.rb +42 -0
- data/lib/rms_api_ruby/item/base.rb +74 -0
- data/lib/rms_api_ruby/item/delete.rb +21 -0
- data/lib/rms_api_ruby/item/get.rb +21 -0
- data/lib/rms_api_ruby/item/insert.rb +21 -0
- data/lib/rms_api_ruby/item/search.rb +21 -0
- data/lib/rms_api_ruby/item/update.rb +21 -0
- data/lib/rms_api_ruby/items.rb +43 -0
- data/lib/rms_api_ruby/utility/hash_keys_camelizable.rb +38 -0
- data/lib/rms_api_ruby/utility/hash_keys_underscorable.rb +38 -0
- data/lib/rms_api_ruby/version.rb +1 -1
- data/rms_api_ruby.gemspec +1 -0
- metadata +30 -3
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08380e4d50146bab769f56f4156751e4ce0b6788333f8c637198b7157994cb9b'
|
4
|
+
data.tar.gz: 9be7202be3b41ec3773ee918bc30c3190cb5b107b22a03f36564f8b655cc5009
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07e89f486b327e760986a491390a93784ea24c0c69f0a382dd5fcc28b529071347be4522101fb01eab727e7c09ca10c9b54a9049acfd290776d14609a2f4a510
|
7
|
+
data.tar.gz: f8edb76474508be2554e536770c2078741f2306d4133e9bb6458ac3f2d8b7da93924169c33c34f8618db597010589a21f34bf24fc49b15737d352b3ca13af1bb
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rms_api_ruby (0.
|
4
|
+
rms_api_ruby (0.3.0)
|
5
5
|
activesupport
|
6
6
|
hashie
|
7
7
|
savon (~> 2.12.0)
|
@@ -15,6 +15,8 @@ GEM
|
|
15
15
|
i18n (>= 0.7, < 2)
|
16
16
|
minitest (~> 5.1)
|
17
17
|
tzinfo (~> 1.1)
|
18
|
+
addressable (2.5.2)
|
19
|
+
public_suffix (>= 2.0.2, < 4.0)
|
18
20
|
akami (1.3.1)
|
19
21
|
gyoku (>= 0.4.0)
|
20
22
|
nokogiri
|
@@ -23,9 +25,12 @@ GEM
|
|
23
25
|
byebug (10.0.2)
|
24
26
|
coderay (1.1.2)
|
25
27
|
concurrent-ruby (1.0.5)
|
28
|
+
crack (0.4.3)
|
29
|
+
safe_yaml (~> 1.0.0)
|
26
30
|
diff-lcs (1.3)
|
27
31
|
gyoku (1.3.1)
|
28
32
|
builder (>= 2.1.2)
|
33
|
+
hashdiff (0.3.7)
|
29
34
|
hashie (3.5.7)
|
30
35
|
httpi (2.4.3)
|
31
36
|
rack
|
@@ -49,6 +54,7 @@ GEM
|
|
49
54
|
pry-byebug (3.6.0)
|
50
55
|
byebug (~> 10.0)
|
51
56
|
pry (~> 0.10)
|
57
|
+
public_suffix (3.0.2)
|
52
58
|
rack (2.0.5)
|
53
59
|
rainbow (3.0.0)
|
54
60
|
rake (10.5.0)
|
@@ -76,6 +82,7 @@ GEM
|
|
76
82
|
ruby-progressbar (~> 1.7)
|
77
83
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
78
84
|
ruby-progressbar (1.9.0)
|
85
|
+
safe_yaml (1.0.4)
|
79
86
|
savon (2.12.0)
|
80
87
|
akami (~> 1.2)
|
81
88
|
builder (>= 2.1.2)
|
@@ -93,6 +100,10 @@ GEM
|
|
93
100
|
httpi (~> 2.0)
|
94
101
|
nokogiri (>= 1.4.2)
|
95
102
|
waterfall (1.2.0)
|
103
|
+
webmock (3.4.2)
|
104
|
+
addressable (>= 2.3.6)
|
105
|
+
crack (>= 0.3.2)
|
106
|
+
hashdiff
|
96
107
|
|
97
108
|
PLATFORMS
|
98
109
|
ruby
|
@@ -105,6 +116,7 @@ DEPENDENCIES
|
|
105
116
|
rspec (~> 3.0)
|
106
117
|
rspec_junit_formatter
|
107
118
|
rubocop (~> 0.57.1)
|
119
|
+
webmock
|
108
120
|
|
109
121
|
BUNDLED WITH
|
110
122
|
1.16.2
|
data/README.md
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
# RmsApiRuby
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rms_api_ruby.svg)](https://badge.fury.io/rb/rms_api_ruby)
|
3
4
|
[![CircleCI](https://circleci.com/gh/Kaicoh/rms_api_ruby/tree/master.svg?style=svg)](https://circleci.com/gh/Kaicoh/rms_api_ruby/tree/master)
|
4
5
|
|
5
6
|
RmsApiRuby is a ruby gem for the RMS(Rakuten Marchant Service) Web API. By default all API calls will return [Hashie::Mash](https://github.com/intridea/hashie/tree/v1.2.0) objects.
|
6
|
-
At this time this gem supports OrderAPI and
|
7
|
+
At this time this gem supports OrderAPI, InventoryAPI and ItemAPI.
|
7
8
|
|
8
9
|
Support
|
9
10
|
- OrderAPI
|
10
11
|
- InventoryAPI
|
12
|
+
- ItemAPI
|
11
13
|
|
12
14
|
Not Support yet
|
13
|
-
- ItemAPI
|
14
15
|
- ProductAPI
|
15
16
|
- CabinetAPI
|
16
17
|
- NavigationAPI
|
@@ -59,92 +60,14 @@ RmsApiRuby.configure do |config|
|
|
59
60
|
config.user_name = 'user name' # default 'rms_api_ruby'
|
60
61
|
config.order_api_version = 'Order API version' # default 1.0
|
61
62
|
config.inventory_api_version = 'Inventory API version' # default 1.0
|
63
|
+
config.item_api_version = 'Item API version' # default 1.0
|
62
64
|
end
|
63
65
|
```
|
64
66
|
|
65
|
-
###
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
##### GetOrder
|
70
|
-
|
71
|
-
```ruby
|
72
|
-
args = {
|
73
|
-
is_order_number_only_flag: false,
|
74
|
-
order_number: ['Rakuten order number you want'],
|
75
|
-
}
|
76
|
-
response = RmsApiRuby::Order.get_order(args)
|
77
|
-
# => #<Hashie::Mash>
|
78
|
-
|
79
|
-
response.error_code
|
80
|
-
# => 'N00-000'
|
81
|
-
|
82
|
-
response.message
|
83
|
-
# => '正常終了'
|
84
|
-
|
85
|
-
rakuten_order = response.order_model
|
86
|
-
# => #<Hashie::Mash>
|
87
|
-
```
|
88
|
-
|
89
|
-
##### ChangeStatus
|
90
|
-
|
91
|
-
```ruby
|
92
|
-
response = RmsApiRuby::Order.get_request_id
|
93
|
-
# => #<Hashie::Mash>
|
94
|
-
|
95
|
-
response.error_code
|
96
|
-
# => 'N00-000'
|
97
|
-
|
98
|
-
response.message
|
99
|
-
# => '正常終了'
|
100
|
-
|
101
|
-
request_id = response.request_id
|
102
|
-
# => 'XXXXXXXXXX'
|
103
|
-
|
104
|
-
args = {
|
105
|
-
request_id: request_id,
|
106
|
-
order_status_model: [
|
107
|
-
{
|
108
|
-
order_number: ['Rakuten order number you want to change status'],
|
109
|
-
status_name: '発送後入金待ち'
|
110
|
-
}
|
111
|
-
]
|
112
|
-
}
|
113
|
-
|
114
|
-
response = RmsApiRuby::Order.change_status(args)
|
115
|
-
# => #<Hashie::Mash>
|
116
|
-
|
117
|
-
response.error_code
|
118
|
-
# => 'N00-000'
|
119
|
-
|
120
|
-
response.message
|
121
|
-
# => '正常終了'
|
122
|
-
|
123
|
-
```
|
124
|
-
|
125
|
-
### InventoryAPI
|
126
|
-
|
127
|
-
#### GetInventoryExternal
|
128
|
-
|
129
|
-
```ruby
|
130
|
-
args = {
|
131
|
-
inventory_search_range: 100
|
132
|
-
}
|
133
|
-
response = RmsApiRuby::Inventory.get_inventory_external(args)
|
134
|
-
# => #<Hashie::Mash>
|
135
|
-
|
136
|
-
response.keys
|
137
|
-
# => ["err_code", "err_message", "get_response_external_item", "@xmlns:n1", "@xmlns:n2", "@xsi:type"]
|
138
|
-
|
139
|
-
response.err_code
|
140
|
-
# => 'N00-000'
|
141
|
-
|
142
|
-
response.err_message
|
143
|
-
# => '正常終了'
|
144
|
-
|
145
|
-
response.get_response_external_item
|
146
|
-
# => #<Hashie::Mash>
|
147
|
-
```
|
67
|
+
### Examples
|
68
|
+
- [OrderAPI](docs/order_api.md)
|
69
|
+
- [InventoryAPI](docs/inventory_api.md)
|
70
|
+
- [ItemAPI](docs/item_api.md)
|
148
71
|
|
149
72
|
## Development
|
150
73
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
## InventoryAPI
|
2
|
+
|
3
|
+
### GetInventoryExternal
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
args = {
|
7
|
+
inventory_search_range: 100
|
8
|
+
}
|
9
|
+
response = RmsApiRuby::Inventory.get_inventory_external(args)
|
10
|
+
# => #<Hashie::Mash>
|
11
|
+
|
12
|
+
response.keys
|
13
|
+
# => ["err_code", "err_message", "get_response_external_item", "@xmlns:n1", "@xmlns:n2", "@xsi:type"]
|
14
|
+
|
15
|
+
response.err_code
|
16
|
+
# => 'N00-000'
|
17
|
+
|
18
|
+
response.err_message
|
19
|
+
# => '正常終了'
|
20
|
+
|
21
|
+
response.get_response_external_item
|
22
|
+
# => #<Hashie::Mash>
|
23
|
+
```
|
data/docs/item_api.md
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
## ItemAPI
|
2
|
+
|
3
|
+
### get
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
args = { item_url: 'test-item-001' }
|
7
|
+
response = RmsApiRuby::Item.get(args)
|
8
|
+
# => #<Hashie::Mash>
|
9
|
+
|
10
|
+
response.keys
|
11
|
+
# => ["status", "item_get_result"]
|
12
|
+
|
13
|
+
response.item_get_result
|
14
|
+
# => #<Hashie::Mash code="N000" item=#<Hashie::Mash ...>>
|
15
|
+
```
|
16
|
+
|
17
|
+
### insert
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
args = {
|
21
|
+
item_insert_request: {
|
22
|
+
item: {
|
23
|
+
item_url: 'test-item-001',
|
24
|
+
item_name: 'My Item',
|
25
|
+
item_price: 10000,
|
26
|
+
genre_id: 999999,
|
27
|
+
is_depot: true,
|
28
|
+
item_inventory: {
|
29
|
+
inventory_type: 1,
|
30
|
+
inventories: {
|
31
|
+
inventory: {
|
32
|
+
inventory_count: 0
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
response = RmsApiRuby::Item.insert(args)
|
40
|
+
# => #<Hashie::Mash>
|
41
|
+
|
42
|
+
response.keys
|
43
|
+
# => ["status", "item_insert_result"]
|
44
|
+
|
45
|
+
response.item_insert_result
|
46
|
+
# => #<Hashie::Mash code="N000" item=#<Hashie::Mash item_url="test-item-001">>
|
47
|
+
```
|
48
|
+
|
49
|
+
### update
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
args = {
|
53
|
+
item_update_request: {
|
54
|
+
item: {
|
55
|
+
item_url: 'test-item-001',
|
56
|
+
item_name: 'My Item2',
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
response = RmsApiRuby::Item.update(args)
|
61
|
+
# => #<Hashie::Mash>
|
62
|
+
|
63
|
+
response.keys
|
64
|
+
# => ["status", "item_update_result"]
|
65
|
+
|
66
|
+
response.item_update_result
|
67
|
+
# => #<Hashie::Mash code="N000" item=#<Hashie::Mash item_url="test-item-001">>
|
68
|
+
```
|
69
|
+
|
70
|
+
### delete
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
args = {
|
74
|
+
item_delete_request: {
|
75
|
+
item: {
|
76
|
+
item_url: 'test-item-001'
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
response = RmsApiRuby::Item.delete(args)
|
81
|
+
# => #<Hashie::Mash>
|
82
|
+
|
83
|
+
response.keys
|
84
|
+
# => ["status", "item_delete_result"]
|
85
|
+
|
86
|
+
response.item_delete_result
|
87
|
+
# => #<Hashie::Mash code="N000" item=#<Hashie::Mash item_url="test-item-001">>
|
88
|
+
```
|
89
|
+
|
90
|
+
### search
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
args = { item_url: 'test-item-001' }
|
94
|
+
response = RmsApiRuby::Item.search(args)
|
95
|
+
# => #<Hashie::Mash>
|
96
|
+
|
97
|
+
response.keys
|
98
|
+
# => ["status", "item_search_result"]
|
99
|
+
|
100
|
+
response.item_search_result
|
101
|
+
# => #<Hashie::Mash code="200-00" items=#<Hashie::Mash item=#<Hashie::Mash ...>> num_found="1">
|
102
|
+
```
|
103
|
+
|
104
|
+
## ItemsAPI
|
105
|
+
|
106
|
+
### update
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
args = {
|
110
|
+
items_update_request: {
|
111
|
+
items: [
|
112
|
+
{
|
113
|
+
item_url: 'test-item-001',
|
114
|
+
item_name: 'My Item updated',
|
115
|
+
},
|
116
|
+
{
|
117
|
+
item_url: 'test-item-002',
|
118
|
+
item_name: 'My Item2 updated',
|
119
|
+
}
|
120
|
+
]
|
121
|
+
}
|
122
|
+
}
|
123
|
+
response = RmsApiRuby::Items.update(args)
|
124
|
+
# => #<Hashie::Mash >
|
125
|
+
|
126
|
+
response.keys
|
127
|
+
# => ["status", "items_update_result"]
|
128
|
+
|
129
|
+
response.items_update_result
|
130
|
+
# => #<Hashie::Mash item_update_result=#<Hashie::Array [#<Hashie::Mash code="N000" item=#<Hashie::Mash item_url="test-item-001">>, #<Hashie::Mash code="N000" item=#<Hashie::Mash item_url="test-item-002">>]>>
|
131
|
+
```
|
data/docs/order_api.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
## OrderAPI
|
2
|
+
|
3
|
+
### GetOrder
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
args = {
|
7
|
+
is_order_number_only_flag: false,
|
8
|
+
order_number: ['Rakuten order number you want'],
|
9
|
+
}
|
10
|
+
response = RmsApiRuby::Order.get_order(args)
|
11
|
+
# => #<Hashie::Mash>
|
12
|
+
|
13
|
+
response.error_code
|
14
|
+
# => 'N00-000'
|
15
|
+
|
16
|
+
response.message
|
17
|
+
# => '正常終了'
|
18
|
+
|
19
|
+
rakuten_order = response.order_model
|
20
|
+
# => #<Hashie::Mash>
|
21
|
+
```
|
22
|
+
|
23
|
+
### ChangeStatus
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
response = RmsApiRuby::Order.get_request_id
|
27
|
+
# => #<Hashie::Mash>
|
28
|
+
|
29
|
+
response.error_code
|
30
|
+
# => 'N00-000'
|
31
|
+
|
32
|
+
response.message
|
33
|
+
# => '正常終了'
|
34
|
+
|
35
|
+
request_id = response.request_id
|
36
|
+
# => 'XXXXXXXXXX'
|
37
|
+
|
38
|
+
args = {
|
39
|
+
request_id: request_id,
|
40
|
+
order_status_model: [
|
41
|
+
{
|
42
|
+
order_number: ['Rakuten order number you want to change status'],
|
43
|
+
status_name: '発送後入金待ち'
|
44
|
+
}
|
45
|
+
]
|
46
|
+
}
|
47
|
+
|
48
|
+
response = RmsApiRuby::Order.change_status(args)
|
49
|
+
# => #<Hashie::Mash>
|
50
|
+
|
51
|
+
response.error_code
|
52
|
+
# => 'N00-000'
|
53
|
+
|
54
|
+
response.message
|
55
|
+
# => '正常終了'
|
56
|
+
|
57
|
+
```
|
data/lib/rms_api_ruby.rb
CHANGED
@@ -15,6 +15,8 @@ module RmsApiRuby
|
|
15
15
|
autoload :Order, 'rms_api_ruby/order'
|
16
16
|
autoload :Orders, 'rms_api_ruby/orders'
|
17
17
|
autoload :Inventory, 'rms_api_ruby/inventory'
|
18
|
+
autoload :Item, 'rms_api_ruby/item'
|
19
|
+
autoload :Items, 'rms_api_ruby/items'
|
18
20
|
|
19
21
|
def self.root
|
20
22
|
File.dirname __dir__
|
data/lib/rms_api_ruby/chain.rb
CHANGED
@@ -2,7 +2,8 @@ module RmsApiRuby
|
|
2
2
|
class Chain
|
3
3
|
include Waterfall
|
4
4
|
|
5
|
-
autoload :
|
6
|
-
autoload :
|
5
|
+
autoload :HttpClient, 'rms_api_ruby/chain/http_client'
|
6
|
+
autoload :SoapClient, 'rms_api_ruby/chain/soap_client'
|
7
|
+
autoload :Logger, 'rms_api_ruby/chain/logger'
|
7
8
|
end
|
8
9
|
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'cgi'
|
3
|
+
require 'uri'
|
4
|
+
require 'hashie/mash'
|
5
|
+
require 'rms_api_ruby/utility/hash_keys_underscorable'
|
6
|
+
|
7
|
+
module RmsApiRuby
|
8
|
+
class Chain
|
9
|
+
class HttpClient < RmsApiRuby::Chain
|
10
|
+
include RmsApiRuby::HashKeysUnderscorable
|
11
|
+
|
12
|
+
SERVER_ERROR = 500
|
13
|
+
|
14
|
+
def initialize(method:, url:, headers: nil, params: nil, return_method:)
|
15
|
+
@uri = URI.parse url_factory(url, method, params)
|
16
|
+
@request = request_class(method).new request_uri(method, @uri)
|
17
|
+
@return_method = return_method
|
18
|
+
|
19
|
+
set_headers(headers) if headers.present?
|
20
|
+
set_body(params) if method != :get && params.present?
|
21
|
+
end
|
22
|
+
|
23
|
+
def set_headers(headers)
|
24
|
+
headers.each { |k, v| @request[k] = v }
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_body(params)
|
28
|
+
@request.body = params
|
29
|
+
end
|
30
|
+
|
31
|
+
def execute_request
|
32
|
+
@response = Net::HTTP.start(@uri.hostname, @uri.port, use_ssl: true) do |http|
|
33
|
+
http.request @request
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def call
|
38
|
+
chain { execute_request }
|
39
|
+
when_truthy { status_code >= SERVER_ERROR }.
|
40
|
+
dam { handle_http_error }
|
41
|
+
chain(:response) { parse_to_mash }
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def url_factory(url, method, params)
|
47
|
+
if method == :get && params.present?
|
48
|
+
url + '?' + params.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
|
49
|
+
else
|
50
|
+
url
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def handle_http_error
|
55
|
+
message = "HTTP Request failed. Response code: #{status_code}"
|
56
|
+
RmsApiRuby::ServerError.new message
|
57
|
+
end
|
58
|
+
|
59
|
+
def status_code
|
60
|
+
@response.try(:code).try(:to_i)
|
61
|
+
end
|
62
|
+
|
63
|
+
def parse_to_mash
|
64
|
+
Hashie::Mash.new(hash_from_response).
|
65
|
+
send(@return_method)
|
66
|
+
end
|
67
|
+
|
68
|
+
def hash_from_response
|
69
|
+
snake_keys Hash.from_xml(@response.body)
|
70
|
+
end
|
71
|
+
|
72
|
+
def request_class(method)
|
73
|
+
case method
|
74
|
+
when :get
|
75
|
+
::Net::HTTP::Get
|
76
|
+
when :post
|
77
|
+
::Net::HTTP::Post
|
78
|
+
when :put
|
79
|
+
::Net::HTTP::Put
|
80
|
+
when :patch
|
81
|
+
::Net::HTTP::Patch
|
82
|
+
when :delete
|
83
|
+
::Net::HTTP::Delete
|
84
|
+
else
|
85
|
+
raise ::ArgumentError, "Unsupported http method '#{method}'"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def request_uri(method, uri)
|
90
|
+
method == :get ? uri.request_uri : uri
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -5,6 +5,7 @@ module RmsApiRuby
|
|
5
5
|
class Chain
|
6
6
|
class SoapClient < RmsApiRuby::Chain
|
7
7
|
SUCCESS = 200
|
8
|
+
FAILURE = 500
|
8
9
|
|
9
10
|
def initialize(wsdl, operation, message, return_method)
|
10
11
|
@client = Savon.client(wsdl: wsdl)
|
@@ -25,7 +26,7 @@ module RmsApiRuby
|
|
25
26
|
def execute_request
|
26
27
|
@response = @client.call(@operation, message: @message)
|
27
28
|
rescue Savon::SOAPFault
|
28
|
-
@response = Hashie::Mash.new(http: { code:
|
29
|
+
@response = Hashie::Mash.new(http: { code: FAILURE })
|
29
30
|
end
|
30
31
|
|
31
32
|
def handle_http_error
|
data/lib/rms_api_ruby/config.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
module RmsApiRuby
|
2
|
+
class Item
|
3
|
+
autoload :Get, 'rms_api_ruby/item/get'
|
4
|
+
autoload :Insert, 'rms_api_ruby/item/insert'
|
5
|
+
autoload :Update, 'rms_api_ruby/item/update'
|
6
|
+
autoload :Delete, 'rms_api_ruby/item/delete'
|
7
|
+
autoload :Search, 'rms_api_ruby/item/search'
|
8
|
+
|
9
|
+
API_METHODS = %w[
|
10
|
+
get
|
11
|
+
insert
|
12
|
+
update
|
13
|
+
delete
|
14
|
+
search
|
15
|
+
].freeze
|
16
|
+
|
17
|
+
class << self
|
18
|
+
API_METHODS.each do |api_method|
|
19
|
+
define_method api_method do |args = nil|
|
20
|
+
api_class = "RmsApiRuby::Item::#{api_method.camelize}"
|
21
|
+
call_api api_class.constantize.new(args)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def call_api(api)
|
28
|
+
Flow.new.
|
29
|
+
chain(response: :response) { api.call }.
|
30
|
+
on_dam { |error| handle_error(error) }.
|
31
|
+
outflow.
|
32
|
+
try(:response)
|
33
|
+
end
|
34
|
+
|
35
|
+
def handle_error(error)
|
36
|
+
raise error
|
37
|
+
rescue ServerError, AuthenticationError => e
|
38
|
+
RmsApiRuby.configuration.logger.error(e.message)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rms_api_ruby/chain'
|
2
|
+
require 'rms_api_ruby/utility/hash_keys_camelizable'
|
3
|
+
|
4
|
+
module RmsApiRuby
|
5
|
+
class Item
|
6
|
+
class Base
|
7
|
+
include Waterfall
|
8
|
+
include RmsApiRuby::HashKeysCamelizable
|
9
|
+
|
10
|
+
def initialize(args, client_class = RmsApiRuby::Chain::HttpClient)
|
11
|
+
@args = args
|
12
|
+
@client = client_class.new(
|
13
|
+
method: http_method,
|
14
|
+
url: url,
|
15
|
+
params: form_params(args),
|
16
|
+
headers: http_headers,
|
17
|
+
return_method: :result
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
chain { log :info, start_message }
|
23
|
+
chain(response: :response) { @client.call }
|
24
|
+
chain { log :info, complete_message }
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def http_method
|
30
|
+
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def url
|
34
|
+
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def api_name
|
38
|
+
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def base_url
|
42
|
+
"https://api.rms.rakuten.co.jp/es/#{api_version}/item/"
|
43
|
+
end
|
44
|
+
|
45
|
+
def api_version
|
46
|
+
RmsApiRuby.configuration.item_api_version
|
47
|
+
end
|
48
|
+
|
49
|
+
def http_headers
|
50
|
+
{ Authorization: RmsApiRuby::Authentication.key }
|
51
|
+
end
|
52
|
+
|
53
|
+
def log(level, message)
|
54
|
+
RmsApiRuby::Chain::Logger.new(level, message)
|
55
|
+
end
|
56
|
+
|
57
|
+
def start_message
|
58
|
+
"RMS ItemAPI '#{api_name}' started. args: #{@args.inspect}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def complete_message
|
62
|
+
"RMS ItemAPI '#{api_name}' completed."
|
63
|
+
end
|
64
|
+
|
65
|
+
def form_params(args)
|
66
|
+
if http_method == :get
|
67
|
+
camelize_keys(args, :lower)
|
68
|
+
else
|
69
|
+
camelize_keys(args, :lower).to_xml(root: :request, skip_types: true)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rms_api_ruby/item/base'
|
2
|
+
|
3
|
+
module RmsApiRuby
|
4
|
+
class Item
|
5
|
+
class Delete < RmsApiRuby::Item::Base
|
6
|
+
private
|
7
|
+
|
8
|
+
def http_method
|
9
|
+
:post
|
10
|
+
end
|
11
|
+
|
12
|
+
def url
|
13
|
+
"#{base_url}delete"
|
14
|
+
end
|
15
|
+
|
16
|
+
def api_name
|
17
|
+
'DELETE'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rms_api_ruby/item/base'
|
2
|
+
|
3
|
+
module RmsApiRuby
|
4
|
+
class Item
|
5
|
+
class Get < RmsApiRuby::Item::Base
|
6
|
+
private
|
7
|
+
|
8
|
+
def http_method
|
9
|
+
:get
|
10
|
+
end
|
11
|
+
|
12
|
+
def url
|
13
|
+
"#{base_url}get"
|
14
|
+
end
|
15
|
+
|
16
|
+
def api_name
|
17
|
+
'GET'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rms_api_ruby/item/base'
|
2
|
+
|
3
|
+
module RmsApiRuby
|
4
|
+
class Item
|
5
|
+
class Insert < RmsApiRuby::Item::Base
|
6
|
+
private
|
7
|
+
|
8
|
+
def http_method
|
9
|
+
:post
|
10
|
+
end
|
11
|
+
|
12
|
+
def url
|
13
|
+
"#{base_url}insert"
|
14
|
+
end
|
15
|
+
|
16
|
+
def api_name
|
17
|
+
'INSERT'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rms_api_ruby/item/base'
|
2
|
+
|
3
|
+
module RmsApiRuby
|
4
|
+
class Item
|
5
|
+
class Search < RmsApiRuby::Item::Base
|
6
|
+
private
|
7
|
+
|
8
|
+
def http_method
|
9
|
+
:get
|
10
|
+
end
|
11
|
+
|
12
|
+
def url
|
13
|
+
"#{base_url}search"
|
14
|
+
end
|
15
|
+
|
16
|
+
def api_name
|
17
|
+
'SEARCH'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rms_api_ruby/item/base'
|
2
|
+
|
3
|
+
module RmsApiRuby
|
4
|
+
class Item
|
5
|
+
class Update < RmsApiRuby::Item::Base
|
6
|
+
private
|
7
|
+
|
8
|
+
def http_method
|
9
|
+
:post
|
10
|
+
end
|
11
|
+
|
12
|
+
def url
|
13
|
+
"#{base_url}update"
|
14
|
+
end
|
15
|
+
|
16
|
+
def api_name
|
17
|
+
'UPDATE'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rms_api_ruby/item/base'
|
2
|
+
|
3
|
+
module RmsApiRuby
|
4
|
+
class Items
|
5
|
+
class << self
|
6
|
+
def update(args)
|
7
|
+
Flow.new.
|
8
|
+
chain(response: :response) { Client.new(args).call }.
|
9
|
+
on_dam { |error| handle_error(error) }.
|
10
|
+
outflow.
|
11
|
+
try(:response)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def handle_error(error)
|
17
|
+
raise error
|
18
|
+
rescue ServerError, AuthenticationError => e
|
19
|
+
RmsApiRuby.configuration.logger.error(e.message)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Client < RmsApiRuby::Item::Base
|
24
|
+
private
|
25
|
+
|
26
|
+
def http_method
|
27
|
+
:post
|
28
|
+
end
|
29
|
+
|
30
|
+
def url
|
31
|
+
"https://api.rms.rakuten.co.jp/es/#{api_version}/items/update"
|
32
|
+
end
|
33
|
+
|
34
|
+
def start_message
|
35
|
+
"RMS ItemsAPI 'UPDATE' started. args: #{@args.inspect}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def complete_message
|
39
|
+
"RMS ItemsAPI 'UPDATE' completed."
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'active_support/core_ext'
|
2
|
+
|
3
|
+
module RmsApiRuby
|
4
|
+
module HashKeysCamelizable
|
5
|
+
def camelize_keys(hash, first_letter = :upper)
|
6
|
+
hash.each_with_object({}) do |(key, val), acc|
|
7
|
+
if val.is_a?(Array)
|
8
|
+
val = val.map { |v| to_camel_keys(v, first_letter) }
|
9
|
+
elsif val.is_a?(Hash)
|
10
|
+
val = camelize_keys(val, first_letter)
|
11
|
+
end
|
12
|
+
acc[camel_key(key, first_letter)] = val
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def camel_key(key, first_letter)
|
19
|
+
if key.is_a?(String)
|
20
|
+
key.camelize(first_letter)
|
21
|
+
elsif key.is_a?(Symbol)
|
22
|
+
key.to_s.camelize(first_letter).to_sym
|
23
|
+
else
|
24
|
+
key
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_camel_keys(val, first_letter)
|
29
|
+
if val.is_a?(Array)
|
30
|
+
val.map { |v| to_camel_keys(v, first_letter) }
|
31
|
+
elsif val.is_a?(Hash)
|
32
|
+
camelize_keys(val, first_letter)
|
33
|
+
else
|
34
|
+
val
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'active_support/core_ext'
|
2
|
+
|
3
|
+
module RmsApiRuby
|
4
|
+
module HashKeysUnderscorable
|
5
|
+
def snake_keys(hash)
|
6
|
+
hash.each_with_object({}) do |(key, val), acc|
|
7
|
+
if val.is_a?(Array)
|
8
|
+
val = val.map { |v| to_snake_keys(v) }
|
9
|
+
elsif val.is_a?(Hash)
|
10
|
+
val = snake_keys(val)
|
11
|
+
end
|
12
|
+
acc[snake_key(key)] = val
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def snake_key(key)
|
19
|
+
if key.is_a?(String)
|
20
|
+
key.underscore
|
21
|
+
elsif key.is_a?(Symbol)
|
22
|
+
key.to_s.underscore.to_sym
|
23
|
+
else
|
24
|
+
key
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_snake_keys(val)
|
29
|
+
if val.is_a?(Array)
|
30
|
+
val.map { |v| to_snake_keys(v) }
|
31
|
+
elsif val.is_a?(Hash)
|
32
|
+
snake_keys(val)
|
33
|
+
else
|
34
|
+
val
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/rms_api_ruby/version.rb
CHANGED
data/rms_api_ruby.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rms_api_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kaicoh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: webmock
|
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'
|
153
167
|
description: A Ruby client for RMS(Rakuten Marchant Service) WEB API
|
154
168
|
email:
|
155
169
|
- sumireminami@gmail.com
|
@@ -161,7 +175,6 @@ files:
|
|
161
175
|
- ".gitignore"
|
162
176
|
- ".rspec"
|
163
177
|
- ".rubocop.yml"
|
164
|
-
- ".travis.yml"
|
165
178
|
- CHANGELOG.md
|
166
179
|
- CODE_OF_CONDUCT.md
|
167
180
|
- Gemfile
|
@@ -172,17 +185,31 @@ files:
|
|
172
185
|
- bin/console
|
173
186
|
- bin/setup
|
174
187
|
- config/wsdl/inventory_v_1.0.wsdl
|
188
|
+
- docs/inventory_api.md
|
189
|
+
- docs/item_api.md
|
190
|
+
- docs/order_api.md
|
175
191
|
- lib/rms_api_ruby.rb
|
176
192
|
- lib/rms_api_ruby/authentication.rb
|
177
193
|
- lib/rms_api_ruby/chain.rb
|
194
|
+
- lib/rms_api_ruby/chain/http_client.rb
|
178
195
|
- lib/rms_api_ruby/chain/logger.rb
|
179
196
|
- lib/rms_api_ruby/chain/soap_client.rb
|
180
197
|
- lib/rms_api_ruby/config.rb
|
181
198
|
- lib/rms_api_ruby/inventory.rb
|
199
|
+
- lib/rms_api_ruby/item.rb
|
200
|
+
- lib/rms_api_ruby/item/base.rb
|
201
|
+
- lib/rms_api_ruby/item/delete.rb
|
202
|
+
- lib/rms_api_ruby/item/get.rb
|
203
|
+
- lib/rms_api_ruby/item/insert.rb
|
204
|
+
- lib/rms_api_ruby/item/search.rb
|
205
|
+
- lib/rms_api_ruby/item/update.rb
|
206
|
+
- lib/rms_api_ruby/items.rb
|
182
207
|
- lib/rms_api_ruby/order.rb
|
183
208
|
- lib/rms_api_ruby/orders.rb
|
184
209
|
- lib/rms_api_ruby/soap_api.rb
|
185
210
|
- lib/rms_api_ruby/soap_api/client.rb
|
211
|
+
- lib/rms_api_ruby/utility/hash_keys_camelizable.rb
|
212
|
+
- lib/rms_api_ruby/utility/hash_keys_underscorable.rb
|
186
213
|
- lib/rms_api_ruby/version.rb
|
187
214
|
- rms_api_ruby.gemspec
|
188
215
|
homepage: https://github.com/Kaicoh
|