rms_web_service 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/README.md +2 -1
- data/lib/rms_web_service/configuration.rb +9 -13
- data/lib/rms_web_service/item/delete.rb +0 -15
- data/lib/rms_web_service/item/get.rb +0 -5
- data/lib/rms_web_service/item/insert.rb +0 -15
- data/lib/rms_web_service/item/items_update.rb +0 -19
- data/lib/rms_web_service/item/search.rb +0 -8
- data/lib/rms_web_service/item/update.rb +0 -15
- data/lib/rms_web_service/item.rb +86 -7
- data/lib/rms_web_service/version.rb +1 -1
- data/lib/rms_web_service.rb +18 -1
- data/rms_web_service.gemspec +3 -3
- data/spec/rms_web_service/configuration_spec.rb +37 -24
- data/spec/rms_web_service/item/delete_spec.rb +2 -2
- data/spec/rms_web_service/item/get_spec.rb +1 -1
- data/spec/rms_web_service/item/insert_spec.rb +2 -2
- data/spec/rms_web_service/item/items_update_spec.rb +1 -1
- data/spec/rms_web_service/item/search_spec.rb +1 -1
- data/spec/rms_web_service/item/update_spec.rb +2 -2
- data/spec/rms_web_service/item_spec.rb +1 -1
- data/spec/rms_web_service_spec.rb +10 -0
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48677c86bf718efe72101c4ceb6ef142e9326b4a
|
4
|
+
data.tar.gz: 813da41d26251b10ed74baf5871261c8b815d870
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b4cbad54e393a229ccd5c51ebb8216c4b8986ced086dbdd2836af3ad4e766499dc87e20e460a0b40f5edaba4fe5bd2c8fc94df2e2967164951e41e67506f27a
|
7
|
+
data.tar.gz: 9be9a613238343dcad86e5f6b75b3cb1bf09780de4c60db32a4c7408303f37db8288dfd6eb65e9e3adfd902d90f372846dc513083ac4a5c55d61d94d747d97f2
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format doc
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
RMS Webservice APIのRubyラッパーです。
|
4
4
|
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/rms_web_service.svg)](http://badge.fury.io/rb/rms_web_service)
|
5
6
|
[![Build Status](https://travis-ci.org/kamiya54/rms_web_service.svg)](https://travis-ci.org/kamiya54/rms_web_service)
|
6
7
|
|
7
8
|
#### ご注意
|
@@ -33,7 +34,7 @@ Or install it yourself as:
|
|
33
34
|
`RmsWebService.configuration`でサービスIDとライセンスキーを設定できます。各キーはRMSより発行できます。
|
34
35
|
|
35
36
|
```ruby
|
36
|
-
RmsWebService.
|
37
|
+
RmsWebService.configure do |c|
|
37
38
|
c.service_secret = "dummy_service_secret"
|
38
39
|
c.license_key = "dummy_license_key"
|
39
40
|
end
|
@@ -4,20 +4,16 @@ module RmsWebService
|
|
4
4
|
class Configuration
|
5
5
|
attr_accessor :service_secret, :license_key
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
else
|
11
|
-
raise AuthError, 'please set serviceSecret and licenseKey'
|
12
|
-
end
|
7
|
+
def initialize(args={})
|
8
|
+
@service_secret = args[:service_secret]
|
9
|
+
@license_key = args[:license_key]
|
13
10
|
end
|
14
|
-
end
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
return @configuration
|
20
|
-
end
|
12
|
+
def encoded_keys
|
13
|
+
raise RmsWebService::ParameterError, 'service_secret is required' unless service_secret.present?
|
14
|
+
raise RmsWebService::ParameterError, 'license_key is required' unless license_key.present?
|
21
15
|
|
22
|
-
|
16
|
+
"ESA " + Base64.encode64(service_secret + ":" + license_key).chomp
|
17
|
+
end
|
18
|
+
end
|
23
19
|
end
|
@@ -1,20 +1,5 @@
|
|
1
1
|
module RmsWebService
|
2
2
|
class Item
|
3
|
-
def self.delete(args)
|
4
|
-
xml_object = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
5
|
-
xml.request do
|
6
|
-
xml.itemDeleteRequest do
|
7
|
-
xml.item do
|
8
|
-
args.each {|key, value| eval("xml.#{key.to_s.camelize(:lower)} '#{value}'")}
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
request = connection("item/delete").post {|req| req.body = xml_object.to_xml}
|
15
|
-
return Delete.new(request.body)
|
16
|
-
end
|
17
|
-
|
18
3
|
class Delete
|
19
4
|
include Response
|
20
5
|
def initialize(xml)
|
@@ -1,20 +1,5 @@
|
|
1
1
|
module RmsWebService
|
2
2
|
class Item
|
3
|
-
def self.insert(args)
|
4
|
-
xml_object = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
5
|
-
xml.request do
|
6
|
-
xml.itemInsertRequest do
|
7
|
-
xml.item do
|
8
|
-
args.each {|key, value| eval("xml.#{key.to_s.camelize(:lower)} '#{value}'")}
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
request = connection("item/insert").post {|req| req.body = xml_object.to_xml}
|
15
|
-
return Insert.new(request.body)
|
16
|
-
end
|
17
|
-
|
18
3
|
class Insert
|
19
4
|
include Response
|
20
5
|
def initialize(xml)
|
@@ -1,24 +1,5 @@
|
|
1
1
|
module RmsWebService
|
2
2
|
class Item
|
3
|
-
def self.items_update(args)
|
4
|
-
xml_object = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
5
|
-
xml.request do
|
6
|
-
xml.itemsUpdateRequest do
|
7
|
-
xml.items do
|
8
|
-
args.each do |item|
|
9
|
-
xml.item do
|
10
|
-
item.each {|key, value| eval("xml.#{key.to_s.camelize(:lower)} '#{value}'")}
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
request = connection("items/update").post {|req| req.body = xml_object.to_xml}
|
19
|
-
return ItemsUpdate.new(request.body)
|
20
|
-
end
|
21
|
-
|
22
3
|
class ItemsUpdate < Array
|
23
4
|
include Response
|
24
5
|
def initialize(xml)
|
@@ -1,13 +1,5 @@
|
|
1
1
|
module RmsWebService
|
2
2
|
class Item
|
3
|
-
def self.search(args)
|
4
|
-
request = connection("item/search").get do |req|
|
5
|
-
args.each {|key, value| req.params["#{key.to_s.camelize(:lower)}"] = args[:"#{key}"]}
|
6
|
-
end
|
7
|
-
|
8
|
-
return Search.new(request.body)
|
9
|
-
end
|
10
|
-
|
11
3
|
class Search < ::Array
|
12
4
|
include Response
|
13
5
|
def initialize(xml)
|
@@ -1,20 +1,5 @@
|
|
1
1
|
module RmsWebService
|
2
2
|
class Item
|
3
|
-
def self.update(args)
|
4
|
-
xml_object = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
5
|
-
xml.request do
|
6
|
-
xml.itemUpdateRequest do
|
7
|
-
xml.item do
|
8
|
-
args.each {|key, value| eval("xml.#{key.to_s.camelize(:lower)} '#{value}'")}
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
request = connection("item/update").post {|req| req.body = xml_object.to_xml}
|
15
|
-
return Update.new(request.body)
|
16
|
-
end
|
17
|
-
|
18
3
|
class Update
|
19
4
|
include Response
|
20
5
|
def initialize(xml)
|
data/lib/rms_web_service/item.rb
CHANGED
@@ -12,15 +12,94 @@ require 'rms_web_service/item/items_update'
|
|
12
12
|
|
13
13
|
module RmsWebService
|
14
14
|
class Item
|
15
|
-
|
16
|
-
connection
|
17
|
-
|
18
|
-
|
15
|
+
class << self
|
16
|
+
def connection(method)
|
17
|
+
connection = Faraday.new(:url => endpoint(method)) do |c|
|
18
|
+
c.adapter Faraday.default_adapter
|
19
|
+
c.headers['Authorization'] = RmsWebService.configuration.encoded_keys
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def endpoint(method)
|
24
|
+
return Endpoint + method
|
25
|
+
end
|
26
|
+
|
27
|
+
def get(args)
|
28
|
+
request = connection('item/get').get {|req| req.params['itemUrl'] = args[:item_url]}
|
29
|
+
return Get.new(request.body)
|
19
30
|
end
|
20
|
-
end
|
21
31
|
|
22
|
-
|
23
|
-
|
32
|
+
def insert(args)
|
33
|
+
xml_object = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
34
|
+
xml.request do
|
35
|
+
xml.itemInsertRequest do
|
36
|
+
xml.item do
|
37
|
+
args.each {|key, value| eval("xml.#{key.to_s.camelize(:lower)} '#{value}'")}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
request = connection("item/insert").post {|req| req.body = xml_object.to_xml}
|
44
|
+
return Insert.new(request.body)
|
45
|
+
end
|
46
|
+
|
47
|
+
def update(args)
|
48
|
+
xml_object = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
49
|
+
xml.request do
|
50
|
+
xml.itemUpdateRequest do
|
51
|
+
xml.item do
|
52
|
+
args.each {|key, value| eval("xml.#{key.to_s.camelize(:lower)} '#{value}'")}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
request = connection("item/update").post {|req| req.body = xml_object.to_xml}
|
59
|
+
return Update.new(request.body)
|
60
|
+
end
|
61
|
+
|
62
|
+
def delete(args)
|
63
|
+
xml_object = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
64
|
+
xml.request do
|
65
|
+
xml.itemDeleteRequest do
|
66
|
+
xml.item do
|
67
|
+
args.each {|key, value| eval("xml.#{key.to_s.camelize(:lower)} '#{value}'")}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
request = connection("item/delete").post {|req| req.body = xml_object.to_xml}
|
74
|
+
return Delete.new(request.body)
|
75
|
+
end
|
76
|
+
|
77
|
+
def search(args)
|
78
|
+
request = connection("item/search").get do |req|
|
79
|
+
args.each {|key, value| req.params["#{key.to_s.camelize(:lower)}"] = args[:"#{key}"]}
|
80
|
+
end
|
81
|
+
|
82
|
+
return Search.new(request.body)
|
83
|
+
end
|
84
|
+
|
85
|
+
def items_update(args)
|
86
|
+
xml_object = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
87
|
+
xml.request do
|
88
|
+
xml.itemsUpdateRequest do
|
89
|
+
xml.items do
|
90
|
+
args.each do |item|
|
91
|
+
xml.item do
|
92
|
+
item.each {|key, value| eval("xml.#{key.to_s.camelize(:lower)} '#{value}'")}
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
request = connection("items/update").post {|req| req.body = xml_object.to_xml}
|
101
|
+
return ItemsUpdate.new(request.body)
|
102
|
+
end
|
24
103
|
end
|
25
104
|
end
|
26
105
|
end
|
data/lib/rms_web_service.rb
CHANGED
@@ -6,5 +6,22 @@ RWS = RmsWebService
|
|
6
6
|
|
7
7
|
module RmsWebService
|
8
8
|
Endpoint = "https://api.rms.rakuten.co.jp/es/1.0/"
|
9
|
-
|
9
|
+
|
10
|
+
@@configuration = Configuration.new
|
11
|
+
|
12
|
+
def configure(&block)
|
13
|
+
block.call @@configuration if block_given?
|
14
|
+
end
|
15
|
+
module_function :configure
|
16
|
+
|
17
|
+
def configuration
|
18
|
+
@@configuration
|
19
|
+
end
|
20
|
+
module_function :configuration
|
21
|
+
|
22
|
+
class AuthError < StandardError
|
23
|
+
end
|
24
|
+
|
25
|
+
class ParameterError < StandardError
|
26
|
+
end
|
10
27
|
end
|
data/rms_web_service.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["kamiya54@gmail.com"]
|
11
11
|
spec.summary = %q{Ruby wrapper for RMS Web Service.}
|
12
12
|
spec.description = %q{Ruby wrapper for RMS Web Service.}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/kamiya54/rms_web_service"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "faraday"
|
22
|
-
spec.add_dependency "nokogiri"
|
21
|
+
spec.add_dependency "faraday"
|
22
|
+
spec.add_dependency "nokogiri"
|
23
23
|
spec.add_dependency "activesupport"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.6"
|
@@ -1,31 +1,44 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
2
|
+
|
3
|
+
describe RmsWebService::Configuration do
|
4
|
+
let(:config){ described_class.new(service_secret: service_secret, license_key: license_key) }
|
5
|
+
let(:service_secret){ "dummy_service_secret" }
|
6
|
+
let(:license_key){ "dummy_license_key" }
|
7
|
+
|
8
|
+
describe "#service_secret" do
|
9
|
+
subject{ config.service_secret }
|
10
|
+
it { is_expected.to eq(service_secret) }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#license_key" do
|
14
|
+
subject{ config.license_key }
|
15
|
+
it { is_expected.to eq(license_key) }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#encoded_keys" do
|
19
|
+
context "with service_secret and license_key" do
|
20
|
+
let(:encoded_string){
|
21
|
+
encoded_credentials = Base64.encode64("#{service_secret}:#{license_key}")
|
22
|
+
"ESA #{encoded_credentials}".chomp
|
23
|
+
}
|
24
|
+
|
25
|
+
subject{ config.encoded_keys }
|
26
|
+
it { is_expected.to eq(encoded_string) }
|
12
27
|
end
|
13
28
|
|
14
|
-
context
|
15
|
-
before
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'can set parameters properly' do
|
23
|
-
expect(config.service_secret).to eq 'dummy_service_secret'
|
24
|
-
expect(config.license_key).to eq 'dummy_license_key'
|
29
|
+
context "without service_secret" do
|
30
|
+
before { config.service_secret = nil }
|
31
|
+
|
32
|
+
it "should raise ParameterError" do
|
33
|
+
expect{ config.encoded_keys }.to raise_error(RmsWebService::ParameterError, /service_secret/)
|
25
34
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
35
|
+
end
|
36
|
+
|
37
|
+
context "without license_key" do
|
38
|
+
before { config.license_key = nil }
|
39
|
+
|
40
|
+
it "should raise ParameterError" do
|
41
|
+
expect{ config.encoded_keys }.to raise_error(RmsWebService::ParameterError, /license_key/)
|
29
42
|
end
|
30
43
|
end
|
31
44
|
end
|
@@ -6,12 +6,12 @@ describe RmsWebService::Item::Delete do
|
|
6
6
|
let(:api) {RmsWebService::Item.delete({:item_url => 'test001'})}
|
7
7
|
|
8
8
|
before :all do
|
9
|
-
RmsWebService.
|
9
|
+
RmsWebService.configure do |c|
|
10
10
|
c.service_secret = 'dummy_service_secret'
|
11
11
|
c.license_key = 'dummy_license_key'
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
before :each do
|
16
16
|
stub_request(:post, "https://api.rms.rakuten.co.jp/es/1.0/item/delete")
|
17
17
|
.to_return(:status => 200, body: fixture('delete.xml'))
|
@@ -6,7 +6,7 @@ describe RmsWebService::Item::Get do
|
|
6
6
|
let(:api) {RmsWebService::Item.get(:item_url => 'test001')}
|
7
7
|
|
8
8
|
before do
|
9
|
-
RmsWebService.
|
9
|
+
RmsWebService.configure do |c|
|
10
10
|
c.service_secret = 'dummy_service_secret'
|
11
11
|
c.license_key = 'dummy_license_key'
|
12
12
|
end
|
@@ -10,12 +10,12 @@ describe RmsWebService::Item::Insert do
|
|
10
10
|
})}
|
11
11
|
|
12
12
|
before :all do
|
13
|
-
RmsWebService.
|
13
|
+
RmsWebService.configure do |c|
|
14
14
|
c.service_secret = 'dummy_service_secret'
|
15
15
|
c.license_key = 'dummy_license_key'
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
before :each do
|
20
20
|
stub_request(:post, "https://api.rms.rakuten.co.jp/es/1.0/item/insert")
|
21
21
|
.to_return(:status => 200, body: fixture('insert.xml'))
|
@@ -6,7 +6,7 @@ describe RmsWebService::Item::Search do
|
|
6
6
|
let(:api) {RmsWebService::Item.search(:item_name => 'test001', :item_price_from => 1)}
|
7
7
|
|
8
8
|
before do
|
9
|
-
RmsWebService.
|
9
|
+
RmsWebService.configure do |c|
|
10
10
|
c.service_secret = 'dummy_service_secret'
|
11
11
|
c.license_key = 'dummy_license_key'
|
12
12
|
end
|
@@ -6,12 +6,12 @@ describe RmsWebService::Item::Update do
|
|
6
6
|
let(:api) {RmsWebService::Item.update({:item_url => 'test001', :item_price => '10000'})}
|
7
7
|
|
8
8
|
before :all do
|
9
|
-
RmsWebService.
|
9
|
+
RmsWebService.configure do |c|
|
10
10
|
c.service_secret = 'dummy_service_secret'
|
11
11
|
c.license_key = 'dummy_license_key'
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
before :each do
|
16
16
|
stub_request(:post, "https://api.rms.rakuten.co.jp/es/1.0/item/update")
|
17
17
|
.to_return(:status => 200, body: fixture('update.xml'))
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rms_web_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kamiya54
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activesupport
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,6 +130,7 @@ extensions: []
|
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
132
|
- .gitignore
|
133
|
+
- .rspec
|
133
134
|
- .travis.yml
|
134
135
|
- Gemfile
|
135
136
|
- Guardfile
|
@@ -165,7 +166,7 @@ files:
|
|
165
166
|
- spec/rms_web_service/item_spec.rb
|
166
167
|
- spec/rms_web_service_spec.rb
|
167
168
|
- spec/spec_helper.rb
|
168
|
-
homepage:
|
169
|
+
homepage: https://github.com/kamiya54/rms_web_service
|
169
170
|
licenses:
|
170
171
|
- MIT
|
171
172
|
metadata: {}
|