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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18eb9ef7e7bb62d418c019eafb350c64741007eb
4
- data.tar.gz: aedde8a60516a595b7cf8e9193b145f963f2cf79
3
+ metadata.gz: d00ab91860aad728eef8944c2f1780820514231f
4
+ data.tar.gz: 6b19986e065a65f05307b3605ab0b5b1fb5379d3
5
5
  SHA512:
6
- metadata.gz: 0eb2e4d62b5a10c1eacd2853862db17e69448ed345a7e433ce3bd89019914933c160c55fe669cecf54b1b0ef24502feaffba0a9a633d4991c27b1cfb7dad346e
7
- data.tar.gz: 6e3c6bd3b8f8fe340dfb13d90972137f8c1a64a06017284cd9e3be42f8aa08f76cb84ff45b955328aa61299620b18baec96ce243f49955f687bead3791b47cf2
6
+ metadata.gz: 692a5db8c82fdf2bcd5a0bd20d5f34f218982974d78860a2e7d9674fd8d21349fb6f97d735e6b8c1cb9613f77c0f5314a9faf52493a1aff837ed8a146244a843
7
+ data.tar.gz: 385c4aff9674d1db52ddfcb4765a091211541b2f28a1bd7904392bd4a6528bb3b19514d13e1a05175648871bbe87532747b5ffb3855d0ead63e8dc3fa77a787c
data/README.md CHANGED
@@ -33,7 +33,7 @@ Next, make requests using the resource class you need:
33
33
  ```ruby
34
34
  customers = LightspeedRestaurant::Customer.all
35
35
  customer = customers.first
36
- customer.firstName = 'Micheal'
36
+ customer.firstName = 'Tom'
37
37
  customer.save
38
38
  ```
39
39
  That's it!
data/circle.yml CHANGED
@@ -5,5 +5,6 @@ machine:
5
5
  RACK_ENV: test
6
6
  test:
7
7
  override:
8
+ - bundle exec bundle-audit check --update
9
+ - bundle exec rubocop
8
10
  - bundle exec rspec --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/junit/rspec.xml --format progress
9
- - bundle exec rubocop
@@ -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, :base_url
14
- end
16
+ attr_accessor :api_token, :base_uri
15
17
 
16
- def self.get(path, body = {}, query = {})
17
- request(path, body, query).perform(method: :get)
18
- end
18
+ def get(path, body = {}, query = {})
19
+ request(path, body, query).perform(method: :get)
20
+ end
19
21
 
20
- def self.post(path, body = {}, query = {})
21
- request(path, body, query).perform(method: :post)
22
- end
22
+ def post(path, body = {}, query = {})
23
+ request(path, body, query).perform(method: :post)
24
+ end
23
25
 
24
- def self.put(path, body = {}, query = {})
25
- request(path, body, query).perform(method: :put)
26
- end
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
- private
30
+ def delete(path, body = {}, query = {})
31
+ request(path, body, query).perform(method: :delete)
32
+ end
33
33
 
34
- def self.request(path, body, query)
35
- LightspeedRestaurant::Request.new(@base_url, path, @api_token, body, query)
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
- self.class.attributes.each do |attribute|
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 to_hash
12
- self.class.attributes.each_with_object({}) do |attribute, h|
13
- h[attribute] = instance_variable_get("@#{attribute}")
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
- to_hash.to_json
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 LightspeedRestaurant::Operations::Save
11
- extend LightspeedRestaurant::Operations::Create
12
- extend LightspeedRestaurant::Operations::Update
13
- extend LightspeedRestaurant::Operations::Find
14
- extend LightspeedRestaurant::Operations::List
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
- new(attributes.merge!(id: response.to_i))
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
- alias_method :all, :list
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(base_url, path, token, body = {}, query = {})
11
- @base_url = base_url || 'http://staging-exact-integration.posios.com'
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(@base_url)
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
- fail invalid_request_error(response)
33
+ raise invalid_request_error(response)
34
34
  when 401
35
- fail authentication_error(response)
35
+ raise authentication_error(response)
36
36
  when 403
37
- fail unauthorized_error(response)
37
+ raise unauthorized_error(response)
38
38
  when 404
39
- fail not_found_error(response)
39
+ raise not_found_error(response)
40
40
  else
41
- fail response_object_error(response)
41
+ raise response_object_error(response)
42
42
  end
43
43
  end
44
44
 
@@ -1,3 +1,3 @@
1
1
  module LightspeedRestaurant
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'.freeze
3
3
  end
@@ -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.3
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: 2015-12-10 00:00:00.000000000 Z
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