rms_api_ruby 0.3.0 → 0.4.0

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
  SHA256:
3
- metadata.gz: '08380e4d50146bab769f56f4156751e4ce0b6788333f8c637198b7157994cb9b'
4
- data.tar.gz: 9be7202be3b41ec3773ee918bc30c3190cb5b107b22a03f36564f8b655cc5009
3
+ metadata.gz: cd997f991888796c31485581f894b02fdb26e1cf0a355fd1c064d8bdb625e9a9
4
+ data.tar.gz: e9eb9d271154aba3e58c8009c22ed126a61fa53783cd7414afa7d5435395ee1e
5
5
  SHA512:
6
- metadata.gz: 07e89f486b327e760986a491390a93784ea24c0c69f0a382dd5fcc28b529071347be4522101fb01eab727e7c09ca10c9b54a9049acfd290776d14609a2f4a510
7
- data.tar.gz: f8edb76474508be2554e536770c2078741f2306d4133e9bb6458ac3f2d8b7da93924169c33c34f8618db597010589a21f34bf24fc49b15737d352b3ca13af1bb
6
+ metadata.gz: 54c1165fb6dd9c3c5c7dc2b3ccbafce5a17606168ab7652a5fb58081800356071573ea5eab6543ddd5860bbc24171c258ee6c4af57ccf71c43c8434ff531915a
7
+ data.tar.gz: 452c6a1eddd87373c2bebeb650db44e5832d24a6a6605b0a20a2d4802725ea3bb371ac4c334b112096b7d757bec83542500f66f5fbfd5002125831fb90bff9e9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.4.0 (Jul 7, 2018)
2
+ * Add Product API and Navigation API
3
+
1
4
  ## 0.3.0 (Jul 1, 2018)
2
5
  * Add Item API
3
6
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rms_api_ruby (0.3.0)
4
+ rms_api_ruby (0.4.0)
5
5
  activesupport
6
6
  hashie
7
7
  savon (~> 2.12.0)
data/README.md CHANGED
@@ -4,17 +4,17 @@
4
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)
5
5
 
6
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.
7
- At this time this gem supports OrderAPI, InventoryAPI and ItemAPI.
7
+ At this time this gem supports OrderAPI, InventoryAPI, ItemAPI, ProductAPI and NavigationAPI.
8
8
 
9
9
  Support
10
10
  - OrderAPI
11
11
  - InventoryAPI
12
12
  - ItemAPI
13
+ - ProductAPI
14
+ - NavigationAPI
13
15
 
14
16
  Not Support yet
15
- - ProductAPI
16
17
  - CabinetAPI
17
- - NavigationAPI
18
18
  - CategoryAPI
19
19
  - CouponAPI
20
20
  - ShopManagimentAPI
@@ -54,13 +54,15 @@ Or can set any of the options via this way
54
54
 
55
55
  ```ruby
56
56
  RmsApiRuby.configure do |config|
57
- config.service_secret = 'Your RMS service secret'
58
- config.license_key = 'Your RMS license key'
59
- config.shop_url = 'Your RMS shop url'
60
- config.user_name = 'user name' # default 'rms_api_ruby'
61
- config.order_api_version = 'Order API version' # default 1.0
62
- config.inventory_api_version = 'Inventory API version' # default 1.0
63
- config.item_api_version = 'Item API version' # default 1.0
57
+ config.service_secret = 'Your RMS service secret'
58
+ config.license_key = 'Your RMS license key'
59
+ config.shop_url = 'Your RMS shop url'
60
+ config.user_name = 'user name' # default 'rms_api_ruby'
61
+ config.order_api_version = 'Order API version' # default 1.0
62
+ config.inventory_api_version = 'Inventory API version' # default 1.0
63
+ config.item_api_version = 'Item API version' # default 1.0
64
+ config.product_api_version = 'Product API version' # default 2.0
65
+ config.navigation_api_version = 'Navigation API version' # default 1.0
64
66
  end
65
67
  ```
66
68
 
@@ -68,12 +70,8 @@ end
68
70
  - [OrderAPI](docs/order_api.md)
69
71
  - [InventoryAPI](docs/inventory_api.md)
70
72
  - [ItemAPI](docs/item_api.md)
71
-
72
- ## Development
73
-
74
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
75
-
76
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
73
+ - [ProductAPI](docs/product_api.md)
74
+ - [NavigationAPI](docs/navigation_api.md)
77
75
 
78
76
  ## Contributing
79
77
 
@@ -0,0 +1,44 @@
1
+ ## NavigationAPI
2
+
3
+ ### genre_get
4
+
5
+ ```ruby
6
+ args = { genre_id: 202513 }
7
+
8
+ response = RmsApiRuby::Navigation.genre_get(args)
9
+ # => #<Hashie::Mash>
10
+
11
+ response.keys
12
+ # => ["status", "navigation_genre_get_result"]
13
+
14
+ response.navigation_genre_get_result
15
+ # => #<Hashie::Mash genre=#<Hashie::Mash ...>>
16
+ ```
17
+
18
+ ### genre_tag_get
19
+
20
+ ```ruby
21
+ args = { genre_id: 202513 }
22
+
23
+ response = RmsApiRuby::Navigation.genre_tag_get(args)
24
+ # => #<Hashie::Mash>
25
+
26
+ response.keys
27
+ # => ["status", "navigation_genre_tag_get_result"]
28
+
29
+ response.navigation_genre_tag_get_result
30
+ # => #<Hashie::Mash genre=#<Hashie::Mash ...>>
31
+ ```
32
+
33
+ ### genre_header_get
34
+
35
+ ```ruby
36
+ response = RmsApiRuby::Navigation.genre_header_get
37
+ # => #<Hashie::Mash>
38
+
39
+ response.keys
40
+ # => ["status", "navigation_header_get_result"]
41
+
42
+ response.navigation_header_get_result
43
+ # => #<Hashie::Mash genre_last_update_date="2018-05-22T10:00:00+09:00" status="Success" tag_last_update_date="2018-05-22T10:00:00+09:00">
44
+ ```
@@ -0,0 +1,19 @@
1
+ ## ProductAPI
2
+
3
+ ### search
4
+
5
+ ```ruby
6
+ args = {
7
+ genre_id: 202513,
8
+ limit: 10,
9
+ }
10
+
11
+ response = RmsApiRuby::Product.search(args)
12
+ # => #<Hashie::Mash>
13
+
14
+ response.keys
15
+ # => ["status", "product_search_result"]
16
+
17
+ response.product_search_result
18
+ # => #<Hashie::Mash pagination=#<Hashie::Mash ...>>
19
+ ```
@@ -85,9 +85,11 @@ module RmsApiRuby
85
85
  option :logger, default: ::Logger.new(STDOUT)
86
86
  option :log_level, default: ::Logger::DEBUG
87
87
 
88
- option :order_api_version, default: '1.0'
89
- option :inventory_api_version, default: '1.0'
90
- option :item_api_version, default: '1.0'
88
+ option :order_api_version, default: '1.0'
89
+ option :inventory_api_version, default: '1.0'
90
+ option :item_api_version, default: '1.0'
91
+ option :product_api_version, default: '2.0'
92
+ option :navigation_api_version, default: '1.0'
91
93
 
92
94
  def options
93
95
  self.class.options
@@ -1,39 +1,10 @@
1
- require 'rms_api_ruby/chain'
2
- require 'rms_api_ruby/utility/hash_keys_camelizable'
1
+ require 'rms_api_ruby/rest_api/base'
3
2
 
4
3
  module RmsApiRuby
5
4
  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
-
5
+ class Base < RmsApiRuby::RestApi::Base
27
6
  private
28
7
 
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
8
  def api_name
38
9
  raise NotImplementedError, "You must implement #{self.class}##{__method__}"
39
10
  end
@@ -46,14 +17,6 @@ module RmsApiRuby
46
17
  RmsApiRuby.configuration.item_api_version
47
18
  end
48
19
 
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
20
  def start_message
58
21
  "RMS ItemAPI '#{api_name}' started. args: #{@args.inspect}"
59
22
  end
@@ -61,14 +24,6 @@ module RmsApiRuby
61
24
  def complete_message
62
25
  "RMS ItemAPI '#{api_name}' completed."
63
26
  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
27
  end
73
28
  end
74
29
  end
@@ -0,0 +1,29 @@
1
+ require 'rms_api_ruby/rest_api/base'
2
+
3
+ module RmsApiRuby
4
+ class Navigation
5
+ class Base < RmsApiRuby::RestApi::Base
6
+ private
7
+
8
+ def api_name
9
+ raise NotImplementedError, "You must implement #{self.class}##{__method__}"
10
+ end
11
+
12
+ def base_url
13
+ "https://api.rms.rakuten.co.jp/es/#{api_version}/navigation/"
14
+ end
15
+
16
+ def api_version
17
+ RmsApiRuby.configuration.navigation_api_version
18
+ end
19
+
20
+ def start_message
21
+ "RMS NavigationAPI '#{api_name}' started. args: #{@args.inspect}"
22
+ end
23
+
24
+ def complete_message
25
+ "RMS NavigationAPI '#{api_name}' completed."
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ require 'rms_api_ruby/navigation/base'
2
+
3
+ module RmsApiRuby
4
+ class Navigation
5
+ class GenreGet < RmsApiRuby::Navigation::Base
6
+ private
7
+
8
+ def http_method
9
+ :get
10
+ end
11
+
12
+ def url
13
+ "#{base_url}genre/get"
14
+ end
15
+
16
+ def api_name
17
+ 'genre get'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'rms_api_ruby/navigation/base'
2
+
3
+ module RmsApiRuby
4
+ class Navigation
5
+ class GenreHeaderGet < RmsApiRuby::Navigation::Base
6
+ private
7
+
8
+ def http_method
9
+ :get
10
+ end
11
+
12
+ def url
13
+ "#{base_url}genre/header/get"
14
+ end
15
+
16
+ def api_name
17
+ 'genre header get'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'rms_api_ruby/navigation/base'
2
+
3
+ module RmsApiRuby
4
+ class Navigation
5
+ class GenreTagGet < RmsApiRuby::Navigation::Base
6
+ private
7
+
8
+ def http_method
9
+ :get
10
+ end
11
+
12
+ def url
13
+ "#{base_url}genre/tag/get"
14
+ end
15
+
16
+ def api_name
17
+ 'genre tag get'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,38 @@
1
+ module RmsApiRuby
2
+ class Navigation
3
+ autoload :GenreGet, 'rms_api_ruby/navigation/genre_get'
4
+ autoload :GenreTagGet, 'rms_api_ruby/navigation/genre_tag_get'
5
+ autoload :GenreHeaderGet, 'rms_api_ruby/navigation/genre_header_get'
6
+
7
+ API_METHODS = %w[
8
+ genre_get
9
+ genre_tag_get
10
+ genre_header_get
11
+ ].freeze
12
+
13
+ class << self
14
+ API_METHODS.each do |api_method|
15
+ define_method api_method do |args = nil|
16
+ api_class = "RmsApiRuby::Navigation::#{api_method.camelize}"
17
+ call_api api_class.constantize.new(args)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def call_api(api)
24
+ Flow.new.
25
+ chain(response: :response) { api.call }.
26
+ on_dam { |error| handle_error(error) }.
27
+ outflow.
28
+ try(:response)
29
+ end
30
+
31
+ def handle_error(error)
32
+ raise error
33
+ rescue ServerError, AuthenticationError => e
34
+ RmsApiRuby.configuration.logger.error(e.message)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,47 @@
1
+ require 'rms_api_ruby/rest_api/base'
2
+
3
+ module RmsApiRuby
4
+ class Product
5
+ class << self
6
+ def search(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::RestApi::Base
24
+ private
25
+
26
+ def http_method
27
+ :get
28
+ end
29
+
30
+ def url
31
+ "https://api.rms.rakuten.co.jp/es/#{api_version}/product/search"
32
+ end
33
+
34
+ def start_message
35
+ "RMS ProductAPI 'SEARCH' started. args: #{@args.inspect}"
36
+ end
37
+
38
+ def complete_message
39
+ "RMS ProductAPI 'SEARCH' completed."
40
+ end
41
+
42
+ def api_version
43
+ RmsApiRuby.configuration.product_api_version
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,65 @@
1
+ require 'rms_api_ruby/chain'
2
+ require 'rms_api_ruby/utility/hash_keys_camelizable'
3
+
4
+ module RmsApiRuby
5
+ class RestApi
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 start_message
38
+ raise NotImplementedError, "You must implement #{self.class}##{__method__}"
39
+ end
40
+
41
+ def complete_message
42
+ raise NotImplementedError, "You must implement #{self.class}##{__method__}"
43
+ end
44
+
45
+ def http_headers
46
+ { Authorization: RmsApiRuby::Authentication.key }
47
+ end
48
+
49
+ def log(level, message)
50
+ RmsApiRuby::Chain::Logger.new(level, message)
51
+ end
52
+
53
+ def form_params(args)
54
+ camelized_params = camelize_keys(args, :lower)
55
+ if http_method == :get
56
+ camelized_params
57
+ elsif camelized_params.nil?
58
+ nil
59
+ else
60
+ camelized_params.to_xml(root: :request, skip_types: true)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -3,6 +3,7 @@ require 'active_support/core_ext'
3
3
  module RmsApiRuby
4
4
  module HashKeysCamelizable
5
5
  def camelize_keys(hash, first_letter = :upper)
6
+ return nil if hash.nil?
6
7
  hash.each_with_object({}) do |(key, val), acc|
7
8
  if val.is_a?(Array)
8
9
  val = val.map { |v| to_camel_keys(v, first_letter) }
@@ -3,6 +3,7 @@ require 'active_support/core_ext'
3
3
  module RmsApiRuby
4
4
  module HashKeysUnderscorable
5
5
  def snake_keys(hash)
6
+ return nil if hash.nil?
6
7
  hash.each_with_object({}) do |(key, val), acc|
7
8
  if val.is_a?(Array)
8
9
  val = val.map { |v| to_snake_keys(v) }
@@ -1,3 +1,3 @@
1
1
  module RmsApiRuby
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
data/lib/rms_api_ruby.rb CHANGED
@@ -17,6 +17,8 @@ module RmsApiRuby
17
17
  autoload :Inventory, 'rms_api_ruby/inventory'
18
18
  autoload :Item, 'rms_api_ruby/item'
19
19
  autoload :Items, 'rms_api_ruby/items'
20
+ autoload :Product, 'rms_api_ruby/product'
21
+ autoload :Navigation, 'rms_api_ruby/navigation'
20
22
 
21
23
  def self.root
22
24
  File.dirname __dir__
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.3.0
4
+ version: 0.4.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-30 00:00:00.000000000 Z
11
+ date: 2018-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -187,7 +187,9 @@ files:
187
187
  - config/wsdl/inventory_v_1.0.wsdl
188
188
  - docs/inventory_api.md
189
189
  - docs/item_api.md
190
+ - docs/navigation_api.md
190
191
  - docs/order_api.md
192
+ - docs/product_api.md
191
193
  - lib/rms_api_ruby.rb
192
194
  - lib/rms_api_ruby/authentication.rb
193
195
  - lib/rms_api_ruby/chain.rb
@@ -204,8 +206,15 @@ files:
204
206
  - lib/rms_api_ruby/item/search.rb
205
207
  - lib/rms_api_ruby/item/update.rb
206
208
  - lib/rms_api_ruby/items.rb
209
+ - lib/rms_api_ruby/navigation.rb
210
+ - lib/rms_api_ruby/navigation/base.rb
211
+ - lib/rms_api_ruby/navigation/genre_get.rb
212
+ - lib/rms_api_ruby/navigation/genre_header_get.rb
213
+ - lib/rms_api_ruby/navigation/genre_tag_get.rb
207
214
  - lib/rms_api_ruby/order.rb
208
215
  - lib/rms_api_ruby/orders.rb
216
+ - lib/rms_api_ruby/product.rb
217
+ - lib/rms_api_ruby/rest_api/base.rb
209
218
  - lib/rms_api_ruby/soap_api.rb
210
219
  - lib/rms_api_ruby/soap_api/client.rb
211
220
  - lib/rms_api_ruby/utility/hash_keys_camelizable.rb