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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1271e4221f23afce69cd775cb68e862261752a23245875b2b18899a3dce925be
4
- data.tar.gz: e005c9236aea083999a2c3f7430802cf829a455b741ef14b7fa6f050cf134c48
3
+ metadata.gz: fcb898002a965d223157c8e9a9fc1f1df746f9ecdaa65d8a4717e6d14629fcdc
4
+ data.tar.gz: 915188dfa294dac38cfe8507d4b9d0611cfe992a339c5c8fc9ec38530f3db7f2
5
5
  SHA512:
6
- metadata.gz: 39904bc01d8d1288840b56f0f9893c3c6d03776d8ce016db021d7f3243ee566ad8a6203efeb2fe4b7beb7dafecb584c9789d0fc3d110b888f9dd2fe22c8f84ae
7
- data.tar.gz: e84173f6f4f2967391450bb4dac7fe60e125bbe1ba066b684a4bbf5eab44b06104221fabbab904e3a1d04d7619da6a359ce25cba39fc929f1c39c9bc10348f56
6
+ metadata.gz: 652561c77ab12b27ceb85cd2cbb239be375ee3c5a699a3fb75f319182e2393b7b917de02b43f046f5cfefa602b099526541e2a956754e2eed83eaeeb4d4ab940
7
+ data.tar.gz: f1fbcf6e664ae71985fb6de22912f821306e0a768b8686c69c73eb177d6b4cd7f17c338e186ff40449a197bf1feec09ef8a0c8e0050c88c1a8adc021ccc624e9
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.6.2
1
+ ruby-2.6.5
data/.travis.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.6.2
4
- before_install: gem install bundler -v 2.0.1
3
+ - 2.6.5
4
+ before_install: gem install bundler -v 2.0.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## 3.3.1 / 2020-02-24
4
+
5
+ - Introducing `RateLimitError` when status code is `429`
6
+
7
+ ## 3.2.0 / 2019-12-17
8
+
9
+ - Fix CVE-2019-16779
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LightspeedRestaurantClient
4
+ class RateLimitError < LightspeedRestaurantClientError
5
+ end
6
+ end
@@ -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 || 'http://staging-integration.posios.com'
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 = @connection.request(args.merge(path: @path, headers: @headers, body: @body, query: @query))
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
- @logger.info('request') do
39
- "#{http_method} #{@base_uri}#{@path} : #{@query} - #{@body}"
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
- @logger.error('response') { "Error : #{response.status} #{response.body}" }
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
- response.status, response.body, response.headers)
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
- response.status, response.body, response.headers)
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
- response.status, response.body, response.headers)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LightspeedRestaurantClient
4
- VERSION = '3.3.0'
4
+ VERSION = '3.3.1'
5
5
  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.0
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: 2019-12-17 00:00:00.000000000 Z
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