sageone_sdk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +15 -0
  5. data/Fudgefile +27 -0
  6. data/Gemfile +12 -0
  7. data/Guardfile +33 -0
  8. data/LICENSE +22 -0
  9. data/README.md +57 -0
  10. data/Rakefile +10 -0
  11. data/fudge_settings.yml +5 -0
  12. data/lib/sageone_sdk.rb +16 -0
  13. data/lib/sageone_sdk/authentication.rb +8 -0
  14. data/lib/sageone_sdk/client.rb +117 -0
  15. data/lib/sageone_sdk/client/account_types.rb +19 -0
  16. data/lib/sageone_sdk/client/bank_accounts.rb +18 -0
  17. data/lib/sageone_sdk/client/chart_of_accounts.rb +21 -0
  18. data/lib/sageone_sdk/client/contact_types.rb +20 -0
  19. data/lib/sageone_sdk/client/contacts.rb +82 -0
  20. data/lib/sageone_sdk/client/countries.rb +18 -0
  21. data/lib/sageone_sdk/client/expenditures.rb +26 -0
  22. data/lib/sageone_sdk/client/expense_methods.rb +19 -0
  23. data/lib/sageone_sdk/client/expense_types.rb +19 -0
  24. data/lib/sageone_sdk/client/financial_settings.rb +23 -0
  25. data/lib/sageone_sdk/client/income_methods.rb +19 -0
  26. data/lib/sageone_sdk/client/income_types.rb +19 -0
  27. data/lib/sageone_sdk/client/incomes.rb +51 -0
  28. data/lib/sageone_sdk/client/journals.rb +27 -0
  29. data/lib/sageone_sdk/client/ledger_accounts.rb +52 -0
  30. data/lib/sageone_sdk/client/payment_statuses.rb +18 -0
  31. data/lib/sageone_sdk/client/period_types.rb +19 -0
  32. data/lib/sageone_sdk/client/products.rb +50 -0
  33. data/lib/sageone_sdk/client/purchase_invoices.rb +61 -0
  34. data/lib/sageone_sdk/client/sales_invoices.rb +65 -0
  35. data/lib/sageone_sdk/client/services.rb +48 -0
  36. data/lib/sageone_sdk/client/tax_rates.rb +18 -0
  37. data/lib/sageone_sdk/client/transactions.rb +13 -0
  38. data/lib/sageone_sdk/configurable.rb +43 -0
  39. data/lib/sageone_sdk/default.rb +47 -0
  40. data/lib/sageone_sdk/middleware.rb +6 -0
  41. data/lib/sageone_sdk/middleware/sdata_parser.rb +29 -0
  42. data/lib/sageone_sdk/middleware/signature.rb +26 -0
  43. data/lib/sageone_sdk/sdata_error_response.rb +36 -0
  44. data/lib/sageone_sdk/sdata_response.rb +58 -0
  45. data/lib/sageone_sdk/signature.rb +115 -0
  46. data/lib/sageone_sdk/version.rb +3 -0
  47. data/sageone_sdk.gemspec +37 -0
  48. data/spec/cassettes/SageoneSdk_Client_AccountTypes/account_types/_id/returns_a_specific_account_type.json +1 -0
  49. data/spec/cassettes/SageoneSdk_Client_AccountTypes/account_types/allows_pagination.json +1 -0
  50. data/spec/cassettes/SageoneSdk_Client_AccountTypes/account_types/returns_all_account_types.json +1 -0
  51. data/spec/cassettes/SageoneSdk_Client_BankAccounts/bank_accounts/_id/returns_a_specific_bank_account.json +1 -0
  52. data/spec/cassettes/SageoneSdk_Client_BankAccounts/bank_accounts/allows_pagination.json +1 -0
  53. data/spec/cassettes/SageoneSdk_Client_BankAccounts/bank_accounts/returns_all_bank_accounts.json +1 -0
  54. data/spec/cassettes/SageoneSdk_Client_ChartOfAccounts/chart_of_accounts_structure/returns_the_chart_of_accounts_structure.json +1 -0
  55. data/spec/cassettes/SageoneSdk_Client_ChartOfAccounts/chart_of_accounts_templates/returns_the_chart_of_accounts_templates.json +1 -0
  56. data/spec/cassettes/SageoneSdk_Client_ContactTypes/contact_types/_id/returns_a_specific_contact_type.json +1 -0
  57. data/spec/cassettes/SageoneSdk_Client_ContactTypes/contact_types/allows_pagination.json +1 -0
  58. data/spec/cassettes/SageoneSdk_Client_ContactTypes/contact_types/returns_all_contact_types.json +1 -0
  59. data/spec/cassettes/SageoneSdk_Client_Contacts/contacts/_id/returns_a_specific_contact.json +1 -0
  60. data/spec/cassettes/SageoneSdk_Client_Contacts/contacts/allows_pagination.json +1 -0
  61. data/spec/cassettes/SageoneSdk_Client_Contacts/contacts/returns_all_contacts.json +1 -0
  62. data/spec/cassettes/SageoneSdk_Client_Contacts/create_contacts/creates_a_new_contact.json +1 -0
  63. data/spec/cassettes/SageoneSdk_Client_Contacts/create_contacts/on_error/responds_with_an_appropriate_error_message.json +1 -0
  64. data/spec/cassettes/SageoneSdk_Client_Contacts/delete_a_contact/deletes_the_contact.json +1 -0
  65. data/spec/cassettes/SageoneSdk_Client_Contacts/update_a_contact/updates_the_given_contact.json +1 -0
  66. data/spec/cassettes/SageoneSdk_Client_Countries/countries/_id/returns_a_specific_account_type.json +1 -0
  67. data/spec/cassettes/SageoneSdk_Client_Countries/countries/allows_pagination.json +1 -0
  68. data/spec/cassettes/SageoneSdk_Client_Countries/countries/returns_all_countries.json +1 -0
  69. data/spec/cassettes/SageoneSdk_Client_Expenditures/create_expenditures/creates_a_new_expenditure.json +1 -0
  70. data/spec/cassettes/SageoneSdk_Client_Expenditures/create_expenditures/on_error/responds_with_an_appropriate_error_message.json +1 -0
  71. data/spec/cassettes/SageoneSdk_Client_Expenditures/delete_an_expenditure/deletes_the_expenditure.json +1 -0
  72. data/spec/cassettes/SageoneSdk_Client_Expenditures/expenditures/_id/returns_a_specific_expenditure.json +1 -0
  73. data/spec/cassettes/SageoneSdk_Client_Expenditures/expenditures/allows_pagination.json +1 -0
  74. data/spec/cassettes/SageoneSdk_Client_Expenditures/expenditures/returns_all_expenditures.json +1 -0
  75. data/spec/cassettes/SageoneSdk_Client_Expenditures/update_an_expenditure/updates_the_given_expenditure.json +1 -0
  76. data/spec/cassettes/SageoneSdk_Client_ExpenseMethods/expense_methods/_id/returns_a_specific_contact_type.json +1 -0
  77. data/spec/cassettes/SageoneSdk_Client_ExpenseMethods/expense_methods/returns_all_expense_methods.json +1 -0
  78. data/spec/cassettes/SageoneSdk_Client_ExpenseMethods/income_methods/_id/returns_a_specific_contact_type.json +1 -0
  79. data/spec/cassettes/SageoneSdk_Client_ExpenseMethods/income_methods/allows_pagination.json +1 -0
  80. data/spec/cassettes/SageoneSdk_Client_ExpenseMethods/income_methods/returns_all_income_methods.json +1 -0
  81. data/spec/cassettes/SageoneSdk_Client_ExpenseTypes/expense_types/_id/returns_a_specific_contact_type.json +1 -0
  82. data/spec/cassettes/SageoneSdk_Client_ExpenseTypes/expense_types/allows_pagination.json +1 -0
  83. data/spec/cassettes/SageoneSdk_Client_ExpenseTypes/expense_types/returns_all_expense_types.json +1 -0
  84. data/spec/cassettes/SageoneSdk_Client_FinancialSettings/financial_settings/returns_the_financial_settings.json +1 -0
  85. data/spec/cassettes/SageoneSdk_Client_FinancialSettings/update_financial_settings/updates_the_financial_settings.json +1 -0
  86. data/spec/cassettes/SageoneSdk_Client_IncomeMethods/income_methods/_id/returns_a_specific_contact_type.json +1 -0
  87. data/spec/cassettes/SageoneSdk_Client_IncomeMethods/income_methods/returns_all_income_methods.json +1 -0
  88. data/spec/cassettes/SageoneSdk_Client_IncomeTypes/income_types/_id/returns_a_specific_contact_type.json +1 -0
  89. data/spec/cassettes/SageoneSdk_Client_IncomeTypes/income_types/allows_pagination.json +1 -0
  90. data/spec/cassettes/SageoneSdk_Client_IncomeTypes/income_types/returns_all_income_types.json +1 -0
  91. data/spec/cassettes/SageoneSdk_Client_Incomes/create_incomes/creates_a_new_income.json +1 -0
  92. data/spec/cassettes/SageoneSdk_Client_Incomes/create_incomes/on_error/responds_with_an_appropriate_error_message.json +1 -0
  93. data/spec/cassettes/SageoneSdk_Client_Incomes/delete_an_income/deletes_the_income.json +1 -0
  94. data/spec/cassettes/SageoneSdk_Client_Incomes/incomes/_id/returns_a_specific_income.json +1 -0
  95. data/spec/cassettes/SageoneSdk_Client_Incomes/incomes/allows_pagination.json +1 -0
  96. data/spec/cassettes/SageoneSdk_Client_Incomes/incomes/returns_all_incomes.json +1 -0
  97. data/spec/cassettes/SageoneSdk_Client_Incomes/update_an_income/updates_the_given_income.json +1 -0
  98. data/spec/cassettes/SageoneSdk_Client_Journals/journals/creates_a_journal.json +1 -0
  99. data/spec/cassettes/SageoneSdk_Client_Journals/journals/on_error/responds_with_an_appropriate_error_message.json +1 -0
  100. data/spec/cassettes/SageoneSdk_Client_LedgerAccounts/create_a_ledger_account/creates_a_new_ledger_account.json +1 -0
  101. data/spec/cassettes/SageoneSdk_Client_LedgerAccounts/create_a_ledger_account/on_error/responds_with_an_appropriate_error_message.json +1 -0
  102. data/spec/cassettes/SageoneSdk_Client_LedgerAccounts/ledger_account_balances/does_not_return_ledger_accounts_with_a_zero_balance.json +1 -0
  103. data/spec/cassettes/SageoneSdk_Client_LedgerAccounts/ledger_account_balances/returns_ledger_accounts_with_a_balance.json +1 -0
  104. data/spec/cassettes/SageoneSdk_Client_LedgerAccounts/ledger_accounts/_id/returns_a_specific_ledger_account.json +1 -0
  105. data/spec/cassettes/SageoneSdk_Client_LedgerAccounts/ledger_accounts/allows_pagination.json +1 -0
  106. data/spec/cassettes/SageoneSdk_Client_LedgerAccounts/ledger_accounts/returns_all_ledger_accounts.json +1 -0
  107. data/spec/cassettes/SageoneSdk_Client_PaymentStatuses/payment_statuses/_id/returns_a_specific_contact_type.json +1 -0
  108. data/spec/cassettes/SageoneSdk_Client_PaymentStatuses/payment_statuses/allows_pagination.json +1 -0
  109. data/spec/cassettes/SageoneSdk_Client_PaymentStatuses/payment_statuses/returns_all_payment_statuses.json +1 -0
  110. data/spec/cassettes/SageoneSdk_Client_PeriodTypes/period_types/_id/returns_a_specific_contact_type.json +1 -0
  111. data/spec/cassettes/SageoneSdk_Client_PeriodTypes/period_types/allows_pagination.json +1 -0
  112. data/spec/cassettes/SageoneSdk_Client_PeriodTypes/period_types/returns_all_period_types.json +1 -0
  113. data/spec/cassettes/SageoneSdk_Client_Products/create_products/creates_a_new_product.json +1 -0
  114. data/spec/cassettes/SageoneSdk_Client_Products/create_products/on_error/responds_with_an_appropriate_error_message.json +1 -0
  115. data/spec/cassettes/SageoneSdk_Client_Products/delete_a_product/deletes_the_product.json +1 -0
  116. data/spec/cassettes/SageoneSdk_Client_Products/products/_id/returns_a_specific_product.json +1 -0
  117. data/spec/cassettes/SageoneSdk_Client_Products/products/allows_pagination.json +1 -0
  118. data/spec/cassettes/SageoneSdk_Client_Products/products/returns_all_products.json +1 -0
  119. data/spec/cassettes/SageoneSdk_Client_Products/update_a_product/updates_the_given_product.json +1 -0
  120. data/spec/cassettes/SageoneSdk_Client_PurchaseInvoices/create_purchase_invoices/creates_a_new_purchase_invoice.json +1 -0
  121. data/spec/cassettes/SageoneSdk_Client_PurchaseInvoices/create_purchase_invoices/on_error/responds_with_an_appropriate_error_message.json +1 -0
  122. data/spec/cassettes/SageoneSdk_Client_PurchaseInvoices/delete_a_purchase_invoice/deletes_the_purchase_invoice.json +1 -0
  123. data/spec/cassettes/SageoneSdk_Client_PurchaseInvoices/purchase_invoices/_id/returns_a_specific_purchase_invoice.json +1 -0
  124. data/spec/cassettes/SageoneSdk_Client_PurchaseInvoices/purchase_invoices/allows_pagination.json +1 -0
  125. data/spec/cassettes/SageoneSdk_Client_PurchaseInvoices/purchase_invoices/returns_all_purchase_invoices.json +1 -0
  126. data/spec/cassettes/SageoneSdk_Client_PurchaseInvoices/update_a_purchase_invoice/updates_the_given_purchase_invoice.json +1 -0
  127. data/spec/cassettes/SageoneSdk_Client_SalesInvoices/create_sales_invoices/creates_a_new_sales_invoice.json +1 -0
  128. data/spec/cassettes/SageoneSdk_Client_SalesInvoices/create_sales_invoices/on_error/responds_with_an_appropriate_error_message.json +1 -0
  129. data/spec/cassettes/SageoneSdk_Client_SalesInvoices/delete_a_sales_invoice/deletes_the_sales_invoice.json +1 -0
  130. data/spec/cassettes/SageoneSdk_Client_SalesInvoices/sales_invoices/_id/returns_a_specific_sales_invoice.json +1 -0
  131. data/spec/cassettes/SageoneSdk_Client_SalesInvoices/sales_invoices/allows_pagination.json +1 -0
  132. data/spec/cassettes/SageoneSdk_Client_SalesInvoices/sales_invoices/returns_all_sales_invoices.json +1 -0
  133. data/spec/cassettes/SageoneSdk_Client_SalesInvoices/update_a_sales_invoice/updates_the_given_sales_invoice.json +1 -0
  134. data/spec/cassettes/SageoneSdk_Client_Services/create_services/creates_a_new_service.json +1 -0
  135. data/spec/cassettes/SageoneSdk_Client_Services/create_services/on_error/responds_with_an_appropriate_error_message.json +1 -0
  136. data/spec/cassettes/SageoneSdk_Client_Services/delete_a_service/deletes_the_service.json +1 -0
  137. data/spec/cassettes/SageoneSdk_Client_Services/services/_id/returns_a_specific_service.json +1 -0
  138. data/spec/cassettes/SageoneSdk_Client_Services/services/allows_pagination.json +1 -0
  139. data/spec/cassettes/SageoneSdk_Client_Services/services/returns_all_services.json +1 -0
  140. data/spec/cassettes/SageoneSdk_Client_Services/update_a_service/updates_the_given_service.json +1 -0
  141. data/spec/cassettes/SageoneSdk_Client_TaxRates/tax_rates/_id/returns_a_specific_contact_type.json +1 -0
  142. data/spec/cassettes/SageoneSdk_Client_TaxRates/tax_rates/allows_pagination.json +1 -0
  143. data/spec/cassettes/SageoneSdk_Client_TaxRates/tax_rates/returns_all_tax_rates.json +1 -0
  144. data/spec/cassettes/SageoneSdk_Client_Transactions/transactions/returns_all_transactions.json +1 -0
  145. data/spec/cassettes/account_types_index.json +1 -0
  146. data/spec/cassettes/bank_accounts_index.json +1 -0
  147. data/spec/cassettes/contact_types_index.json +1 -0
  148. data/spec/cassettes/contacts_index.json +1 -0
  149. data/spec/cassettes/countries_index.json +1 -0
  150. data/spec/cassettes/customer_create.json +1 -0
  151. data/spec/cassettes/customers_index.json +1 -0
  152. data/spec/cassettes/expenditure_create.json +1 -0
  153. data/spec/cassettes/expenditures_index.json +1 -0
  154. data/spec/cassettes/expense_methods_index.json +1 -0
  155. data/spec/cassettes/expense_types_index.json +1 -0
  156. data/spec/cassettes/income_create.json +1 -0
  157. data/spec/cassettes/income_methods_index.json +1 -0
  158. data/spec/cassettes/income_types_index.json +1 -0
  159. data/spec/cassettes/incomes_index.json +1 -0
  160. data/spec/cassettes/ledger_accounts_index.json +1 -0
  161. data/spec/cassettes/payment_statuses_index.json +1 -0
  162. data/spec/cassettes/period_types_index.json +1 -0
  163. data/spec/cassettes/product_create.json +1 -0
  164. data/spec/cassettes/products_index.json +1 -0
  165. data/spec/cassettes/purchase_invoice_create.json +1 -0
  166. data/spec/cassettes/purchase_invoices_index.json +1 -0
  167. data/spec/cassettes/sales_invoice_create.json +1 -0
  168. data/spec/cassettes/sales_invoices_index.json +1 -0
  169. data/spec/cassettes/service_create.json +1 -0
  170. data/spec/cassettes/services_index.json +1 -0
  171. data/spec/cassettes/suppliers_index.json +1 -0
  172. data/spec/cassettes/tax_rates_index.json +1 -0
  173. data/spec/sageone_sdk/client/account_types_spec.rb +29 -0
  174. data/spec/sageone_sdk/client/bank_accounts_spec.rb +34 -0
  175. data/spec/sageone_sdk/client/chart_of_accounts_spec.rb +23 -0
  176. data/spec/sageone_sdk/client/contact_types_spec.rb +29 -0
  177. data/spec/sageone_sdk/client/contacts_spec.rb +75 -0
  178. data/spec/sageone_sdk/client/countries_spec.rb +29 -0
  179. data/spec/sageone_sdk/client/expenditures_spec.rb +113 -0
  180. data/spec/sageone_sdk/client/expense_methods_spec.rb +29 -0
  181. data/spec/sageone_sdk/client/expense_types_spec.rb +29 -0
  182. data/spec/sageone_sdk/client/financial_settings_spec.rb +23 -0
  183. data/spec/sageone_sdk/client/income_methods_spec.rb +29 -0
  184. data/spec/sageone_sdk/client/income_types_spec.rb +29 -0
  185. data/spec/sageone_sdk/client/incomes_spec.rb +114 -0
  186. data/spec/sageone_sdk/client/journals_spec.rb +39 -0
  187. data/spec/sageone_sdk/client/ledger_accounts_spec.rb +65 -0
  188. data/spec/sageone_sdk/client/payment_statuses_spec.rb +29 -0
  189. data/spec/sageone_sdk/client/period_types_spec.rb +29 -0
  190. data/spec/sageone_sdk/client/products_spec.rb +75 -0
  191. data/spec/sageone_sdk/client/purchase_invoices_spec.rb +124 -0
  192. data/spec/sageone_sdk/client/sales_invoices_spec.rb +126 -0
  193. data/spec/sageone_sdk/client/services_spec.rb +75 -0
  194. data/spec/sageone_sdk/client/tax_rates_spec.rb +29 -0
  195. data/spec/sageone_sdk/client/transactions_spec.rb +16 -0
  196. data/spec/sageone_sdk_spec.rb +19 -0
  197. data/spec/spec_helper.rb +40 -0
  198. 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,6 @@
1
+ module SageoneSdk
2
+ module Middleware
3
+ autoload :Signature, "sageone_sdk/middleware/signature"
4
+ autoload :SDataParser, "sageone_sdk/middleware/sdata_parser"
5
+ end
6
+ 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