lightspeed_pos 0.1.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +5 -5
  2. data/.mailmap +4 -0
  3. data/.rubocop.yml +32 -24
  4. data/.rubocop_todo.yml +284 -0
  5. data/.travis.yml +5 -3
  6. data/Gemfile +2 -0
  7. data/README.markdown +85 -28
  8. data/Rakefile +2 -0
  9. data/bin/console +33 -6
  10. data/lib/lightspeed/account.rb +50 -43
  11. data/lib/lightspeed/accounts.rb +24 -0
  12. data/lib/lightspeed/categories.rb +7 -5
  13. data/lib/lightspeed/category.rb +18 -7
  14. data/lib/lightspeed/client.rb +41 -27
  15. data/lib/lightspeed/collection.rb +214 -0
  16. data/lib/lightspeed/customer.rb +36 -0
  17. data/lib/lightspeed/customers.rb +11 -0
  18. data/lib/lightspeed/employee.rb +27 -0
  19. data/lib/lightspeed/employees.rb +10 -0
  20. data/lib/lightspeed/error.rb +17 -0
  21. data/lib/lightspeed/image.rb +37 -0
  22. data/lib/lightspeed/images.rb +18 -0
  23. data/lib/lightspeed/inventories.rb +10 -0
  24. data/lib/lightspeed/inventory.rb +14 -0
  25. data/lib/lightspeed/item.rb +55 -18
  26. data/lib/lightspeed/item_attribute_set.rb +15 -0
  27. data/lib/lightspeed/item_attribute_sets.rb +10 -0
  28. data/lib/lightspeed/item_matrices.rb +6 -3
  29. data/lib/lightspeed/item_matrix.rb +50 -10
  30. data/lib/lightspeed/items.rb +6 -7
  31. data/lib/lightspeed/order.rb +36 -0
  32. data/lib/lightspeed/orders.rb +12 -0
  33. data/lib/lightspeed/price_level.rb +16 -0
  34. data/lib/lightspeed/price_levels.rb +10 -0
  35. data/lib/lightspeed/prices.rb +45 -0
  36. data/lib/lightspeed/request.rb +98 -29
  37. data/lib/lightspeed/request_throttler.rb +33 -0
  38. data/lib/lightspeed/resource.rb +221 -0
  39. data/lib/lightspeed/sale.rb +59 -0
  40. data/lib/lightspeed/sale_line.rb +54 -0
  41. data/lib/lightspeed/sale_lines.rb +11 -0
  42. data/lib/lightspeed/sales.rb +12 -0
  43. data/lib/lightspeed/shop.rb +32 -0
  44. data/lib/lightspeed/shops.rb +10 -0
  45. data/lib/lightspeed/special_order.rb +24 -0
  46. data/lib/lightspeed/special_orders.rb +12 -0
  47. data/lib/lightspeed/vendor.rb +25 -0
  48. data/lib/lightspeed/vendors.rb +11 -0
  49. data/lib/lightspeed/version.rb +3 -1
  50. data/lib/lightspeed_pos.rb +5 -5
  51. data/lightspeed_pos.gemspec +11 -7
  52. data/script/buildkite +24 -0
  53. data/script/docker_tests +29 -0
  54. metadata +96 -38
  55. data/lib/lightspeed/account_resources.rb +0 -103
  56. data/lib/lightspeed/base.rb +0 -17
  57. data/lib/lightspeed/errors.rb +0 -8
@@ -1,103 +0,0 @@
1
- require 'active_support/core_ext/string'
2
-
3
- module Lightspeed
4
- class AccountResources
5
- attr_accessor :account
6
-
7
- def initialize(account)
8
- @account = account
9
- end
10
-
11
- def all
12
- response = get
13
- account.instantiate(response[resource_name], Lightspeed.const_get(resource_name))
14
- end
15
-
16
- def find(id)
17
- params = { "#{resource_name.camelize(:lower)}ID" => id }
18
- response = get(params: params)
19
- if response[resource_name]
20
- resource_class.new(account, response[resource_name])
21
- else
22
- raise Lightspeed::Errors::NotFound, "Could not find a #{resource_name} by #{params.inspect}"
23
- end
24
- end
25
-
26
- def create(attributes = {})
27
- craft_instance(post(body: attributes.to_json))
28
- end
29
-
30
- def update(id, attributes = {})
31
- craft_instance(put(id, body: attributes.to_json))
32
- end
33
-
34
- def destroy(id)
35
- craft_instance(delete(id))
36
- end
37
-
38
- private
39
-
40
- def craft_instance(response)
41
- resource_class.new(client, response[resource_name])
42
- end
43
-
44
- def client
45
- account.client
46
- end
47
-
48
- def resource_class
49
- Lightspeed.const_get(resource_name)
50
- end
51
-
52
- def resource_name
53
- self.class.resource_name
54
- end
55
-
56
- def get(params: nil)
57
- request = client.request(
58
- method: :get,
59
- path: collection_path,
60
- params: params
61
- )
62
- request.perform
63
- end
64
-
65
- def post(body:)
66
- request = client.request(
67
- method: :post,
68
- path: collection_path,
69
- body: body
70
- )
71
- request.perform
72
- end
73
-
74
- def put(id, body:)
75
- request = client.request(
76
- method: :put,
77
- path: item_path(id),
78
- body: body,
79
- )
80
- request.perform
81
- end
82
-
83
- def delete(id)
84
- request = client.request(
85
- method: :delete,
86
- path: item_path(id)
87
- )
88
- request.perform
89
- end
90
-
91
- def base_path
92
- "/Account/#{account.id}/#{self.class.resource_name}"
93
- end
94
-
95
- def collection_path
96
- base_path + ".json"
97
- end
98
-
99
- def item_path(id)
100
- base_path + "/#{id}.json"
101
- end
102
- end
103
- end
@@ -1,17 +0,0 @@
1
- module Lightspeed
2
- class Base
3
- attr_accessor :id, :owner
4
-
5
- def initialize(owner, data = {})
6
- @owner = owner
7
- self.id = data.delete(self.class.id_field)
8
- data.each do |k, v|
9
- send("#{k}=", v)
10
- end
11
- end
12
-
13
- def inspect
14
- "#<#{self.class.name} id=#{id}>"
15
- end
16
- end
17
- end
@@ -1,8 +0,0 @@
1
- module Lightspeed
2
- module Errors
3
- class BadRequest < Exception; end # 400
4
- class Unauthorized < Exception; end # 401
5
- class NotFound < Exception; end # 404
6
- class InternalServerError < Exception; end # 500
7
- end
8
- end