lightspeed_pos 0.3.0 → 0.4.0

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
- SHA1:
3
- metadata.gz: 3e50edadd52d55b1ed3b2def3b6b10b765d8ac2a
4
- data.tar.gz: b59ae04766b48a27126491e94a4b88fbf7a71902
2
+ SHA256:
3
+ metadata.gz: 8b42db3649e13304941c1fb7770b350bccb22d5751c1f8277c290df0134ea468
4
+ data.tar.gz: b2f9b9005019a428f673e7d6999fbc3f4900f2923b13342c9050d0deb88dbc51
5
5
  SHA512:
6
- metadata.gz: 7951c24a7ee73b3840a1145b8f8c8d797e074a1b03277ea4fe814618fd7045116a41d06ae9ea1c8c723f1561e1b84547c0799a5a3d0d13f74fe0bf500a9841bd
7
- data.tar.gz: f1c67e762048bfc0a08660027e2742ed6d3d85b33467062cb558b0569fc094498f2490ee41c6e3f250cc39b0316ffd971b3a1162181a8b943b8ccb512beee387
6
+ metadata.gz: 34f6532de1edfe8417970b7b255557b7882d2bc4df373bdf69631f29bed3b941f7db5eb4a38a1a074bebc539b5e3c6e192d47d3d6db8a5294b6aa4d156fc1c10
7
+ data.tar.gz: 78455dc05e80e7246e13dd858bcb30d40956a75967ed9e8bb516e24b122be63287b8678d508d29c25483615be7ad7488395cb7a2f1a3c93631c6f819dddef06f
@@ -0,0 +1,4 @@
1
+ Dana Sherson <robot@dana.sh> Dan Sherson <me@dansherson.com>
2
+ Dana Sherson <robot@dana.sh> Daniel Sherson <me@dansherson.com>
3
+ Dana Sherson <robot@dana.sh> Dan Sherson <me@danielsherson.com>
4
+ Dana Sherson <robot@dana.sh> Daniel Sherson <me@danielsherson.com>
@@ -1,3 +1,5 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
1
3
  AlignHash:
2
4
  EnforcedLastArgumentHashStyle: always_ignore
3
5
 
@@ -42,7 +44,7 @@ PredicateName:
42
44
  - is_
43
45
  - have_
44
46
 
45
- IndentHash:
47
+ IndentFirstHashElement:
46
48
  EnforcedStyle: consistent
47
49
 
48
50
  # breaks using if blocks with assignments
@@ -65,7 +67,7 @@ SignalException:
65
67
  DoubleNegation:
66
68
  Enabled: false
67
69
 
68
- Style/TrailingCommaInLiteral:
70
+ Style/TrailingCommaInArrayLiteral:
69
71
  Enabled: false
70
72
 
71
73
  Style/TrailingCommaInArguments:
@@ -0,0 +1,298 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2019-05-06 09:20:12 +1000 using RuboCop version 0.68.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 3
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: TreatCommentsAsGroupSeparators, Include.
12
+ # Include: **/*.gemspec
13
+ Gemspec/OrderedDependencies:
14
+ Exclude:
15
+ - 'lightspeed_pos.gemspec'
16
+
17
+ # Offense count: 5
18
+ # Cop supports --auto-correct.
19
+ Layout/EmptyLineAfterGuardClause:
20
+ Exclude:
21
+ - 'bin/console'
22
+ - 'lib/lightspeed/collection.rb'
23
+ - 'lib/lightspeed/request.rb'
24
+
25
+ # Offense count: 1
26
+ # Cop supports --auto-correct.
27
+ Layout/EmptyLineAfterMagicComment:
28
+ Exclude:
29
+ - 'lightspeed_pos.gemspec'
30
+
31
+ # Offense count: 1
32
+ # Cop supports --auto-correct.
33
+ # Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines.
34
+ Layout/EmptyLineBetweenDefs:
35
+ Exclude:
36
+ - 'lib/lightspeed/resource.rb'
37
+
38
+ # Offense count: 1
39
+ # Cop supports --auto-correct.
40
+ Layout/EmptyLines:
41
+ Exclude:
42
+ - 'lib/lightspeed/resource.rb'
43
+
44
+ # Offense count: 7
45
+ # Cop supports --auto-correct.
46
+ # Configuration parameters: EnforcedStyle.
47
+ # SupportedStyles: empty_lines, no_empty_lines
48
+ Layout/EmptyLinesAroundBlockBody:
49
+ Exclude:
50
+ - 'spec/lightspeed/orders_spec.rb'
51
+ - 'spec/lightspeed/sale_line_spec.rb'
52
+ - 'spec/lightspeed/sale_spec.rb'
53
+ - 'spec/lightspeed/sales_spec.rb'
54
+ - 'spec/lightspeed/special_order_spec.rb'
55
+ - 'spec/lightspeed/special_orders_spec.rb'
56
+ - 'spec/lightspeed/vendor_spec.rb'
57
+
58
+ # Offense count: 7
59
+ # Cop supports --auto-correct.
60
+ # Configuration parameters: EnforcedStyle.
61
+ # SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only
62
+ Layout/EmptyLinesAroundClassBody:
63
+ Exclude:
64
+ - 'lib/lightspeed/customer.rb'
65
+ - 'lib/lightspeed/order.rb'
66
+ - 'lib/lightspeed/request_throttler.rb'
67
+ - 'lib/lightspeed/sale.rb'
68
+ - 'lib/lightspeed/sale_line.rb'
69
+ - 'lib/lightspeed/vendor.rb'
70
+
71
+ # Offense count: 1
72
+ # Cop supports --auto-correct.
73
+ Layout/LeadingBlankLines:
74
+ Exclude:
75
+ - 'lib/lightspeed/item.rb'
76
+
77
+ # Offense count: 3
78
+ # Cop supports --auto-correct.
79
+ # Configuration parameters: EnforcedStyle, IndentationWidth.
80
+ # SupportedStyles: aligned, indented, indented_relative_to_receiver
81
+ Layout/MultilineMethodCallIndentation:
82
+ Exclude:
83
+ - 'lib/lightspeed/collection.rb'
84
+
85
+ # Offense count: 1
86
+ # Cop supports --auto-correct.
87
+ Layout/SpaceAfterNot:
88
+ Exclude:
89
+ - 'lib/lightspeed/request.rb'
90
+
91
+ # Offense count: 1
92
+ # Cop supports --auto-correct.
93
+ # Configuration parameters: AllowForAlignment.
94
+ Layout/SpaceAroundOperators:
95
+ Exclude:
96
+ - 'lib/lightspeed/request_throttler.rb'
97
+
98
+ # Offense count: 3
99
+ # Cop supports --auto-correct.
100
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
101
+ # SupportedStyles: space, no_space, compact
102
+ # SupportedStylesForEmptyBraces: space, no_space
103
+ Layout/SpaceInsideHashLiteralBraces:
104
+ Exclude:
105
+ - 'spec/lightspeed/sales_spec.rb'
106
+
107
+ # Offense count: 14
108
+ # Cop supports --auto-correct.
109
+ # Configuration parameters: EnforcedStyle.
110
+ # SupportedStyles: final_newline, final_blank_line
111
+ Layout/TrailingBlankLines:
112
+ Exclude:
113
+ - 'lib/lightspeed/customer.rb'
114
+ - 'lib/lightspeed/customers.rb'
115
+ - 'lib/lightspeed/order.rb'
116
+ - 'lib/lightspeed/orders.rb'
117
+ - 'lib/lightspeed/sale.rb'
118
+ - 'lib/lightspeed/sale_line.rb'
119
+ - 'lib/lightspeed/sale_lines.rb'
120
+ - 'lib/lightspeed/sales.rb'
121
+ - 'lib/lightspeed/special_order.rb'
122
+ - 'lib/lightspeed/special_orders.rb'
123
+ - 'spec/lightspeed/sale_line_spec.rb'
124
+ - 'spec/lightspeed/sale_spec.rb'
125
+ - 'spec/lightspeed/sales_spec.rb'
126
+ - 'spec/lightspeed/special_order_spec.rb'
127
+
128
+ # Offense count: 1
129
+ # Configuration parameters: AllowSafeAssignment.
130
+ Lint/AssignmentInCondition:
131
+ Exclude:
132
+ - 'lib/lightspeed/request.rb'
133
+
134
+ # Offense count: 2
135
+ # Cop supports --auto-correct.
136
+ Lint/BigDecimalNew:
137
+ Exclude:
138
+ - 'lib/lightspeed/prices.rb'
139
+ - 'lib/lightspeed/resource.rb'
140
+
141
+ # Offense count: 3
142
+ Lint/DuplicateMethods:
143
+ Exclude:
144
+ - 'lib/lightspeed/resource.rb'
145
+
146
+ # Offense count: 1
147
+ # Cop supports --auto-correct.
148
+ # Configuration parameters: EnforcedStyle.
149
+ # SupportedStyles: runtime_error, standard_error
150
+ Lint/InheritException:
151
+ Exclude:
152
+ - 'lib/lightspeed/error.rb'
153
+
154
+ # Offense count: 3
155
+ # Cop supports --auto-correct.
156
+ Lint/ToJSON:
157
+ Exclude:
158
+ - 'lib/lightspeed/collection.rb'
159
+ - 'lib/lightspeed/prices.rb'
160
+ - 'lib/lightspeed/resource.rb'
161
+
162
+ # Offense count: 1
163
+ # Configuration parameters: CheckForMethodsWithNoSideEffects.
164
+ Lint/Void:
165
+ Exclude:
166
+ - 'lib/lightspeed/resource.rb'
167
+
168
+ # Offense count: 7
169
+ # Configuration parameters: CountComments, ExcludedMethods.
170
+ # ExcludedMethods: refine
171
+ Metrics/BlockLength:
172
+ Max: 82
173
+
174
+ # Offense count: 2
175
+ # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
176
+ # AllowedNames: io, id, to, by, on, in, at, ip, db
177
+ Naming/UncommunicativeMethodParamName:
178
+ Exclude:
179
+ - 'lib/lightspeed/accounts.rb'
180
+ - 'lib/lightspeed/collection.rb'
181
+
182
+ # Offense count: 14
183
+ # Cop supports --auto-correct.
184
+ # Configuration parameters: EnforcedStyle.
185
+ # SupportedStyles: prefer_alias, prefer_alias_method
186
+ Style/Alias:
187
+ Exclude:
188
+ - 'lib/lightspeed/collection.rb'
189
+ - 'lib/lightspeed/customer.rb'
190
+ - 'lib/lightspeed/customers.rb'
191
+ - 'lib/lightspeed/item.rb'
192
+ - 'lib/lightspeed/items.rb'
193
+ - 'lib/lightspeed/order.rb'
194
+ - 'lib/lightspeed/orders.rb'
195
+ - 'lib/lightspeed/prices.rb'
196
+ - 'lib/lightspeed/resource.rb'
197
+ - 'lib/lightspeed/sale.rb'
198
+ - 'lib/lightspeed/sales.rb'
199
+ - 'lib/lightspeed/vendor.rb'
200
+ - 'lib/lightspeed/vendors.rb'
201
+
202
+ # Offense count: 1
203
+ # Cop supports --auto-correct.
204
+ # Configuration parameters: EnforcedStyle.
205
+ # SupportedStyles: braces, no_braces, context_dependent
206
+ Style/BracesAroundHashParameters:
207
+ Exclude:
208
+ - 'spec/lightspeed/sales_spec.rb'
209
+
210
+ # Offense count: 1
211
+ # Cop supports --auto-correct.
212
+ # Configuration parameters: Keywords.
213
+ # Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW
214
+ Style/CommentAnnotation:
215
+ Exclude:
216
+ - 'spec/lightspeed/sales_spec.rb'
217
+
218
+ # Offense count: 6
219
+ Style/CommentedKeyword:
220
+ Exclude:
221
+ - 'lib/lightspeed/error.rb'
222
+
223
+ # Offense count: 1
224
+ # Cop supports --auto-correct.
225
+ Style/EmptyCaseCondition:
226
+ Exclude:
227
+ - 'lib/lightspeed/resource.rb'
228
+
229
+ # Offense count: 1
230
+ # Cop supports --auto-correct.
231
+ Style/Encoding:
232
+ Exclude:
233
+ - 'lightspeed_pos.gemspec'
234
+
235
+ # Offense count: 2
236
+ # Cop supports --auto-correct.
237
+ Style/ExpandPathArguments:
238
+ Exclude:
239
+ - 'lightspeed_pos.gemspec'
240
+ - 'spec/spec_helper.rb'
241
+
242
+ # Offense count: 2
243
+ # Configuration parameters: MinBodyLength.
244
+ Style/GuardClause:
245
+ Exclude:
246
+ - 'lib/lightspeed/request.rb'
247
+ - 'lib/lightspeed/resource.rb'
248
+
249
+ # Offense count: 4
250
+ # Cop supports --auto-correct.
251
+ Style/IfUnlessModifier:
252
+ Exclude:
253
+ - 'lib/lightspeed/resource.rb'
254
+ - 'spec/spec_helper.rb'
255
+
256
+ # Offense count: 1
257
+ Style/MissingRespondToMissing:
258
+ Exclude:
259
+ - 'lib/lightspeed/prices.rb'
260
+
261
+ # Offense count: 1
262
+ # Cop supports --auto-correct.
263
+ # Configuration parameters: EnforcedStyle.
264
+ # SupportedStyles: literals, strict
265
+ Style/MutableConstant:
266
+ Exclude:
267
+ - 'lib/lightspeed/version.rb'
268
+
269
+ # Offense count: 1
270
+ # Cop supports --auto-correct.
271
+ Style/OneLineConditional:
272
+ Exclude:
273
+ - 'lib/lightspeed/request_throttler.rb'
274
+
275
+ # Offense count: 1
276
+ # Cop supports --auto-correct.
277
+ Style/ParallelAssignment:
278
+ Exclude:
279
+ - 'lib/lightspeed/request_throttler.rb'
280
+
281
+ # Offense count: 1
282
+ # Cop supports --auto-correct.
283
+ Style/RedundantSelf:
284
+ Exclude:
285
+ - 'lib/lightspeed/resource.rb'
286
+
287
+ # Offense count: 1
288
+ # Cop supports --auto-correct.
289
+ Style/SelfAssignment:
290
+ Exclude:
291
+ - 'spec/lightspeed/client_spec.rb'
292
+
293
+ # Offense count: 3
294
+ # Cop supports --auto-correct.
295
+ # Configuration parameters: MinSize.
296
+ # SupportedStyles: percent, brackets
297
+ Style/SymbolArray:
298
+ EnforcedStyle: brackets
@@ -1,9 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.2
4
- - 2.1.6
3
+ - 2.3
4
+ - 2.4
5
+ - 2.5
5
6
  script:
6
- - 'bundle exec rspec spec'
7
7
  - 'bundle exec rubocop'
8
+ - 'bundle exec rspec spec'
8
9
  cache: bundler
9
10
  sudo: false
@@ -44,6 +44,7 @@ resources share a common API. Resources that are currently supported by this lib
44
44
  * Shops
45
45
  * Special Orders
46
46
  * Vendors
47
+ * Customers
47
48
 
48
49
  To work with account resources, you first need to fetch an account. The examples below are for items, but will also work with other types listed above.
49
50
 
@@ -126,3 +127,29 @@ For the `Item` resource, `destroy` is aliased to `archive`:
126
127
  ## Rate Limiting
127
128
 
128
129
  This gem respects the `X-LS-API-Bucket-Level` header by pausing before a request that would otherwise overrun the API rate limit. It calls `Kernel.sleep` with the minimum number of seconds needed to avoid hitting the limit, which suspends the current thread during that time. If you need to make API calls across multiple Lightspeed accounts using this gem, its recommended to make requests against each account in a separate thread.
130
+
131
+ ## Contributing
132
+
133
+ ### Local setup
134
+
135
+ ```
136
+ $ bundle install
137
+ ```
138
+
139
+ ### How to run Tests
140
+
141
+ ```
142
+ $ rspec
143
+ ```
144
+
145
+ ### How to write Tests
146
+
147
+ This repository uses the [`vcr` gem](https://github.com/vcr/vcr) to record HTTP interactions and replay them during next tests runs.
148
+
149
+ The following `ENV` variables are required for recording new HTTP interactions.
150
+
151
+ * `LIGHTSPEED_OAUTH_TOKEN` : not expired OAuth token
152
+ * `LIGHTSPEED_OAUTH_REFRESH_TOKEN` : the OAuth refresh token
153
+ * `LIGHTSPEED_ACCOUNT_ID` : a Ligthspeed account id
154
+
155
+ **Be careful with the data you set as real API calls will be performed.**
@@ -12,6 +12,7 @@ require_relative 'sales'
12
12
  require_relative 'shops'
13
13
  require_relative 'special_orders'
14
14
  require_relative 'vendors'
15
+ require_relative 'customers'
15
16
 
16
17
  module Lightspeed
17
18
  class Account < Lightspeed::Resource
@@ -33,7 +34,8 @@ module Lightspeed
33
34
  :Sales,
34
35
  :Shops,
35
36
  :SpecialOrders,
36
- :Vendors
37
+ :Vendors,
38
+ :Customers
37
39
  )
38
40
 
39
41
  def account
@@ -0,0 +1,34 @@
1
+ require_relative 'resource'
2
+
3
+ module Lightspeed
4
+ class Customer < Lightspeed::Resource
5
+ alias_method :archive, :destroy
6
+
7
+ fields(
8
+ customerID: :id,
9
+ firstName: :string,
10
+ lastName: :string,
11
+ dob: :timestamp,
12
+ archived: :boolean,
13
+ title: :string,
14
+ company: :string,
15
+ companyRegistrationNumber: :string,
16
+ vatNumber: :string,
17
+ createTime: :timestamp,
18
+ timeStamp: :timestamp,
19
+ creditAccountID: :id,
20
+ customerTypeID: :id,
21
+ discountID: :id,
22
+ taxCategoryID: :id,
23
+ Contact: :hash,
24
+ CreditAccount: :hash,
25
+ CustomerType: :hash,
26
+ Discount: :hash,
27
+ Note: :hash,
28
+ TaxCategory: :hash,
29
+ CustomFieldValues: :hash
30
+ )
31
+
32
+ end
33
+ end
34
+
@@ -0,0 +1,9 @@
1
+ require_relative 'collection'
2
+
3
+ require_relative 'customer'
4
+
5
+ module Lightspeed
6
+ class Customers < Lightspeed::Collection
7
+ alias_method :archive, :destroy
8
+ end
9
+ end
@@ -56,10 +56,12 @@ module Lightspeed
56
56
  perform_raw
57
57
  rescue Lightspeed::Error::Throttled
58
58
  retry_throttled_request
59
- rescue Lightspeed::Error::Unauthorized
59
+ rescue Lightspeed::Error::Unauthorized => e
60
+ raise e if @attempted_oauth_token_refresh
60
61
  @client.refresh_oauth_token
61
62
  set_authorization_header
62
- perform_raw
63
+ @attempted_oauth_token_refresh = true
64
+ perform
63
65
  end
64
66
 
65
67
  private
@@ -77,7 +79,6 @@ module Lightspeed
77
79
  end
78
80
 
79
81
  def handle_error(response)
80
- data = Yajl::Parser.parse(response.body)
81
82
  error = case response.code.to_s
82
83
  when '400' then Lightspeed::Error::BadRequest
83
84
  when '401' then Lightspeed::Error::Unauthorized
@@ -87,7 +88,14 @@ module Lightspeed
87
88
  when /5../ then Lightspeed::Error::InternalServerError
88
89
  else Lightspeed::Error
89
90
  end
90
- raise error, data["message"]
91
+
92
+ # We may not get back valid JSON for a failed request
93
+ begin
94
+ data = Yajl::Parser.parse(response.body)
95
+ raise error, data["message"]
96
+ rescue Yajl::ParseError
97
+ raise error, response.code
98
+ end
91
99
  end
92
100
 
93
101
  def extract_rate_limits(response)
@@ -110,6 +118,5 @@ module Lightspeed
110
118
  when :delete then Net::HTTP::Delete
111
119
  end
112
120
  end
113
-
114
121
  end
115
122
  end
@@ -1,3 +1,3 @@
1
1
  module Lightspeed
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lightspeed_pos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-16 00:00:00.000000000 Z
11
+ date: 2019-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -158,8 +158,10 @@ extensions: []
158
158
  extra_rdoc_files: []
159
159
  files:
160
160
  - ".gitignore"
161
+ - ".mailmap"
161
162
  - ".rspec"
162
163
  - ".rubocop.yml"
164
+ - ".rubocop_todo.yml"
163
165
  - ".travis.yml"
164
166
  - Gemfile
165
167
  - LICENSE
@@ -173,6 +175,8 @@ files:
173
175
  - lib/lightspeed/category.rb
174
176
  - lib/lightspeed/client.rb
175
177
  - lib/lightspeed/collection.rb
178
+ - lib/lightspeed/customer.rb
179
+ - lib/lightspeed/customers.rb
176
180
  - lib/lightspeed/employee.rb
177
181
  - lib/lightspeed/employees.rb
178
182
  - lib/lightspeed/error.rb
@@ -229,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
233
  version: '0'
230
234
  requirements: []
231
235
  rubyforge_project:
232
- rubygems_version: 2.6.14
236
+ rubygems_version: 2.7.6
233
237
  signing_key:
234
238
  specification_version: 4
235
239
  summary: A gem for interacting with Lightspeed's Point of Sale system