rakuten_web_service 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +1 -1
- data/lib/rakuten_web_service/client.rb +18 -1
- data/lib/rakuten_web_service/version.rb +1 -1
- data/spec/rakuten_web_service/client_spec.rb +75 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTMxYmJkZDY4MjE0MDI0MDIzZDIyOTRkN2EyMGU1NjRhMDMzMDg5NA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODY4NjQ2MGI2Mzc0OTE4ZDE0OWE4ZmIwNTZiNGYyN2UxMTFmOWJmNQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2ZhY2UzYmY0ZjlhZDAwNWY3OThkMWIzODVkZDZhMmUyNDczYjY0NDRjNzM3
|
10
|
+
M2IzYjM1NzY1NzBlNWFjODhlNWRiNTkyYjE4NmQ3ODE3MjI0ZjEwMWMwY2E3
|
11
|
+
NzNhM2YxZGZkYTQwYjA2MWUyMWJhZmQ2MGE2YmIyNzdkYzJjZjk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGNjNzQzNWFlNTBhNjg1ZTZkNWYyMjk0ZjcyODcwMGM5ZDg5YzQ5MTVkOTBi
|
14
|
+
N2E0NTViMjc3MTg3MTAwNTkxYzZmMjhkMTQzODE0NjE0ZGEzNWFjYTY0NjNj
|
15
|
+
NWQ0MDJhYzZkMzMwMDc4MzUzMWE0YjUwZGRlMGYxM2FiMjQyZWU=
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# RakutenWebService
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/satoryu/rakuten_web_service.png?branch=master)](https://travis-ci.org/satoryu/rakuten_web_service)
|
3
|
+
[![Build Status](https://travis-ci.org/satoryu/rakuten_web_service.png?branch=master)](https://travis-ci.org/satoryu/rakuten_web_service) [![Gem Version](https://badge.fury.io/rb/rakuten_web_service.png)](http://badge.fury.io/rb/rakuten_web_service)
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -2,6 +2,11 @@ require 'faraday'
|
|
2
2
|
require 'faraday_middleware'
|
3
3
|
|
4
4
|
module RakutenWebService
|
5
|
+
class WrongParameter < StandardError; end
|
6
|
+
class TooManyRequests < StandardError; end
|
7
|
+
class SystemError < StandardError; end
|
8
|
+
class ServiceUnavailable < StandardError; end
|
9
|
+
|
5
10
|
class Client
|
6
11
|
attr_reader :url, :path
|
7
12
|
|
@@ -14,7 +19,19 @@ module RakutenWebService
|
|
14
19
|
def get(query)
|
15
20
|
query = RakutenWebService.configuration.generate_parameters.merge(query)
|
16
21
|
query = convert_snake_key_to_camel_key(query)
|
17
|
-
connection.get(path, query)
|
22
|
+
response = connection.get(path, query)
|
23
|
+
case response.status
|
24
|
+
when 200
|
25
|
+
return response
|
26
|
+
when 400
|
27
|
+
raise WrongParameter, response.body['error_description']
|
28
|
+
when 429
|
29
|
+
raise TooManyRequests, response.body['error_description']
|
30
|
+
when 500
|
31
|
+
raise SystemError, response.body['error_description']
|
32
|
+
when 503
|
33
|
+
raise ServiceUnavailable, response.body['error_description']
|
34
|
+
end
|
18
35
|
end
|
19
36
|
|
20
37
|
private
|
@@ -9,11 +9,14 @@ describe RakutenWebService::Client do
|
|
9
9
|
let(:expected_query) do
|
10
10
|
{ :affiliateId => affiliate_id, :applicationId => application_id }
|
11
11
|
end
|
12
|
+
let(:expected_response) do
|
13
|
+
{ :body => '{"status":"ok"}' }
|
14
|
+
end
|
12
15
|
|
13
16
|
before do
|
14
17
|
@expected_request = stub_request(:get, endpoint).
|
15
18
|
with(:query => expected_query).
|
16
|
-
to_return(
|
19
|
+
to_return(expected_response)
|
17
20
|
|
18
21
|
RakutenWebService.configuration do |c|
|
19
22
|
c.affiliate_id = 'default_affiliate_id'
|
@@ -21,28 +24,85 @@ describe RakutenWebService::Client do
|
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
describe '#get' do
|
28
|
+
context 'call get without any parameters' do
|
29
|
+
before do
|
30
|
+
client.get({})
|
31
|
+
end
|
32
|
+
|
33
|
+
specify 'call endpoint with default parameters' do
|
34
|
+
expect(@expected_request).to have_been_made.once
|
35
|
+
end
|
27
36
|
end
|
28
37
|
|
29
|
-
|
30
|
-
|
38
|
+
context 'call get with parameters' do
|
39
|
+
let(:affiliate_id) { 'latest_affiliate_id' }
|
40
|
+
let(:application_id) { 'latest_application_id' }
|
41
|
+
|
42
|
+
before do
|
43
|
+
client.get(:affiliate_id => affiliate_id,
|
44
|
+
:application_id => application_id)
|
45
|
+
end
|
46
|
+
|
47
|
+
specify 'call endpoint with given parameters' do
|
48
|
+
expect(@expected_request).to have_been_made.once
|
49
|
+
end
|
31
50
|
end
|
32
51
|
end
|
33
52
|
|
34
|
-
|
35
|
-
|
36
|
-
|
53
|
+
describe 'about exceptions' do
|
54
|
+
context 'parameter error' do
|
55
|
+
let(:expected_response) do
|
56
|
+
{ :status => 400,
|
57
|
+
:body => '{"error": "wrong_parameter",
|
58
|
+
"error_description": "specify valid applicationId"}'
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
specify 'raises WrongParameter exception' do
|
63
|
+
expect { client.get({}) }.to raise_error(RWS::WrongParameter, 'specify valid applicationId')
|
64
|
+
end
|
37
65
|
|
38
|
-
before do
|
39
|
-
client.get(:affiliate_id => affiliate_id,
|
40
|
-
:application_id => application_id)
|
41
66
|
end
|
42
67
|
|
43
|
-
|
44
|
-
|
68
|
+
context 'Too many requests' do
|
69
|
+
let(:expected_response) do
|
70
|
+
{ :status => 429,
|
71
|
+
:body => '{ "error": "too_many_requests",
|
72
|
+
"error_description": "number of allowed requests has been exceeded for this API. please try again soon." }'
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
specify 'raises TooManyRequests exception' do
|
77
|
+
expect { client.get({}) }.to raise_error(RWS::TooManyRequests,
|
78
|
+
'number of allowed requests has been exceeded for this API. please try again soon.')
|
79
|
+
end
|
45
80
|
end
|
46
|
-
end
|
47
81
|
|
82
|
+
context 'Internal error in Rakuten Web Service' do
|
83
|
+
let(:expected_response) do
|
84
|
+
{ :status => 500,
|
85
|
+
:body => '{ "error": "system_error",
|
86
|
+
"error_description": "api logic error" }'
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
specify 'raises SystemError exception' do
|
91
|
+
expect { client.get({}) }.to raise_error(RWS::SystemError, 'api logic error')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'Unavaiable due to maintainance or overloaded' do
|
96
|
+
let(:expected_response) do
|
97
|
+
{ :status => 503,
|
98
|
+
:body => '{ "error": "service_unavailable",
|
99
|
+
"error_description": "XXX/XXX is under maintenance" }'
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
specify 'raises ServiceUnavailable exception' do
|
104
|
+
expect { client.get({}) }.to raise_error(RWS::ServiceUnavailable, 'XXX/XXX is under maintenance')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
48
108
|
end
|
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: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tatsuya Sato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|