Module: ACTIVEWAVE
- Defined in:
- lib/activewave.rb
Constant Summary collapse
- WAVE_API_URL =
"https://gql.waveapps.com/graphql/public"- BUSINESS_ID =
"QnVzaW5lc3M6MDkyMWM2NjItODlhMy00NDk3LTkzYTktNTI2MzE3MGUyNTcx"- API_TOKEN =
"falcL269UemwhAuiPDbu9EirrINIrQ"- LIST_ALL_PRODUCTS_QUERY =
%{ business(id: "#{BUSINESS_ID}") { id products(page: 1, pageSize: 100) { pageInfo { currentPage totalPages totalCount } edges { node { id name description unitPrice defaultSalesTaxes { id name abbreviation rate } isSold isBought isArchived createdAt modifiedAt } } } } }- LIST_CUSTOMERS_QUERY =
%{ business(id: "#{BUSINESS_ID}") { id customers(page: 1, pageSize: 100, sort: [NAME_ASC]) { pageInfo { currentPage totalPages totalCount } edges { node { id name email } } } } }- LIST_ALL_INVOICES_QUERY =
%{ business(id: "#{BUSINESS_ID}") { id isClassicInvoicing invoices(page: 0, pageSize: 100) { pageInfo { currentPage totalPages totalCount } edges { node { id createdAt modifiedAt pdfUrl viewUrl status title subhead invoiceNumber invoiceDate poNumber customer { id name # Can add additional customer fields here } currency { code } dueDate amountDue { value currency { symbol } } amountPaid { value currency { symbol } } taxTotal { value currency { symbol } } total { value currency { symbol } } exchangeRate footer memo disableCreditCardPayments disableBankPayments itemTitle unitTitle priceTitle amountTitle hideName hideDescription hideUnit hidePrice hideAmount items { product { id name # Can add additional product fields here } description quantity price subtotal { value currency { symbol } } total { value currency { symbol } } account { id name subtype { name value } # Can add additional account fields here } taxes { amount { value } salesTax { id name # Can add additional sales tax fields here } } } lastSentAt lastSentVia lastViewedAt } } } } }- LIST_BUSINESSES =
%{ businesses(page: 1, pageSize: 10) { pageInfo { currentPage totalPages totalCount } edges { node { id name isClassicAccounting isClassicInvoicing isPersonal } } } }- LIST_USERS =
%{ user { id defaultEmail } }- @@https =
Net::HTTP.new(url.host, url.port)
- @@request =
Net::HTTP::Post.new(url)
Class Method Summary collapse
- .create_a_customer(name, first_name, last_name, email) ⇒ Object
- .create_a_transaction(date, anchor_account_id, line_item_account_id, amount, desc, type = "SALES") ⇒ Object
- .create_an_invoice(driver_id, product_id, status = "SAVED") ⇒ Object
- .create_customer(name, first_name, last_name, email = nil) ⇒ Object
- .create_expense_record(date, anchor_account_id, line_item_account_id, amount, desc) ⇒ Object
- .create_invoice(driver_id, product_id, status = "SAVED") ⇒ Object
- .create_sales_record(date, anchor_account_id, line_item_account_id, amount, desc) ⇒ Object
- .current_user ⇒ Object
- .execute(query) ⇒ Object
- .get_current_user ⇒ Object
- .get_user_details ⇒ Object
- .list_all_assets ⇒ Object
- .list_all_businesses ⇒ Object
- .list_all_customers ⇒ Object
- .list_all_expenses ⇒ Object
- .list_all_income ⇒ Object
- .list_all_incomes ⇒ Object
- .list_all_invoices ⇒ Object
- .list_all_products ⇒ Object
- .list_assets_or_liabilities(filter = "ASSET") ⇒ Object
- .list_incomes ⇒ Object
- .list_users ⇒ Object
- .user ⇒ Object
Class Method Details
.create_a_customer(name, first_name, last_name, email) ⇒ Object
310 311 312 313 314 |
# File 'lib/activewave.rb', line 310 def self.create_a_customer(name, first_name, last_name, email) @@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\"}}}" response = @@https.request(@@request) JSON.parse(response.read_body) end |
.create_a_transaction(date, anchor_account_id, line_item_account_id, amount, desc, type = "SALES") ⇒ Object
295 296 297 298 299 300 301 |
# File 'lib/activewave.rb', line 295 def self.create_a_transaction(date, anchor_account_id, line_item_account_id, amount, desc, type="SALES") action = {SALES: ["DEPOSIT", "INCREASE"], EXPENSES: ["WITHDRAWAL", "INCREASE"]} current_action = action[type.to_sym] @@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]}\"}]}}}" response = @@https.request(@@request) JSON.parse(response.read_body) end |
.create_an_invoice(driver_id, product_id, status = "SAVED") ⇒ Object
303 304 305 306 307 |
# File 'lib/activewave.rb', line 303 def self.create_an_invoice(driver_id, product_id, status="SAVED") @@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}\"}}}" response = @@https.request(@@request) JSON.parse(response.read_body) end |
.create_customer(name, first_name, last_name, email = nil) ⇒ Object
221 222 223 |
# File 'lib/activewave.rb', line 221 def self.create_customer(name, first_name, last_name, email=nil) create_a_customer(name, first_name, last_name, email) end |
.create_expense_record(date, anchor_account_id, line_item_account_id, amount, desc) ⇒ Object
234 235 236 |
# File 'lib/activewave.rb', line 234 def self.create_expense_record(date, anchor_account_id, line_item_account_id, amount, desc) create_a_transaction(date, anchor_account_id, line_item_account_id, amount, desc, "EXPENSES") end |
.create_invoice(driver_id, product_id, status = "SAVED") ⇒ Object
225 226 227 |
# File 'lib/activewave.rb', line 225 def self.create_invoice(driver_id, product_id, status="SAVED") create_an_invoice(driver_id, product_id, status) end |
.create_sales_record(date, anchor_account_id, line_item_account_id, amount, desc) ⇒ Object
230 231 232 |
# File 'lib/activewave.rb', line 230 def self.create_sales_record(date, anchor_account_id, line_item_account_id, amount, desc) create_a_transaction(date, anchor_account_id, line_item_account_id, amount, desc) end |
.current_user ⇒ Object
242 243 244 |
# File 'lib/activewave.rb', line 242 def self.current_user execute(LIST_USERS) end |
.execute(query) ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/activewave.rb', line 325 def self.execute(query) HTTParty.post( WAVE_API_URL, headers: { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{API_TOKEN}" }, body: { query: "{#{query}}" }.to_json ) end |
.get_current_user ⇒ Object
250 251 252 |
# File 'lib/activewave.rb', line 250 def self.get_current_user execute(LIST_USERS) end |
.get_user_details ⇒ Object
246 247 248 |
# File 'lib/activewave.rb', line 246 def self.get_user_details execute(LIST_USERS) end |
.list_all_assets ⇒ Object
274 275 276 |
# File 'lib/activewave.rb', line 274 def self.list_all_assets list_assets_or_liabilities() end |
.list_all_businesses ⇒ Object
270 271 272 |
# File 'lib/activewave.rb', line 270 def self.list_all_businesses execute(LIST_BUSINESSES) end |
.list_all_customers ⇒ Object
262 263 264 |
# File 'lib/activewave.rb', line 262 def self.list_all_customers execute(LIST_CUSTOMERS_QUERY) end |
.list_all_expenses ⇒ Object
290 291 292 |
# File 'lib/activewave.rb', line 290 def self.list_all_expenses list_assets_or_liabilities("EXPENSE") end |
.list_all_income ⇒ Object
282 283 284 |
# File 'lib/activewave.rb', line 282 def self.list_all_income list_assets_or_liabilities("INCOME") end |
.list_all_incomes ⇒ Object
278 279 280 |
# File 'lib/activewave.rb', line 278 def self.list_all_incomes list_assets_or_liabilities("INCOME") end |
.list_all_invoices ⇒ Object
266 267 268 |
# File 'lib/activewave.rb', line 266 def self.list_all_invoices execute(LIST_ALL_INVOICES_QUERY) end |
.list_all_products ⇒ Object
258 259 260 |
# File 'lib/activewave.rb', line 258 def self.list_all_products execute(LIST_ALL_PRODUCTS_QUERY) end |
.list_assets_or_liabilities(filter = "ASSET") ⇒ Object
317 318 319 320 321 |
# File 'lib/activewave.rb', line 317 def self.list_assets_or_liabilities(filter="ASSET") @@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}}" response = @@https.request(@@request) JSON.parse(response.read_body) end |
.list_incomes ⇒ Object
286 287 288 |
# File 'lib/activewave.rb', line 286 def self.list_incomes list_assets_or_liabilities("INCOME") end |
.list_users ⇒ Object
238 239 240 |
# File 'lib/activewave.rb', line 238 def self.list_users execute(LIST_USERS) end |
.user ⇒ Object
254 255 256 |
# File 'lib/activewave.rb', line 254 def self.user execute(LIST_USERS) end |