lightspeed_restaurant 3.3.0 → 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +2 -2
- data/CHANGELOG.md +9 -0
- data/lib/lightspeed_restaurant/errors/rate_limit_error.rb +6 -0
- data/lib/lightspeed_restaurant/request.rb +20 -8
- data/lib/lightspeed_restaurant/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcb898002a965d223157c8e9a9fc1f1df746f9ecdaa65d8a4717e6d14629fcdc
|
4
|
+
data.tar.gz: 915188dfa294dac38cfe8507d4b9d0611cfe992a339c5c8fc9ec38530f3db7f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 652561c77ab12b27ceb85cd2cbb239be375ee3c5a699a3fb75f319182e2393b7b917de02b43f046f5cfefa602b099526541e2a956754e2eed83eaeeb4d4ab940
|
7
|
+
data.tar.gz: f1fbcf6e664ae71985fb6de22912f821306e0a768b8686c69c73eb177d6b4cd7f17c338e186ff40449a197bf1feec09ef8a0c8e0050c88c1a8adc021ccc624e9
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.6.
|
1
|
+
ruby-2.6.5
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -5,12 +5,17 @@ require 'lightspeed_restaurant/errors/api_error'
|
|
5
5
|
require 'lightspeed_restaurant/errors/authentication_error'
|
6
6
|
require 'lightspeed_restaurant/errors/invalid_request_error'
|
7
7
|
require 'lightspeed_restaurant/errors/not_found_error'
|
8
|
+
require 'lightspeed_restaurant/errors/rate_limit_error'
|
8
9
|
require 'uri'
|
9
10
|
|
10
11
|
module LightspeedRestaurantClient
|
11
12
|
class Request
|
13
|
+
STAGING_URL = 'http://staging-integration.posios.com'
|
14
|
+
|
15
|
+
attr_reader :base_uri, :path, :token, :body, :headers, :query, :logger, :connection
|
16
|
+
|
12
17
|
def initialize(base_uri, path, token, body = {}, query = {}, logger = nil)
|
13
|
-
@base_uri = base_uri ||
|
18
|
+
@base_uri = base_uri || STAGING_URL
|
14
19
|
@headers = { 'Content-Type' => 'application/json', 'X-Auth-Token' => token }
|
15
20
|
@body = body.to_json
|
16
21
|
@query = query
|
@@ -24,7 +29,7 @@ module LightspeedRestaurantClient
|
|
24
29
|
|
25
30
|
def perform(**args)
|
26
31
|
log_request(args[:method])
|
27
|
-
response =
|
32
|
+
response = connection.request(args.merge(path: path, headers: headers, body: body, query: query))
|
28
33
|
if [200, 201].include?(response.status)
|
29
34
|
response.body
|
30
35
|
else
|
@@ -35,13 +40,13 @@ module LightspeedRestaurantClient
|
|
35
40
|
private
|
36
41
|
|
37
42
|
def log_request(http_method)
|
38
|
-
|
39
|
-
"#{http_method} #{
|
43
|
+
logger.info('request') do
|
44
|
+
"#{http_method} #{base_uri}#{path} : #{query} - #{body}"
|
40
45
|
end
|
41
46
|
end
|
42
47
|
|
43
48
|
def handle_error(response)
|
44
|
-
|
49
|
+
logger.error('response') { "Error : #{response.status} #{response.body}" }
|
45
50
|
case response.status
|
46
51
|
when 400
|
47
52
|
raise invalid_request_error(response)
|
@@ -51,6 +56,8 @@ module LightspeedRestaurantClient
|
|
51
56
|
raise unauthorized_error(response)
|
52
57
|
when 404
|
53
58
|
raise not_found_error(response)
|
59
|
+
when 429
|
60
|
+
raise rate_limit_error(response)
|
54
61
|
else
|
55
62
|
raise response_object_error(response)
|
56
63
|
end
|
@@ -66,17 +73,22 @@ module LightspeedRestaurantClient
|
|
66
73
|
|
67
74
|
def response_object_error(response)
|
68
75
|
APIError.new("Invalid response object from API: #{JSON.parse(response.body)['description']}",
|
69
|
-
|
76
|
+
response.status, response.body, response.headers)
|
70
77
|
end
|
71
78
|
|
72
79
|
def invalid_request_error(response)
|
73
80
|
InvalidRequestError.new(JSON.parse(response.body)['description'],
|
74
|
-
|
81
|
+
response.status, response.body, response.headers)
|
75
82
|
end
|
76
83
|
|
77
84
|
def authentication_error(response)
|
78
85
|
AuthenticationError.new(JSON.parse(response.body)['description'],
|
79
|
-
|
86
|
+
response.status, response.body, response.headers)
|
87
|
+
end
|
88
|
+
|
89
|
+
def rate_limit_error(response)
|
90
|
+
RateLimitError.new(JSON.parse(response.body)['description'],
|
91
|
+
response.status, response.body, response.headers)
|
80
92
|
end
|
81
93
|
end
|
82
94
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lightspeed_restaurant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olivier Buffon, Laurent Cobos, Sybil Deboin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -179,6 +179,7 @@ files:
|
|
179
179
|
- ".ruby-gemset"
|
180
180
|
- ".ruby-version"
|
181
181
|
- ".travis.yml"
|
182
|
+
- CHANGELOG.md
|
182
183
|
- Gemfile
|
183
184
|
- LICENSE.txt
|
184
185
|
- README.md
|
@@ -199,6 +200,7 @@ files:
|
|
199
200
|
- lib/lightspeed_restaurant/errors/invalid_request_error.rb
|
200
201
|
- lib/lightspeed_restaurant/errors/lightspeed_restaurant_error.rb
|
201
202
|
- lib/lightspeed_restaurant/errors/not_found_error.rb
|
203
|
+
- lib/lightspeed_restaurant/errors/rate_limit_error.rb
|
202
204
|
- lib/lightspeed_restaurant/errors/unauthorized_error.rb
|
203
205
|
- lib/lightspeed_restaurant/operations/create.rb
|
204
206
|
- lib/lightspeed_restaurant/operations/destroy.rb
|