lightspeed_restaurant 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/circle.yml +2 -1
- data/lib/lightspeed_restaurant.rb +19 -18
- data/lib/lightspeed_restaurant/base.rb +16 -9
- data/lib/lightspeed_restaurant/customer.rb +5 -26
- data/lib/lightspeed_restaurant/customer_credit_change.rb +22 -0
- data/lib/lightspeed_restaurant/operations/create.rb +5 -1
- data/lib/lightspeed_restaurant/operations/list.rb +2 -2
- data/lib/lightspeed_restaurant/receipt.rb +16 -0
- data/lib/lightspeed_restaurant/request.rb +8 -8
- data/lib/lightspeed_restaurant/version.rb +1 -1
- data/lightspeed_restaurant.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d00ab91860aad728eef8944c2f1780820514231f
|
4
|
+
data.tar.gz: 6b19986e065a65f05307b3605ab0b5b1fb5379d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 692a5db8c82fdf2bcd5a0bd20d5f34f218982974d78860a2e7d9674fd8d21349fb6f97d735e6b8c1cb9613f77c0f5314a9faf52493a1aff837ed8a146244a843
|
7
|
+
data.tar.gz: 385c4aff9674d1db52ddfcb4765a091211541b2f28a1bd7904392bd4a6528bb3b19514d13e1a05175648871bbe87532747b5ffb3855d0ead63e8dc3fa77a787c
|
data/README.md
CHANGED
data/circle.yml
CHANGED
@@ -6,32 +6,33 @@ require 'json'
|
|
6
6
|
|
7
7
|
require 'lightspeed_restaurant/version'
|
8
8
|
require 'lightspeed_restaurant/request'
|
9
|
+
|
9
10
|
require 'lightspeed_restaurant/customer'
|
11
|
+
require 'lightspeed_restaurant/customer_credit_change'
|
12
|
+
require 'lightspeed_restaurant/receipt'
|
10
13
|
|
11
14
|
module LightspeedRestaurant
|
12
15
|
class << self
|
13
|
-
attr_accessor :api_token, :
|
14
|
-
end
|
16
|
+
attr_accessor :api_token, :base_uri
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
def get(path, body = {}, query = {})
|
19
|
+
request(path, body, query).perform(method: :get)
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
def post(path, body = {}, query = {})
|
23
|
+
request(path, body, query).perform(method: :post)
|
24
|
+
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
def self.delete(path, body = {}, query = {})
|
29
|
-
request(path, body, query).perform(method: :delete)
|
30
|
-
end
|
26
|
+
def put(path, body = {}, query = {})
|
27
|
+
request(path, body, query).perform(method: :put)
|
28
|
+
end
|
31
29
|
|
32
|
-
|
30
|
+
def delete(path, body = {}, query = {})
|
31
|
+
request(path, body, query).perform(method: :delete)
|
32
|
+
end
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
def request(path, body, query)
|
35
|
+
Request.new(@base_uri, path, @api_token, body, query)
|
36
|
+
end
|
36
37
|
end
|
37
38
|
end
|
@@ -1,21 +1,28 @@
|
|
1
1
|
module LightspeedRestaurant
|
2
2
|
class Base
|
3
3
|
def initialize(data = {})
|
4
|
-
|
5
|
-
data = data.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
|
6
|
-
value = ['N/A', ''].include?(data[attribute]) ? nil : data[attribute]
|
7
|
-
send("#{attribute}=", value)
|
8
|
-
end
|
4
|
+
convert_to_obj(data)
|
9
5
|
end
|
10
6
|
|
11
|
-
def
|
12
|
-
|
13
|
-
h[
|
7
|
+
def attributes
|
8
|
+
instance_variables.each_with_object({}) do |instance_variable, h|
|
9
|
+
h[instance_variable[1..instance_variable.length]] = instance_variable_get(instance_variable)
|
14
10
|
end
|
15
11
|
end
|
16
12
|
|
17
13
|
def to_json
|
18
|
-
|
14
|
+
attributes.to_json
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def convert_to_obj(h)
|
20
|
+
h.each do |key, value|
|
21
|
+
self.class.send(:attr_accessor, key)
|
22
|
+
value = ['Missing', 'N/A', ''].include?(value) ? nil : value
|
23
|
+
instance_variable_set("@#{key}", value)
|
24
|
+
convert_to_obj(value) if value.is_a? Hash
|
25
|
+
end
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
@@ -7,32 +7,11 @@ require 'lightspeed_restaurant/operations/save'
|
|
7
7
|
|
8
8
|
module LightspeedRestaurant
|
9
9
|
class Customer < LightspeedRestaurant::Base
|
10
|
-
include
|
11
|
-
extend
|
12
|
-
extend
|
13
|
-
extend
|
14
|
-
extend
|
15
|
-
|
16
|
-
def self.attributes
|
17
|
-
[:id,
|
18
|
-
:city,
|
19
|
-
:country,
|
20
|
-
:deliveryCity,
|
21
|
-
:deliveryCountry,
|
22
|
-
:deliveryStreet,
|
23
|
-
:deliveryStreetNumber,
|
24
|
-
:deliveryZip,
|
25
|
-
:email,
|
26
|
-
:firstName,
|
27
|
-
:lastName,
|
28
|
-
:street,
|
29
|
-
:streetNumber,
|
30
|
-
:telephone,
|
31
|
-
:zip,
|
32
|
-
:links].freeze
|
33
|
-
end
|
34
|
-
|
35
|
-
attr_accessor(*attributes)
|
10
|
+
include Operations::Save
|
11
|
+
extend Operations::Create
|
12
|
+
extend Operations::Update
|
13
|
+
extend Operations::Find
|
14
|
+
extend Operations::List
|
36
15
|
|
37
16
|
def self.resource_name
|
38
17
|
'Customer'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'lightspeed_restaurant/base'
|
2
|
+
require 'lightspeed_restaurant/operations/list'
|
3
|
+
require 'lightspeed_restaurant/operations/create'
|
4
|
+
|
5
|
+
module LightspeedRestaurant
|
6
|
+
class CustomerCreditChange < LightspeedRestaurant::Base
|
7
|
+
include Operations::List
|
8
|
+
include Operations::Create
|
9
|
+
|
10
|
+
def initialize(customer_id)
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.resource_name
|
15
|
+
'CreditChange'
|
16
|
+
end
|
17
|
+
|
18
|
+
def resource_path
|
19
|
+
"#{Customer.resource_path}/#{customer_id}/#{self.class.resource_name.downcase}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -3,7 +3,11 @@ module LightspeedRestaurant
|
|
3
3
|
module Create
|
4
4
|
def create(attributes)
|
5
5
|
response = LightspeedRestaurant.post(resource_path, attributes)
|
6
|
-
|
6
|
+
if is_a?(Class)
|
7
|
+
new(attributes.merge!(id: response.to_i))
|
8
|
+
else
|
9
|
+
self.class.new(attributes.merge!(id: response.to_i))
|
10
|
+
end
|
7
11
|
end
|
8
12
|
end
|
9
13
|
end
|
@@ -5,13 +5,13 @@ module LightspeedRestaurant
|
|
5
5
|
response = JSON.parse(LightspeedRestaurant.get(resource_path, {}, params))
|
6
6
|
instantiate(response['results'])
|
7
7
|
end
|
8
|
-
|
8
|
+
alias all list
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
12
|
def instantiate(records)
|
13
13
|
records.map do |record|
|
14
|
-
new(record)
|
14
|
+
is_a?(Class) ? new(record) : self.class.new(record)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'lightspeed_restaurant/base'
|
2
|
+
require 'lightspeed_restaurant/operations/list'
|
3
|
+
|
4
|
+
module LightspeedRestaurant
|
5
|
+
class Receipt < LightspeedRestaurant::Base
|
6
|
+
extend Operations::List
|
7
|
+
|
8
|
+
def self.resource_name
|
9
|
+
'Receipt'
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.resource_path
|
13
|
+
"/rest/financial/#{resource_name.downcase}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -7,13 +7,13 @@ require 'uri'
|
|
7
7
|
|
8
8
|
module LightspeedRestaurant
|
9
9
|
class Request
|
10
|
-
def initialize(
|
11
|
-
@
|
10
|
+
def initialize(base_uri, path, token, body = {}, query = {})
|
11
|
+
@base_uri = base_uri || 'http://staging-exact-integration.posios.com'
|
12
12
|
@headers = { 'Content-Type' => 'application/json', 'X-Auth-Token' => token }
|
13
13
|
@body = body.to_json
|
14
14
|
@query = query
|
15
15
|
@path = '/PosServer' + path
|
16
|
-
@connection = Excon.new(@
|
16
|
+
@connection = Excon.new(@base_uri)
|
17
17
|
end
|
18
18
|
|
19
19
|
def perform(**args)
|
@@ -30,15 +30,15 @@ module LightspeedRestaurant
|
|
30
30
|
def handle_error(response)
|
31
31
|
case response.status
|
32
32
|
when 400
|
33
|
-
|
33
|
+
raise invalid_request_error(response)
|
34
34
|
when 401
|
35
|
-
|
35
|
+
raise authentication_error(response)
|
36
36
|
when 403
|
37
|
-
|
37
|
+
raise unauthorized_error(response)
|
38
38
|
when 404
|
39
|
-
|
39
|
+
raise not_found_error(response)
|
40
40
|
else
|
41
|
-
|
41
|
+
raise response_object_error(response)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency('rspec')
|
29
29
|
spec.add_development_dependency('pry')
|
30
30
|
spec.add_development_dependency('rubocop')
|
31
|
+
spec.add_development_dependency('bundler-audit')
|
31
32
|
spec.add_development_dependency('rspec_junit_formatter')
|
32
33
|
spec.add_development_dependency('webmock')
|
33
34
|
spec.add_development_dependency('vcr')
|
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: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olivier Buffon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler-audit
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: rspec_junit_formatter
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -161,6 +175,7 @@ files:
|
|
161
175
|
- lib/lightspeed_restaurant.rb
|
162
176
|
- lib/lightspeed_restaurant/base.rb
|
163
177
|
- lib/lightspeed_restaurant/customer.rb
|
178
|
+
- lib/lightspeed_restaurant/customer_credit_change.rb
|
164
179
|
- lib/lightspeed_restaurant/errors/api_error.rb
|
165
180
|
- lib/lightspeed_restaurant/errors/authentication_error.rb
|
166
181
|
- lib/lightspeed_restaurant/errors/invalid_request_error.rb
|
@@ -173,6 +188,7 @@ files:
|
|
173
188
|
- lib/lightspeed_restaurant/operations/list.rb
|
174
189
|
- lib/lightspeed_restaurant/operations/save.rb
|
175
190
|
- lib/lightspeed_restaurant/operations/update.rb
|
191
|
+
- lib/lightspeed_restaurant/receipt.rb
|
176
192
|
- lib/lightspeed_restaurant/request.rb
|
177
193
|
- lib/lightspeed_restaurant/version.rb
|
178
194
|
- lightspeed_restaurant.gemspec
|