rms_item_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7bc421856e9768665f44c9684746309ab7b516bf
4
+ data.tar.gz: 16bc5288b7d512741cc0020ab7114f2e37fd1f43
5
+ SHA512:
6
+ metadata.gz: bcb16ad734fc0041f595d2eb1972f7f4cd4c5bb77536786c667f864ab9e85736f0eef3e59fb31dc35ade1f3db54b3375de203dea854827bc99360c8645787f48
7
+ data.tar.gz: 1428d304e05437a8e95afb35fcf4ffa74666afe57f56ed15238131f84ce0651ad3a73f3fdb1c721cdea4d4ac4a0538a43ee822a6eae6027286ae12727c0ba1f2
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ test_code.rb
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rms_item_api.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Tatsuro Moriyama
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # RmsItemApi
2
+
3
+ 楽天市場に出店している店舗が使えるRMSの商品APIを叩くためのrubyラッパーです。シンプルなCRUD(作成、取得、更新、削除)のみを実装してあります。検索と複数更新は必要があれば追加したいと思います。
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ gem install rms_item_api
9
+ ```
10
+ ## Usage
11
+
12
+ 取得や更新する項目に関しては楽天RMS WEB APIのドキュメント(要ログイン)にて。
13
+ https://webservice.rms.rakuten.co.jp/merchant-portal/view?page=document0002
14
+
15
+ ### Initialize
16
+
17
+ RMS内の「[拡張サービス一覧>WEB APIサービス>利用設定](https://webservice.rms.rakuten.co.jp/merchant-portal/configurationApi)」にあるserviceSecretとlicenseKeyが必要です(事前にWEB APIの利用申し込みが必要)。
18
+
19
+ ```ruby
20
+ client = RmsItemApi::RmsItemApi.new(
21
+ serviceSecret: "your_serviceSecret",
22
+ licenseKey: "your_licenseKey"
23
+ )
24
+ ```
25
+
26
+ ### Get
27
+
28
+ この機能を利用すると、RMSに登録している商品情報を商品管理番号を指定して取得することができます。
29
+
30
+ ```ruby
31
+ item = client.get('test123')
32
+
33
+ # 商品名を取得
34
+ item.item_name
35
+ # 表示価格を取得
36
+ item.item_price
37
+ ```
38
+
39
+ ### Insert
40
+
41
+ この機能を利用すると、RMSに商品情報を登録することができます。
42
+
43
+ ```ruby
44
+ item = client.insert({
45
+ item_url: 'test123',
46
+ item_name: 'api_insert_test_item',
47
+ item_price: '298000',
48
+ genreId: 564040,
49
+ images: {
50
+ image: {
51
+ image_url: 'http://image.rakuten.co.jp/your_shop_id/cabinet/test.jpg'
52
+ }
53
+ },
54
+ item_layout: 2,
55
+ is_included_postage: true
56
+ })
57
+ ```
58
+
59
+ ### Update
60
+
61
+ この機能を利用すると、RMSに登録されている商品情報を更新することができます。
62
+
63
+ ```ruby
64
+ item = client.update({
65
+ item_url: 'test123',
66
+ item_name: 'api_update_test_item',
67
+ item_price: '198000',
68
+ categories: {
69
+ categoryInfo: {
70
+ categoryId: '0000000123'
71
+ }
72
+ }
73
+ })
74
+ ```
75
+
76
+ ### Delete
77
+
78
+ この機能を利用すると、RMSに登録されている商品情報を削除することができます。
79
+
80
+ ```ruby
81
+ item = client.update({
82
+ item_url: 'test123',
83
+ })
84
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rms_item_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,63 @@
1
+ 501: '商品管理番号'
2
+ 502: '商品名'
3
+ 503: '販売価格'
4
+ 504: '全商品ディレクトリID'
5
+ 505: '商品情報レイアウト'
6
+ 506: '消費税'
7
+ 507: '送料'
8
+ 508: '代引き手数料'
9
+ 509: '在庫タイプ'
10
+ 510: '注文受付数'
11
+ 511: '倉庫指定'
12
+ 512: '注文ボタン'
13
+ 513: '資料請求ボタン'
14
+ 514: '商品問い合わせボタン'
15
+ 515: 'モバイル表示'
16
+ 516: 'のし対応'
17
+ 517: 'ポイント変倍率'
18
+ 518: 'ポイント変倍適応期間(開始)'
19
+ 518: 'ポイント変倍適応期間(終了)'
20
+ 519: '商品画像名(ALT)'
21
+ 520: '商品番号'
22
+ 521: 'PC用商品説明文'
23
+ 522: 'モバイル用商品説明文'
24
+ 523: '表示価格'
25
+ 524: '商品画像URL'
26
+ 525: '動画URL'
27
+ 526: 'PC用キャッチコピー'
28
+ 527: 'モバイル用キャッチコピー'
29
+ 528: 'PC用販売説明文'
30
+ 529: '個別送料'
31
+ 530: '送料区分1'
32
+ 531: '送料区分2'
33
+ 532: '期間限定販売フラグ'
34
+ 532: '期間限定販売開始日'
35
+ 532: '期間限定販売終了日'
36
+ 534: '在庫数表示'
37
+ 535: '項目選択肢別在庫用縦軸選択肢項目名'
38
+ 536: '項目選択肢別在庫用横軸選択肢項目名'
39
+ 537: '項目選択肢別在庫用残り表示閾値'
40
+ 540: 'カタログID'
41
+ 542: '在庫切れ時の注文受付'
42
+ 543: '在庫あり時納期管理番号'
43
+ 544: '在庫切れ時納期管理番号'
44
+ 552: 'タグID'
45
+ 553: 'レビュー表示'
46
+ 554: 'あす楽配送管理番号'
47
+ 556: 'サイズ表リンクコード'
48
+ 564: '再入荷のお知らせボタン'
49
+ 565: 'サーチ非表示'
50
+ 566: '医薬品説明文'
51
+ 567: '医薬品注意事項'
52
+ 568: '二重価格文言ID'
53
+ 570: 'スマートフォン用商品説明文'
54
+ 702: '選択肢スタイル'
55
+ 703: 'Select/Checkbox用項目名'
56
+ 704: 'Select/Checkbox用選択肢'
57
+ 705: '項目選択肢別在庫用横軸選択肢'
58
+ 706: '項目選択肢別在庫用横軸選択肢子番号'
59
+ 707: '項目選択肢別在庫用縦軸選択肢'
60
+ 708: '項目選択肢別在庫用縦軸選択肢子番号'
61
+ 709: '項目選択肢別在庫用取り寄せ可能表示'
62
+ 710: '在庫数'
63
+ 711: '在庫戻し設定'
@@ -0,0 +1,3 @@
1
+ module RmsItemApi
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,119 @@
1
+ require "rms_item_api/version"
2
+
3
+ require 'yaml'
4
+ require 'faraday'
5
+ require 'active_support'
6
+ require 'active_support/core_ext'
7
+ require 'active_model'
8
+ require 'oga'
9
+ require 'hashie'
10
+
11
+ module RmsItemApi
12
+ class RmsItemApi
13
+ ENDPOINT = 'https://api.rms.rakuten.co.jp/es/1.0/item/'.freeze
14
+
15
+ def initialize(serviceSecret:, licenseKey:)
16
+ @serviceSecret = serviceSecret
17
+ @licenseKey = licenseKey
18
+ end
19
+
20
+ def get(item_data)
21
+ result = connection('get').get {|r| r.params['itemUrl'] = item_data}
22
+ parse_response(result.body, "Get")
23
+ end
24
+
25
+ def update(item_data)
26
+ request_xml = {itemUpdateRequest: {item: item_data}}.to_xml(
27
+ root: 'request', camelize: :lower, skip_types: true)
28
+ result = connection('update').post {|r| r.body = request_xml}
29
+ parse_response(result.body, "Update")
30
+ end
31
+
32
+ def insert(item_data)
33
+ request_xml = {itemInsertRequest: {item: item_data}}.to_xml(
34
+ root: 'request', camelize: :lower, skip_types: true)
35
+ result = connection('insert').post {|r| r.body = request_xml}
36
+ parse_response(result.body, "Insert")
37
+ end
38
+
39
+ def delete(item_data)
40
+ request_xml = {itemDeleteRequest: {item: item_data}}.to_xml(
41
+ root: 'request', camelize: :lower, skip_types: true)
42
+ result = connection('delete').post {|r| r.body = request_xml}
43
+ parse_response(result.body, "Delete")
44
+ end
45
+
46
+ private
47
+
48
+ def connection(method)
49
+ Faraday.new(url: ENDPOINT + method) do |conn|
50
+ conn.adapter(Faraday.default_adapter)
51
+ conn.headers['Authorization'] = encoded_key
52
+ end
53
+ end
54
+
55
+ def encoded_key
56
+ if @serviceSecret.blank? && @licenseKey.blank?
57
+ error_msg = "serviceSecret and licenseKey are required"
58
+ raise StandardError, error_msg
59
+ else
60
+ "ESA " + Base64.strict_encode64(@serviceSecret + ":" + @licenseKey)
61
+ end
62
+ end
63
+
64
+ def parse_response(result, method)
65
+ parsed_xml = Oga.parse_xml(result)
66
+ result_code = parsed_xml.xpath("result/item#{method}Result/code").text
67
+ case method
68
+ when 'Get'
69
+ puts "#{method} succeeded"
70
+ if result_code == 'N000'
71
+ xpoint = 'result/itemGetResult/item'
72
+ parsed_xml.xpath(xpoint).each do |xml|
73
+ xml.children.each_with_index do |x, index|
74
+ not_have_children = true
75
+
76
+ x.children.each do |y|
77
+ y.children.each do |z|
78
+ not_have_children = false
79
+ begin
80
+ self.define_singleton_method(z.name.underscore) {
81
+ z.text.force_encoding('utf-8')
82
+ }
83
+ rescue => e
84
+ puts e
85
+ end
86
+ end
87
+ end
88
+
89
+ if not_have_children
90
+ self.define_singleton_method(x.name.underscore) {
91
+ x.text.force_encoding('utf-8')
92
+ }
93
+ end
94
+
95
+ end
96
+ end
97
+ return self
98
+ else
99
+ puts "指定された商品管理番号は存在しません"
100
+ end
101
+ when 'Update', 'Insert', 'Delete'
102
+ if result_code == 'N000'
103
+ puts "#{method} succeeded"
104
+ else
105
+ config_file = "#{File.dirname(__FILE__)}/../config/field_name.yml"
106
+ field_name = Hashie::Mash.new(YAML.load_file(config_file))
107
+ xpoint = "result/item#{method}Result/errormessages"
108
+ parsed_xml.xpath(xpoint).each do |xml|
109
+ xml.children.each do |x|
110
+ error_field = x.xpath('fieldId').text
111
+ error_description = x.xpath('msg').text.force_encoding('utf-8')
112
+ puts error_msg = "#{field_name[error_field]}:#{error_description}"
113
+ end
114
+ end
115
+ end
116
+ end # case method
117
+ end # def parse_response
118
+ end # class rms_item_api
119
+ end # module rms_item_api
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rms_item_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rms_item_api"
8
+ spec.version = RmsItemApi::VERSION
9
+ spec.authors = ["t4traw"]
10
+ spec.email = ["t4traw@gmail.com"]
11
+
12
+ spec.summary = %q{RMSの商品APIを簡単に叩けるrubyラッパー}
13
+ spec.description = %q{RMSの商品APIを簡単に叩けるrubyラッパー}
14
+ spec.homepage = "https://github.com/t4traw/rms_item_api"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "faraday"
22
+ spec.add_dependency "activesupport"
23
+ spec.add_dependency "activemodel"
24
+ spec.add_dependency "oga"
25
+ spec.add_dependency "hashie"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.10"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec"
30
+ spec.add_development_dependency "pry"
31
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rms_item_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - t4traw
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activemodel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: oga
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: hashie
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: RMSの商品APIを簡単に叩けるrubyラッパー
140
+ email:
141
+ - t4traw@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".travis.yml"
149
+ - Gemfile
150
+ - LICENSE
151
+ - README.md
152
+ - Rakefile
153
+ - bin/console
154
+ - bin/setup
155
+ - config/field_name.yml
156
+ - lib/rms_item_api.rb
157
+ - lib/rms_item_api/version.rb
158
+ - rms_item_api.gemspec
159
+ homepage: https://github.com/t4traw/rms_item_api
160
+ licenses: []
161
+ metadata: {}
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 2.4.5
179
+ signing_key:
180
+ specification_version: 4
181
+ summary: RMSの商品APIを簡単に叩けるrubyラッパー
182
+ test_files: []