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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +67 -36
  3. data/lib/kounta/address.rb +14 -17
  4. data/lib/kounta/break.rb +6 -0
  5. data/lib/kounta/category.rb +12 -15
  6. data/lib/kounta/company.rb +59 -50
  7. data/lib/kounta/customer.rb +33 -32
  8. data/lib/kounta/errors.rb +8 -7
  9. data/lib/kounta/inventory.rb +5 -7
  10. data/lib/kounta/line.rb +18 -21
  11. data/lib/kounta/order.rb +45 -49
  12. data/lib/kounta/payment.rb +14 -17
  13. data/lib/kounta/person.rb +21 -24
  14. data/lib/kounta/price_list.rb +7 -9
  15. data/lib/kounta/product.rb +25 -27
  16. data/lib/kounta/register.rb +11 -14
  17. data/lib/kounta/resource.rb +105 -93
  18. data/lib/kounta/rest/client.rb +177 -79
  19. data/lib/kounta/shift.rb +25 -0
  20. data/lib/kounta/site.rb +46 -38
  21. data/lib/kounta/staff.rb +30 -0
  22. data/lib/kounta/tax.rb +7 -9
  23. data/lib/kounta/version.rb +1 -1
  24. data/lib/kounta/webhook.rb +16 -0
  25. data/lib/kounta.rb +42 -72
  26. metadata +77 -145
  27. data/.gitignore +0 -20
  28. data/.gitmodules +0 -3
  29. data/Gemfile +0 -4
  30. data/Rakefile +0 -1
  31. data/console.rb +0 -14
  32. data/kounta.gemspec +0 -33
  33. data/spec/fixtures/address.json +0 -12
  34. data/spec/fixtures/addresses.json +0 -25
  35. data/spec/fixtures/base_price_list.json +0 -52
  36. data/spec/fixtures/categories.json +0 -217
  37. data/spec/fixtures/category.json +0 -11
  38. data/spec/fixtures/companies_me.json +0 -45
  39. data/spec/fixtures/customer.json +0 -39
  40. data/spec/fixtures/customers.json +0 -26
  41. data/spec/fixtures/inventory.json +0 -10
  42. data/spec/fixtures/line.json +0 -7
  43. data/spec/fixtures/order.json +0 -67
  44. data/spec/fixtures/orders.json +0 -134
  45. data/spec/fixtures/payment.json +0 -6
  46. data/spec/fixtures/people.json +0 -20
  47. data/spec/fixtures/person.json +0 -41
  48. data/spec/fixtures/price_list.json +0 -52
  49. data/spec/fixtures/price_lists.json +0 -12
  50. data/spec/fixtures/product.json +0 -25
  51. data/spec/fixtures/products.json +0 -119
  52. data/spec/fixtures/site.json +0 -6
  53. data/spec/fixtures/sites.json +0 -14
  54. data/spec/fixtures/tax.json +0 -7
  55. data/spec/fixtures/taxes.json +0 -16
  56. data/spec/helper.rb +0 -28
  57. data/spec/kounta/address_spec.rb +0 -11
  58. data/spec/kounta/category_spec.rb +0 -11
  59. data/spec/kounta/company_spec.rb +0 -24
  60. data/spec/kounta/customer_spec.rb +0 -15
  61. data/spec/kounta/kounta_spec.rb +0 -21
  62. data/spec/kounta/line_spec.rb +0 -14
  63. data/spec/kounta/order_spec.rb +0 -37
  64. data/spec/kounta/payment_spec.rb +0 -14
  65. data/spec/kounta/person_spec.rb +0 -15
  66. data/spec/kounta/product_spec.rb +0 -16
  67. data/spec/kounta/resource_spec.rb +0 -95
  68. data/spec/kounta/rest/client_spec.rb +0 -38
  69. data/spec/kounta/site_spec.rb +0 -11
  70. data/spec/support/endpoints.rb +0 -72
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 508beffc4c5a0e5b96f76b9f3d9a26287c470203
4
- data.tar.gz: 56a675417171a2e97486a00c1fe0d71b7dab88b8
3
+ metadata.gz: 863569524aae1949058648ddce027a8e28b39ad7
4
+ data.tar.gz: c778266f6a424de8d64f39c4bc26bf1578fe102d
5
5
  SHA512:
6
- metadata.gz: 249606d473b6d0a8882b0c77b0547b3af84c9f2a5f2c0c53f7116e0c942000ddc678e5a7ecff99697e47e253069eda6f4308ad04833a6076122540c80918e12f
7
- data.tar.gz: 8d405fcd1dd6a871137adebad28b3dff5a3675c49f50c1bc97e047c3f18efc34e21f5ec3205d14270fa26a92e30fbdf16079cbf7f56550e1284db406ba5274e4
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
- gem 'kounta_rest'
11
+ ```ruby
12
+ gem 'kounta_rest'
13
+ ```
10
14
 
11
15
  And then execute:
12
16
 
13
- $ bundle
17
+ ```
18
+ $ bundle
19
+ ```
14
20
 
15
21
  Or install it yourself as:
16
22
 
17
- $ gem install kounta_rest
23
+ ```
24
+ $ gem install kounta_rest
25
+ ```
18
26
 
19
27
  ## Usage
20
28
 
21
- require 'kounta'
22
-
23
- Then add your API details / other configuration options
24
-
25
- Kounta.configure do |config|
26
- config.client_id = "abcd1234"
27
- config.client_secret = "abcd1234"
28
- config.client_token = "abcd1234"
29
- config.client_refresh_token = "abcd1234"
30
- end
31
-
32
- You may also enable / disable logging (disabled by default)
33
-
34
- config.enable_logging = true
35
-
36
- Use the gem by creating a Kounta company object:
37
-
38
- company = Kounta::Company.new
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
- sites = company.sites
80
+ ```ruby
81
+ sites = company.sites
82
+ ```
45
83
 
46
84
  For the products belonging to a site
47
85
 
48
- sites.first.products
49
-
50
- Please see the test sweet for full details of these.
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
- client_id: abcd1234
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
- Then run:
92
+ ## Development
62
93
 
63
- ruby console.rb
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
- Get started by creating a Kounta::Company object (see above for detailed usage).
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
 
@@ -1,18 +1,15 @@
1
1
  module Kounta
2
-
3
- class Address < Kounta::Resource
4
- property :company_id
5
- property :people_id
6
- property :lines
7
- property :city
8
- property :zone
9
- property :postal_code
10
- property :country
11
-
12
- def resource_path
13
- {people: people_id, addresses: id}
14
- end
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
@@ -0,0 +1,6 @@
1
+ module Kounta
2
+ class Break < Kounta::Resource
3
+ property :started_at
4
+ property :finished_at
5
+ end
6
+ end
@@ -1,16 +1,13 @@
1
1
  module Kounta
2
-
3
- class Category < Kounta::Resource
4
- property :company_id
5
- property :name
6
- property :description
7
- property :image
8
- property :products
9
-
10
- def resource_path
11
- {companies: company_id, categories: id}
12
- end
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
@@ -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
- class Company < Kounta::Resource
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
- property :name
6
- property :shipping_address
7
- property :postal_address
8
- property :addresses
9
- property :business_number
10
- property :contact_staff_member
11
- property :image
12
- property :website
13
- property :currency
14
- property :timezone
15
- property :sites
16
- property :registers
17
- property :email
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
- has_one :product, Kounta::Product, {:company_id => :id}, lambda { |klass, item_id| {companies: klass.id, products: item_id} }
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
- has_many :products, Kounta::Product, {:company_id => :id}, lambda { |klass| {companies: klass.id, products: nil} }
30
- has_many :categories, Kounta::Category, {:company_id => :id}, lambda { |klass| {companies: klass.id, categories: nil} }
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
- def initialize(hash={})
40
- if hash.empty?
41
- response = client.perform({:companies => "me"}, :get).parsed
42
- super(response)
43
- else
44
- super(hash)
45
- end
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
- def base_price_list
49
- client.object_from_response(Kounta::PriceList, :get, {companies: id, price_lists: 'base'})
50
- end
59
+ def base_price_list
60
+ client.object_from_response(Kounta::PriceList, :get, companies: id, price_lists: 'base')
61
+ end
51
62
 
52
- def resource_path
53
- {companies: id}
54
- end
55
-
56
- end
57
-
58
- end
63
+ def resource_path
64
+ { companies: id }
65
+ end
66
+ end
67
+ end
@@ -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
- class Customer < Kounta::Resource
4
- property :company_id
5
- property :people_id
6
- property :first_name
7
- property :last_name
8
- property :email
9
- property :primary_email_address
10
- property :description
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
- has_one :address, Kounta::Address, {:company_id => :company_id}, lambda { |klass, item_id| {companies: klass.company_id, customers: klass.id, addresses: item_id} }
22
- has_one :order, Kounta::Order, {:company_id => :company_id}, lambda { |klass, item_id| {companies: klass.company_id, customers: klass.id, orders: item_id} }
23
- has_many :addresses, Kounta::Address, {:company_id => :company_id}, lambda { |klass| {companies: klass.company_id, customers: klass.id, addresses: nil} }
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
- def name
27
- "#{first_name} #{last_name}"
28
- end
29
-
30
- def resource_path
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
- module Errors
3
- class KountaError < StandardError; end
4
- class MissingOauthDetails < KountaError; end
5
- class UnknownResourceAttribute < KountaError; end
6
- class APIError < KountaError; end
7
- end
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
@@ -1,8 +1,6 @@
1
1
  module Kounta
2
-
3
- class Inventory < Kounta::Resource
4
- property :company_id
5
- property :stock
6
- end
7
-
8
- end
2
+ class Inventory < Kounta::Resource
3
+ property :company_id
4
+ property :stock
5
+ end
6
+ end
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
- class Line < Kounta::Resource
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
- coerce_key :product, Kounta::Product
17
-
18
- def resource_path
19
- {companies: company_id, orders: order_id, lines: id}
20
- end
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
- class Order < Kounta::Resource
4
- property :company_id
5
- property :status
6
- property :customer
7
- property :customer_id
8
- property :register_id
9
- property :site_id
10
- property :lines
11
- property :payments
12
- property :callback_uri
13
- property :placed_at
14
- property :fulfil_at
15
- property :notes
16
- property :total
17
- property :paid
18
- property :product
19
- property :sale_number
20
- property :price_variation
21
- property :lock
22
-
23
- coerce_key :lines, Kounta::Line
24
- coerce_key :payments, Kounta::Payment
25
-
26
- def initialize(hash={})
27
- super(hash)
28
- self.payments ||= []
29
- self.lines ||= []
30
- end
31
-
32
- def to_hash
33
- returning = {}
34
- returning[:lines] = lines.map {|line| line.to_hash } if lines && lines.length > 0
35
- returning[:payments] = payments.map {|payment| payment.to_hash } if payments && payments.length > 0
36
- super(returning)
37
- end
38
-
39
- def resource_path
40
- {companies: company_id, orders: id}
41
- end
42
-
43
- # we manually map these
44
- def ignored_properties
45
- super([:lock, :site_id])
46
- end
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
-
@@ -1,18 +1,15 @@
1
1
  module Kounta
2
-
3
- class Payment < Kounta::Resource
4
- property :company_id
5
- property :order_id
6
- property :method_id
7
- property :amount
8
- property :ref
9
- property :method
10
- property :number
11
-
12
- def resource_path
13
- {companies: company_id, orders: order_id, payments: id}
14
- end
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
- class Person < Kounta::Resource
4
- property :company_id
5
- property :customer_id
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
- def name
18
- "#{first_name} #{last_name}"
19
- end
20
-
21
- def resource_path
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