kounta_rest 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 508beffc4c5a0e5b96f76b9f3d9a26287c470203
4
+ data.tar.gz: 56a675417171a2e97486a00c1fe0d71b7dab88b8
5
+ SHA512:
6
+ metadata.gz: 249606d473b6d0a8882b0c77b0547b3af84c9f2a5f2c0c53f7116e0c942000ddc678e5a7ecff99697e47e253069eda6f4308ad04833a6076122540c80918e12f
7
+ data.tar.gz: 8d405fcd1dd6a871137adebad28b3dff5a3675c49f50c1bc97e047c3f18efc34e21f5ec3205d14270fa26a92e30fbdf16079cbf7f56550e1284db406ba5274e4
@@ -24,6 +24,7 @@ module Kounta
24
24
  has_one :price_list, Kounta::PriceList, {:company_id => :id}, lambda { |klass, item_id| {companies: klass.id, price_lists: item_id} }
25
25
  has_one :tax, Kounta::Tax, {:company_id => :id}, lambda { |klass, item_id| {companies: klass.id, taxes: item_id} }
26
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} }
27
28
 
28
29
  has_many :products, Kounta::Product, {:company_id => :id}, lambda { |klass| {companies: klass.id, products: nil} }
29
30
  has_many :categories, Kounta::Category, {:company_id => :id}, lambda { |klass| {companies: klass.id, categories: nil} }
@@ -33,6 +34,7 @@ module Kounta
33
34
  has_many :price_lists, Kounta::PriceList, {:company_id => :id}, lambda { |klass| {companies: klass.id, price_lists: nil} }
34
35
  has_many :taxes, Kounta::Tax, {:company_id => :id}, lambda { |klass| {companies: klass.id, taxes: nil} }
35
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} }
36
38
 
37
39
  def initialize(hash={})
38
40
  if hash.empty?
@@ -18,10 +18,10 @@ module Kounta
18
18
  property :image
19
19
  property :tags
20
20
 
21
- has_one :address, Kounta::Address, {:company_id => :company_id}, lambda { |klass, item_id| {companies: klass.company_id, addresses: item_id} }
22
- has_one :order, Kounta::Order, {:company_id => :company_id}, lambda { |klass, item_id| {companies: klass.company_id, orders: item_id} }
23
- has_many :addresses, Kounta::Address, {:company_id => :company_id}, lambda { |klass| {companies: klass.company_id, addresses: nil} }
24
- has_many :orders, Kounta::Order, {:company_id => :company_id}, lambda { |klass| {companies: klass.company_id, orders: nil} }
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} }
25
25
 
26
26
  def name
27
27
  "#{first_name} #{last_name}"
data/lib/kounta/line.rb CHANGED
@@ -11,6 +11,7 @@ module Kounta
11
11
  property :product
12
12
  property :unit_price
13
13
  property :unit_tax
14
+ property :modifiers
14
15
 
15
16
  coerce_key :product, Kounta::Product
16
17
 
data/lib/kounta/order.rb CHANGED
@@ -16,6 +16,9 @@ module Kounta
16
16
  property :total
17
17
  property :paid
18
18
  property :product
19
+ property :sale_number
20
+ property :price_variation
21
+ property :lock
19
22
 
20
23
  coerce_key :lines, Kounta::Line
21
24
  coerce_key :payments, Kounta::Payment
@@ -28,8 +31,8 @@ module Kounta
28
31
 
29
32
  def to_hash
30
33
  returning = {}
31
- returning[:lines] = lines.map {|line| line.to_hash } if lines
32
- returning[:payments] = payments.map {|payment| payment.to_hash } if payments
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
33
36
  super(returning)
34
37
  end
35
38
 
@@ -39,7 +42,7 @@ module Kounta
39
42
 
40
43
  # we manually map these
41
44
  def ignored_properties
42
- super([:lines, :payments])
45
+ super([:lock, :site_id])
43
46
  end
44
47
 
45
48
  end
@@ -7,6 +7,7 @@ module Kounta
7
7
  property :amount
8
8
  property :ref
9
9
  property :method
10
+ property :number
10
11
 
11
12
  def resource_path
12
13
  {companies: company_id, orders: order_id, payments: id}
@@ -13,6 +13,7 @@ module Kounta
13
13
  property :cost_price
14
14
  property :taxes
15
15
  property :sites
16
+ property :number
16
17
 
17
18
  has_many :categories, Kounta::Category, {:company_id => :company_id}, lambda { |klass| {companies: klass.company_id, products: klass.id, categories: nil} }
18
19
  coerce_key :taxes, Kounta::Tax
@@ -0,0 +1,15 @@
1
+ module Kounta
2
+
3
+ class Register < Kounta::Resource
4
+ property :company_id
5
+ property :code
6
+ property :name
7
+ property :site_id
8
+
9
+ def resource_path
10
+ {companies: company_id, registers: id}
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -38,7 +38,7 @@ module Kounta
38
38
  if hash
39
39
  hash.each_pair do |k,v|
40
40
  begin
41
- self[k] = v
41
+ self[k] = v if self.respond_to? k.to_sym
42
42
  rescue NoMethodError => e
43
43
  raise Kounta::Errors::UnknownResourceAttribute.new("Unknown attribute: #{k} on resource #{self.class}")
44
44
  end
@@ -61,9 +61,16 @@ module Kounta
61
61
 
62
62
  def save!
63
63
  response = new? ? client.perform(resource_path, :post, {:body => to_hash}) : client.perform(resource_path, :put, {:body => to_hash})
64
+
65
+ # automatically follow redirects to resources
66
+ if response.status == 201
67
+ response = client.perform(response.headers["location"], :get)
68
+ end
69
+
64
70
  response.parsed.each_pair do |k,v|
65
- self[k] = v
71
+ self[k] = v if self.respond_to? k.to_sym
66
72
  end
73
+
67
74
  self
68
75
  end
69
76
 
@@ -30,13 +30,20 @@ module Kounta
30
30
 
31
31
  def perform(url_hash, request_method, options={})
32
32
  begin
33
- response = @conn.request(request_method, "#{path_from_hash(url_hash)}.#{FORMAT.to_s}", options)
33
+ if url_hash.kind_of? Hash
34
+ response = @conn.request(request_method, "#{path_from_hash(url_hash)}.#{FORMAT.to_s}", options)
35
+ else
36
+ response = @conn.request(request_method, url_hash, options)
37
+ end
34
38
  rescue OAuth2::Error => ex
35
- if ex.message.include? 'The access token provided has expired'
39
+ puts "-- in error"
40
+ puts response.inspect
41
+ if ex.message.include?('expired') || ex.message.include?('invalid')
36
42
  @conn = refreshed_token
37
43
  retry
38
44
  end
39
- raise Kounta::Errors::APIError.new(ex.message)
45
+
46
+ #raise Kounta::Errors::APIError.new(ex.message)
40
47
  end
41
48
  response
42
49
  end
@@ -1,3 +1,3 @@
1
1
  module Kounta
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
data/lib/kounta.rb CHANGED
@@ -11,6 +11,7 @@ require_relative "kounta/line"
11
11
  require_relative "kounta/order"
12
12
  require_relative "kounta/person"
13
13
  require_relative "kounta/customer"
14
+ require_relative "kounta/register"
14
15
  require_relative "kounta/price_list"
15
16
  require_relative "kounta/inventory"
16
17
  require_relative "kounta/site"
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kounta_rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
5
- prerelease:
4
+ version: 0.1.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - Samuel Richardson
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-20 00:00:00.000000000 Z
11
+ date: 2014-04-18 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,23 +27,20 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: simplecov
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - '='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - '='
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: webmock
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - '='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - '='
92
81
  - !ruby/object:Gem::Version
@@ -94,7 +83,6 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: oj
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ~>
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :runtime
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ~>
108
95
  - !ruby/object:Gem::Version
@@ -110,7 +97,6 @@ dependencies:
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: hashie
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
101
  - - ~>
116
102
  - !ruby/object:Gem::Version
@@ -118,7 +104,6 @@ dependencies:
118
104
  type: :runtime
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
108
  - - ~>
124
109
  - !ruby/object:Gem::Version
@@ -126,7 +111,6 @@ dependencies:
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: oauth2
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
115
  - - '='
132
116
  - !ruby/object:Gem::Version
@@ -134,7 +118,6 @@ dependencies:
134
118
  type: :runtime
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
122
  - - '='
140
123
  - !ruby/object:Gem::Version
@@ -142,7 +125,6 @@ dependencies:
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: pry
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
129
  - - '='
148
130
  - !ruby/object:Gem::Version
@@ -150,7 +132,6 @@ dependencies:
150
132
  type: :runtime
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
136
  - - '='
156
137
  - !ruby/object:Gem::Version
@@ -158,7 +139,6 @@ dependencies:
158
139
  - !ruby/object:Gem::Dependency
159
140
  name: yell
160
141
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
142
  requirements:
163
143
  - - '='
164
144
  - !ruby/object:Gem::Version
@@ -166,7 +146,6 @@ dependencies:
166
146
  type: :runtime
167
147
  prerelease: false
168
148
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
149
  requirements:
171
150
  - - '='
172
151
  - !ruby/object:Gem::Version
@@ -174,7 +153,6 @@ dependencies:
174
153
  - !ruby/object:Gem::Dependency
175
154
  name: faraday_middleware
176
155
  requirement: !ruby/object:Gem::Requirement
177
- none: false
178
156
  requirements:
179
157
  - - '='
180
158
  - !ruby/object:Gem::Version
@@ -182,7 +160,6 @@ dependencies:
182
160
  type: :runtime
183
161
  prerelease: false
184
162
  version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
163
  requirements:
187
164
  - - '='
188
165
  - !ruby/object:Gem::Version
@@ -215,6 +192,7 @@ files:
215
192
  - lib/kounta/person.rb
216
193
  - lib/kounta/price_list.rb
217
194
  - lib/kounta/product.rb
195
+ - lib/kounta/register.rb
218
196
  - lib/kounta/resource.rb
219
197
  - lib/kounta/rest/client.rb
220
198
  - lib/kounta/site.rb
@@ -261,27 +239,26 @@ files:
261
239
  homepage: https://github.com/Rodeoclash/Kounta
262
240
  licenses:
263
241
  - MIT
242
+ metadata: {}
264
243
  post_install_message:
265
244
  rdoc_options: []
266
245
  require_paths:
267
246
  - lib
268
247
  required_ruby_version: !ruby/object:Gem::Requirement
269
- none: false
270
248
  requirements:
271
- - - ! '>='
249
+ - - '>='
272
250
  - !ruby/object:Gem::Version
273
251
  version: '0'
274
252
  required_rubygems_version: !ruby/object:Gem::Requirement
275
- none: false
276
253
  requirements:
277
- - - ! '>='
254
+ - - '>='
278
255
  - !ruby/object:Gem::Version
279
256
  version: '0'
280
257
  requirements: []
281
258
  rubyforge_project:
282
- rubygems_version: 1.8.23
259
+ rubygems_version: 2.0.3
283
260
  signing_key:
284
- specification_version: 3
261
+ specification_version: 4
285
262
  summary: A wrapper around Kounta's RESTful API
286
263
  test_files:
287
264
  - spec/fixtures/address.json
@@ -322,4 +299,3 @@ test_files:
322
299
  - spec/kounta/rest/client_spec.rb
323
300
  - spec/kounta/site_spec.rb
324
301
  - spec/support/endpoints.rb
325
- has_rdoc: