activewave 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/activewave.rb +316 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6a6060d056766fe30473be0cf81458cba70ac464b60f1b80ef7d4c3baa760531
|
4
|
+
data.tar.gz: e0aea8db60e4aa74c36746137fbd9775a2bee331b9434131d66265fa0474a636
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9533d5ce3283b87b61a88b0a3f9d6a626a3d48312d4bd728b6295f2580ebbbbde41ea9b80d25607f9cf31d1202f4c7e29de0a7a4cefc8169a368f12594c90c2c
|
7
|
+
data.tar.gz: 5191ee9f5e1723687f47a9dfa42689dabc255cb0071ff68d8d0ff466e22468332a633c7c03e9419d5dd2d0497cfff76bb887546d0f7a5910340af6d6f1366a1e
|
data/lib/activewave.rb
ADDED
@@ -0,0 +1,316 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require "uri"
|
4
|
+
require "net/http"
|
5
|
+
require 'dotenv'
|
6
|
+
Dotenv.load
|
7
|
+
|
8
|
+
module ACTIVEWAVE
|
9
|
+
|
10
|
+
WAVE_API_URL = ENV['WAVE_API_URL']
|
11
|
+
BUSINESS_ID = ENV['BUSINESS_ID']
|
12
|
+
API_TOKEN = ENV['API_TOKEN']
|
13
|
+
|
14
|
+
url = URI(WAVE_API_URL)
|
15
|
+
|
16
|
+
@@https = Net::HTTP.new(url.host, url.port)
|
17
|
+
@@https.use_ssl = true
|
18
|
+
|
19
|
+
@@request = Net::HTTP::Post.new(url)
|
20
|
+
@@request["Authorization"] = "Bearer #{API_TOKEN}"
|
21
|
+
@@request["Content-Type"] = "application/json"
|
22
|
+
|
23
|
+
LIST_ALL_PRODUCTS_QUERY = %{
|
24
|
+
business(id: "#{BUSINESS_ID}") {
|
25
|
+
id
|
26
|
+
products(page: 1, pageSize: 100) {
|
27
|
+
pageInfo {
|
28
|
+
currentPage
|
29
|
+
totalPages
|
30
|
+
totalCount
|
31
|
+
}
|
32
|
+
edges {
|
33
|
+
node {
|
34
|
+
id
|
35
|
+
name
|
36
|
+
description
|
37
|
+
unitPrice
|
38
|
+
defaultSalesTaxes {
|
39
|
+
id
|
40
|
+
name
|
41
|
+
abbreviation
|
42
|
+
rate
|
43
|
+
}
|
44
|
+
isSold
|
45
|
+
isBought
|
46
|
+
isArchived
|
47
|
+
createdAt
|
48
|
+
modifiedAt
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
LIST_CUSTOMERS_QUERY = %{
|
56
|
+
business(id: "#{BUSINESS_ID}") {
|
57
|
+
id
|
58
|
+
customers(page: 1, pageSize: 100, sort: [NAME_ASC]) {
|
59
|
+
pageInfo {
|
60
|
+
currentPage
|
61
|
+
totalPages
|
62
|
+
totalCount
|
63
|
+
}
|
64
|
+
edges {
|
65
|
+
node {
|
66
|
+
id
|
67
|
+
name
|
68
|
+
email
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
LIST_ALL_INVOICES_QUERY = %{
|
76
|
+
business(id: "#{BUSINESS_ID}") {
|
77
|
+
id
|
78
|
+
isClassicInvoicing
|
79
|
+
invoices(page: 0, pageSize: 100) {
|
80
|
+
pageInfo {
|
81
|
+
currentPage
|
82
|
+
totalPages
|
83
|
+
totalCount
|
84
|
+
}
|
85
|
+
edges {
|
86
|
+
node {
|
87
|
+
id
|
88
|
+
createdAt
|
89
|
+
modifiedAt
|
90
|
+
pdfUrl
|
91
|
+
viewUrl
|
92
|
+
status
|
93
|
+
title
|
94
|
+
subhead
|
95
|
+
invoiceNumber
|
96
|
+
invoiceDate
|
97
|
+
poNumber
|
98
|
+
customer {
|
99
|
+
id
|
100
|
+
name
|
101
|
+
# Can add additional customer fields here
|
102
|
+
}
|
103
|
+
currency {
|
104
|
+
code
|
105
|
+
}
|
106
|
+
dueDate
|
107
|
+
amountDue {
|
108
|
+
value
|
109
|
+
currency {
|
110
|
+
symbol
|
111
|
+
}
|
112
|
+
}
|
113
|
+
amountPaid {
|
114
|
+
value
|
115
|
+
currency {
|
116
|
+
symbol
|
117
|
+
}
|
118
|
+
}
|
119
|
+
taxTotal {
|
120
|
+
value
|
121
|
+
currency {
|
122
|
+
symbol
|
123
|
+
}
|
124
|
+
}
|
125
|
+
total {
|
126
|
+
value
|
127
|
+
currency {
|
128
|
+
symbol
|
129
|
+
}
|
130
|
+
}
|
131
|
+
exchangeRate
|
132
|
+
footer
|
133
|
+
memo
|
134
|
+
disableCreditCardPayments
|
135
|
+
disableBankPayments
|
136
|
+
itemTitle
|
137
|
+
unitTitle
|
138
|
+
priceTitle
|
139
|
+
amountTitle
|
140
|
+
hideName
|
141
|
+
hideDescription
|
142
|
+
hideUnit
|
143
|
+
hidePrice
|
144
|
+
hideAmount
|
145
|
+
items {
|
146
|
+
product {
|
147
|
+
id
|
148
|
+
name
|
149
|
+
# Can add additional product fields here
|
150
|
+
}
|
151
|
+
description
|
152
|
+
quantity
|
153
|
+
price
|
154
|
+
subtotal {
|
155
|
+
value
|
156
|
+
currency {
|
157
|
+
symbol
|
158
|
+
}
|
159
|
+
}
|
160
|
+
total {
|
161
|
+
value
|
162
|
+
currency {
|
163
|
+
symbol
|
164
|
+
}
|
165
|
+
}
|
166
|
+
account {
|
167
|
+
id
|
168
|
+
name
|
169
|
+
subtype {
|
170
|
+
name
|
171
|
+
value
|
172
|
+
}
|
173
|
+
# Can add additional account fields here
|
174
|
+
}
|
175
|
+
taxes {
|
176
|
+
amount {
|
177
|
+
value
|
178
|
+
}
|
179
|
+
salesTax {
|
180
|
+
id
|
181
|
+
name
|
182
|
+
# Can add additional sales tax fields here
|
183
|
+
}
|
184
|
+
}
|
185
|
+
}
|
186
|
+
lastSentAt
|
187
|
+
lastSentVia
|
188
|
+
lastViewedAt
|
189
|
+
}
|
190
|
+
}
|
191
|
+
}
|
192
|
+
}
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
LIST_BUSINESSES = %{
|
197
|
+
businesses(page: 1, pageSize: 10) {
|
198
|
+
pageInfo {
|
199
|
+
currentPage
|
200
|
+
totalPages
|
201
|
+
totalCount
|
202
|
+
}
|
203
|
+
edges {
|
204
|
+
node {
|
205
|
+
id
|
206
|
+
name
|
207
|
+
isClassicAccounting
|
208
|
+
isClassicInvoicing
|
209
|
+
isPersonal
|
210
|
+
}
|
211
|
+
}
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
LIST_USERS = %{
|
216
|
+
user {
|
217
|
+
id
|
218
|
+
defaultEmail
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
|
223
|
+
def self.create_customer(name, first_name, last_name, email=nil)
|
224
|
+
create_a_customer(name, first_name, last_name, email)
|
225
|
+
end
|
226
|
+
|
227
|
+
def self.create_invoice(driver_id, product_id, status="SAVED")
|
228
|
+
create_an_invoice(driver_id, product_id, status)
|
229
|
+
end
|
230
|
+
|
231
|
+
|
232
|
+
def self.create_sales_record(date, anchor_account_id, line_item_account_id, amount, desc)
|
233
|
+
create_a_transaction(date, anchor_account_id, line_item_account_id, amount, desc)
|
234
|
+
end
|
235
|
+
|
236
|
+
def self.create_expense_record(date, anchor_account_id, line_item_account_id, amount, desc)
|
237
|
+
create_a_transaction(date, anchor_account_id, line_item_account_id, amount, desc, "EXPENSES")
|
238
|
+
end
|
239
|
+
|
240
|
+
def self.list_users
|
241
|
+
execute(LIST_USERS)
|
242
|
+
end
|
243
|
+
|
244
|
+
def self.list_all_products
|
245
|
+
execute(LIST_ALL_PRODUCTS_QUERY)
|
246
|
+
end
|
247
|
+
|
248
|
+
def self.list_all_customers
|
249
|
+
execute(LIST_CUSTOMERS_QUERY)
|
250
|
+
end
|
251
|
+
|
252
|
+
def self.list_all_invoices
|
253
|
+
execute(LIST_ALL_INVOICES_QUERY)
|
254
|
+
end
|
255
|
+
|
256
|
+
def self.list_all_businesses
|
257
|
+
execute(LIST_BUSINESSES)
|
258
|
+
end
|
259
|
+
|
260
|
+
def self.list_all_assets
|
261
|
+
list_assets_or_liabilities()
|
262
|
+
end
|
263
|
+
|
264
|
+
def self.list_all_incomes
|
265
|
+
list_assets_or_liabilities("INCOME")
|
266
|
+
end
|
267
|
+
|
268
|
+
def self.list_all_expenses
|
269
|
+
list_assets_or_liabilities("EXPENSE")
|
270
|
+
end
|
271
|
+
|
272
|
+
private
|
273
|
+
def self.create_a_transaction(date, anchor_account_id, line_item_account_id, amount, desc, type="SALES")
|
274
|
+
action = {SALES: ["DEPOSIT", "INCREASE"], EXPENSES: ["WITHDRAWAL", "INCREASE"]}
|
275
|
+
current_action = action[type.to_sym]
|
276
|
+
@@request.body = "{\"query\":\" mutation ($input:MoneyTransactionCreateInput!){\\n moneyTransactionCreate(input:$input){\\n didSucceed\\n inputErrors{\\n path\\n message\\n code\\n }\\n transaction{\\n id\\n }\\n }\\n }\",\"variables\":{\"input\":{\"businessId\":\"#{BUSINESS_ID}\",\"externalId\":\"#{desc + Time.now.to_s}\",\"date\":\"#{date}\",\"description\":\"#{desc}\",\"anchor\":{\"accountId\":\"#{anchor_account_id}\",\"amount\":#{amount},\"direction\":\"#{current_action[0]}\"},\"lineItems\":[{\"accountId\":\"#{line_item_account_id}\",\"amount\":#{amount},\"balance\":\"#{current_action[1]}\"}]}}}"
|
277
|
+
response = @@https.request(@@request)
|
278
|
+
response.read_body
|
279
|
+
end
|
280
|
+
|
281
|
+
def self.create_an_invoice(driver_id, product_id, status="SAVED")
|
282
|
+
@@request.body = "{\"query\":\"mutation ($input: InvoiceCreateInput!) {\\n invoiceCreate(input: $input) {\\n didSucceed\\n inputErrors {\\n message\\n code\\n path\\n }\\n invoice {\\n id\\n createdAt\\n modifiedAt\\n pdfUrl\\n viewUrl\\n status\\n title\\n subhead\\n invoiceNumber\\n invoiceDate\\n poNumber\\n customer {\\n id\\n name\\n # Can add additional customer fields here\\n }\\n currency {\\n code\\n }\\n dueDate\\n amountDue {\\n value\\n currency {\\n symbol\\n }\\n }\\n amountPaid {\\n value\\n currency {\\n symbol\\n }\\n }\\n taxTotal {\\n value\\n currency {\\n symbol\\n }\\n }\\n total {\\n value\\n currency {\\n symbol\\n }\\n }\\n exchangeRate\\n footer\\n memo\\n disableCreditCardPayments\\n disableBankPayments\\n itemTitle\\n unitTitle\\n priceTitle\\n amountTitle\\n hideName\\n hideDescription\\n hideUnit\\n hidePrice\\n hideAmount\\n items {\\n product {\\n id\\n name\\n # Can add additional product fields here\\n }\\n description\\n quantity\\n price\\n subtotal {\\n value\\n currency {\\n symbol\\n }\\n }\\n total {\\n value\\n currency {\\n symbol\\n }\\n }\\n account {\\n id\\n name\\n subtype {\\n name\\n value\\n }\\n # Can add additional account fields here\\n }\\n taxes {\\n amount {\\n value\\n }\\n salesTax {\\n id\\n name\\n # Can add additional sales tax fields here\\n }\\n }\\n }\\n lastSentAt\\n lastSentVia\\n lastViewedAt\\n }\\n }\\n}\",\"variables\":{\"input\":{\"businessId\":\"#{BUSINESS_ID}\",\"customerId\":\"#{driver_id}\",\"items\":[{\"productId\":\"#{product_id}\"}], \"status\":\"#{status}\"}}}"
|
283
|
+
response = @@https.request(@@request)
|
284
|
+
response.read_body
|
285
|
+
end
|
286
|
+
|
287
|
+
|
288
|
+
def self.create_a_customer(name, first_name, last_name, email)
|
289
|
+
@@request.body = "{\"query\":\"mutation ($input: CustomerCreateInput!) {\\n customerCreate(input: $input) {\\n didSucceed\\n inputErrors {\\n code\\n message\\n path\\n }\\n customer {\\n id\\n name\\n firstName\\n lastName\\n email\\n address {\\n addressLine1\\n addressLine2\\n city\\n province {\\n code\\n name\\n }\\n country {\\n code\\n name\\n }\\n postalCode\\n }\\n currency {\\n code\\n }\\n }\\n }\\n}\",\"variables\":{\"input\":{\"businessId\":\"#{BUSINESS_ID}\",\"name\":\"#{name}\",\"firstName\":\"#{first_name}\",\"lastName\":\"#{last_name}\",\"email\":\"#{email}\",\"currency\":\"GHS\"}}}"
|
290
|
+
response = @@https.request(@@request)
|
291
|
+
response.read_body
|
292
|
+
end
|
293
|
+
|
294
|
+
|
295
|
+
def self.list_assets_or_liabilities(filter="ASSET")
|
296
|
+
@@request.body = "{\"query\":\"query ($businessId: ID!, $page: Int!, $pageSize: Int!) {\\n business(id: $businessId) {\\n id\\n accounts(page: $page, pageSize: $pageSize, types: [#{filter}]) {\\n pageInfo {\\n currentPage\\n totalPages\\n totalCount\\n }\\n edges {\\n node {\\n id\\n name\\n description\\n displayId\\n type {\\n name\\n value\\n }\\n subtype {\\n name\\n value\\n }\\n normalBalanceType\\n isArchived\\n }\\n }\\n }\\n }\\n}\",\"variables\":{\"businessId\":\"#{BUSINESS_ID}\",\"page\":1,\"pageSize\":100}}"
|
297
|
+
response = @@https.request(@@request)
|
298
|
+
response.read_body
|
299
|
+
end
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
def self.execute(query)
|
304
|
+
HTTParty.post(
|
305
|
+
WAVE_API_URL,
|
306
|
+
headers: {
|
307
|
+
'Content-Type' => 'application/json',
|
308
|
+
'Authorization' => "Bearer #{API_TOKEN}"
|
309
|
+
},
|
310
|
+
body: {
|
311
|
+
query: "{#{query}}"
|
312
|
+
}.to_json
|
313
|
+
)
|
314
|
+
end
|
315
|
+
|
316
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activewave
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- CHARALES OPOKU-AGYEMANG
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A Wrapper For Waveapps graphql API
|
14
|
+
email: opokuagyemangcharles@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/activewave.rb
|
20
|
+
homepage: https://github.com/charlesagyemang/waveapps_ruby_gem
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.1.4
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: ACTIVEWAVE!
|
43
|
+
test_files: []
|