kounta_rest 0.1.7 → 0.2.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 +67 -36
- data/lib/kounta/address.rb +14 -17
- data/lib/kounta/break.rb +6 -0
- data/lib/kounta/category.rb +12 -15
- data/lib/kounta/company.rb +59 -50
- data/lib/kounta/customer.rb +33 -32
- data/lib/kounta/errors.rb +8 -7
- data/lib/kounta/inventory.rb +5 -7
- data/lib/kounta/line.rb +18 -21
- data/lib/kounta/order.rb +45 -49
- data/lib/kounta/payment.rb +14 -17
- data/lib/kounta/person.rb +21 -24
- data/lib/kounta/price_list.rb +7 -9
- data/lib/kounta/product.rb +25 -27
- data/lib/kounta/register.rb +11 -14
- data/lib/kounta/resource.rb +105 -93
- data/lib/kounta/rest/client.rb +177 -79
- data/lib/kounta/shift.rb +25 -0
- data/lib/kounta/site.rb +46 -38
- data/lib/kounta/staff.rb +30 -0
- data/lib/kounta/tax.rb +7 -9
- data/lib/kounta/version.rb +1 -1
- data/lib/kounta/webhook.rb +16 -0
- data/lib/kounta.rb +42 -72
- metadata +77 -145
- data/.gitignore +0 -20
- data/.gitmodules +0 -3
- data/Gemfile +0 -4
- data/Rakefile +0 -1
- data/console.rb +0 -14
- data/kounta.gemspec +0 -33
- data/spec/fixtures/address.json +0 -12
- data/spec/fixtures/addresses.json +0 -25
- data/spec/fixtures/base_price_list.json +0 -52
- data/spec/fixtures/categories.json +0 -217
- data/spec/fixtures/category.json +0 -11
- data/spec/fixtures/companies_me.json +0 -45
- data/spec/fixtures/customer.json +0 -39
- data/spec/fixtures/customers.json +0 -26
- data/spec/fixtures/inventory.json +0 -10
- data/spec/fixtures/line.json +0 -7
- data/spec/fixtures/order.json +0 -67
- data/spec/fixtures/orders.json +0 -134
- data/spec/fixtures/payment.json +0 -6
- data/spec/fixtures/people.json +0 -20
- data/spec/fixtures/person.json +0 -41
- data/spec/fixtures/price_list.json +0 -52
- data/spec/fixtures/price_lists.json +0 -12
- data/spec/fixtures/product.json +0 -25
- data/spec/fixtures/products.json +0 -119
- data/spec/fixtures/site.json +0 -6
- data/spec/fixtures/sites.json +0 -14
- data/spec/fixtures/tax.json +0 -7
- data/spec/fixtures/taxes.json +0 -16
- data/spec/helper.rb +0 -28
- data/spec/kounta/address_spec.rb +0 -11
- data/spec/kounta/category_spec.rb +0 -11
- data/spec/kounta/company_spec.rb +0 -24
- data/spec/kounta/customer_spec.rb +0 -15
- data/spec/kounta/kounta_spec.rb +0 -21
- data/spec/kounta/line_spec.rb +0 -14
- data/spec/kounta/order_spec.rb +0 -37
- data/spec/kounta/payment_spec.rb +0 -14
- data/spec/kounta/person_spec.rb +0 -15
- data/spec/kounta/product_spec.rb +0 -16
- data/spec/kounta/resource_spec.rb +0 -95
- data/spec/kounta/rest/client_spec.rb +0 -38
- data/spec/kounta/site_spec.rb +0 -11
- data/spec/support/endpoints.rb +0 -72
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 863569524aae1949058648ddce027a8e28b39ad7
|
4
|
+
data.tar.gz: c778266f6a424de8d64f39c4bc26bf1578fe102d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b556aa4720e769b097f636128006d2d06bc08bb4847bdee4e32c21bd5c6925d134d468e19177f11849e38fd8439d8f939f3c6be130bba581670f21db490c4991
|
7
|
+
data.tar.gz: 38b9b6295d83153c5a6fc720cd143babafe44bfaba220a3c81320116587bc3288ecc9e44ec536cd2e19f7216e5a55897c787037aa8daa9f09ee0fb5beb222e35
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/TandaHQ/Kounta.svg?branch=master)](https://travis-ci.org/TandaHQ/Kounta)
|
2
|
+
|
1
3
|
# Kounta
|
2
4
|
|
3
5
|
Allows easy access to the Kounta POS RESTful API.
|
@@ -6,63 +8,92 @@ Allows easy access to the Kounta POS RESTful API.
|
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
8
10
|
|
9
|
-
|
11
|
+
```ruby
|
12
|
+
gem 'kounta_rest'
|
13
|
+
```
|
10
14
|
|
11
15
|
And then execute:
|
12
16
|
|
13
|
-
|
17
|
+
```
|
18
|
+
$ bundle
|
19
|
+
```
|
14
20
|
|
15
21
|
Or install it yourself as:
|
16
22
|
|
17
|
-
|
23
|
+
```
|
24
|
+
$ gem install kounta_rest
|
25
|
+
```
|
18
26
|
|
19
27
|
## Usage
|
20
28
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
```ruby
|
30
|
+
require 'kounta'
|
31
|
+
```
|
32
|
+
|
33
|
+
### Multi-legged OAuth
|
34
|
+
|
35
|
+
If you've already got an OAuth access token, feel free to skip to API Client Setup.
|
36
|
+
|
37
|
+
The Kounta API uses 3 legged OAuth2. Here's an example controller you can use to authenticate:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
class KountaSessionController
|
41
|
+
def new
|
42
|
+
redirect_to kounta_client.get_access_code_url
|
43
|
+
end
|
44
|
+
|
45
|
+
def create
|
46
|
+
token = kounta_client.get_access_token(params[:code])
|
47
|
+
kounta_client.company.sites # start loading data from the client
|
48
|
+
end
|
49
|
+
|
50
|
+
def kounta_client
|
51
|
+
@kounta_client ||= Kounta::REST::Client.new({
|
52
|
+
:redirect_url => YOUR_REDIRECT_URL,
|
53
|
+
:consumer => {
|
54
|
+
:key => YOUR_CONSUMER_KEY,
|
55
|
+
:secret => YOUR_CONSUMER_SECRET,
|
56
|
+
},
|
57
|
+
})
|
58
|
+
end
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
### API Client Setup
|
63
|
+
|
64
|
+
Use the gem by creating a Kounta client:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
company = Kounta::REST::Client.new({
|
68
|
+
:consumer => {
|
69
|
+
:key => YOUR_CONSUMER_KEY,
|
70
|
+
:secret => YOUR_CONSUMER_SECRET,
|
71
|
+
},
|
72
|
+
:access_token => YOUR_OAUTH_ACCESS_TOKEN
|
73
|
+
}).company
|
74
|
+
```
|
39
75
|
|
40
76
|
This will automatically download data about the company associated with your authentication details.
|
41
77
|
|
42
78
|
From here you can start to fetch relationships of that data, e.g. for all the sites belonging to your company
|
43
79
|
|
44
|
-
|
80
|
+
```ruby
|
81
|
+
sites = company.sites
|
82
|
+
```
|
45
83
|
|
46
84
|
For the products belonging to a site
|
47
85
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
### Console
|
53
|
-
|
54
|
-
To aid debugging their is an interactive console. To get started, you'll need to create a "tokens.yml" file in the root of gem, like:
|
86
|
+
```ruby
|
87
|
+
sites.first.products
|
88
|
+
```
|
55
89
|
|
56
|
-
|
57
|
-
client_secret: abcd1234
|
58
|
-
client_token: abcd1234
|
59
|
-
client_refresh_token: abcd1234
|
90
|
+
Please see the test suite for full details of these.
|
60
91
|
|
61
|
-
|
92
|
+
## Development
|
62
93
|
|
63
|
-
|
94
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
64
95
|
|
65
|
-
|
96
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
66
97
|
|
67
98
|
## Contributing
|
68
99
|
|
data/lib/kounta/address.rb
CHANGED
@@ -1,18 +1,15 @@
|
|
1
1
|
module Kounta
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
2
|
+
class Address < Kounta::Resource
|
3
|
+
property :company_id
|
4
|
+
property :people_id
|
5
|
+
property :lines
|
6
|
+
property :city
|
7
|
+
property :zone
|
8
|
+
property :postal_code
|
9
|
+
property :country
|
10
|
+
|
11
|
+
def resource_path
|
12
|
+
{ people: people_id, addresses: id }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/kounta/break.rb
ADDED
data/lib/kounta/category.rb
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
module Kounta
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
2
|
+
class Category < Kounta::Resource
|
3
|
+
property :company_id
|
4
|
+
property :name
|
5
|
+
property :description
|
6
|
+
property :image
|
7
|
+
property :products
|
8
|
+
|
9
|
+
def resource_path
|
10
|
+
{ companies: company_id, categories: id }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/kounta/company.rb
CHANGED
@@ -1,58 +1,67 @@
|
|
1
1
|
module Kounta
|
2
|
+
class Company < Kounta::Resource
|
3
|
+
property :name
|
4
|
+
property :shipping_address
|
5
|
+
property :postal_address
|
6
|
+
property :addresses
|
7
|
+
property :business_number
|
8
|
+
property :contact_staff_member
|
9
|
+
property :image
|
10
|
+
property :website
|
11
|
+
property :currency
|
12
|
+
property :timezone
|
13
|
+
property :sites
|
14
|
+
property :registers
|
15
|
+
property :staff
|
16
|
+
property :email
|
17
|
+
property :webhooks
|
2
18
|
|
3
|
-
|
19
|
+
has_one(:product, Kounta::Product, { company_id: :id }, proc { |klass, item_id| { companies: klass.id, products: item_id } })
|
20
|
+
has_one(:category, Kounta::Category, { company_id: :id }, proc { |klass, item_id| { companies: klass.id, categories: item_id } })
|
21
|
+
has_one(:customer, Kounta::Customer, { company_id: :id }, proc { |klass, item_id| { companies: klass.id, customers: item_id } })
|
22
|
+
has_one(:person, Kounta::Person, { company_id: :id }, proc { |klass, item_id| { companies: klass.id, people: item_id } })
|
23
|
+
has_one(:site, Kounta::Site, { company_id: :id }, proc { |klass, item_id| { companies: klass.id, sites: item_id } })
|
24
|
+
has_one(:price_list, Kounta::PriceList, { company_id: :id }, proc { |klass, item_id| { companies: klass.id, price_lists: item_id } })
|
25
|
+
has_one(:tax, Kounta::Tax, { company_id: :id }, proc { |klass, item_id| { companies: klass.id, taxes: item_id } })
|
26
|
+
has_one(:order, Kounta::Order, { company_id: :id }, proc { |klass, item_id| { companies: klass.id, orders: item_id } })
|
27
|
+
has_one(:register, Kounta::Register, { company_id: :id }, proc { |klass, item_id| { companies: klass.id, registers: item_id } })
|
28
|
+
has_one(:employee, Kounta::Staff, { company_id: :id }, proc { |klass, item_id| { companies: klass.id, staff: item_id } })
|
29
|
+
has_one(:webhook, Kounta::Webhook, { company_id: :id }, proc { |klass, item_id| { companies: klass.id, webhooks: item_id } })
|
4
30
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
31
|
+
has_many(:products, Kounta::Product, { company_id: :id }, proc { |klass| { companies: klass.id, products: nil } })
|
32
|
+
has_many(:categories, Kounta::Category, { company_id: :id }, proc { |klass| { companies: klass.id, categories: nil } })
|
33
|
+
has_many(:customers, Kounta::Customer, { company_id: :id }, proc { |klass| { companies: klass.id, customers: nil } })
|
34
|
+
has_many(:people, Kounta::Person, { company_id: :id }, proc { |klass| { companies: klass.id, people: nil } })
|
35
|
+
has_many(:sites, Kounta::Site, { company_id: :id }, proc { |klass| { companies: klass.id, sites: nil } })
|
36
|
+
has_many(:price_lists, Kounta::PriceList, { company_id: :id }, proc { |klass| { companies: klass.id, price_lists: nil } })
|
37
|
+
has_many(:taxes, Kounta::Tax, { company_id: :id }, proc { |klass| { companies: klass.id, taxes: nil } })
|
38
|
+
has_many(:orders, Kounta::Order, { company_id: :id }, proc { |klass| { companies: klass.id, orders: nil } })
|
39
|
+
has_many(:registers, Kounta::Register, { company_id: :id }, proc { |klass| { companies: klass.id, registers: nil } })
|
40
|
+
has_many(:employees, Kounta::Staff, { company_id: :id }, proc { |klass| { companies: klass.id, staff: nil } })
|
41
|
+
has_many(:shifts, Kounta::Shift, { company_id: :id }, proc { |klass, date| { companies: klass.id, shifts: Kounta.format_date(date) } })
|
42
|
+
has_many(:shifts_since, Kounta::Shift, { company_id: :id },
|
43
|
+
proc { |klass, date| { companies: klass.id, shifts: nil, since: Kounta.format_date(date) } })
|
44
|
+
has_many(:webhooks, Kounta::Webhook, { company_id: :id }, proc { |klass, _item_id| { companies: klass.id, webhooks: nil } })
|
18
45
|
|
19
|
-
|
20
|
-
has_one :category, Kounta::Category, {:company_id => :id}, lambda { |klass, item_id| {companies: klass.id, categories: item_id} }
|
21
|
-
has_one :customer, Kounta::Customer, {:company_id => :id}, lambda { |klass, item_id| {companies: klass.id, customers: item_id} }
|
22
|
-
has_one :person, Kounta::Person, {:company_id => :id}, lambda { |klass, item_id| {companies: klass.id, people: item_id} }
|
23
|
-
has_one :site, Kounta::Site, {:company_id => :id}, lambda { |klass, item_id| {companies: klass.id, sites: item_id} }
|
24
|
-
has_one :price_list, Kounta::PriceList, {:company_id => :id}, lambda { |klass, item_id| {companies: klass.id, price_lists: item_id} }
|
25
|
-
has_one :tax, Kounta::Tax, {:company_id => :id}, lambda { |klass, item_id| {companies: klass.id, taxes: item_id} }
|
26
|
-
has_one :order, Kounta::Order, {:company_id => :id}, lambda { |klass, item_id| {companies: klass.id, orders: item_id} }
|
27
|
-
has_one :register, Kounta::Register, {:company_id => :id}, lambda { |klass, item_id| {companies: klass.id, registers: item_id} }
|
46
|
+
has_many_in_time_range(:orders_in_time_range, Kounta::Order, { company_id: :id }, proc { |klass| { companies: klass.id, orders: nil } })
|
28
47
|
|
29
|
-
|
30
|
-
|
31
|
-
has_many :customers, Kounta::Customer, {:company_id => :id}, lambda { |klass| {companies: klass.id, customers: nil} }
|
32
|
-
has_many :people, Kounta::Person, {:company_id => :id}, lambda { |klass| {companies: klass.id, people: nil} }
|
33
|
-
has_many :sites, Kounta::Site, {:company_id => :id}, lambda { |klass| {companies: klass.id, sites: nil} }
|
34
|
-
has_many :price_lists, Kounta::PriceList, {:company_id => :id}, lambda { |klass| {companies: klass.id, price_lists: nil} }
|
35
|
-
has_many :taxes, Kounta::Tax, {:company_id => :id}, lambda { |klass| {companies: klass.id, taxes: nil} }
|
36
|
-
has_many :orders, Kounta::Order, {:company_id => :id}, lambda { |klass| {companies: klass.id, orders: nil} }
|
37
|
-
has_many :registers, Kounta::Register, {:company_id => :id}, lambda { |klass| {companies: klass.id, registers: nil} }
|
48
|
+
def initialize(client, hash = {})
|
49
|
+
@client = client
|
38
50
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
51
|
+
if hash.empty?
|
52
|
+
response = client.perform({ companies: 'me' }, :get).parsed
|
53
|
+
super(response)
|
54
|
+
else
|
55
|
+
super(hash)
|
56
|
+
end
|
57
|
+
end
|
47
58
|
|
48
|
-
|
49
|
-
|
50
|
-
|
59
|
+
def base_price_list
|
60
|
+
client.object_from_response(Kounta::PriceList, :get, companies: id, price_lists: 'base')
|
61
|
+
end
|
51
62
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
63
|
+
def resource_path
|
64
|
+
{ companies: id }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/kounta/customer.rb
CHANGED
@@ -1,36 +1,37 @@
|
|
1
1
|
module Kounta
|
2
|
+
class Customer < Kounta::Resource
|
3
|
+
property :company_id
|
4
|
+
property :people_id
|
5
|
+
property :first_name
|
6
|
+
property :last_name
|
7
|
+
property :email
|
8
|
+
property :primary_email_address
|
9
|
+
property :description
|
10
|
+
property :email_addresses
|
11
|
+
property :phone
|
12
|
+
property :mobile
|
13
|
+
property :fax
|
14
|
+
property :shipping_address
|
15
|
+
property :postal_address
|
16
|
+
property :addresses
|
17
|
+
property :image
|
18
|
+
property :tags
|
2
19
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
property :email_addresses
|
12
|
-
property :phone
|
13
|
-
property :mobile
|
14
|
-
property :fax
|
15
|
-
property :shipping_address
|
16
|
-
property :postal_address
|
17
|
-
property :addresses
|
18
|
-
property :image
|
19
|
-
property :tags
|
20
|
+
has_one(:address, Kounta::Address, { company_id: :company_id },
|
21
|
+
proc { |klass, item_id| { companies: klass.company_id, customers: klass.id, addresses: item_id } })
|
22
|
+
has_one(:order, Kounta::Order, { company_id: :company_id },
|
23
|
+
proc { |klass, item_id| { companies: klass.company_id, customers: klass.id, orders: item_id } })
|
24
|
+
has_many(:addresses, Kounta::Address, { company_id: :company_id },
|
25
|
+
proc { |klass| { companies: klass.company_id, customers: klass.id, addresses: nil } })
|
26
|
+
has_many(:orders, Kounta::Order, { company_id: :company_id },
|
27
|
+
proc { |klass| { companies: klass.company_id, customers: klass.id, orders: nil } })
|
20
28
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
has_many :orders, Kounta::Order, {:company_id => :company_id}, lambda { |klass| {companies: klass.company_id, customers: klass.id, orders: nil} }
|
29
|
+
def name
|
30
|
+
"#{first_name} #{last_name}"
|
31
|
+
end
|
25
32
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
{companies: company_id, customers: id}
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
33
|
+
def resource_path
|
34
|
+
{ companies: company_id, customers: id }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/kounta/errors.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
module Kounta
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
2
|
+
module Errors
|
3
|
+
class KountaError < StandardError; end
|
4
|
+
class MissingOauthDetails < KountaError; end
|
5
|
+
class UnknownResourceAttribute < KountaError; end
|
6
|
+
class APIError < KountaError; end
|
7
|
+
class RequestError < KountaError; end
|
8
|
+
end
|
9
|
+
end
|
data/lib/kounta/inventory.rb
CHANGED
data/lib/kounta/line.rb
CHANGED
@@ -1,24 +1,21 @@
|
|
1
1
|
module Kounta
|
2
|
+
class Line < Kounta::Resource
|
3
|
+
property :company_id
|
4
|
+
property :order_id
|
5
|
+
property :product_id
|
6
|
+
property :number
|
7
|
+
property :quantity
|
8
|
+
property :notes
|
9
|
+
property :price_variation
|
10
|
+
property :product
|
11
|
+
property :unit_price
|
12
|
+
property :unit_tax
|
13
|
+
property :modifiers
|
2
14
|
|
3
|
-
|
4
|
-
property :company_id
|
5
|
-
property :order_id
|
6
|
-
property :product_id
|
7
|
-
property :number
|
8
|
-
property :quantity
|
9
|
-
property :notes
|
10
|
-
property :price_variation
|
11
|
-
property :product
|
12
|
-
property :unit_price
|
13
|
-
property :unit_tax
|
14
|
-
property :modifiers
|
15
|
+
coerce_key :product, Kounta::Product
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
17
|
+
def resource_path
|
18
|
+
{ companies: company_id, orders: order_id, lines: id }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/kounta/order.rb
CHANGED
@@ -1,51 +1,47 @@
|
|
1
1
|
module Kounta
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
2
|
+
class Order < Kounta::Resource
|
3
|
+
property :company_id
|
4
|
+
property :status
|
5
|
+
property :customer
|
6
|
+
property :customer_id
|
7
|
+
property :register_id
|
8
|
+
property :site_id
|
9
|
+
property :lines
|
10
|
+
property :payments
|
11
|
+
property :callback_uri
|
12
|
+
property :placed_at
|
13
|
+
property :fulfil_at
|
14
|
+
property :notes
|
15
|
+
property :total
|
16
|
+
property :paid
|
17
|
+
property :product
|
18
|
+
property :sale_number
|
19
|
+
property :price_variation
|
20
|
+
property :lock
|
21
|
+
|
22
|
+
coerce_key :lines, Kounta::Line
|
23
|
+
coerce_key :payments, Kounta::Payment
|
24
|
+
|
25
|
+
def initialize(hash = {})
|
26
|
+
super(hash)
|
27
|
+
self.payments ||= []
|
28
|
+
self.lines ||= []
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_hash
|
32
|
+
returning = {}
|
33
|
+
returning[:lines] = lines.map(&:to_hash) if lines && !lines.empty?
|
34
|
+
returning[:payments] = payments.map(&:to_hash) if payments && !payments.empty?
|
35
|
+
super(returning)
|
36
|
+
end
|
37
|
+
|
38
|
+
def resource_path
|
39
|
+
{ companies: company_id, orders: id }
|
40
|
+
end
|
41
|
+
|
42
|
+
# we manually map these
|
43
|
+
def ignored_properties
|
44
|
+
super(%i[lock site_id])
|
45
|
+
end
|
46
|
+
end
|
50
47
|
end
|
51
|
-
|
data/lib/kounta/payment.rb
CHANGED
@@ -1,18 +1,15 @@
|
|
1
1
|
module Kounta
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
2
|
+
class Payment < Kounta::Resource
|
3
|
+
property :company_id
|
4
|
+
property :order_id
|
5
|
+
property :method_id
|
6
|
+
property :amount
|
7
|
+
property :ref
|
8
|
+
property :method
|
9
|
+
property :number
|
10
|
+
|
11
|
+
def resource_path
|
12
|
+
{ companies: company_id, orders: order_id, payments: id }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/kounta/person.rb
CHANGED
@@ -1,27 +1,24 @@
|
|
1
1
|
module Kounta
|
2
|
+
class Person < Kounta::Resource
|
3
|
+
property :company_id
|
4
|
+
property :customer_id
|
5
|
+
property :staff_id
|
6
|
+
property :first_name
|
7
|
+
property :last_name
|
8
|
+
property :primary_email_address
|
9
|
+
property :email_addresses
|
10
|
+
property :shipping_address
|
11
|
+
property :postal_address
|
12
|
+
property :addresses
|
13
|
+
property :phone_numbers
|
14
|
+
property :image
|
2
15
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
property :staff_id
|
7
|
-
property :first_name
|
8
|
-
property :last_name
|
9
|
-
property :primary_email_address
|
10
|
-
property :email_addresses
|
11
|
-
property :shipping_address
|
12
|
-
property :postal_address
|
13
|
-
property :addresses
|
14
|
-
property :phone_numbers
|
15
|
-
property :image
|
16
|
+
def name
|
17
|
+
"#{first_name} #{last_name}"
|
18
|
+
end
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
{companies: company_id, people: id}
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
20
|
+
def resource_path
|
21
|
+
{ companies: company_id, people: id }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|