vending-machine 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +39 -8
- data/lib/vend/remote_resource.rb +27 -19
- data/lib/vend/resource_collection.rb +4 -0
- data/lib/vend/resources/inventory.rb +1 -4
- data/lib/vend/resources/product.rb +7 -0
- data/lib/vend/resources/sale.rb +3 -1
- data/lib/vend/version.rb +1 -1
- metadata +2 -3
- data/LICENSE.txt +0 -22
data/README.md
CHANGED
@@ -51,7 +51,7 @@ Once you have a store instance you can retrieve your objects
|
|
51
51
|
```ruby
|
52
52
|
customers = store.customers
|
53
53
|
customers.first.customer_code
|
54
|
-
=>
|
54
|
+
=> "WALKIN"
|
55
55
|
```
|
56
56
|
|
57
57
|
### Payment Types
|
@@ -69,6 +69,7 @@ store.products.map &:name
|
|
69
69
|
=> ["Coffee (Demo)", "T-shirt (Demo)", "Discount", "test"]
|
70
70
|
```
|
71
71
|
|
72
|
+
#### Scopes
|
72
73
|
Scopes available: `active`, `order_by`, `order_direction` and an `order` shortcut to do both order by and direction at once. Scopes are chainable.
|
73
74
|
|
74
75
|
```ruby
|
@@ -85,6 +86,34 @@ store.products.order('name', 'DESC').map &:name
|
|
85
86
|
=> ["test", "T-shirt (Demo)", "Discount", "Coffee (Demo)"]
|
86
87
|
```
|
87
88
|
|
89
|
+
#### Creating a Product
|
90
|
+
|
91
|
+
Initialize a new product with `#build`, `#create` or `#create!`.
|
92
|
+
|
93
|
+
* `build` create an unsaved instance
|
94
|
+
* `create` create an instance, and call `#save`
|
95
|
+
* `create!` create an instance, and call `#save!`
|
96
|
+
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
product = store.products.build name: "Product Name", handle: "prod1", retail_price: 25
|
100
|
+
|
101
|
+
# Safe save
|
102
|
+
product.save
|
103
|
+
=> false
|
104
|
+
|
105
|
+
product.error
|
106
|
+
=> ["Could not Add or Update: Missing sku"]
|
107
|
+
|
108
|
+
# Explosive save
|
109
|
+
product.save!
|
110
|
+
=> Vend::ValidationFailed: Could not Add or Update: Missing sku
|
111
|
+
|
112
|
+
product.sku = 'prod1'
|
113
|
+
product.save!
|
114
|
+
=> true
|
115
|
+
```
|
116
|
+
|
88
117
|
### Register Sales
|
89
118
|
|
90
119
|
```ruby
|
@@ -93,10 +122,10 @@ sales = store.sales
|
|
93
122
|
sales.map{|sale| sale.total_price + sale.total_tax }
|
94
123
|
=> [1337.0, 1341.95]
|
95
124
|
|
96
|
-
sales.first.
|
97
|
-
=> ["T-shirt (Demo)"]
|
125
|
+
sales.first.products.map &:name
|
126
|
+
=> ["T-shirt (Demo)", "Coffee (Demo)"]
|
98
127
|
|
99
|
-
sales.first.
|
128
|
+
sales.first.products.first
|
100
129
|
=> "#<Vend::RegisterSaleProduct:0x007fe238720d68>"
|
101
130
|
```
|
102
131
|
|
@@ -104,7 +133,7 @@ sales.first.register_sale_products.first.to_s
|
|
104
133
|
|
105
134
|
```ruby
|
106
135
|
store.registers.map &:name
|
107
|
-
=> ["Main Register"]
|
136
|
+
=> ["Main Register", "Back office Register"]
|
108
137
|
```
|
109
138
|
|
110
139
|
### Suppliers
|
@@ -118,10 +147,10 @@ store.suppliers.map &:name
|
|
118
147
|
|
119
148
|
```ruby
|
120
149
|
store.taxes.map &:name
|
121
|
-
=> ["NZ GST", "AU GST", "
|
150
|
+
=> ["NZ GST", "AU GST", "Asshole Tax"]
|
122
151
|
```
|
123
152
|
|
124
|
-
The `default` scope will provide you the first returned default tax (note, this still retrieves all taxes).
|
153
|
+
The `default` scope will provide you the first returned default tax (note, this still retrieves all taxes from the API).
|
125
154
|
|
126
155
|
```ruby
|
127
156
|
store.taxes.default.name
|
@@ -138,7 +167,9 @@ store.users.map &:name
|
|
138
167
|
## Status
|
139
168
|
* COMPLETE: GET index resources are implemented, with the exception of Stock Control
|
140
169
|
* IN PROGRESS: find singular resources `store.products.find('some_id')`
|
141
|
-
* IN PROGRESS: create
|
170
|
+
* IN PROGRESS: create register sales `store.sale.create products: [product1, product2]`
|
171
|
+
* COMPLETE: create products
|
172
|
+
* IN PROGRESS: Create Product Variants (This seems to happen when posting a new product with a same handle, but different sku)
|
142
173
|
* TODO: Delete resources
|
143
174
|
* TODO: Scopes for Customer and Register Sales
|
144
175
|
|
data/lib/vend/remote_resource.rb
CHANGED
@@ -1,10 +1,36 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module Vend
|
2
4
|
class RemoteResource < Resource
|
3
5
|
include Vend::DeclarativeSetters
|
4
6
|
include Vend::Paths
|
5
7
|
|
8
|
+
attr_reader :error
|
9
|
+
|
6
10
|
def save
|
7
|
-
|
11
|
+
begin
|
12
|
+
save!
|
13
|
+
rescue ValidationFailed
|
14
|
+
(@error ||= []) << $!.message
|
15
|
+
false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def save!
|
20
|
+
save_path = id ? update_path : self.class.create_path
|
21
|
+
method = id ? :put : :post
|
22
|
+
response = store.send(method, path: save_path,
|
23
|
+
data: sendable_attributes.to_json,
|
24
|
+
status: 200
|
25
|
+
).data
|
26
|
+
|
27
|
+
if response['status'] && response['status'] == 'error'
|
28
|
+
raise ValidationFailed.
|
29
|
+
new [response['error'], response['details']].join(': ')
|
30
|
+
end
|
31
|
+
|
32
|
+
self.attributes = response[self.class.path]
|
33
|
+
true
|
8
34
|
end
|
9
35
|
|
10
36
|
def load
|
@@ -24,23 +50,5 @@ module Vend
|
|
24
50
|
}
|
25
51
|
attributes.delete_if{|name,value| blacklist.include? name }.dup
|
26
52
|
end
|
27
|
-
|
28
|
-
def save_new
|
29
|
-
self.attributes = store.post(
|
30
|
-
path: create_path,
|
31
|
-
parameters: sendable_attributes,
|
32
|
-
status: 200
|
33
|
-
).data
|
34
|
-
self
|
35
|
-
end
|
36
|
-
|
37
|
-
def save_existing
|
38
|
-
self.attributes = store.put(
|
39
|
-
path: update_path,
|
40
|
-
parameters: sendable_attributes,
|
41
|
-
status: 200
|
42
|
-
).data
|
43
|
-
self
|
44
|
-
end
|
45
53
|
end
|
46
54
|
end
|
@@ -1,9 +1,6 @@
|
|
1
1
|
# TODO: Implement the attribute declaration as a Proc to avoid this
|
2
2
|
module Vend
|
3
|
-
class Product < RemoteResource
|
4
|
-
end
|
5
|
-
end
|
6
|
-
module Vend
|
3
|
+
class Product < RemoteResource; end
|
7
4
|
class Inventory < RemoteResource
|
8
5
|
attribute :attributed_cost, Float
|
9
6
|
attribute :count, Integer
|
@@ -15,6 +15,13 @@ module Vend
|
|
15
15
|
attribute :tax, Float
|
16
16
|
attribute :tax_rate, Float
|
17
17
|
|
18
|
+
##
|
19
|
+
# Required Attributes
|
20
|
+
attribute :name, String
|
21
|
+
attribute :handle, String
|
22
|
+
attribute :sku, String
|
23
|
+
attribute :retail_price, Float
|
24
|
+
|
18
25
|
##
|
19
26
|
# Scopes
|
20
27
|
collection_scope :active, default: true
|
data/lib/vend/resources/sale.rb
CHANGED
@@ -8,9 +8,11 @@ module Vend
|
|
8
8
|
attribute :total_price, Float
|
9
9
|
attribute :total_tax, Float
|
10
10
|
attribute :totals, Hash[Symbol => Float] # Requires updated virtus gem
|
11
|
-
#attribute :totals, Array[Float]
|
12
11
|
attribute :user, Vend::User
|
13
12
|
|
13
|
+
alias_method :products, :register_sale_products
|
14
|
+
alias_method :payments, :register_sale_payments
|
15
|
+
|
14
16
|
path "register_sale"
|
15
17
|
end
|
16
18
|
end
|
data/lib/vend/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vending-machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -165,7 +165,6 @@ files:
|
|
165
165
|
- .gitignore
|
166
166
|
- Gemfile
|
167
167
|
- LICENSE
|
168
|
-
- LICENSE.txt
|
169
168
|
- README.md
|
170
169
|
- Rakefile
|
171
170
|
- lib/vend.rb
|
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2012 Mal Curtis
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|