waveapps 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -15
- data/examples/invoice.md +60 -0
- data/lib/waveapps/api.rb +21 -0
- data/lib/waveapps/invoice.rb +143 -44
- data/lib/waveapps/ruby/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cfd2cadda9a1b89374e0a887abf1372db8a66e312eef095d46ee0bd24a4196a
|
4
|
+
data.tar.gz: 58c8f49781184a986b8d4770426750f4ed20a4acdb484b9ab1c2026e023ec8a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2155906045ed527d4549c8a298710b25af9732a4523ad8301e4f162e63cca140ce98d3bb0728993e772492d8be82706dafeade722520447394f23624e6a132d4
|
7
|
+
data.tar.gz: fe76a4d5ff85406621adf1dcea78ea9ad6efa52b36ea2ccb1b2b6a008bcd48aeee2b3c4569c8119a4ffb0fa9598bde11e032bf49e110bacfbc403b451ca9b5c8
|
data/README.md
CHANGED
@@ -28,21 +28,7 @@ The library needs to be configured with your account's access token which is ava
|
|
28
28
|
require "waveapps"
|
29
29
|
Waveapps.access_token = "sjblah_..."
|
30
30
|
```
|
31
|
-
|
32
|
-
|
33
|
-
### Create invoices
|
34
|
-
Replace `<BUSINESS_ID>`, `<CUSTOMER_ID>`, and `<PRODUCT_ID>` with real ids.
|
35
|
-
|
36
|
-
```ruby
|
37
|
-
Waveapps::Invoice.create_invoice(business_id: <BUSINESS_ID>, customer_id: <CUSTOMER_ID>, items: [{product_id: <PRODUCT_ID>}])
|
38
|
-
```
|
39
|
-
Optional arguments
|
40
|
-
|
41
|
-
`status`, `currency`, `title`, `invoice_number`,
|
42
|
-
`po_number`, `invoice_date`, `exchange_rate`, `due_date`,
|
43
|
-
`memo`, `footer`, `disable_amex_payments`, `disable_credit_card_payments`,
|
44
|
-
`disable_bank_payments`, `item_title`, `unit_title`, `price_title`, `amount_title`, `hide_name`, `hide_description`, `hide_unit`, `hide_price`, `hide_amount`
|
45
|
-
|
31
|
+
See [examples](/examples) for specific methods
|
46
32
|
|
47
33
|
## Development
|
48
34
|
|
data/examples/invoice.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Invoice
|
2
|
+
|
3
|
+
## Create invoice
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
Waveapps::Invoice.create_invoice(business_id: <BUSINESS_ID>, customer_id: <CUSTOMER_ID>, items: [{product_id: <PRODUCT_ID>}])
|
7
|
+
```
|
8
|
+
Optional arguments
|
9
|
+
|
10
|
+
`status`, `currency`, `title`, `invoice_number`,
|
11
|
+
`po_number`, `invoice_date`, `exchange_rate`, `due_date`,
|
12
|
+
`memo`, `footer`, `disable_amex_payments`, `disable_credit_card_payments`,
|
13
|
+
`disable_bank_payments`, `item_title`, `unit_title`, `price_title`, `amount_title`, `hide_name`, `hide_description`, `hide_unit`, `hide_price`, `hide_amount`
|
14
|
+
|
15
|
+
## List invoices
|
16
|
+
```ruby
|
17
|
+
Waveapps::Invoice.list_invoices(business_id: <BUSINESS_ID>)
|
18
|
+
```
|
19
|
+
|
20
|
+
## Send invoice
|
21
|
+
|
22
|
+
Provide email of recipients in the `to` argument. Note that this must be an array.
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
Waveapps::Invoice.send_invoice(invoice_id: <INVOICE_ID>, to: [<EMAIL>])
|
26
|
+
```
|
27
|
+
|
28
|
+
Optional arguments
|
29
|
+
|
30
|
+
`subject`, `message`, `attach_pdf`
|
31
|
+
|
32
|
+
The default value of `attach_pdf` is `false`
|
33
|
+
|
34
|
+
|
35
|
+
## Approve invoice
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
Waveapps::Invoice.approve_invoice(invoice_id: <INVOICE_ID>)
|
39
|
+
```
|
40
|
+
|
41
|
+
## Delete invoice
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
Waveapps::Invoice.delete_invoice(invoice_id: <INVOICE_ID>)
|
45
|
+
```
|
46
|
+
|
47
|
+
## Mark invoice as sent
|
48
|
+
|
49
|
+
Provide one of the following for `send_method`
|
50
|
+
`EXPORT_PDF`, `GMAIL`, `MARKED_SENT`, `NOT_SENT`, `OUTLOOK`, `SHARED_LINK`, `SKIPPED`, `WAVE`, `YAHOO`
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
Waveapps::Invoice.mark_as_sent(invoice_id: <INVOICE_ID>, send_method: <SEND_METHOD>)
|
54
|
+
```
|
55
|
+
|
56
|
+
Optional arguments
|
57
|
+
|
58
|
+
`sent_at`
|
59
|
+
|
60
|
+
If `sent_at` is not provided, Wave will use the current time
|
data/lib/waveapps/api.rb
CHANGED
@@ -26,5 +26,26 @@ module Waveapps
|
|
26
26
|
# Schema = GraphQL::Client.load_schema("./tmp/schema.json")
|
27
27
|
|
28
28
|
Client = GraphQL::Client.new(schema: Schema, execute: HTTP)
|
29
|
+
|
30
|
+
def self.handle_errors(response, mutation)
|
31
|
+
# Parse/validation errors will have `response.data = nil`. The top level
|
32
|
+
# errors object will report these.
|
33
|
+
if response.errors.any?
|
34
|
+
# "Could not resolve to a node with the global id of 'abc'"
|
35
|
+
message = response.errors[:data].join(", ")
|
36
|
+
return ::Waveapps::Error.new(message)
|
37
|
+
|
38
|
+
# The server will likely give us a message about why the node()
|
39
|
+
# lookup failed.
|
40
|
+
elsif data = response.data
|
41
|
+
# "Could not resolve to a node with the global id of 'abc'"
|
42
|
+
if data.errors[mutation].any?
|
43
|
+
message = data.errors[mutation].join(", ")
|
44
|
+
return ::Waveapps::Error.new(message)
|
45
|
+
end
|
46
|
+
else
|
47
|
+
Waveapps::Error.new("Something went wrong!")
|
48
|
+
end
|
49
|
+
end
|
29
50
|
end
|
30
51
|
end
|
data/lib/waveapps/invoice.rb
CHANGED
@@ -125,12 +125,15 @@ module Waveapps
|
|
125
125
|
GRAPHQL
|
126
126
|
|
127
127
|
def self.list_invoices(page: 1, page_size: 10, business_id:)
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
128
|
+
response = Waveapps::Api::Client.query(
|
129
|
+
ListInvoicesQuery, variables: {
|
130
|
+
businessId: business_id, page: page, pageSize: page_size
|
131
|
+
})
|
132
132
|
|
133
|
-
|
133
|
+
if response.data && response.data.business
|
134
|
+
return response.data.business.invoices.edges.map(&:node)
|
135
|
+
end
|
136
|
+
Waveapps::Api.handle_errors(response, :business)
|
134
137
|
end
|
135
138
|
|
136
139
|
CreateInvoiceQuery = Waveapps::Api::Client.parse <<-'GRAPHQL'
|
@@ -259,42 +262,48 @@ module Waveapps
|
|
259
262
|
hide_price: nil, hide_amount: nil, items:, business_id:, customer_id:
|
260
263
|
)
|
261
264
|
|
262
|
-
Waveapps::Api::Client.query(
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
265
|
+
response = Waveapps::Api::Client.query(
|
266
|
+
CreateInvoiceQuery, variables: {
|
267
|
+
input: {
|
268
|
+
businessId: business_id,
|
269
|
+
customerId: customer_id,
|
270
|
+
items: items.map do |pid|
|
271
|
+
{
|
272
|
+
productId: pid[:product_id],
|
273
|
+
quantity: pid[:quantity],
|
274
|
+
description: pid[:description],
|
275
|
+
unitPrice: pid[:unit_price]
|
276
|
+
}
|
277
|
+
end,
|
278
|
+
status: status,
|
279
|
+
currency: currency,
|
280
|
+
title: title,
|
281
|
+
invoiceNumber: invoice_number,
|
282
|
+
poNumber: po_number,
|
283
|
+
invoiceDate: invoice_date,
|
284
|
+
exchangeRate: exchange_rate,
|
285
|
+
dueDate: due_date,
|
286
|
+
memo: memo,
|
287
|
+
footer: footer,
|
288
|
+
disableAmexPayments: disable_amex_payments,
|
289
|
+
disableCreditCardPayments: disable_credit_card_payments,
|
290
|
+
disableBankPayments: disable_bank_payments,
|
291
|
+
itemTitle: item_title,
|
292
|
+
unitTitle: unit_title,
|
293
|
+
priceTitle: price_title,
|
294
|
+
amountTitle: amount_title,
|
295
|
+
hideName: hide_name,
|
296
|
+
hideDescription: hide_description,
|
297
|
+
hideUnit: hide_unit,
|
298
|
+
hidePrice: hide_price,
|
299
|
+
hideAmount: hide_amount
|
300
|
+
}
|
301
|
+
})
|
302
|
+
|
303
|
+
if response.data && response.data.invoice_create
|
304
|
+
return response.data.invoice_create
|
305
|
+
end
|
306
|
+
Waveapps::Api.handle_errors(response, :invoice_create)
|
298
307
|
end
|
299
308
|
|
300
309
|
DeleteInvoiceQuery = Waveapps::Api::Client.parse <<-'GRAPHQL'
|
@@ -310,9 +319,99 @@ module Waveapps
|
|
310
319
|
}
|
311
320
|
GRAPHQL
|
312
321
|
|
313
|
-
def self.delete_invoice(
|
314
|
-
|
315
|
-
|
322
|
+
def self.delete_invoice(invoice_id:)
|
323
|
+
response = Waveapps::Api::Client.query(DeleteInvoiceQuery, variables:
|
324
|
+
{ input: { invoiceId: invoice_id }
|
325
|
+
})
|
326
|
+
|
327
|
+
if response.data && response.data.invoice_delete
|
328
|
+
return response.data.invoice_delete
|
329
|
+
end
|
330
|
+
Waveapps::Api.handle_errors(response, :invoice_delete)
|
331
|
+
end
|
332
|
+
|
333
|
+
SendInvoiceQuery = Waveapps::Api::Client.parse <<-'GRAPHQL'
|
334
|
+
mutation ($input: InvoiceSendInput!) {
|
335
|
+
invoiceSend(input: $input) {
|
336
|
+
didSucceed
|
337
|
+
inputErrors {
|
338
|
+
message
|
339
|
+
code
|
340
|
+
path
|
341
|
+
}
|
342
|
+
}
|
343
|
+
}
|
344
|
+
GRAPHQL
|
345
|
+
|
346
|
+
def self.send_invoice(subject: "", message: "", attach_pdf: false, invoice_id:, to: )
|
347
|
+
response = Waveapps::Api::Client.query(
|
348
|
+
SendInvoiceQuery, variables: {
|
349
|
+
input: {
|
350
|
+
invoiceId: invoice_id,
|
351
|
+
to: to,
|
352
|
+
attachPDF: attach_pdf,
|
353
|
+
subject: subject,
|
354
|
+
message: message
|
355
|
+
}
|
356
|
+
})
|
357
|
+
|
358
|
+
if response.data && response.data.invoice_send
|
359
|
+
return response.data.invoice_send
|
360
|
+
end
|
361
|
+
Waveapps::Api.handle_errors(response, :invoice_send)
|
362
|
+
end
|
363
|
+
|
364
|
+
ApproveInvoiceQuery = Waveapps::Api::Client.parse <<-'GRAPHQL'
|
365
|
+
mutation ($input: InvoiceApproveInput!) {
|
366
|
+
invoiceApprove(input: $input) {
|
367
|
+
didSucceed
|
368
|
+
inputErrors {
|
369
|
+
message
|
370
|
+
code
|
371
|
+
path
|
372
|
+
}
|
373
|
+
}
|
374
|
+
}
|
375
|
+
GRAPHQL
|
376
|
+
|
377
|
+
def self.approve_invoice(invoice_id: )
|
378
|
+
response = Waveapps::Api::Client.query(ApproveInvoiceQuery, variables: {
|
379
|
+
input: { invoiceId: invoice_id }
|
380
|
+
})
|
381
|
+
|
382
|
+
if response.data && response.data.invoice_approve
|
383
|
+
return response.data.invoice_approve
|
384
|
+
end
|
385
|
+
Waveapps::Api.handle_errors(response, :invoice_approve)
|
386
|
+
end
|
387
|
+
|
388
|
+
MarkSentInvoiceQuery = Waveapps::Api::Client.parse <<-'GRAPHQL'
|
389
|
+
mutation ($input: InvoiceMarkSentInput!) {
|
390
|
+
invoiceMarkSent(input: $input) {
|
391
|
+
didSucceed
|
392
|
+
inputErrors {
|
393
|
+
message
|
394
|
+
code
|
395
|
+
path
|
396
|
+
}
|
397
|
+
}
|
398
|
+
}
|
399
|
+
GRAPHQL
|
400
|
+
|
401
|
+
def self.mark_as_sent(sent_at: nil, send_method: , invoice_id: )
|
402
|
+
response = Waveapps::Api::Client.query(
|
403
|
+
MarkSentInvoiceQuery, variables: {
|
404
|
+
input: {
|
405
|
+
invoiceId: invoice_id,
|
406
|
+
sentAt: sent_at,
|
407
|
+
sendMethod: send_method
|
408
|
+
}
|
409
|
+
})
|
410
|
+
|
411
|
+
if response.data && response.data.invoice_mark_sent
|
412
|
+
return response.data.invoice_mark_sent
|
413
|
+
end
|
414
|
+
Waveapps::Api.handle_errors(response, :invoice_mark_sent)
|
316
415
|
end
|
317
416
|
end
|
318
417
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: waveapps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hannah Masila
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- Rakefile
|
86
86
|
- bin/console
|
87
87
|
- bin/setup
|
88
|
+
- examples/invoice.md
|
88
89
|
- lib/tasks/schema.rake
|
89
90
|
- lib/waveapps.rb
|
90
91
|
- lib/waveapps/api.rb
|