sagekit 0.1.0

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.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/CHANGELOG.md +3 -0
  4. data/CODE_OF_CONDUCT.md +84 -0
  5. data/Gemfile +10 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.org +346 -0
  8. data/Rakefile +8 -0
  9. data/bin/console +18 -0
  10. data/bin/setup +8 -0
  11. data/docs/index.html +940 -0
  12. data/docs/style.css +82 -0
  13. data/lib/sagekit/client.rb +97 -0
  14. data/lib/sagekit/error.rb +3 -0
  15. data/lib/sagekit/object.rb +18 -0
  16. data/lib/sagekit/objects/account_set.rb +4 -0
  17. data/lib/sagekit/objects/category.rb +4 -0
  18. data/lib/sagekit/objects/credit_note.rb +4 -0
  19. data/lib/sagekit/objects/customer.rb +4 -0
  20. data/lib/sagekit/objects/invoice.rb +4 -0
  21. data/lib/sagekit/objects/item.rb +4 -0
  22. data/lib/sagekit/objects/location.rb +4 -0
  23. data/lib/sagekit/objects/purchase_order.rb +4 -0
  24. data/lib/sagekit/objects/receipt.rb +4 -0
  25. data/lib/sagekit/objects/sales_history.rb +4 -0
  26. data/lib/sagekit/objects/sales_order.rb +4 -0
  27. data/lib/sagekit/objects/sales_person.rb +4 -0
  28. data/lib/sagekit/objects/vendor.rb +4 -0
  29. data/lib/sagekit/objects/vendor_contract_cost.rb +4 -0
  30. data/lib/sagekit/resource.rb +55 -0
  31. data/lib/sagekit/resources/account_sets.rb +27 -0
  32. data/lib/sagekit/resources/categories.rb +26 -0
  33. data/lib/sagekit/resources/credit_notes.rb +17 -0
  34. data/lib/sagekit/resources/customer_groups.rb +26 -0
  35. data/lib/sagekit/resources/customer_terms.rb +26 -0
  36. data/lib/sagekit/resources/customers.rb +26 -0
  37. data/lib/sagekit/resources/invoices.rb +12 -0
  38. data/lib/sagekit/resources/items.rb +27 -0
  39. data/lib/sagekit/resources/locations.rb +26 -0
  40. data/lib/sagekit/resources/purchase_orders.rb +16 -0
  41. data/lib/sagekit/resources/receipts.rb +16 -0
  42. data/lib/sagekit/resources/sales_history.rb +16 -0
  43. data/lib/sagekit/resources/sales_orders.rb +40 -0
  44. data/lib/sagekit/resources/sales_persons.rb +34 -0
  45. data/lib/sagekit/resources/vendor_contract_costs.rb +27 -0
  46. data/lib/sagekit/resources/vendor_groups.rb +26 -0
  47. data/lib/sagekit/resources/vendor_terms.rb +26 -0
  48. data/lib/sagekit/resources/vendors.rb +30 -0
  49. data/lib/sagekit/version.rb +5 -0
  50. data/lib/sagekit.rb +56 -0
  51. metadata +120 -0
data/docs/style.css ADDED
@@ -0,0 +1,82 @@
1
+ /* Read the Org custom CSS */
2
+
3
+ /* Body andHeaders */
4
+ h4,h5,h6 {
5
+ color:#6272a4;
6
+ font-weight:300;
7
+ }
8
+
9
+ body{
10
+ background:#282A36;
11
+ color:#404040;
12
+ font-family:"Lato","proxima-nova","Helvetica Neue",Arial,sans-serif;
13
+ font-weight:normal;
14
+ margin:0;
15
+ min-height:100%;
16
+ overflow-x:hidden;
17
+ }
18
+
19
+ /* Code block */
20
+ .codeblock,pre.src,#content .literal-block{
21
+ border:1px solid #e1e4e5;
22
+ padding:12px;
23
+ overflow-x:auto;
24
+ background:#282A36;
25
+ margin:1px 0 24px 0;
26
+ color: #F8F8F2;
27
+ }
28
+
29
+ /* Links */
30
+ a{
31
+ color:#6272a4;
32
+ text-decoration:none;
33
+ cursor:pointer}
34
+
35
+ a:hover,a:active{
36
+ outline:0;
37
+ }
38
+
39
+ a:hover{
40
+ color:#bd93f9}
41
+
42
+ a:visited{
43
+ color:#9B59B6}
44
+
45
+ /* Table of Content */
46
+ #table-of-contents{
47
+ position:fixed;
48
+ top:0;
49
+ left:0;
50
+ width:300px;
51
+ overflow-x:hidden;
52
+ overflow-y:scroll;
53
+ height:100%;
54
+ background:#44475A;
55
+ z-index:200;
56
+ scrollbar-base-color: #1F1D1D;
57
+ scrollbar-arrow-color: #b3b3b3;
58
+ scrollbar-shadow-color: #1F1D1D;
59
+ scrollbar-track-color : #343131;
60
+ }
61
+
62
+ #table-of-contents h2{
63
+ z-index:200;
64
+ background-color:#282A36;
65
+ text-align:center;
66
+ padding:0.809em;
67
+ display:block;
68
+ color:#fcfcfc;
69
+ font-size: 100%;
70
+ margin-bottom:0.809em}
71
+
72
+ /* Footer */
73
+ #postamble .author {
74
+ font-size: 100%;
75
+ margin-bottom: 0px;
76
+ }
77
+
78
+ #postamble .date {
79
+ font-size: 90%;
80
+ margin-bottom: 0px;
81
+ color: #00f769;
82
+ }
@@ -0,0 +1,97 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+
4
+ module Sagekit
5
+ class Client
6
+ DEFAULT_TIMEOUT = 120
7
+
8
+ attr_reader :auth, :base_url, :adapter
9
+
10
+ def initialize(auth:, base_url:, adapter: Faraday.default_adapter)
11
+ @auth = auth
12
+ @base_url = base_url
13
+ @adapter = adapter
14
+ end
15
+
16
+ def sales_orders
17
+ SalesOrdersResource.new(self)
18
+ end
19
+
20
+ def invoices
21
+ InvoicesResource.new(self)
22
+ end
23
+
24
+ def sales_history
25
+ SalesHistoryResource.new(self)
26
+ end
27
+
28
+ def purchase_orders
29
+ PurchaseOrdersResource.new(self)
30
+ end
31
+
32
+ def receipts
33
+ ReceiptsResource.new(self)
34
+ end
35
+
36
+ def vendor_contract_cost
37
+ VendorContractCostsResource.new(self)
38
+ end
39
+
40
+ def customers
41
+ CustomersResource.new(self)
42
+ end
43
+
44
+ def customer_groups
45
+ CustomerGroupsResource.new(self)
46
+ end
47
+
48
+ def customer_terms
49
+ CustomerTermsResource.new(self)
50
+ end
51
+
52
+ def account_sets
53
+ AccountSetsResource.new(self)
54
+ end
55
+
56
+ def credit_notes
57
+ CreditNotesResource.new(self)
58
+ end
59
+
60
+ def sales_persons
61
+ SalesPersonsResource.new(self)
62
+ end
63
+
64
+ def vendors
65
+ VendorsResource.new(self)
66
+ end
67
+
68
+ def vendor_groups
69
+ VendorGroupsResource.new(self)
70
+ end
71
+
72
+ def vendor_terms
73
+ VendorTermsResource.new(self)
74
+ end
75
+
76
+ def items
77
+ ItemsResource.new(self)
78
+ end
79
+
80
+ def categories
81
+ CategoriesResource.new(self)
82
+ end
83
+
84
+ def locations
85
+ LocationsResource.new(self)
86
+ end
87
+
88
+ def connection
89
+ @connection ||= Faraday.new do |con|
90
+ con.url_prefix = base_url
91
+ con.request :json
92
+ con.response :json, content_type: "application/json"
93
+ con.adapter adapter
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,3 @@
1
+ module Sagekit
2
+ class Error < StandardError; end
3
+ end
@@ -0,0 +1,18 @@
1
+ require "ostruct"
2
+
3
+ module Sagekit
4
+ class Object
5
+ def initialize(attributes)
6
+ @attributes = OpenStruct.new(attributes)
7
+ end
8
+
9
+ def method_missing(method, *args, &block)
10
+ attribute = @attributes.send(method, *args, &block)
11
+ attribute.is_a?(Hash) ? Object.new(attribute) : attribute
12
+ end
13
+
14
+ def respond_to_missing?(method, inlcude_private = false)
15
+ true
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ module Sagekit
2
+ class AccountSet < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Sagekit
2
+ class Category < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Sagekit
2
+ class CreditNote < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Sagekit
2
+ class Customer < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Sagekit
2
+ class Invoice < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Sagekit
2
+ class Item < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Sagekit
2
+ class Location < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Sagekit
2
+ class PurchaseOrder < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Sagekit
2
+ class Receipt < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Sagekit
2
+ class SalesHistory < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Sagekit
2
+ class SalesOrder < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Sagekit
2
+ class SalesPerson < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Sagekit
2
+ class Vendor < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Sagekit
2
+ class VendorContractCost < Object
3
+ end
4
+ end
@@ -0,0 +1,55 @@
1
+ module Sagekit
2
+ class Resource
3
+ attr_reader :client
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ def get_request(url, params: {}, headers: {})
10
+ handle_response client.connection.get(url, params, default_headers.merge(headers))
11
+ end
12
+
13
+ def post_request(url, body:, headers: {})
14
+ handle_response client.connection.post(url, body, default_headers.merge(headers))
15
+ end
16
+
17
+ def patch_request(url, body:, headers: {})
18
+ handle_response client.connection.patch(url, body, default_headers.merge(headers))
19
+ end
20
+
21
+ def put_request(url, body:, headers: {})
22
+ handle_response client.connection.put(url, body, default_headers.merge(headers))
23
+ end
24
+
25
+ def delete_request(url, params: {}, headers: {})
26
+ handle_response client.connection.delete(url, params, default_headers.merge(headers))
27
+ end
28
+
29
+ def default_headers
30
+ { Authorization: client.auth }
31
+ end
32
+
33
+ def handle_response(response)
34
+ case response.status
35
+ when 400
36
+ raise Error, "#{response.body}"
37
+ when 401
38
+ raise Error, "#{response.body}"
39
+ when 403
40
+ raise Error, "#{response.body}"
41
+ when 404
42
+ raise Error, "#{response.body}"
43
+ when 429
44
+ raise Error, "#{response.body}"
45
+ when 500
46
+ raise Error, "#{response.body}"
47
+ when 503
48
+ raise Error, "#{response.body}"
49
+ end
50
+
51
+ response
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,27 @@
1
+ module Sagekit
2
+ class AccountSetsResource < Resource
3
+
4
+ def list(company, **params)
5
+ AccountSet.new get_request("#{company}/AR/ARAccountSets", params: params).body
6
+ end
7
+
8
+ def retreive(company, id, **params)
9
+ AccountSet.new get_request("#{company}/AR/ARAccountSets('#{id}')", params: params).body
10
+ end
11
+
12
+ def create(company, **attributes)
13
+ AccountSet.new post_request("#{company}/AR/ARAccountSets", body: attributes).body
14
+ end
15
+
16
+ def update(company, id, **attributes)
17
+ patch_request("#{company}/AR/ARAccountSets('#{id}')", body: attributes)
18
+ true
19
+ end
20
+
21
+ def delete(company, id)
22
+ delete_request("#{company}/AR/ARAccountSets('#{id}')")
23
+ true
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ module Sagekit
2
+ class CategoriesResource < Resource
3
+
4
+ def list(company, **params)
5
+ Category.new get_request("#{company}/IC/ICCategories", params: params).body
6
+ end
7
+
8
+ def retreive(company, cat_id, **params)
9
+ Category.new get_request("#{company}/IC/ICCategories('#{cat_id}')", params: params).body
10
+ end
11
+
12
+ def create(company, **attributes)
13
+ Category.new post_request("#{company}/IC/ICCategories", body: attributes).body
14
+ end
15
+
16
+ def update(company, cat_id, **attributes)
17
+ patch_request("#{company}/IC/ICCategories('#{cat_id}')", body: attributes)
18
+ true
19
+ end
20
+
21
+ def delete(company, item_id)
22
+ delete_request("#{company}/IC/ICCategories('#{item_id}')")
23
+ true
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ module Sagekit
2
+ class CreditNotesResource < Resource
3
+
4
+ def list(company, **params)
5
+ CreditNote.new get_request("#{company}/OE/OECreditDebitNotes", params: params).body
6
+ end
7
+
8
+ def retreive(company, id, **params)
9
+ CreditNote.new get_request("#{company}/OE/OECreditDebitNotes('#{id}')", params: params).body
10
+ end
11
+
12
+ def create(company, **attributes)
13
+ CreditNote.new post_request("#{company}/OE/OECreditDebitNotes", body: attributes).body
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ module Sagekit
2
+ class CustomerGroupsResource < Resource
3
+
4
+ def list(company, **params)
5
+ Customer.new get_request("#{company}/AR/ARCustomerGroups", params: params).body
6
+ end
7
+
8
+ def retreive(company, id, **params)
9
+ Customer.new get_request("#{company}/AR/ARCustomerGroups('#{id}')", params: params).body
10
+ end
11
+
12
+ def create(company, **attributes)
13
+ Customer.new post_request("#{company}/AR/ARCustomerGroups", body: attributes).body
14
+ end
15
+
16
+ def update(company, id, **attributes)
17
+ patch_request("#{company}/AR/ARCustomerGroups('#{id}')", body: attributes)
18
+ true
19
+ end
20
+
21
+ def delete(company, id)
22
+ delete_request("#{company}/AR/ARCustomerGroups('#{id}')")
23
+ true
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module Sagekit
2
+ class CustomerTermsResource < Resource
3
+
4
+ def list(company, **params)
5
+ Customer.new get_request("#{company}/AR/ARTerms", params: params).body
6
+ end
7
+
8
+ def retreive(company, terms_code, **params)
9
+ Customer.new get_request("#{company}/AR/ARTerms('#{terms_code}')", params: params).body
10
+ end
11
+
12
+ def create(company, **attributes)
13
+ Customer.new post_request("#{company}/AR/ARTerms", body: attributes).body
14
+ end
15
+
16
+ def update(company, terms_code, **attributes)
17
+ patch_request("#{company}/AR/ARTerms('#{terms_code}')", body: attributes)
18
+ true
19
+ end
20
+
21
+ def delete(company, terms_code)
22
+ delete_request("#{company}/AR/ARTerms('#{terms_code}')")
23
+ true
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module Sagekit
2
+ class CustomersResource < Resource
3
+
4
+ def list(company, **params)
5
+ Customer.new get_request("#{company}/AR/ARCustomers", params: params).body
6
+ end
7
+
8
+ def retreive(company, customer_id, **params)
9
+ Customer.new get_request("#{company}/AR/ARCustomers('#{customer_id}')", params: params).body
10
+ end
11
+
12
+ def create(company, **attributes)
13
+ Customer.new post_request("#{company}/AR/ARCustomers", body: attributes).body
14
+ end
15
+
16
+ def update(company, customer_id, **attributes)
17
+ patch_request("#{company}/AR/ARCustomers('#{customer_id}')", body: attributes)
18
+ true
19
+ end
20
+
21
+ def delete(company, customer_id)
22
+ delete_request("#{company}/AR/ARCustomers('#{customer_id}')")
23
+ true
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ module Sagekit
2
+ class InvoicesResource < Resource
3
+
4
+ def list(company, **params)
5
+ Invoice.new get_request("#{company}/OE/OEOrders", params: params).body
6
+ end
7
+
8
+ def retreive(invoice_id, **params)
9
+ Invoice.new get_request("#{company}/OE/OEOrders(#{order_id})", params: params).body
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,27 @@
1
+ module Sagekit
2
+ class ItemsResource < Resource
3
+
4
+ def list(company, **params)
5
+ Item.new get_request("#{company}/IC/ICItems", params: params).body
6
+ end
7
+
8
+ def retreive(company, item_id, **params)
9
+ Item.new get_request("#{company}/IC/ICItems('#{item_id}')", params: params).body
10
+ end
11
+
12
+ def create(company, **attributes)
13
+ Item.new post_request("#{company}/IC/ICItems", body: attributes).body
14
+ end
15
+
16
+ def update(company, item_id, **attributes)
17
+ patch_request("#{company}/IC/ICItems('#{item_id}')", body: attributes)
18
+ true
19
+ end
20
+
21
+ # Delete record
22
+ def delete(company, item_id)
23
+ delete_request("#{company}/IC/ICItems('#{item_id}')")
24
+ true
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ module Sagekit
2
+ class LocationsResource < Resource
3
+
4
+ def list(company, **params)
5
+ Location.new get_request("#{company}/IC/ICLocations", params: params).body
6
+ end
7
+
8
+ def retreive(company, location_id, **params)
9
+ Location.new get_request("#{company}/IC/ICLocations('#{locations_id}')", params: params).body
10
+ end
11
+
12
+ def create(company, **attributes)
13
+ Location.new post_request("#{company}/IC/ICLocations", body: attributes).body
14
+ end
15
+
16
+ def update(company, location_id, **attributes)
17
+ patch_request("#{company}/IC/ICLocations('#{location_id}')", body: attributes)
18
+ true
19
+ end
20
+
21
+ def delete(company, location_id)
22
+ delete_request("#{company}/IC/ICLocations('#{location_id}')")
23
+ true
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ module Sagekit
2
+ class PurchaseOrdersResource < Resource
3
+
4
+ def list(company, **params)
5
+ PurchaseOrder.new get_request("#{company}/PO/POPurchaseOrders", params: params).body
6
+ end
7
+
8
+ def retreive(company, order_id, **params)
9
+ PurchaseOrder.new get_request("#{company}/PO/POPurchaseOrders(#{order_id})", params: params).body
10
+ end
11
+
12
+ def create(company, **attributes)
13
+ PurchaseOrder.new post_request("#{company}/PO/POPurchaseOrders", body: attributes).body
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Sagekit
2
+ class ReceiptsResource < Resource
3
+
4
+ def list(company, **params)
5
+ Receipt.new get_request("#{company}/PO/POReceipts", params: params).body
6
+ end
7
+
8
+ def retreive(company, receipt_id, **params)
9
+ Receipt.new get_request("#{company}/PO/POReceipts(#{receipt_id})", params: params).body
10
+ end
11
+
12
+ def create(company, **attributes)
13
+ Receipt.new post_request("#{company}/PO/POReceipts", body: attributes).body
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Sagekit
2
+ class SalesHistoryResource < Resource
3
+
4
+ def list(company, **params)
5
+ SalesHistory.new get_request("#{company}/OE/OESalesHistory", params: params).body
6
+ end
7
+
8
+ def details(company, **params)
9
+ SalesHistory.new get_request("#{company}/OE/OESalesHistoryDetails", params: params).body
10
+ end
11
+
12
+ def stats(company, **params)
13
+ SalesHistory.new get_request("#{company}/OE/OESalesStatistics", params: params).body
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,40 @@
1
+ module Sagekit
2
+ class SalesOrdersResource < Resource
3
+
4
+ def list(company, **params)
5
+ SalesOrder.new get_request("#{company}/OE/OEOrders", params: params).body
6
+ end
7
+
8
+ def retreive(company, order_id, **params)
9
+ SalesOrder.new get_request("#{company}/OE/OEOrders(#{order_id})", params: params).body
10
+ end
11
+
12
+ # Create new record:
13
+ # body: json
14
+ # client.sales_orders.create(
15
+ # "ACCLTD",
16
+ # {
17
+ # "CustomerNumber":"33016L",
18
+ # "OrderReference":"26",
19
+ # "OrderDescription":"Ship via: Delivery",
20
+ # "OrderComment":"Ordered form ERP: 26. Testing UOM!",
21
+ # "OrderDetails":
22
+ # [
23
+ # {
24
+ # "Item":"0-005-39-00100",
25
+ # "StockItem":true,
26
+ # "QuantityOrdered":55.12
27
+ # },
28
+ # {
29
+ # "Item":"0-005-19-00200",
30
+ # "StockItem":true,
31
+ # "QuantityOrdered":101.05
32
+ # }
33
+ # ]
34
+ # }
35
+ #)
36
+ def create(company, **attributes)
37
+ SalesOrder.new post_request("#{company}/OE/OEOrders", body: attributes).body
38
+ end
39
+ end
40
+ end