sageone_sdk 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.travis.yml +15 -0
- data/Fudgefile +27 -0
- data/Gemfile +12 -0
- data/Guardfile +33 -0
- data/LICENSE +22 -0
- data/README.md +57 -0
- data/Rakefile +10 -0
- data/fudge_settings.yml +5 -0
- data/lib/sageone_sdk.rb +16 -0
- data/lib/sageone_sdk/authentication.rb +8 -0
- data/lib/sageone_sdk/client.rb +117 -0
- data/lib/sageone_sdk/client/account_types.rb +19 -0
- data/lib/sageone_sdk/client/bank_accounts.rb +18 -0
- data/lib/sageone_sdk/client/chart_of_accounts.rb +21 -0
- data/lib/sageone_sdk/client/contact_types.rb +20 -0
- data/lib/sageone_sdk/client/contacts.rb +82 -0
- data/lib/sageone_sdk/client/countries.rb +18 -0
- data/lib/sageone_sdk/client/expenditures.rb +26 -0
- data/lib/sageone_sdk/client/expense_methods.rb +19 -0
- data/lib/sageone_sdk/client/expense_types.rb +19 -0
- data/lib/sageone_sdk/client/financial_settings.rb +23 -0
- data/lib/sageone_sdk/client/income_methods.rb +19 -0
- data/lib/sageone_sdk/client/income_types.rb +19 -0
- data/lib/sageone_sdk/client/incomes.rb +51 -0
- data/lib/sageone_sdk/client/journals.rb +27 -0
- data/lib/sageone_sdk/client/ledger_accounts.rb +52 -0
- data/lib/sageone_sdk/client/payment_statuses.rb +18 -0
- data/lib/sageone_sdk/client/period_types.rb +19 -0
- data/lib/sageone_sdk/client/products.rb +50 -0
- data/lib/sageone_sdk/client/purchase_invoices.rb +61 -0
- data/lib/sageone_sdk/client/sales_invoices.rb +65 -0
- data/lib/sageone_sdk/client/services.rb +48 -0
- data/lib/sageone_sdk/client/tax_rates.rb +18 -0
- data/lib/sageone_sdk/client/transactions.rb +13 -0
- data/lib/sageone_sdk/configurable.rb +43 -0
- data/lib/sageone_sdk/default.rb +47 -0
- data/lib/sageone_sdk/middleware.rb +6 -0
- data/lib/sageone_sdk/middleware/sdata_parser.rb +29 -0
- data/lib/sageone_sdk/middleware/signature.rb +26 -0
- data/lib/sageone_sdk/sdata_error_response.rb +36 -0
- data/lib/sageone_sdk/sdata_response.rb +58 -0
- data/lib/sageone_sdk/signature.rb +115 -0
- data/lib/sageone_sdk/version.rb +3 -0
- data/sageone_sdk.gemspec +37 -0
- data/spec/cassettes/SageoneSdk_Client_AccountTypes/account_types/_id/returns_a_specific_account_type.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_AccountTypes/account_types/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_AccountTypes/account_types/returns_all_account_types.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_BankAccounts/bank_accounts/_id/returns_a_specific_bank_account.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_BankAccounts/bank_accounts/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_BankAccounts/bank_accounts/returns_all_bank_accounts.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_ChartOfAccounts/chart_of_accounts_structure/returns_the_chart_of_accounts_structure.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_ChartOfAccounts/chart_of_accounts_templates/returns_the_chart_of_accounts_templates.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_ContactTypes/contact_types/_id/returns_a_specific_contact_type.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_ContactTypes/contact_types/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_ContactTypes/contact_types/returns_all_contact_types.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Contacts/contacts/_id/returns_a_specific_contact.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Contacts/contacts/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Contacts/contacts/returns_all_contacts.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Contacts/create_contacts/creates_a_new_contact.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Contacts/create_contacts/on_error/responds_with_an_appropriate_error_message.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Contacts/delete_a_contact/deletes_the_contact.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Contacts/update_a_contact/updates_the_given_contact.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Countries/countries/_id/returns_a_specific_account_type.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Countries/countries/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Countries/countries/returns_all_countries.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Expenditures/create_expenditures/creates_a_new_expenditure.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Expenditures/create_expenditures/on_error/responds_with_an_appropriate_error_message.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Expenditures/delete_an_expenditure/deletes_the_expenditure.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Expenditures/expenditures/_id/returns_a_specific_expenditure.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Expenditures/expenditures/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Expenditures/expenditures/returns_all_expenditures.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Expenditures/update_an_expenditure/updates_the_given_expenditure.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_ExpenseMethods/expense_methods/_id/returns_a_specific_contact_type.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_ExpenseMethods/expense_methods/returns_all_expense_methods.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_ExpenseMethods/income_methods/_id/returns_a_specific_contact_type.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_ExpenseMethods/income_methods/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_ExpenseMethods/income_methods/returns_all_income_methods.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_ExpenseTypes/expense_types/_id/returns_a_specific_contact_type.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_ExpenseTypes/expense_types/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_ExpenseTypes/expense_types/returns_all_expense_types.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_FinancialSettings/financial_settings/returns_the_financial_settings.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_FinancialSettings/update_financial_settings/updates_the_financial_settings.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_IncomeMethods/income_methods/_id/returns_a_specific_contact_type.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_IncomeMethods/income_methods/returns_all_income_methods.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_IncomeTypes/income_types/_id/returns_a_specific_contact_type.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_IncomeTypes/income_types/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_IncomeTypes/income_types/returns_all_income_types.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Incomes/create_incomes/creates_a_new_income.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Incomes/create_incomes/on_error/responds_with_an_appropriate_error_message.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Incomes/delete_an_income/deletes_the_income.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Incomes/incomes/_id/returns_a_specific_income.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Incomes/incomes/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Incomes/incomes/returns_all_incomes.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Incomes/update_an_income/updates_the_given_income.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Journals/journals/creates_a_journal.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Journals/journals/on_error/responds_with_an_appropriate_error_message.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_LedgerAccounts/create_a_ledger_account/creates_a_new_ledger_account.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_LedgerAccounts/create_a_ledger_account/on_error/responds_with_an_appropriate_error_message.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_LedgerAccounts/ledger_account_balances/does_not_return_ledger_accounts_with_a_zero_balance.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_LedgerAccounts/ledger_account_balances/returns_ledger_accounts_with_a_balance.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_LedgerAccounts/ledger_accounts/_id/returns_a_specific_ledger_account.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_LedgerAccounts/ledger_accounts/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_LedgerAccounts/ledger_accounts/returns_all_ledger_accounts.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_PaymentStatuses/payment_statuses/_id/returns_a_specific_contact_type.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_PaymentStatuses/payment_statuses/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_PaymentStatuses/payment_statuses/returns_all_payment_statuses.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_PeriodTypes/period_types/_id/returns_a_specific_contact_type.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_PeriodTypes/period_types/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_PeriodTypes/period_types/returns_all_period_types.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Products/create_products/creates_a_new_product.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Products/create_products/on_error/responds_with_an_appropriate_error_message.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Products/delete_a_product/deletes_the_product.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Products/products/_id/returns_a_specific_product.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Products/products/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Products/products/returns_all_products.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Products/update_a_product/updates_the_given_product.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_PurchaseInvoices/create_purchase_invoices/creates_a_new_purchase_invoice.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_PurchaseInvoices/create_purchase_invoices/on_error/responds_with_an_appropriate_error_message.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_PurchaseInvoices/delete_a_purchase_invoice/deletes_the_purchase_invoice.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_PurchaseInvoices/purchase_invoices/_id/returns_a_specific_purchase_invoice.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_PurchaseInvoices/purchase_invoices/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_PurchaseInvoices/purchase_invoices/returns_all_purchase_invoices.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_PurchaseInvoices/update_a_purchase_invoice/updates_the_given_purchase_invoice.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_SalesInvoices/create_sales_invoices/creates_a_new_sales_invoice.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_SalesInvoices/create_sales_invoices/on_error/responds_with_an_appropriate_error_message.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_SalesInvoices/delete_a_sales_invoice/deletes_the_sales_invoice.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_SalesInvoices/sales_invoices/_id/returns_a_specific_sales_invoice.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_SalesInvoices/sales_invoices/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_SalesInvoices/sales_invoices/returns_all_sales_invoices.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_SalesInvoices/update_a_sales_invoice/updates_the_given_sales_invoice.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Services/create_services/creates_a_new_service.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Services/create_services/on_error/responds_with_an_appropriate_error_message.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Services/delete_a_service/deletes_the_service.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Services/services/_id/returns_a_specific_service.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Services/services/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Services/services/returns_all_services.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Services/update_a_service/updates_the_given_service.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_TaxRates/tax_rates/_id/returns_a_specific_contact_type.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_TaxRates/tax_rates/allows_pagination.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_TaxRates/tax_rates/returns_all_tax_rates.json +1 -0
- data/spec/cassettes/SageoneSdk_Client_Transactions/transactions/returns_all_transactions.json +1 -0
- data/spec/cassettes/account_types_index.json +1 -0
- data/spec/cassettes/bank_accounts_index.json +1 -0
- data/spec/cassettes/contact_types_index.json +1 -0
- data/spec/cassettes/contacts_index.json +1 -0
- data/spec/cassettes/countries_index.json +1 -0
- data/spec/cassettes/customer_create.json +1 -0
- data/spec/cassettes/customers_index.json +1 -0
- data/spec/cassettes/expenditure_create.json +1 -0
- data/spec/cassettes/expenditures_index.json +1 -0
- data/spec/cassettes/expense_methods_index.json +1 -0
- data/spec/cassettes/expense_types_index.json +1 -0
- data/spec/cassettes/income_create.json +1 -0
- data/spec/cassettes/income_methods_index.json +1 -0
- data/spec/cassettes/income_types_index.json +1 -0
- data/spec/cassettes/incomes_index.json +1 -0
- data/spec/cassettes/ledger_accounts_index.json +1 -0
- data/spec/cassettes/payment_statuses_index.json +1 -0
- data/spec/cassettes/period_types_index.json +1 -0
- data/spec/cassettes/product_create.json +1 -0
- data/spec/cassettes/products_index.json +1 -0
- data/spec/cassettes/purchase_invoice_create.json +1 -0
- data/spec/cassettes/purchase_invoices_index.json +1 -0
- data/spec/cassettes/sales_invoice_create.json +1 -0
- data/spec/cassettes/sales_invoices_index.json +1 -0
- data/spec/cassettes/service_create.json +1 -0
- data/spec/cassettes/services_index.json +1 -0
- data/spec/cassettes/suppliers_index.json +1 -0
- data/spec/cassettes/tax_rates_index.json +1 -0
- data/spec/sageone_sdk/client/account_types_spec.rb +29 -0
- data/spec/sageone_sdk/client/bank_accounts_spec.rb +34 -0
- data/spec/sageone_sdk/client/chart_of_accounts_spec.rb +23 -0
- data/spec/sageone_sdk/client/contact_types_spec.rb +29 -0
- data/spec/sageone_sdk/client/contacts_spec.rb +75 -0
- data/spec/sageone_sdk/client/countries_spec.rb +29 -0
- data/spec/sageone_sdk/client/expenditures_spec.rb +113 -0
- data/spec/sageone_sdk/client/expense_methods_spec.rb +29 -0
- data/spec/sageone_sdk/client/expense_types_spec.rb +29 -0
- data/spec/sageone_sdk/client/financial_settings_spec.rb +23 -0
- data/spec/sageone_sdk/client/income_methods_spec.rb +29 -0
- data/spec/sageone_sdk/client/income_types_spec.rb +29 -0
- data/spec/sageone_sdk/client/incomes_spec.rb +114 -0
- data/spec/sageone_sdk/client/journals_spec.rb +39 -0
- data/spec/sageone_sdk/client/ledger_accounts_spec.rb +65 -0
- data/spec/sageone_sdk/client/payment_statuses_spec.rb +29 -0
- data/spec/sageone_sdk/client/period_types_spec.rb +29 -0
- data/spec/sageone_sdk/client/products_spec.rb +75 -0
- data/spec/sageone_sdk/client/purchase_invoices_spec.rb +124 -0
- data/spec/sageone_sdk/client/sales_invoices_spec.rb +126 -0
- data/spec/sageone_sdk/client/services_spec.rb +75 -0
- data/spec/sageone_sdk/client/tax_rates_spec.rb +29 -0
- data/spec/sageone_sdk/client/transactions_spec.rb +16 -0
- data/spec/sageone_sdk_spec.rb +19 -0
- data/spec/spec_helper.rb +40 -0
- metadata +601 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
module SageoneSdk
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Represents the purchase invoices for the authenticated user's business.
|
5
|
+
module PurchaseInvoices
|
6
|
+
|
7
|
+
# @return [object] Returns all purchase invoices for the authenticated user's business.
|
8
|
+
def purchase_invoices(options = {})
|
9
|
+
paginate "purchase_invoices", options
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [object] Returns the purchase invoice with the given id.
|
13
|
+
def purchase_invoice(id, options = {})
|
14
|
+
get "purchase_invoices/#{id}", options
|
15
|
+
end
|
16
|
+
|
17
|
+
# Creates a purchase invoice with the data provided.
|
18
|
+
# @example Create a new purchase invoice
|
19
|
+
# @client.create_purchase_invoice({"contact_id" => "371",
|
20
|
+
# "contact_name" => "Bob's Building Supplies",
|
21
|
+
# "due_date" => "2016-01-31",
|
22
|
+
# "date" => "2016-01-01",
|
23
|
+
# "line_items_attributes[0][description]" => "Line item description",
|
24
|
+
# "line_items_attributes[0][quantity]" => 10.0,
|
25
|
+
# "line_items_attributes[0][unit_price]" => 19.5,
|
26
|
+
# "line_items_attributes[0][tax_code_id]" => 1,
|
27
|
+
# "line_items_attributes[0][ledger_account_id]" => 434})
|
28
|
+
# @param data [hash] The purchase invoice information.
|
29
|
+
# @param options [hash]
|
30
|
+
def create_purchase_invoice(data, options = {})
|
31
|
+
lines = data.delete(:line_items)
|
32
|
+
|
33
|
+
if lines
|
34
|
+
data[:line_items_attributes] = {}
|
35
|
+
lines.each_with_index do |value, index|
|
36
|
+
data[:line_items_attributes][index] = value
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
post "purchase_invoices", :purchase_invoice => data
|
41
|
+
end
|
42
|
+
|
43
|
+
# Updates the given purchase invoice with the data provided.
|
44
|
+
# @example Update a purchase invoice due_date
|
45
|
+
# @client.update_purchase_invoice(11243, {"due_date" => "2016-01-31"})
|
46
|
+
# @param id [integer] The id of the purchase invoice to update.
|
47
|
+
# @param data [hash] The purchase invoice information to update.
|
48
|
+
# @param options [hash]
|
49
|
+
def update_purchase_invoice(id, data, options = {})
|
50
|
+
put "purchase_invoices/#{id}", :purchase_invoice => data
|
51
|
+
end
|
52
|
+
|
53
|
+
# Deletes the purchase invoice with the given id.
|
54
|
+
# @param id [integer] The id of the purchase invoice to delete.
|
55
|
+
# @param options [hash]
|
56
|
+
def delete_purchase_invoice(id, options = {})
|
57
|
+
delete "purchase_invoices/#{id}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module SageoneSdk
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Represents the sales invoices for the authenticated user's business.
|
5
|
+
module SalesInvoices
|
6
|
+
|
7
|
+
# @return [object] Returns all sales invoices for the authenticated user's business.
|
8
|
+
def sales_invoices(options = {})
|
9
|
+
paginate "sales_invoices", options
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [object] Returns the sales invoice with the given id.
|
13
|
+
def sales_invoice(id, options = {})
|
14
|
+
get "sales_invoices/#{id}", options
|
15
|
+
end
|
16
|
+
|
17
|
+
# Creates a sales invoice with the data provided.
|
18
|
+
# @example Create a new sales invoice
|
19
|
+
# @client.create_sales_invoice({"contact_id" => "237",
|
20
|
+
# "contact_name" => "My best customer",
|
21
|
+
# "due_date" => "2016-01-31",
|
22
|
+
# "date" => "2016-01-01",
|
23
|
+
# "main_address" => "25 Station Road...",
|
24
|
+
# "carriage_tax_code_id" => 1,
|
25
|
+
# "line_items_attributes[0][description]" => "Line item description",
|
26
|
+
# "line_items_attributes[0][product_id]" => 17,
|
27
|
+
# "line_items_attributes[0][product_code]" => "PROD001",
|
28
|
+
# "line_items_attributes[0][quantity]" => 10.0,
|
29
|
+
# "line_items_attributes[0][unit_price]" => 29.5,
|
30
|
+
# "line_items_attributes[0][tax_code_id]" => 1,
|
31
|
+
# "line_items_attributes[0][ledger_account_id]" => 434})
|
32
|
+
# @param data [hash] The sales invoice information.
|
33
|
+
# @param options [hash]
|
34
|
+
def create_sales_invoice(data, options = {})
|
35
|
+
lines = data.delete(:line_items)
|
36
|
+
|
37
|
+
if lines
|
38
|
+
data[:line_items_attributes] = {}
|
39
|
+
lines.each_with_index do |value, index|
|
40
|
+
data[:line_items_attributes][index] = value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
post "sales_invoices", :sales_invoice => data
|
45
|
+
end
|
46
|
+
|
47
|
+
# Updates the given sales invoice with the data provided.
|
48
|
+
# @example Update a sales invoice due_date
|
49
|
+
# @client.update_sales_invoice(1243, {"due_date" => "2016-01-31"})
|
50
|
+
# @param id [integer] The id of the sales invoice to update.
|
51
|
+
# @param data [hash] The sales invoice information to update.
|
52
|
+
# @param options [hash]
|
53
|
+
def update_sales_invoice(id, data, options = {})
|
54
|
+
put "sales_invoices/#{id}", :sales_invoice => data
|
55
|
+
end
|
56
|
+
|
57
|
+
# Deletes the sales invoice with the given id.
|
58
|
+
# @param id [integer] The id of the sales invoice to delete.
|
59
|
+
# @param options [hash]
|
60
|
+
def delete_sales_invoice(id, options = {})
|
61
|
+
delete "sales_invoices/#{id}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module SageoneSdk
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Represents the services for the authenticated user's business.
|
5
|
+
module Services
|
6
|
+
|
7
|
+
# @return [object] Returns all services for the authenticated user's business.
|
8
|
+
def services(options = {})
|
9
|
+
paginate "services", options
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [object] Returns the service record with the given id.
|
13
|
+
def service(id, options = {})
|
14
|
+
get "services/#{id}", options
|
15
|
+
end
|
16
|
+
|
17
|
+
# Creates a service record with the data provided.
|
18
|
+
# @example Create a new service record
|
19
|
+
# @client.create_service({description: "My new service",
|
20
|
+
# rate_includes_tax: false,
|
21
|
+
# ledger_account_id: 438,
|
22
|
+
# tax_code_id: 1,
|
23
|
+
# period_rate_price: 99.99})
|
24
|
+
# @param data [hash] The service record information.
|
25
|
+
# @param options [hash]
|
26
|
+
def create_service(data, options = {})
|
27
|
+
post "services", :service => data
|
28
|
+
end
|
29
|
+
|
30
|
+
# Updates the given service record with the data provided.
|
31
|
+
# @example Update a service record description
|
32
|
+
# @client.update_service(11232, {description: "My updated service"})
|
33
|
+
# @param id [integer] The id of the service record to update.
|
34
|
+
# @param data [hash] The service information to update.
|
35
|
+
# @param options [hash]
|
36
|
+
def update_service(id, data, options = {})
|
37
|
+
put "services/#{id}", :service => data
|
38
|
+
end
|
39
|
+
|
40
|
+
# Deletes the given service record.
|
41
|
+
# @param id [integer] The id of the service record to delete.
|
42
|
+
# @param options [hash]
|
43
|
+
def delete_service(id, options = {})
|
44
|
+
delete "services/#{id}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module SageoneSdk
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Represents the tax rates in Sage One. For example, standard or zero-rated.
|
5
|
+
module TaxRates
|
6
|
+
|
7
|
+
# @return [object] Returns all tax rates.
|
8
|
+
def tax_rates(options = {})
|
9
|
+
get "tax_rates", options
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [object] Returns the tax rate with the given id.
|
13
|
+
def tax_rate(id, options = {})
|
14
|
+
get "tax_rates/#{id}", options
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module SageoneSdk
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Represents the transactions for the authenticated user's business.
|
5
|
+
module Transactions
|
6
|
+
|
7
|
+
# @return [object] Returns all transactions for the authenticated user's business.
|
8
|
+
def transactions(options = {})
|
9
|
+
get "transactions", options
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module SageoneSdk
|
2
|
+
# Configurable
|
3
|
+
module Configurable
|
4
|
+
attr_accessor :access_token, :connection_options, :default_media_type, :user_agent, :signing_secret
|
5
|
+
|
6
|
+
attr_writer :api_endpoint
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def keys
|
10
|
+
@keys ||= [
|
11
|
+
:access_token,
|
12
|
+
:signing_secret,
|
13
|
+
:api_endpoint,
|
14
|
+
:connection_options,
|
15
|
+
:default_media_type,
|
16
|
+
:user_agent
|
17
|
+
]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def configure
|
22
|
+
yield self
|
23
|
+
end
|
24
|
+
|
25
|
+
def reset!
|
26
|
+
SageoneSdk::Configurable.keys.each do |key|
|
27
|
+
instance_variable_set(:"@#{key}", SageoneSdk::Default.options[key])
|
28
|
+
end
|
29
|
+
self
|
30
|
+
end
|
31
|
+
alias :setup :reset!
|
32
|
+
|
33
|
+
def api_endpoint
|
34
|
+
File.join(@api_endpoint, "")
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def options
|
40
|
+
Hash[SageoneSdk::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'sageone_sdk/version'
|
2
|
+
|
3
|
+
module SageoneSdk
|
4
|
+
# Default
|
5
|
+
module Default
|
6
|
+
ACCESS_TOKEN = "default_access_token"
|
7
|
+
SIGNING_SECRET = "default_signing_secret"
|
8
|
+
API_ENDPOINT = "https://api.sageone.com".freeze
|
9
|
+
USER_AGENT = "sageone_sdk Ruby Gem #{SageoneSdk::VERSION}".freeze
|
10
|
+
MEDIA_TYPE = "application/json"
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def options
|
14
|
+
Hash[SageoneSdk::Configurable.keys.map{|key| [key, send(key)]}]
|
15
|
+
end
|
16
|
+
|
17
|
+
def access_token
|
18
|
+
ENV["SAGE_ONE_ACCESS_TOKEN"] || ACCESS_TOKEN
|
19
|
+
end
|
20
|
+
|
21
|
+
def signing_secret
|
22
|
+
ENV["SAGE_ONE_SIGNING_SECRET"] || SIGNING_SECRET
|
23
|
+
end
|
24
|
+
|
25
|
+
def api_endpoint
|
26
|
+
ENV["SAGE_ONE_API_ENDPOINT"] || API_ENDPOINT
|
27
|
+
end
|
28
|
+
|
29
|
+
def default_media_type
|
30
|
+
ENV["SAGE_ONE_DEFAULT_MEDIA_TYPE"] || MEDIA_TYPE
|
31
|
+
end
|
32
|
+
|
33
|
+
def user_agent
|
34
|
+
ENV["SAGE_ONE_USER_AGENT"] || USER_AGENT
|
35
|
+
end
|
36
|
+
|
37
|
+
def connection_options
|
38
|
+
{
|
39
|
+
:headers => {
|
40
|
+
:accept => default_media_type,
|
41
|
+
:user_agent => user_agent
|
42
|
+
}
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'sageone_sdk/signature'
|
2
|
+
require 'sageone_sdk/sdata_error_response'
|
3
|
+
require 'sageone_sdk/sdata_response'
|
4
|
+
require "json"
|
5
|
+
require "hashie/mash"
|
6
|
+
|
7
|
+
module SageoneSdk
|
8
|
+
module Middleware
|
9
|
+
# Sdata parser
|
10
|
+
class SDataParser < Faraday::Middleware
|
11
|
+
def call(environment)
|
12
|
+
@app.call(environment).on_complete do |env|
|
13
|
+
element = ::JSON.parse(env[:body])
|
14
|
+
|
15
|
+
if element.respond_to?(:each_pair)
|
16
|
+
response_body = Hashie::Mash.new(element)
|
17
|
+
if env.success?
|
18
|
+
env[:body] = SageoneSdk::SDataResponse.new(response_body)
|
19
|
+
else
|
20
|
+
env[:body] = SageoneSdk::SDataErrorResponse.new(response_body)
|
21
|
+
end
|
22
|
+
else
|
23
|
+
env[:body] = element.map { |x| Hashie::Mash.new(x) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'sageone_sdk/signature'
|
2
|
+
require "active_support/core_ext"
|
3
|
+
|
4
|
+
module SageoneSdk
|
5
|
+
module Middleware
|
6
|
+
# Signature
|
7
|
+
class Signature < Faraday::Middleware
|
8
|
+
def initialize(app, access_token, signing_secret)
|
9
|
+
super(app)
|
10
|
+
|
11
|
+
@access_token = access_token
|
12
|
+
@signing_secret = signing_secret
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
nonce = SageoneSdk::Signature.generate_nonce
|
17
|
+
signature = SageoneSdk::Signature.new(env.method, env.url, env.body, nonce, @signing_secret, @access_token)
|
18
|
+
|
19
|
+
env[:request_headers]['X-Nonce'] = nonce
|
20
|
+
env[:request_headers]['X-Signature'] = signature.to_s
|
21
|
+
|
22
|
+
@app.call(env)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module SageoneSdk
|
2
|
+
# SData error response
|
3
|
+
class SDataErrorResponse
|
4
|
+
attr_reader :data
|
5
|
+
|
6
|
+
def initialize(data = {})
|
7
|
+
@data = data
|
8
|
+
end
|
9
|
+
|
10
|
+
def diagnoses
|
11
|
+
@data["$diagnoses"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def full_messages
|
15
|
+
diagnoses.map do |x|
|
16
|
+
"#{x["$source"].humanize}: #{x["$message"]}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def error?
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
def respond_to_missing?(method, include_private = false)
|
25
|
+
resources.respond_to?(method, include_private)
|
26
|
+
end
|
27
|
+
|
28
|
+
def method_missing(method, *args, &block)
|
29
|
+
if diagnoses.respond_to?(method)
|
30
|
+
diagnoses.send(method, *args)
|
31
|
+
else
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module SageoneSdk
|
2
|
+
# SData response
|
3
|
+
class SDataResponse
|
4
|
+
attr_reader :data
|
5
|
+
|
6
|
+
def initialize(data = {})
|
7
|
+
@data = data
|
8
|
+
end
|
9
|
+
|
10
|
+
def total_results
|
11
|
+
@data["$totalResults"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def start_index
|
15
|
+
@data["startIndex"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def items_per_page
|
19
|
+
@data["$itemsPerPage"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def resources
|
23
|
+
@data["$resources"]
|
24
|
+
end
|
25
|
+
|
26
|
+
def error?
|
27
|
+
false
|
28
|
+
end
|
29
|
+
|
30
|
+
def find_by(conditions)
|
31
|
+
resources.detect do |resource|
|
32
|
+
@skip = false
|
33
|
+
conditions.each do |field, value|
|
34
|
+
unless resource.public_send(field) == value
|
35
|
+
@skip = true
|
36
|
+
break
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
!@skip
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def respond_to_missing?(method, include_private = false)
|
45
|
+
resources.respond_to?(method, include_private) || data.respond_to?(method, include_private)
|
46
|
+
end
|
47
|
+
|
48
|
+
def method_missing(method, *args, &block)
|
49
|
+
if resources.respond_to?(method)
|
50
|
+
resources.send(method, *args)
|
51
|
+
elsif data.respond_to?(method)
|
52
|
+
data.send(method, *args)
|
53
|
+
else
|
54
|
+
super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|