quaderno 1.16.0 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c06a424989f613db0191cce31b7acd854b4ba01f
4
- data.tar.gz: 3075394c13a2add9a27ef1a9e969d0cf4c820100
2
+ SHA256:
3
+ metadata.gz: 80ac06b981bcae525ea523aef71452980fba4a7e36bb8beec9bb72b8d3831d5f
4
+ data.tar.gz: 7130b682ec295ef787559cca17c3a55e7fc7f0343fc6170c25d92ef4d41eb029
5
5
  SHA512:
6
- metadata.gz: 9e6f8fe0b4bfb388386c2e5eaf5bb4d14af6099a868ea9f3db2309024c7896af5eae823d63adde5c7818cb6ba46d38376f63cac3c26c7a5b8cffeea5a3d91eac
7
- data.tar.gz: 4b66fcebba6da2b411b9f249a2bffd809a5857ea16ed4c5ea261028de7f219ad672d787b64a90cb1a84f175c3b8935969246cc72d8fe3432b314d94bfdb883c5
6
+ metadata.gz: f61d7417b9928b2ebd192a3e113c67b5bc53447049798dfbb4c5bc206a6b1b9968be0245f32a2bc1f684447a076804bf3ff46b0c9c4b231a116702fae221e45d
7
+ data.tar.gz: c85c55d68a167a7a318d80e054b41ad5d21e64806bf55475a9a118ab9ae1e1add30ddbeac881a420e5d60e22fa83a48d0c89c43c19b9292755a5bc215f26d31a
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Quaderno-ruby is a ruby wrapper for [Quaderno API] (https://github.com/quaderno/quaderno-api).
4
4
 
5
- Current version is 1.16.0 See the changelog [here](https://github.com/quaderno/quaderno-ruby/blob/master/changelog.md)
5
+ Current version is 1.17.0 See the changelog [here](https://github.com/quaderno/quaderno-ruby/blob/master/changelog.md)
6
6
 
7
7
  ## Installation & Configuration
8
8
 
@@ -29,8 +29,8 @@ To configure just add this to your initializers
29
29
  You can get your account subdomain by grabbing it from your account url or by calling the authorization method with your personal api token.
30
30
 
31
31
  ```ruby
32
- Quaderno::Base.authorization 'my_authenticate_token', environment
33
- # => {"identity"=>{"id"=>737000, "name"=>"Walter White", "email"=>"cooking@br.bd", "href"=>"https://my_subdomain.quadernoapp.com/api/"}}
32
+ response = Quaderno::Base.authorization 'my_authenticate_token', environment #=> Quaderno::Base
33
+ response.identity # => {"id"=>737000, "name"=>"Walter White", "email"=>"cooking@br.bd", "href"=>"https://my_subdomain.quadernoapp.com/api/"}
34
34
  ```
35
35
 
36
36
  `environment` is an optional argument. By passing `:sandbox`, you will retrieve your credentials for the sandbox environment and not for production.
@@ -41,19 +41,48 @@ This will return a hash with the information about your api url, which includes
41
41
  You can ping the service in order to check if it is up with:
42
42
 
43
43
  ```ruby
44
- Quaderno::Base.ping #=> Boolean
44
+ response = Quaderno::Base.ping #=> Quaderno::Base
45
+
46
+ response.status #=> Boolean
45
47
  ```
46
48
 
47
- This will return true if the service is up or false if it is not.
49
+ This will return `status: true` if the service is up or `status: false` if it is not.
48
50
 
49
51
  ## Check the rate limit
50
52
 
51
53
  ```ruby
52
- Quaderno::Base.rate_limit_info #=> {:reset=>4, :remaining=>0}
54
+ response = Quaderno::Base.ping #=> Quaderno::Base
55
+ response.rate_limit_info #=> { :reset=> 4, :remaining=> 0 }
56
+
53
57
  ```
54
58
 
55
59
  This will return a hash with information about the seconds until the rate limit reset and your remaining requests per minute ([check the API documentation for more information](https://github.com/quaderno/quaderno-api#rate-limiting)).
56
60
 
61
+ You can also check the rate limit for each request by checking the `rate_limit_info` method on the response:
62
+
63
+ ```ruby
64
+
65
+ invoices = Quaderno::Invoice.all #=> Quaderno::Collection
66
+ invoices.rate_limit_info #=> {:reset=> 5, :remaning=>6}
67
+
68
+ invoice = Quaderno::Invoice.find INVOICE_ID #=> Quaderno::Invoice
69
+ invoice.rate_limit_info #=> {:reset=>4, :remaining=>5}
70
+
71
+ result = invoice.deliver #=> Quaderno::Base
72
+ result.rate_limit_info #=> {:reset=>3, :remaining=>4}
73
+
74
+ begin
75
+ deleted_invoice = Quaderno::Invoice.delete(ANOTHER_INVOICE_ID) #=> Quaderno::Invoice
76
+ rescue Quaderno::Exceptions::InvalidSubdomainOrToken => e
77
+ # If the exception is triggered you can check the rate limit on the raised exception
78
+ e.rate_limit_info #=> {:reset=>2, :remaining=>3}
79
+ end
80
+
81
+ deleted_invoice.rate_limit_info #=> {:reset=>2, :remaining=>3}
82
+
83
+ # etc.
84
+ ```
85
+
57
86
  ## Reading the values
58
87
 
59
88
  Quaderno-ruby parses all the json responses in human readable data, so you can access each value just like this:
@@ -69,7 +98,7 @@ Quaderno-ruby parses all the json responses in human readable data, so you can a
69
98
 
70
99
  ### Getting contacts
71
100
  ```ruby
72
- Quaderno::Contact.all() #=> Array
101
+ Quaderno::Contact.all #=> Array
73
102
  Quaderno::Contact.all(page: 1) #=> Array
74
103
  ```
75
104
 
@@ -111,16 +140,16 @@ will update the specified contact with the data of the hash passed as second par
111
140
 
112
141
  ### Deleting a contact
113
142
  ```ruby
114
- Quaderno::Contact.delete(id) #=> Boolean
143
+ Quaderno::Contact.delete(id) #=> Quaderno::Contact
115
144
  ```
116
145
 
117
- will delete the contact with the id passed as parameter.
146
+ will delete the contact with the id passed as parameter. If the deletion was successful, an instance of `Quaderno::Contact` with the `deleted` attribute set to `true` will be returned.
118
147
 
119
148
  ## Managing items
120
149
 
121
150
  ### Getting items
122
151
  ```ruby
123
- Quaderno::Item.all() #=> Array
152
+ Quaderno::Item.all #=> Array
124
153
  ```
125
154
 
126
155
  will return an array with all your items.
@@ -148,10 +177,10 @@ will update the specified item with the data of the hash passed as second parame
148
177
 
149
178
  ### Deleting an item
150
179
  ```ruby
151
- Quaderno::Item.delete(id) #=> Boolean
180
+ Quaderno::Item.delete(id) #=> Quaderno::Item
152
181
  ```
153
182
 
154
- will delete the item with the id passed as parameter.
183
+ will delete the item with the id passed as parameter. If the deletion was successful, an instance of `Quaderno::Item` with the `deleted` attribute set to `true` will be returned.
155
184
 
156
185
 
157
186
  ## Managing invoices
@@ -196,10 +225,10 @@ will update the specified invoice with the data of the hash passed as second par
196
225
  ### Deleting an invoice
197
226
 
198
227
  ```ruby
199
- Quaderno::Invoice.delete(id) #=> Boolean
228
+ Quaderno::Invoice.delete(id) #=> Quaderno::Invoice
200
229
  ```
201
230
 
202
- will delete the invoice with the id passed as parameter.
231
+ will delete the invoice with the id passed as parameter. If the deletion was successful, an instance of `Quaderno::Item` with the `deleted` attribute set to `true` will be returned.
203
232
 
204
233
 
205
234
  ###Adding or removing a payment
@@ -219,13 +248,15 @@ In order to remove a payment you will need the Invoice instance you want to upd
219
248
  invoice.remove_payment(payment_id) #=> Boolean
220
249
  ```
221
250
 
222
- ###Delivering the invoice
251
+ ### Delivering the invoice
223
252
 
224
253
  In order to deliver the invoice to the default recipient you will need the invoice you want to send.
225
254
 
226
255
  ```ruby
227
256
  invoice = Quaderno::Invoice.find(invoice_id)
228
- invoice.deliver
257
+ result = invoice.deliver #=> Quaderno::Base
258
+
259
+ result.success #=> Boolean
229
260
  ```
230
261
 
231
262
  ## Managing receipts
@@ -263,18 +294,20 @@ will update the specified receipt with the data of the hash passed as second par
263
294
  ### Deleting an receipt
264
295
 
265
296
  ```ruby
266
- Quaderno::Receipt.delete(id) #=> Boolean
297
+ Quaderno::Receipt.delete(id) #=> Quaderno::Receipt
267
298
  ```
268
299
 
269
- will delete the receipt with the id passed as parameter.
300
+ will delete the receipt with the id passed as parameter. If the deletion was successful, an instance of `Quaderno::Receipt` with the `deleted` attribute set to `true` will be returned.
270
301
 
271
- ###Delivering the receipt
302
+ ### Delivering the receipt
272
303
 
273
304
  In order to deliver the receipt to the default recipient you will need the receipt you want to send.
274
305
 
275
306
  ```ruby
276
307
  receipt = Quaderno::Receipt.find(receipt_id)
277
- receipt.deliver
308
+ result = receipt.deliver #=> Quaderno::Base
309
+
310
+ result.success #=> Boolean
278
311
  ```
279
312
 
280
313
 
@@ -319,13 +352,13 @@ will update the specified credit with the data of the hash passed as second para
319
352
  ### Deleting a credit
320
353
 
321
354
  ```ruby
322
- Quaderno::Credit.delete(id) #=> Boolean
355
+ Quaderno::Credit.delete(id) #=> Quaderno::Credit
323
356
  ```
324
357
 
325
- will delete the credit with the id passed as parameter.
358
+ will delete the credit with the id passed as parameter. If the deletion was successful, an instance of `Quaderno::Credit` with the `deleted` attribute set to `true` will be returned.
326
359
 
327
360
 
328
- ###Adding or removing a payment
361
+ ### Adding or removing a payment
329
362
  In order to add a payment you will need the Credit instance you want to update.
330
363
 
331
364
  ```ruby
@@ -339,16 +372,20 @@ In order to remove a payment you will need the Credit instance you want to upda
339
372
 
340
373
  ```ruby
341
374
  credit = Quaderno::Credit.find(credit_id)
342
- credit.remove_payment(payment_id) #=> Boolean
375
+ credit.remove_payment(payment_id) #=> Quaderno::Payment
343
376
  ```
344
377
 
345
- ###Delivering the credit
378
+ If the deletion was successful, an instance of `Quaderno::Payment` with the `deleted` attribute set to `true` will be returned.
379
+
380
+ ### Delivering the credit
346
381
 
347
382
  In order to deliver the credit to the default recipient you will need the credit you want to send.
348
383
 
349
384
  ```ruby
350
385
  credit = Quaderno::Credit.find(credit_id)
351
- credit.deliver
386
+ result = credit.deliver #=> Quaderno::Base
387
+
388
+ result.success #=> Boolean
352
389
  ```
353
390
 
354
391
 
@@ -357,7 +394,7 @@ In order to remove a payment you will need the Credit instance you want to upda
357
394
 
358
395
  ### Getting estimates
359
396
  ```ruby
360
- Quaderno::Estimate.all() #=> Array
397
+ Quaderno::Estimate.all #=> Array
361
398
  Quaderno::Estimate.all(page: 1) #=> Array
362
399
  ```
363
400
 
@@ -388,10 +425,10 @@ will update the specified estimate with the data of the hash passed as second pa
388
425
  ### Deleting an estimate
389
426
 
390
427
  ```ruby
391
- Quaderno::Estimate.delete(id) #=> Boolean
428
+ Quaderno::Estimate.delete(id) #=> Quaderno::Estimate
392
429
  ```
393
430
 
394
- will delete the estimate with the id passed as parameter.
431
+ will delete the estimate with the id passed as parameter. If the deletion was successful, an instance of `Quaderno::Contact` with the `deleted` attribute set to `true` will be returned.
395
432
 
396
433
 
397
434
  ###Adding or removing a payment
@@ -411,12 +448,14 @@ In order to remove a payment you will need the estimate you want to update.
411
448
  estimate.remove_payment(payment_id) #=> Boolean
412
449
  ```
413
450
 
414
- ###Delivering the estimate
451
+ ### Delivering the estimate
415
452
  In order to deliver the estimate to the default recipient you will need the estimate you want to send.
416
453
 
417
454
  ```ruby
418
455
  estimate = Quaderno::Estimate.find(estimate_id)
419
- estimate.deliver
456
+ result = estimate.deliver #=> Quaderno::Base
457
+
458
+ result.success #=> Boolean
420
459
  ```
421
460
 
422
461
 
@@ -424,7 +463,7 @@ In order to remove a payment you will need the estimate you want to update.
424
463
 
425
464
  ### Getting expenses
426
465
  ```ruby
427
- Quaderno::Expense.all() #=> Array
466
+ Quaderno::Expense.all #=> Array
428
467
  Quaderno::Expense.all(page: 1) #=> Array
429
468
  ```
430
469
 
@@ -453,10 +492,10 @@ will update the specified expense with the data of the hash passed as second par
453
492
 
454
493
  ### Deleting an expense
455
494
  ```ruby
456
- Quaderno::Expense.delete(id) #=> Boolean
495
+ Quaderno::Expense.delete(id) #=> Quaderno::Expense
457
496
  ```
458
497
 
459
- will delete the expense with the id passed as parameter.
498
+ will delete the expense with the id passed as parameter. If the deletion was successful, an instance of `Quaderno::Expense` with the `deleted` attribute set to `true` will be returned.
460
499
 
461
500
 
462
501
  ## Managing recurrings
@@ -494,17 +533,17 @@ will update the specified recurring with the data of the hash passed as second p
494
533
  ### Deleting a recurring
495
534
 
496
535
  ```ruby
497
- Quaderno::Recurring.delete(id) #=> Boolean
536
+ Quaderno::Recurring.delete(id) #=> Quaderno::Recurring
498
537
  ```
499
538
 
500
- will delete the recurring with the id passed as parameter.
539
+ will delete the recurring with the id passed as parameter. If the deletion was successful, an instance of `Quaderno::Recurring` with the `deleted` attribute set to `true` will be returned.
501
540
 
502
541
 
503
542
  ## Managing webhooks
504
543
 
505
544
  ### Getting webhooks
506
545
  ```ruby
507
- Quaderno::Webhook.all() #=> Array
546
+ Quaderno::Webhook.all #=> Array
508
547
  ```
509
548
 
510
549
  will return an array with all the webhooks you have subscribed.
@@ -532,9 +571,9 @@ will update the specified webhook with the data of the hash passed as second par
532
571
 
533
572
  ### Deleting a webhook
534
573
  ```ruby
535
- Quaderno::Webhook.delete(id) #=> Boolean
574
+ Quaderno::Webhook.delete(id) #=> Quaderno::Webhook
536
575
  ```
537
- will delete the webhook with the id passed as parameter.
576
+ will delete the webhook with the id passed as parameter. If the deletion was successful, an instance of `Quaderno::Webhook` with the `deleted` attribute set to `true` will be returned.
538
577
 
539
578
 
540
579
  ## Taxes
@@ -548,10 +587,12 @@ will calculate the taxes applied for a customer based on the data pased as param
548
587
 
549
588
  ### Validate VAT numbers
550
589
  ```ruby
551
- country = 'IE'
552
- vat_number = 'IE6388047V'
590
+ country = 'IE'
591
+ vat_number = 'IE6388047V'
592
+
593
+ result = Quaderno::Tax.validate_vat_number(country, vat_number) #=> Quaderno::Tax
553
594
 
554
- Quaderno::Tax.validate_vat_number(country, vat_number) #=> Boolean
595
+ result.valid #=> Boolean or nil
555
596
  ```
556
597
 
557
598
  will validate the vat number for the passed country.
@@ -569,7 +610,7 @@ will create an evidence based on the data pased as parameters.
569
610
 
570
611
  ### Getting checkout sessions
571
612
  ```ruby
572
- Quaderno::CheckoutSession.all() #=> Array
613
+ Quaderno::CheckoutSession.all #=> Array
573
614
  ```
574
615
 
575
616
  will return an array with all the checkout sessions in your account.
@@ -597,9 +638,9 @@ will update the specified checkout session with the data of the hash passed as s
597
638
 
598
639
  ### Deleting a checkout session
599
640
  ```ruby
600
- Quaderno::CheckoutSession.delete(id) #=> Boolean
641
+ Quaderno::CheckoutSession.delete(id) #=> Quaderno::CheckoutSession
601
642
  ```
602
- will delete the checkout session with the id passed as parameter.
643
+ will delete the checkout session with the id passed as parameter. If the deletion was successful, an instance of `Quaderno::CheckoutSession` with the `deleted` attribute set to `true` will be returned.
603
644
 
604
645
 
605
646
  ## Exceptions
@@ -1,160 +1,171 @@
1
- #Changelog
2
- ##1.16.0
1
+ # Changelog
2
+
3
+ ## 1.17.0
4
+ * Added `rate_limit_info` method to each API response
5
+ * **Breaking change:** `.delete` methods no longer returns a boolean but an instance of the removed object with a `deleted` attribute set to `true`
6
+ * **Breaking change:** `Quaderno::Base.ping` no longer returns a boolean but a `Quaderno::Base` instance with a `status` attribute.
7
+ * **Breaking change:** `Quaderno::Base.authorization` no longer returns a `Hash` but a `Quaderno::Base` instance with an `identity` attribute.
8
+ * **Breaking change:** `Quaderno::Base.me` no longer returns a `Hash` but a `Quaderno::Base` instance with all the attributes contained in the previous format.
9
+ * **Breaking change:** `Quaderno::Tax.validate_vat_number` no longer returns a boolean but a `Quaderno::Tax` instance with a `valid` attribute.
10
+ * **Breaking change:** `.deliver` no longer returns a `Hash` but a `Quaderno::Base` instance with a `success` attribute.
11
+ * **Breaking change:** Removed `Quaderno::Base.rate_limit_info`. Now it's an alias of `Quaderno::Base.ping`.
12
+
13
+ ## 1.16.0
3
14
  * Added `Quaderno::CheckoutSession`
4
15
 
5
- ##1.15.2
16
+ ## 1.15.2
6
17
  * Relax `httparty` version requirement.
7
18
 
8
- ##1.15.1
19
+ ## 1.15.1
9
20
  * Fix `Quaderno` load order.
10
21
 
11
- ##1.15.0
22
+ ## 1.15.0
12
23
  * Removed `jeweler` and updated the gem structure.
13
24
 
14
- ##1.14.0
25
+ ## 1.14.0
15
26
  * Added `domestic_taxes`, `sales_taxes`, `vat_moss`, `ec_sales` and `international_taxes` to `Quaderno::Report`
16
27
 
17
- ##1.13.2
28
+ ## 1.13.2
18
29
  * Added index method to `Quaderno::Tax` as `Quaderno::Tax.all()`.
19
30
 
20
- ##1.13.1
31
+ ## 1.13.1
21
32
  * Added `taxes` report to `Quaderno::Report`.
22
33
 
23
- ##1.13.0
34
+ ## 1.13.0
24
35
  * Added `Quaderno::Report`.
25
36
 
26
- ##1.12.5
37
+ ## 1.12.5
27
38
  * Added `create` method to `Quaderno::Income`.
28
39
  * Fix `Quaderno::Base.ping` and `Quaderno::Base.me` methods.
29
40
 
30
- ##1.12.4
41
+ ## 1.12.4
31
42
  * Use version headers on taxes requests.
32
43
 
33
- ##1.12.3
44
+ ## 1.12.3
34
45
  * Return integers insteado of strings on pagination readers.
35
46
 
36
- ##1.12.2
47
+ ## 1.12.2
37
48
  * Added `me` method.
38
49
 
39
- ##1.12.0
50
+ ## 1.12.0
40
51
  * Added thread-safe credentials configuration.
41
52
  * `all` methods returns a `Quaderno::Object` with pagination info instead of an `Array`
42
53
 
43
- ##1.11.2
54
+ ## 1.11.2
44
55
  * Specify `Content-Type` header so `HTTParty` don't merge the elements within the body content.
45
56
 
46
- ##1.11.1
57
+ ## 1.11.1
47
58
  * Added `retrieve` method for `Quaderno::Contact`, `Quaderno::Invoice`, `Quaderno::Credit`
48
59
  * Deprecate `retrieve_customer` as an alias of `retrieve`
49
60
 
50
- ##1.11.0
61
+ ## 1.11.0
51
62
  * Added `Quaderno::Tax.validate_vat_number` method
52
63
 
53
- ##1.10.0
64
+ ## 1.10.0
54
65
  * Added location evidences support
55
66
 
56
- ##1.9.2
67
+ ## 1.9.2
57
68
  * Added `Quaderno::Contact.retrieve` method
58
69
  * Code cleanup
59
70
  * Update tests
60
71
 
61
- ##1.9.1
72
+ ## 1.9.1
62
73
  * `Quaderno::Base.authorization` raises `Quaderno::Exceptions::InvalidSubdomainOrToken` instead returning false on wrong credentials
63
74
  * Inherit from `StandardError` instead of `Exception` for `Quaderno::Exceptions` by **@mvelikov**
64
75
 
65
- ##1.9.0
76
+ ## 1.9.0
66
77
  * Add support for new versioning system
67
78
 
68
- ##1.8.0
79
+ ## 1.8.0
69
80
  * Add Quaderno::Receipt support
70
81
  * Fix errors in README
71
82
 
72
- ##1.7.3
83
+ ## 1.7.3
73
84
  * Raise exception on failed updates
74
85
 
75
- ##1.7.2
76
- * Fix URL in `Quaderno::Tax.calculate` by [**@jcxplorer**] (https://github.com/jcxplorer)
86
+ ## 1.7.2
87
+ * Fix URL in `Quaderno::Tax.calculate` by [**@jcxplorer**](https://github.com/jcxplorer)
77
88
 
78
- ##1.7.1
89
+ ## 1.7.1
79
90
  * Breaking change: change configuration options
80
91
 
81
- ##1.7.0
92
+ ## 1.7.0
82
93
  * Added recurring documents
83
94
  * Raise existent exception
84
95
 
85
- ##1.6.1
96
+ ## 1.6.1
86
97
  * Fixed typo from old version released as 1.6.0
87
98
 
88
- ##1.6.0 (yanked)
99
+ ## 1.6.0 (yanked)
89
100
  * Crud module refactor
90
101
  * Added support for credit notes
91
102
 
92
- ##1.5.5
103
+ ## 1.5.5
93
104
  * Move rdoc as a development dependency
94
105
 
95
- ##1.5.4
106
+ ## 1.5.4
96
107
  * Remove transaction class.
97
108
 
98
- ##1.5.3
109
+ ## 1.5.3
99
110
  * Update `rate_limit_info` to fit the new rate limit
100
111
  * Remove transaction information from README (future resource name change)
101
112
  * Added new throttle limit exception (will be activated in future releases)
102
113
 
103
- ##1.5.1 and 1.5.2
114
+ ## 1.5.1 and 1.5.2
104
115
  * Remove debugger
105
116
  * `Quaderno::Exceptions::RequiredFieldsEmpty` replaced with `Quaderno::Exceptions::RequiredFieldsEmptyOrInvalid`
106
117
 
107
- ##1.5.0
118
+ ## 1.5.0
108
119
  * Added transactions
109
120
  * Raise `Quaderno::Exceptions::RequiredFieldsEmpty` for 422 responses
110
121
 
111
- ##1.4.2
122
+ ## 1.4.2
112
123
  * Find method hotfix
113
124
 
114
- ##1.4.1
125
+ ## 1.4.1
115
126
  * Fix wrong method name
116
127
  * Use correct organization in url
117
128
  * Add short description of the gem
118
129
 
119
- ##1.4.0
130
+ ## 1.4.0
120
131
  * Added taxes calculations support
121
132
  * Added webhooks documentation
122
133
 
123
- ##1.3.2
134
+ ## 1.3.2
124
135
 
125
136
  * Use new urls format
126
137
 
127
- ##1.3.1
138
+ ## 1.3.1
128
139
 
129
140
  * Added sandbox environment
130
141
  * Added `to_hash` instance method
131
142
 
132
- ##1.3.0
143
+ ## 1.3.0
133
144
 
134
145
  * Removed debug mode
135
146
 
136
- ##1.2.2
147
+ ## 1.2.2
137
148
 
138
149
  * Added ruby 2.0.0 compatibility
139
150
 
140
- ##1.2.1
151
+ ## 1.2.1
141
152
 
142
153
  * Deleted debugger dependency
143
154
 
144
- ##1.2.0
155
+ ## 1.2.0
145
156
 
146
157
  * Added Quaderno webhooks as a resource
147
158
  * Added authorization method
148
159
 
149
- ##1.1.2
160
+ ## 1.1.2
150
161
 
151
162
  * Fixed minor bugs
152
163
 
153
- ##1.1.0
164
+ ## 1.1.0
154
165
 
155
166
  * Added Quaderno items as a resource
156
167
  * Added filter in index queries
157
168
 
158
- ##1.0.0
169
+ ## 1.0.0
159
170
 
160
171
  * Initial release
@@ -3,6 +3,7 @@ end
3
3
 
4
4
  require 'ostruct'
5
5
 
6
+ require 'quaderno-ruby/helpers/rate_limit'
6
7
  require 'quaderno-ruby/exceptions/exceptions'
7
8
  require 'quaderno-ruby/helpers/authentication'
8
9
  require 'quaderno-ruby/collection'
@@ -6,6 +6,7 @@ class Quaderno::Base < OpenStruct
6
6
  include Quaderno::Exceptions
7
7
  include Quaderno::Behavior::Crud
8
8
  include Quaderno::Helpers::Authentication
9
+ include Quaderno::Helpers::RateLimit
9
10
 
10
11
  PRODUCTION_URL = 'https://quadernoapp.com/api/'
11
12
  SANDBOX_URL = 'http://sandbox-quadernoapp.com/api/'
@@ -51,9 +52,12 @@ class Quaderno::Base < OpenStruct
51
52
  response = get("#{url}authorization.json", basic_auth: { username: auth_token }, headers: version_header)
52
53
 
53
54
  if response.code == 200
54
- response.parsed_response
55
+ data = self.new(response.parsed_response)
56
+ data.rate_limit_info = response
57
+
58
+ data
55
59
  else
56
- raise(Quaderno::Exceptions::InvalidSubdomainOrToken, 'Invalid subdomain or token')
60
+ raise_exception(Quaderno::Exceptions::InvalidSubdomainOrToken, 'Invalid subdomain or token', response)
57
61
  end
58
62
  end
59
63
 
@@ -72,9 +76,16 @@ class Quaderno::Base < OpenStruct
72
76
 
73
77
  check_exception_for(party_response, { subdomain_or_token: true })
74
78
  rescue Errno::ECONNREFUSED
75
- return false
79
+ return Quaderno::Base.new({ status: false })
76
80
  end
77
- true
81
+
82
+ data = self.new({ status: true })
83
+ data.rate_limit_info = party_response
84
+
85
+ data
86
+ end
87
+ class <<self
88
+ alias_method :rate_limit_info, :ping
78
89
  end
79
90
 
80
91
  def self.me(options = {})
@@ -90,14 +101,10 @@ class Quaderno::Base < OpenStruct
90
101
 
91
102
  check_exception_for(party_response, { subdomain_or_token: true })
92
103
 
93
- party_response.parsed_response
94
- end
104
+ data = self.new(party_response.parsed_response)
105
+ data.rate_limit_info = party_response
95
106
 
96
- #Returns the rate limit information: limit and remaining requests
97
- def self.rate_limit_info
98
- party_response = get("#{@@url}ping.json", basic_auth: { username: auth_token }, headers: version_header)
99
- check_exception_for(party_response, { subdomain_or_token: true })
100
- @@rate_limit_info = { reset: party_response.headers['x-ratelimit-reset'].to_i, remaining: party_response.headers["x-ratelimit-remaining"].to_i }
107
+ data
101
108
  end
102
109
 
103
110
  # Instance methods
@@ -19,7 +19,10 @@ module Quaderno::Behavior
19
19
  check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true })
20
20
  doc = response.parsed_response
21
21
 
22
- new doc
22
+ object = new doc
23
+ object.rate_limit_info = response
24
+
25
+ object
23
26
  end
24
27
  end
25
28
  end
@@ -47,6 +47,7 @@ module Quaderno::Behavior
47
47
  array.each { |element| collection << (new element) }
48
48
  end
49
49
 
50
+ collection.rate_limit_info = response
50
51
  collection.current_page = response.headers['x-pages-currentpage']
51
52
  collection.total_pages = response.headers['x-pages-totalpages']
52
53
 
@@ -67,7 +68,10 @@ module Quaderno::Behavior
67
68
 
68
69
  api_model.parse_nested(hash) if is_a_document?
69
70
 
70
- new hash
71
+ object = new hash
72
+ object.rate_limit_info = response
73
+
74
+ object
71
75
  end
72
76
 
73
77
  def create(params = {})
@@ -86,7 +90,10 @@ module Quaderno::Behavior
86
90
 
87
91
  api_model.parse_nested(hash) if is_a_document?
88
92
 
89
- new hash
93
+ object = new hash
94
+ object.rate_limit_info = response
95
+
96
+ object
90
97
  end
91
98
 
92
99
  def update(id, params = {})
@@ -105,7 +112,10 @@ module Quaderno::Behavior
105
112
 
106
113
  api_model.parse_nested(hash) if is_a_document?
107
114
 
108
- new hash
115
+ object = new hash
116
+ object.rate_limit_info = response
117
+
118
+ object
109
119
  end
110
120
 
111
121
  def delete(id, options = {})
@@ -117,7 +127,12 @@ module Quaderno::Behavior
117
127
  )
118
128
  check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true, has_documents: true })
119
129
 
120
- true
130
+ hash = { deleted: true, id: id }
131
+
132
+ object = new hash
133
+ object.rate_limit_info = response
134
+
135
+ object
121
136
  end
122
137
  end
123
138
  end
@@ -17,7 +17,11 @@ module Quaderno::Behavior
17
17
  )
18
18
 
19
19
  api_model.check_exception_for(party_response, { rate_limit: true, subdomain_or_token: true, id: true, required_fields: true })
20
- { limit: party_response.headers["x-ratelimit-limit"].to_i, remaining: party_response.headers["x-ratelimit-remaining"].to_i }
20
+
21
+ data = Quaderno::Base.new(success: true)
22
+ data.rate_limit_info = party_response
23
+
24
+ data
21
25
  end
22
26
  end
23
27
  end
@@ -25,13 +25,14 @@ module Quaderno::Behavior
25
25
  instance = Quaderno::Payment.new(response.parsed_response)
26
26
  self.payments << instance
27
27
 
28
- Quaderno::Payment.new instance
28
+ instance.rate_limit_info = response
29
+
30
+ instance
29
31
  end
30
32
 
31
33
  def remove_payment(payment_id, options = nil)
32
34
  self.authentication_data = get_authentication(options.merge(api_model: api_model)) if options.is_a?(Hash)
33
35
 
34
-
35
36
  response = HTTParty.delete("#{authentication_data[:url]}#{api_model.api_path}/#{id}/payments/#{payment_id}.json",
36
37
  basic_auth: authentication_data[:basic_auth],
37
38
  headers: self.class.version_header.merge(authentication_data[:headers])
@@ -41,7 +42,12 @@ module Quaderno::Behavior
41
42
 
42
43
  self.payments.delete_if { |payment| payment.id == payment_id }
43
44
 
44
- true
45
+ hash = { deleted: true, id: payment_id}
46
+
47
+ object = Quaderno::Payment.new(hash)
48
+ object.rate_limit_info = response
49
+
50
+ object
45
51
  end
46
52
  end
47
53
  end
@@ -20,7 +20,10 @@ module Quaderno::Behavior
20
20
  hash = response.parsed_response
21
21
  hash[:authentication_data] = authentication
22
22
 
23
- new hash
23
+ object = new hash
24
+ object.rate_limit_info = response
25
+
26
+ object
24
27
  end
25
28
  alias_method :retrieve_customer, :retrieve
26
29
 
@@ -1,4 +1,5 @@
1
1
  class Quaderno::Collection < Array
2
+ include Quaderno::Helpers::RateLimit
2
3
 
3
4
  def current_page=(page_number)
4
5
  @page = page_number
@@ -1,5 +1,6 @@
1
1
  module Quaderno::Exceptions
2
2
  class BaseException < StandardError
3
+ include Quaderno::Helpers::RateLimit
3
4
  end
4
5
 
5
6
  class InvalidSubdomainOrToken < BaseException
@@ -29,26 +30,33 @@ module Quaderno::Exceptions
29
30
 
30
31
  module ClassMethods
31
32
  def check_exception_for(party_response, params = {})
32
- raise(Quaderno::Exceptions::UnsupportedApiVersion, 'Unsupported API version') if !!(party_response.body =~ /Unsupported API version/)
33
+ raise_exception(Quaderno::Exceptions::UnsupportedApiVersion, 'Unsupported API version', party_response) if !!(party_response.body =~ /Unsupported API version/)
33
34
 
34
- if params[:throttle_limit].nil? == false
35
- raise(Quaderno::Exceptions::ThrottleLimitExceeded, 'Throttle limit exceeded, please try again later') if party_response.response.class == Net::HTTPServiceUnavailable
35
+ if params[:throttle_limit].nil? == false && party_response.response.class == Net::HTTPServiceUnavailable
36
+ raise_exception(Quaderno::Exceptions::ThrottleLimitExceeded, 'Throttle limit exceeded, please try again later', party_response)
36
37
  end
37
- if params[:rate_limit].nil? == false
38
- raise(Quaderno::Exceptions::RateLimitExceeded, 'Rate limit exceeded') if party_response.response.class == Net::HTTPForbidden
38
+ if params[:rate_limit].nil? == false && party_response.response.class == Net::HTTPForbidden
39
+ raise_exception(Quaderno::Exceptions::RateLimitExceeded, 'Rate limit exceeded', party_response)
39
40
  end
40
41
  if params[:subdomain_or_token].nil? == false
41
- raise(Quaderno::Exceptions::InvalidSubdomainOrToken, 'Invalid subdomain or token') if party_response.response.class == Net::HTTPUnauthorized
42
+ raise_exception(Quaderno::Exceptions::InvalidSubdomainOrToken, 'Invalid subdomain or token', party_response) if party_response.response.class == Net::HTTPUnauthorized
42
43
  end
43
44
  if params[:id].nil? == false
44
- raise(Quaderno::Exceptions::InvalidID, "Invalid #{ api_model } instance identifier") if (party_response.response.class == Net::HTTPInternalServerError) || (party_response.response.class == Net::HTTPNotFound)
45
+ raise_exception(Quaderno::Exceptions::InvalidID, "Invalid #{ api_model } instance identifier", party_response) if (party_response.response.class == Net::HTTPInternalServerError) || (party_response.response.class == Net::HTTPNotFound)
45
46
  end
46
47
  if params[:required_fields].nil? == false
47
- raise(Quaderno::Exceptions::RequiredFieldsEmptyOrInvalid, party_response.body) if party_response.response.class == Net::HTTPUnprocessableEntity
48
+ raise_exception(Quaderno::Exceptions::RequiredFieldsEmptyOrInvalid, party_response.body, party_response) if party_response.response.class == Net::HTTPUnprocessableEntity
48
49
  end
49
50
  if params[:has_documents].nil? == false
50
- raise(Quaderno::Exceptions::HasAssociatedDocuments, party_response.body) if party_response.response.class == Net::HTTPClientError
51
+ raise_exception(Quaderno::Exceptions::HasAssociatedDocuments, party_response.body, party_response) if party_response.response.class == Net::HTTPClientError
51
52
  end
52
53
  end
54
+
55
+ def raise_exception(klass, message, response)
56
+ exception = klass.new(message)
57
+ exception.rate_limit_info = response
58
+
59
+ raise exception
60
+ end
53
61
  end
54
62
  end
@@ -0,0 +1,12 @@
1
+ module Quaderno::Helpers
2
+ module RateLimit
3
+
4
+ def rate_limit_info=(response)
5
+ @rate_limit_info = { reset: response.headers['x-ratelimit-reset'].to_i, remaining: response.headers["x-ratelimit-remaining"].to_i }
6
+ end
7
+
8
+ def rate_limit_info
9
+ @rate_limit_info
10
+ end
11
+ end
12
+ end
@@ -1,2 +1,3 @@
1
1
  class Quaderno::Payment < OpenStruct
2
+ include Quaderno::Helpers::RateLimit
2
3
  end
@@ -20,7 +20,10 @@ class Quaderno::Tax < Quaderno::Base
20
20
  )
21
21
 
22
22
  check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true })
23
- new response.parsed_response
23
+ data = new response.parsed_response
24
+ data.rate_limit_info = response
25
+
26
+ data
24
27
  end
25
28
 
26
29
  def self.validate_vat_number(country, vat_number, options = {})
@@ -34,7 +37,10 @@ class Quaderno::Tax < Quaderno::Base
34
37
 
35
38
  check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true })
36
39
 
37
- response.parsed_response['valid']
40
+ data = new({ valid: response.parsed_response['valid'] })
41
+ data.rate_limit_info = response
42
+
43
+ data
38
44
  end
39
45
 
40
46
  def self.reports(options = {})
@@ -49,6 +55,7 @@ class Quaderno::Tax < Quaderno::Base
49
55
 
50
56
  array = response.parsed_response
51
57
  collection = Quaderno::Collection.new
58
+ collection.rate_limit_info = response
52
59
  collection.current_page = response.headers['x-pages-currentpage']
53
60
  collection.total_pages = response.headers['x-pages-totalpages']
54
61
 
@@ -1,3 +1,3 @@
1
1
  class Quaderno
2
- VERSION = "1.16.0"
2
+ VERSION = "1.17.0"
3
3
  end
@@ -28,6 +28,6 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency('webmock', "~> 1.22.6")
29
29
  spec.add_development_dependency('vcr', ">= 0")
30
30
  spec.add_development_dependency("bundler", "~> 1.11")
31
- spec.add_development_dependency("rake", "~> 10.0")
31
+ spec.add_development_dependency("rake", ">= 12.3.3")
32
32
  spec.add_development_dependency("rspec", "~> 3.0")
33
33
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quaderno
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.0
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Recrea
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
  date: 2018-05-07 00:00:00.000000000 Z
@@ -98,16 +98,16 @@ dependencies:
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '10.0'
103
+ version: 12.3.3
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '10.0'
110
+ version: 12.3.3
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -156,6 +156,7 @@ files:
156
156
  - lib/quaderno-ruby/exceptions/exceptions.rb
157
157
  - lib/quaderno-ruby/expense.rb
158
158
  - lib/quaderno-ruby/helpers/authentication.rb
159
+ - lib/quaderno-ruby/helpers/rate_limit.rb
159
160
  - lib/quaderno-ruby/income.rb
160
161
  - lib/quaderno-ruby/invoice.rb
161
162
  - lib/quaderno-ruby/item.rb
@@ -171,7 +172,7 @@ homepage: http://github.com/quaderno/quaderno-ruby
171
172
  licenses:
172
173
  - MIT
173
174
  metadata: {}
174
- post_install_message:
175
+ post_install_message:
175
176
  rdoc_options: []
176
177
  require_paths:
177
178
  - lib
@@ -186,9 +187,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
187
  - !ruby/object:Gem::Version
187
188
  version: '0'
188
189
  requirements: []
189
- rubyforge_project:
190
- rubygems_version: 2.4.3
191
- signing_key:
190
+ rubygems_version: 3.0.8
191
+ signing_key:
192
192
  specification_version: 4
193
193
  summary: Ruby wrapper for the Quaderno API (https://quaderno.io/docs/api)
194
194
  test_files: []