activewave 0.0.6 → 0.0.7

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