activewave 0.0.2 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/activewave.rb +65 -40
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c79c9fb72268a1fa1be829de419b9bcb516d5053bbc6ea7cf5046dd6d4db7249
|
4
|
+
data.tar.gz: 9da24281983c5b0d27c210dbeedb9e21a849b1de520107f9c94bf93bfeb39570
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79fe27e4c03a24d991dfe89e7d12c3016d456fb9e46e45879c784aa96d5194abdbbae93e7f7d97963fb60d6fbf4829a2b4ec3b0ef841d81c16c3322546d6ea5b
|
7
|
+
data.tar.gz: c67ddef291e681f75ea099016387a54bccdbbcbad35ebeeac836efb241f3fa5e4f00f2b2074967ddea3bb21ad67d0a992aba3a4151d7bb6fb8d53e3bc29a5c45
|
data/lib/activewave.rb
CHANGED
@@ -2,26 +2,27 @@ require 'httparty'
|
|
2
2
|
require 'json'
|
3
3
|
require "uri"
|
4
4
|
require "net/http"
|
5
|
-
require 'dotenv'
|
6
|
-
Dotenv.load
|
7
5
|
|
8
|
-
|
6
|
+
class Activewave
|
9
7
|
|
10
|
-
|
11
|
-
BUSINESS_ID = ENV['BUSINESS_ID']
|
12
|
-
API_TOKEN = ENV['API_TOKEN']
|
8
|
+
attr_accessor :business_id, :api_token
|
13
9
|
|
14
|
-
|
10
|
+
def initialize(business_id, api_token)
|
11
|
+
@business_id = business_id
|
12
|
+
@api_token = api_token
|
15
13
|
|
14
|
+
end
|
15
|
+
|
16
|
+
@@wave_api_url = "https://gql.waveapps.com/graphql/public"
|
17
|
+
url = URI(@@wave_api_url)
|
16
18
|
@@https = Net::HTTP.new(url.host, url.port)
|
17
19
|
@@https.use_ssl = true
|
18
|
-
|
19
20
|
@@request = Net::HTTP::Post.new(url)
|
20
|
-
@@request["Authorization"] = "Bearer #{
|
21
|
+
@@request["Authorization"] = "Bearer #{@api_token}"
|
21
22
|
@@request["Content-Type"] = "application/json"
|
22
23
|
|
23
24
|
LIST_ALL_PRODUCTS_QUERY = %{
|
24
|
-
business(id: "#{
|
25
|
+
business(id: "#{@business_id}") {
|
25
26
|
id
|
26
27
|
products(page: 1, pageSize: 100) {
|
27
28
|
pageInfo {
|
@@ -53,7 +54,7 @@ module ACTIVEWAVE
|
|
53
54
|
}
|
54
55
|
|
55
56
|
LIST_CUSTOMERS_QUERY = %{
|
56
|
-
business(id: "#{
|
57
|
+
business(id: "#{@business_id}") {
|
57
58
|
id
|
58
59
|
customers(page: 1, pageSize: 100, sort: [NAME_ASC]) {
|
59
60
|
pageInfo {
|
@@ -73,7 +74,7 @@ module ACTIVEWAVE
|
|
73
74
|
}
|
74
75
|
|
75
76
|
LIST_ALL_INVOICES_QUERY = %{
|
76
|
-
business(id: "#{
|
77
|
+
business(id: "#{@business_id}") {
|
77
78
|
id
|
78
79
|
isClassicInvoicing
|
79
80
|
invoices(page: 0, pageSize: 100) {
|
@@ -220,97 +221,121 @@ module ACTIVEWAVE
|
|
220
221
|
}
|
221
222
|
|
222
223
|
|
223
|
-
def
|
224
|
+
def create_customer(name, first_name, last_name, email=nil)
|
224
225
|
create_a_customer(name, first_name, last_name, email)
|
225
226
|
end
|
226
227
|
|
227
|
-
def
|
228
|
+
def create_invoice(driver_id, product_id, status="SAVED")
|
228
229
|
create_an_invoice(driver_id, product_id, status)
|
229
230
|
end
|
230
231
|
|
231
232
|
|
232
|
-
def
|
233
|
+
def create_sales_record(date, anchor_account_id, line_item_account_id, amount, desc)
|
233
234
|
create_a_transaction(date, anchor_account_id, line_item_account_id, amount, desc)
|
234
235
|
end
|
235
236
|
|
236
|
-
def
|
237
|
+
def create_expense_record(date, anchor_account_id, line_item_account_id, amount, desc)
|
237
238
|
create_a_transaction(date, anchor_account_id, line_item_account_id, amount, desc, "EXPENSES")
|
238
239
|
end
|
239
240
|
|
240
|
-
def
|
241
|
+
def list_users
|
242
|
+
execute(LIST_USERS)
|
243
|
+
end
|
244
|
+
|
245
|
+
def current_user
|
241
246
|
execute(LIST_USERS)
|
242
247
|
end
|
243
248
|
|
244
|
-
def
|
249
|
+
def get_user_details
|
250
|
+
execute(LIST_USERS)
|
251
|
+
end
|
252
|
+
|
253
|
+
def get_current_user
|
254
|
+
execute(LIST_USERS)
|
255
|
+
end
|
256
|
+
|
257
|
+
def user
|
258
|
+
execute(LIST_USERS)
|
259
|
+
end
|
260
|
+
|
261
|
+
def list_all_products
|
245
262
|
execute(LIST_ALL_PRODUCTS_QUERY)
|
246
263
|
end
|
247
264
|
|
248
|
-
def
|
265
|
+
def list_all_customers
|
249
266
|
execute(LIST_CUSTOMERS_QUERY)
|
250
267
|
end
|
251
268
|
|
252
|
-
def
|
269
|
+
def list_all_invoices
|
253
270
|
execute(LIST_ALL_INVOICES_QUERY)
|
254
271
|
end
|
255
272
|
|
256
|
-
def
|
273
|
+
def list_all_businesses
|
257
274
|
execute(LIST_BUSINESSES)
|
258
275
|
end
|
259
276
|
|
260
|
-
def
|
277
|
+
def list_all_assets
|
261
278
|
list_assets_or_liabilities()
|
262
279
|
end
|
263
280
|
|
264
|
-
def
|
281
|
+
def list_all_incomes
|
282
|
+
list_assets_or_liabilities("INCOME")
|
283
|
+
end
|
284
|
+
|
285
|
+
def list_all_income
|
286
|
+
list_assets_or_liabilities("INCOME")
|
287
|
+
end
|
288
|
+
|
289
|
+
def list_incomes
|
265
290
|
list_assets_or_liabilities("INCOME")
|
266
291
|
end
|
267
292
|
|
268
|
-
def
|
293
|
+
def list_all_expenses
|
269
294
|
list_assets_or_liabilities("EXPENSE")
|
270
295
|
end
|
271
296
|
|
272
297
|
private
|
273
|
-
def
|
298
|
+
def create_a_transaction(date, anchor_account_id, line_item_account_id, amount, desc, type="SALES")
|
274
299
|
action = {SALES: ["DEPOSIT", "INCREASE"], EXPENSES: ["WITHDRAWAL", "INCREASE"]}
|
275
300
|
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\":\"#{
|
301
|
+
@@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
302
|
response = @@https.request(@@request)
|
278
|
-
response.read_body
|
303
|
+
JSON.parse(response.read_body)
|
279
304
|
end
|
280
305
|
|
281
|
-
def
|
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\":\"#{
|
306
|
+
def create_an_invoice(driver_id, product_id, status="SAVED")
|
307
|
+
@@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
308
|
response = @@https.request(@@request)
|
284
|
-
response.read_body
|
309
|
+
JSON.parse(response.read_body)
|
285
310
|
end
|
286
311
|
|
287
312
|
|
288
|
-
def
|
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\":\"#{
|
313
|
+
def create_a_customer(name, first_name, last_name, email)
|
314
|
+
@@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
315
|
response = @@https.request(@@request)
|
291
|
-
response.read_body
|
316
|
+
JSON.parse(response.read_body)
|
292
317
|
end
|
293
318
|
|
294
319
|
|
295
|
-
def
|
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\":\"#{
|
320
|
+
def list_assets_or_liabilities(filter="ASSET")
|
321
|
+
@@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
322
|
response = @@https.request(@@request)
|
298
|
-
response.read_body
|
323
|
+
JSON.parse(response.read_body)
|
299
324
|
end
|
300
325
|
|
301
326
|
|
302
327
|
|
303
|
-
def
|
328
|
+
def execute(query)
|
304
329
|
HTTParty.post(
|
305
|
-
|
330
|
+
@@wave_api_url,
|
306
331
|
headers: {
|
307
332
|
'Content-Type' => 'application/json',
|
308
|
-
'Authorization' => "Bearer #{
|
333
|
+
'Authorization' => "Bearer #{@api_token}"
|
309
334
|
},
|
310
335
|
body: {
|
311
336
|
query: "{#{query}}"
|
312
337
|
}.to_json
|
313
|
-
)
|
338
|
+
).parsed_response
|
314
339
|
end
|
315
340
|
|
316
341
|
end
|