gecko-ruby 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rubocop.yml +9 -0
  4. data/.travis.yml +5 -0
  5. data/CHANGELOG.md +41 -0
  6. data/CONTRIBUTING.md +0 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +144 -0
  10. data/Rakefile +19 -0
  11. data/gecko-ruby.gemspec +34 -0
  12. data/generate.thor +81 -0
  13. data/lib/gecko-ruby.rb +1 -0
  14. data/lib/gecko.rb +31 -0
  15. data/lib/gecko/client.rb +132 -0
  16. data/lib/gecko/helpers/association_helper.rb +69 -0
  17. data/lib/gecko/helpers/inspection_helper.rb +51 -0
  18. data/lib/gecko/helpers/record_helper.rb +29 -0
  19. data/lib/gecko/helpers/serialization_helper.rb +61 -0
  20. data/lib/gecko/helpers/validation_helper.rb +91 -0
  21. data/lib/gecko/record/account.rb +66 -0
  22. data/lib/gecko/record/address.rb +33 -0
  23. data/lib/gecko/record/base.rb +66 -0
  24. data/lib/gecko/record/base_adapter.rb +365 -0
  25. data/lib/gecko/record/company.rb +41 -0
  26. data/lib/gecko/record/contact.rb +25 -0
  27. data/lib/gecko/record/currency.rb +23 -0
  28. data/lib/gecko/record/exceptions.rb +15 -0
  29. data/lib/gecko/record/fulfillment.rb +42 -0
  30. data/lib/gecko/record/fulfillment_line_item.rb +26 -0
  31. data/lib/gecko/record/image.rb +38 -0
  32. data/lib/gecko/record/invoice.rb +29 -0
  33. data/lib/gecko/record/invoice_line_item.rb +18 -0
  34. data/lib/gecko/record/location.rb +23 -0
  35. data/lib/gecko/record/order.rb +50 -0
  36. data/lib/gecko/record/order_line_item.rb +35 -0
  37. data/lib/gecko/record/product.rb +27 -0
  38. data/lib/gecko/record/purchase_order.rb +43 -0
  39. data/lib/gecko/record/purchase_order_line_item.rb +29 -0
  40. data/lib/gecko/record/tax_type.rb +21 -0
  41. data/lib/gecko/record/user.rb +44 -0
  42. data/lib/gecko/record/variant.rb +96 -0
  43. data/lib/gecko/version.rb +3 -0
  44. data/test/client_test.rb +29 -0
  45. data/test/fixtures/vcr_cassettes/accounts.yml +57 -0
  46. data/test/fixtures/vcr_cassettes/accounts_current.yml +57 -0
  47. data/test/fixtures/vcr_cassettes/addresses.yml +68 -0
  48. data/test/fixtures/vcr_cassettes/addresses_count.yml +58 -0
  49. data/test/fixtures/vcr_cassettes/companies.yml +62 -0
  50. data/test/fixtures/vcr_cassettes/companies_count.yml +58 -0
  51. data/test/fixtures/vcr_cassettes/contacts.yml +60 -0
  52. data/test/fixtures/vcr_cassettes/contacts_count.yml +58 -0
  53. data/test/fixtures/vcr_cassettes/currencies.yml +62 -0
  54. data/test/fixtures/vcr_cassettes/currencies_count.yml +58 -0
  55. data/test/fixtures/vcr_cassettes/fulfillments.yml +59 -0
  56. data/test/fixtures/vcr_cassettes/fulfillments_count.yml +58 -0
  57. data/test/fixtures/vcr_cassettes/images.yml +59 -0
  58. data/test/fixtures/vcr_cassettes/images_count.yml +58 -0
  59. data/test/fixtures/vcr_cassettes/invoice_line_items.yml +63 -0
  60. data/test/fixtures/vcr_cassettes/invoice_line_items_count.yml +62 -0
  61. data/test/fixtures/vcr_cassettes/invoices.yml +63 -0
  62. data/test/fixtures/vcr_cassettes/invoices_count.yml +62 -0
  63. data/test/fixtures/vcr_cassettes/locations.yml +65 -0
  64. data/test/fixtures/vcr_cassettes/locations_count.yml +58 -0
  65. data/test/fixtures/vcr_cassettes/order_line_items.yml +63 -0
  66. data/test/fixtures/vcr_cassettes/order_line_items_count.yml +62 -0
  67. data/test/fixtures/vcr_cassettes/orders.yml +62 -0
  68. data/test/fixtures/vcr_cassettes/orders_count.yml +58 -0
  69. data/test/fixtures/vcr_cassettes/products.yml +79 -0
  70. data/test/fixtures/vcr_cassettes/products_count.yml +58 -0
  71. data/test/fixtures/vcr_cassettes/products_new_invalid.yml +54 -0
  72. data/test/fixtures/vcr_cassettes/products_new_valid.yml +58 -0
  73. data/test/fixtures/vcr_cassettes/purchase_order_line_items.yml +64 -0
  74. data/test/fixtures/vcr_cassettes/purchase_order_line_items_count.yml +62 -0
  75. data/test/fixtures/vcr_cassettes/purchase_orders.yml +63 -0
  76. data/test/fixtures/vcr_cassettes/purchase_orders_count.yml +62 -0
  77. data/test/fixtures/vcr_cassettes/tax_types.yml +74 -0
  78. data/test/fixtures/vcr_cassettes/tax_types_count.yml +62 -0
  79. data/test/fixtures/vcr_cassettes/users.yml +60 -0
  80. data/test/fixtures/vcr_cassettes/users_count.yml +58 -0
  81. data/test/fixtures/vcr_cassettes/users_current.yml +54 -0
  82. data/test/fixtures/vcr_cassettes/variants.yml +60 -0
  83. data/test/fixtures/vcr_cassettes/variants_count.yml +58 -0
  84. data/test/gecko_test.rb +7 -0
  85. data/test/helpers/association_helper_test.rb +56 -0
  86. data/test/helpers/inspection_helper_test.rb +27 -0
  87. data/test/helpers/serialization_helper_test.rb +30 -0
  88. data/test/helpers/validation_helper_test.rb +24 -0
  89. data/test/record/account_adapter_test.rb +43 -0
  90. data/test/record/address_adapter_test.rb +14 -0
  91. data/test/record/address_test.rb +18 -0
  92. data/test/record/company_adapter_test.rb +14 -0
  93. data/test/record/company_test.rb +18 -0
  94. data/test/record/contact_adapter_test.rb +14 -0
  95. data/test/record/contact_test.rb +18 -0
  96. data/test/record/currency_adapter_test.rb +14 -0
  97. data/test/record/currency_test.rb +18 -0
  98. data/test/record/fulfillment_adapter_test.rb +24 -0
  99. data/test/record/fulfillment_line_item_adapter_test.rb +21 -0
  100. data/test/record/fulfillment_line_item_test.rb +18 -0
  101. data/test/record/fulfillment_test.rb +27 -0
  102. data/test/record/image_adapter_test.rb +14 -0
  103. data/test/record/image_test.rb +25 -0
  104. data/test/record/invoice_adapter_test.rb +14 -0
  105. data/test/record/invoice_line_item_adapter_test.rb +20 -0
  106. data/test/record/invoice_line_item_test.rb +18 -0
  107. data/test/record/invoice_test.rb +18 -0
  108. data/test/record/location_adapter_test.rb +14 -0
  109. data/test/record/location_test.rb +18 -0
  110. data/test/record/order_adapter_test.rb +14 -0
  111. data/test/record/order_line_item_adapter_test.rb +14 -0
  112. data/test/record/order_line_item_test.rb +18 -0
  113. data/test/record/order_test.rb +18 -0
  114. data/test/record/product_adapter_test.rb +32 -0
  115. data/test/record/product_test.rb +18 -0
  116. data/test/record/purchase_order_adapter_test.rb +14 -0
  117. data/test/record/purchase_order_line_item_adapter_test.rb +14 -0
  118. data/test/record/purchase_order_line_item_test.rb +18 -0
  119. data/test/record/purchase_order_test.rb +18 -0
  120. data/test/record/tax_type_adapter_test.rb +14 -0
  121. data/test/record/tax_type_test.rb +18 -0
  122. data/test/record/user_adapter_test.rb +27 -0
  123. data/test/record/user_test.rb +18 -0
  124. data/test/record/variant_adapter_test.rb +14 -0
  125. data/test/record/variant_test.rb +44 -0
  126. data/test/support/let.rb +10 -0
  127. data/test/support/shared_adapter_examples.rb +159 -0
  128. data/test/support/shared_record_examples.rb +21 -0
  129. data/test/support/testing_adapter.rb +11 -0
  130. data/test/support/vcr_support.rb +7 -0
  131. data/test/test_helper.rb +21 -0
  132. metadata +430 -0
@@ -0,0 +1,15 @@
1
+ module Gecko
2
+ module Record
3
+ # Generic Gecko::Record exception class.
4
+ class BaseError < StandardError
5
+ end
6
+
7
+ # Raise when a record can not be found via API
8
+ class RecordNotFound < BaseError
9
+ end
10
+
11
+ # Raised when a record can not be found in the Identity Map
12
+ class RecordNotInIdentityMap < BaseError
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,42 @@
1
+ require 'gecko/record/base'
2
+ require 'gecko/record/fulfillment_line_item'
3
+
4
+ module Gecko
5
+ module Record
6
+ class Fulfillment < Base
7
+ belongs_to :order
8
+ belongs_to :shipping_address, class_name: 'Address'
9
+ belongs_to :billing_address, class_name: 'Address'
10
+ has_many :fulfillment_line_items
11
+
12
+ attribute :status, String
13
+ attribute :exchange_rate, String
14
+ attribute :delivery_type, String
15
+ attribute :tracking_number, String
16
+ attribute :notes, String
17
+ attribute :tracking_url, String
18
+ attribute :tracking_company, String
19
+ attribute :destination_url, String, readonly: true
20
+
21
+ attribute :packed_at, Date
22
+ attribute :shipped_at, DateTime
23
+ attribute :received_at, DateTime
24
+
25
+ attribute :receipt, Hash
26
+ end
27
+
28
+ class FulfillmentAdapter < BaseAdapter
29
+ # Parse sideloaded FulfillmentLineItems into the Identity map
30
+ # instead of refetching them
31
+ def parse_records(json)
32
+ records = super
33
+ parse_line_items(json) if json['fulfillment_line_items']
34
+ records
35
+ end
36
+
37
+ def parse_line_items(json)
38
+ @client.FulfillmentLineItem.parse_records(json)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ require 'gecko/record/base'
2
+
3
+ module Gecko
4
+ module Record
5
+ class FulfillmentLineItem < Base
6
+ belongs_to :fulfillment
7
+ belongs_to :order_line_item
8
+
9
+ attribute :quantity, BigDecimal
10
+ attribute :base_price, BigDecimal, readonly: true
11
+
12
+ attribute :position, Integer
13
+ end
14
+
15
+ class FulfillmentLineItemAdapter < BaseAdapter
16
+ # Returns all cached records for testing
17
+ #
18
+ # @return [Array<Gecko::Record::FulfillmentLineItem>]
19
+ #
20
+ # @api private
21
+ def all
22
+ @identity_map.values
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,38 @@
1
+ require 'gecko/record/base'
2
+
3
+ module Gecko
4
+ module Record
5
+ class Image < Base
6
+ AVAILABLE_SIZES = [:full, :thumbnail]
7
+
8
+ belongs_to :variant
9
+ belongs_to :uploader, class_name: "User"
10
+ attribute :name, String
11
+ attribute :position, Integer
12
+ attribute :base_path, String
13
+ attribute :file_name, String
14
+ attribute :versions, Array[String]
15
+ # attribute :image_processing, Boolean
16
+
17
+ # URL for image
18
+ #
19
+ # @param [Symbol] :size (:full) The image size, currently only :full
20
+ # and :thumbnail supported
21
+ #
22
+ # @return [String]
23
+ #
24
+ # @api public
25
+ def url(size = :full)
26
+ if size == :full
27
+ file_path = file_name
28
+ else
29
+ file_path = "#{size}_#{file_name}"
30
+ end
31
+ [base_path, file_path].join("/")
32
+ end
33
+ end
34
+
35
+ class ImageAdapter < BaseAdapter
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,29 @@
1
+ require 'gecko/record/base'
2
+
3
+ module Gecko
4
+ module Record
5
+ class Invoice < Base
6
+ belongs_to :order
7
+ belongs_to :shipping_address
8
+ belongs_to :billing_address
9
+ belongs_to :payment_term
10
+
11
+ has_many :invoice_line_items
12
+
13
+ attribute :invoice_number, String
14
+ attribute :invoiced_at, Date
15
+ attribute :due_at, Date
16
+ attribute :notes, String
17
+ attribute :exchange_rate, BigDecimal
18
+
19
+ attribute :destination_url, String, readonly: true
20
+ attribute :document_url, String, readonly: true
21
+ attribute :created_at, DateTime, readonly: true
22
+ attribute :updated_at, DateTime, readonly: true
23
+ end
24
+
25
+ class InvoiceAdapter < BaseAdapter
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ require 'gecko/record/base'
2
+
3
+ module Gecko
4
+ module Record
5
+ class InvoiceLineItem < Base
6
+ belongs_to :invoice
7
+ belongs_to :order_line_item
8
+ belongs_to :ledger_account
9
+
10
+ attribute :quantity, BigDecimal
11
+ attribute :position, Integer
12
+ end
13
+
14
+ class InvoiceLineItemAdapter < BaseAdapter
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ require 'gecko/record/base'
2
+
3
+ module Gecko
4
+ module Record
5
+ class Location < Base
6
+
7
+ attribute :address1, String
8
+ attribute :address2, String
9
+ attribute :suburb, String
10
+ attribute :city, String
11
+ attribute :country, String
12
+ attribute :label, String
13
+ attribute :state, String
14
+ attribute :zip_code, String
15
+ attribute :holds_stock, Boolean
16
+
17
+ attribute :status, String, readonly: true
18
+ end
19
+
20
+ class LocationAdapter < BaseAdapter
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,50 @@
1
+ require 'gecko/record/base'
2
+
3
+ module Gecko
4
+ module Record
5
+ class Order < Base
6
+ has_many :fulfillments
7
+ has_many :invoices
8
+ has_many :order_line_items
9
+
10
+ belongs_to :company
11
+ belongs_to :shipping_address, class_name: 'Address'
12
+ belongs_to :billing_address, class_name: 'Address'
13
+ belongs_to :contact, class_name: 'Contact'
14
+ belongs_to :user, readonly: true
15
+ belongs_to :assignee, class_name: 'User'
16
+ belongs_to :stock_location, class_name: 'Location'
17
+ belongs_to :currency
18
+ # belongs_to :default_price_list, class_name: 'PriceList'
19
+
20
+ attribute :order_number, String
21
+ attribute :phone_number, String
22
+ attribute :email, String
23
+ attribute :notes, String
24
+ attribute :reference_number, String
25
+ attribute :status, String
26
+ attribute :packed_status, String, readonly: true
27
+ attribute :fulfillment_status, String, readonly: true
28
+ attribute :invoice_status, String, readonly: true
29
+ attribute :payment_status, String
30
+ attribute :tax_type, String
31
+ attribute :issued_at, Date
32
+ attribute :ship_at, Date
33
+ attribute :tax_override, String, readonly: true
34
+ attribute :tax_label, String, readonly: true
35
+ attribute :source_url, String
36
+ attribute :document_url, String, readonly: true
37
+ attribute :total, BigDecimal, readonly: true
38
+
39
+ attribute :source_id, String, readonly: true
40
+
41
+ ## DEPRECATED
42
+ attribute :tracking_number, String, readonly: true
43
+ # attribute :source, String
44
+ # attribute :invoice_numbers, Hash[Integer => String], readonly: true
45
+ end
46
+
47
+ class OrderAdapter < BaseAdapter
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,35 @@
1
+ require 'gecko/record/base'
2
+
3
+ module Gecko
4
+ module Record
5
+ class OrderLineItem < Base
6
+ belongs_to :order
7
+ belongs_to :variant
8
+ belongs_to :tax_type
9
+
10
+ has_many :fulfillment_line_items
11
+ has_many :invoice_line_items
12
+
13
+ attribute :label, String
14
+ attribute :line_type, String
15
+
16
+ attribute :freeform, Boolean
17
+ attribute :shippable, Boolean, readonly: true
18
+
19
+ attribute :discount, BigDecimal
20
+ attribute :quantity, BigDecimal
21
+ attribute :price, BigDecimal
22
+ attribute :tax_rate_override, BigDecimal
23
+
24
+ attribute :position, Integer
25
+
26
+ attribute :image_url, String, readonly: true
27
+
28
+ # DEPRECATED
29
+ attribute :tax_rate, BigDecimal
30
+ end
31
+
32
+ class OrderLineItemAdapter < BaseAdapter
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,27 @@
1
+ require 'gecko/record/base'
2
+
3
+ module Gecko
4
+ module Record
5
+ class Product < Base
6
+ has_many :variants
7
+ attribute :name, String
8
+ attribute :description, String
9
+ attribute :product_type, String
10
+ attribute :supplier, String
11
+ attribute :brand, String
12
+ attribute :opt1, String
13
+ attribute :opt2, String
14
+ attribute :opt3, String
15
+ attribute :tags, String
16
+
17
+ attribute :status, String
18
+
19
+ # attribute :image_url, String, readonly: true
20
+ # attribute :quantity, Integer, readonly: true
21
+ # attribute :search_cache, String, readonly: true
22
+ end
23
+
24
+ class ProductAdapter < BaseAdapter
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,43 @@
1
+ require 'gecko/record/base'
2
+
3
+ module Gecko
4
+ module Record
5
+ class PurchaseOrder < Base
6
+ has_many :purchase_order_line_items
7
+ has_many :procurements
8
+
9
+ belongs_to :company
10
+ belongs_to :supplier_address, class_name: "Address"
11
+ belongs_to :stock_location, class_name: "Location"
12
+ belongs_to :billing_address, class_name: "Location"
13
+
14
+ belongs_to :currency
15
+ belongs_to :default_price_list, class_name: "PriceList"
16
+
17
+ attribute :order_number, String
18
+ attribute :reference_number, String
19
+ attribute :email, String
20
+ attribute :due_at, Date
21
+
22
+ attribute :status, String
23
+ attribute :procurement_status, String
24
+ attribute :notes, String
25
+ attribute :tax_treatment, String
26
+
27
+ attribute :destination_url, String
28
+ attribute :document_url, String
29
+
30
+ attribute :total, BigDecimal
31
+ attribute :cached_quantity, BigDecimal
32
+ attribute :cached_total, BigDecimal
33
+
34
+ # DEPRECATED
35
+ # attribute :tax_type, String
36
+ # attribute :default_price_type_id
37
+ end
38
+
39
+ class PurchaseOrderAdapter < BaseAdapter
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,29 @@
1
+ require 'gecko/record/base'
2
+
3
+ module Gecko
4
+ module Record
5
+ class PurchaseOrderLineItem < Base
6
+ belongs_to :purchase_order
7
+ belongs_to :variant
8
+ belongs_to :procurement
9
+ belongs_to :tax_type
10
+
11
+ attribute :quantity, BigDecimal
12
+ attribute :position, Integer
13
+ attribute :tax_rate_override, BigDecimal
14
+ attribute :price, BigDecimal
15
+ attribute :label, String
16
+ attribute :freeform, Boolean
17
+ attribute :base_price, BigDecimal
18
+ attribute :extra_cost_value, BigDecimal
19
+ attribute :image_url, String
20
+
21
+ # DEPRECATED
22
+ # attribute :tax_rate, String
23
+ end
24
+
25
+ class PurchaseOrderLineItemAdapter < BaseAdapter
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ require 'gecko/record/base'
2
+
3
+ module Gecko
4
+ module Record
5
+ class TaxType < Base
6
+ attribute :name, String
7
+ attribute :code, String
8
+ attribute :xero_online_id, String
9
+ attribute :imported_from, String
10
+ attribute :effective_rate, BigDecimal
11
+
12
+ attribute :status, String
13
+
14
+ # has_many :tax_components
15
+ end
16
+
17
+ class TaxTypeAdapter < BaseAdapter
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,44 @@
1
+ require 'gecko/record/base'
2
+
3
+ module Gecko
4
+ module Record
5
+ class User < Base
6
+ attribute :first_name, String
7
+ attribute :last_name, String
8
+ attribute :email, String
9
+ attribute :location, String
10
+ attribute :position, String
11
+ attribute :phone_number, String
12
+ attribute :mobile_phone, String
13
+ attribute :last_sign_in_at, DateTime
14
+ attribute :avatar_url, String
15
+
16
+ attribute :status, String
17
+
18
+ # attribute :sales_report_email, Boolean
19
+ # attribute :action_items_email, String
20
+
21
+ # attribute :billing_contact, Boolean
22
+ # attribute :notification_email, Boolean
23
+ # attribute :permisssions, Array[String]
24
+ # attribute :account_id, Integer
25
+ end
26
+
27
+ class UserAdapter < BaseAdapter
28
+ undef :build
29
+
30
+ # Return the the logged in user
31
+ #
32
+ # @return [Gecko::Record::User]
33
+ #
34
+ # @api public
35
+ def current
36
+ if self.has_record_for_id?(:current)
37
+ record_for_id(:current)
38
+ else
39
+ @identity_map[:current] = find(:current)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end