bigcommerce 0.10.0 → 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +620 -0
  5. data/.travis.yml +15 -0
  6. data/CHANGELOG.md +11 -0
  7. data/CONTRIBUTING.md +119 -0
  8. data/DEPENDENCIES.md +7 -0
  9. data/Gemfile +15 -0
  10. data/Guardfile +22 -0
  11. data/LICENSE +15 -15
  12. data/README.md +61 -70
  13. data/RELEASING.md +64 -0
  14. data/Rakefile +8 -6
  15. data/bigcommerce.gemspec +22 -53
  16. data/examples/README.md +148 -0
  17. data/examples/configuration/legacy_auth.rb +12 -0
  18. data/examples/configuration/oauth.rb +9 -0
  19. data/examples/content/blog_post.rb +39 -0
  20. data/examples/content/blog_tag.rb +10 -0
  21. data/examples/content/redirect.rb +43 -0
  22. data/examples/customers/customer.rb +36 -0
  23. data/examples/customers/customer_address.rb +50 -0
  24. data/examples/customers/customer_group.rb +35 -0
  25. data/examples/exception_handling.rb +50 -0
  26. data/examples/geography/country.rb +16 -0
  27. data/examples/geography/state.rb +19 -0
  28. data/examples/marketing/coupon.rb +44 -0
  29. data/examples/orders/order.rb +53 -0
  30. data/examples/orders/order_coupon.rb +17 -0
  31. data/examples/orders/order_message.rb +17 -0
  32. data/examples/orders/order_product.rb +23 -0
  33. data/examples/orders/order_shipping_address.rb +23 -0
  34. data/examples/orders/order_status.rb +15 -0
  35. data/examples/orders/order_tax.rb +17 -0
  36. data/examples/orders/shipment.rb +57 -0
  37. data/examples/payments/payment_method.rb +10 -0
  38. data/examples/products/brand.rb +36 -0
  39. data/examples/products/bulk_pricing_rule.rb +47 -0
  40. data/examples/products/category.rb +37 -0
  41. data/examples/products/configurable_field.rb +29 -0
  42. data/examples/products/custom_field.rb +44 -0
  43. data/examples/products/google_product_search_mapping.rb +12 -0
  44. data/examples/products/option.rb +37 -0
  45. data/examples/products/option_set.rb +35 -0
  46. data/examples/products/option_set_option.rb +50 -0
  47. data/examples/products/option_value.rb +43 -0
  48. data/examples/products/product.rb +44 -0
  49. data/examples/products/product_image.rb +42 -0
  50. data/examples/products/product_option.rb +17 -0
  51. data/examples/products/product_review.rb +12 -0
  52. data/examples/products/product_rule.rb +54 -0
  53. data/examples/products/product_video.rb +45 -0
  54. data/examples/products/sku.rb +48 -0
  55. data/examples/shipping/shipping_method.rb +13 -0
  56. data/examples/store/store_info.rb +10 -0
  57. data/examples/system/time.rb +10 -0
  58. data/examples/tax/tax_class.rb +13 -0
  59. data/examples/webhooks/webhook.rb +29 -0
  60. data/lib/bigcommerce.rb +50 -8
  61. data/lib/bigcommerce/exception.rb +51 -0
  62. data/lib/bigcommerce/middleware/auth.rb +16 -0
  63. data/lib/bigcommerce/middleware/http_exception.rb +14 -0
  64. data/lib/bigcommerce/request.rb +89 -0
  65. data/lib/bigcommerce/resource_actions.rb +51 -0
  66. data/lib/bigcommerce/resources/content/blog_post.rb +31 -0
  67. data/lib/bigcommerce/resources/content/blog_tag.rb +17 -0
  68. data/lib/bigcommerce/resources/content/redirect.rb +21 -0
  69. data/lib/bigcommerce/resources/customers/customer.rb +30 -0
  70. data/lib/bigcommerce/resources/customers/customer_address.rb +34 -0
  71. data/lib/bigcommerce/resources/customers/customer_group.rb +21 -0
  72. data/lib/bigcommerce/resources/geography/country.rb +22 -0
  73. data/lib/bigcommerce/resources/geography/state.rb +25 -0
  74. data/lib/bigcommerce/resources/marketing/coupon.rb +30 -0
  75. data/lib/bigcommerce/resources/orders/order.rb +73 -0
  76. data/lib/bigcommerce/resources/orders/order_coupon.rb +20 -0
  77. data/lib/bigcommerce/resources/orders/order_message.rb +23 -0
  78. data/lib/bigcommerce/resources/orders/order_product.rb +64 -0
  79. data/lib/bigcommerce/resources/orders/order_shipping_address.rb +50 -0
  80. data/lib/bigcommerce/resources/orders/order_status.rb +16 -0
  81. data/lib/bigcommerce/resources/orders/order_tax.rb +23 -0
  82. data/lib/bigcommerce/resources/orders/shipment.rb +30 -0
  83. data/lib/bigcommerce/resources/payments/payment_method.rb +17 -0
  84. data/lib/bigcommerce/resources/products/brand.rb +23 -0
  85. data/lib/bigcommerce/resources/products/bulk_pricing_rule.rb +26 -0
  86. data/lib/bigcommerce/resources/products/category.rb +29 -0
  87. data/lib/bigcommerce/resources/products/configurable_field.rb +30 -0
  88. data/lib/bigcommerce/resources/products/custom_field.rb +24 -0
  89. data/lib/bigcommerce/resources/products/google_product_search_mapping.rb +26 -0
  90. data/lib/bigcommerce/resources/products/option.rb +20 -0
  91. data/lib/bigcommerce/resources/products/option_set.rb +18 -0
  92. data/lib/bigcommerce/resources/products/option_set_option.rb +19 -0
  93. data/lib/bigcommerce/resources/products/option_value.rb +15 -0
  94. data/lib/bigcommerce/resources/products/product.rb +97 -0
  95. data/lib/bigcommerce/resources/products/product_image.rb +31 -0
  96. data/lib/bigcommerce/resources/products/product_option.rb +17 -0
  97. data/lib/bigcommerce/resources/products/product_review.rb +22 -0
  98. data/lib/bigcommerce/resources/products/product_rule.rb +31 -0
  99. data/lib/bigcommerce/resources/products/product_video.rb +24 -0
  100. data/lib/bigcommerce/resources/products/sku.rb +29 -0
  101. data/lib/bigcommerce/resources/resource.rb +10 -0
  102. data/lib/bigcommerce/resources/shipping/shipping_method.rb +15 -0
  103. data/lib/bigcommerce/resources/store/store_information.rb +37 -0
  104. data/lib/bigcommerce/resources/system/time.rb +15 -0
  105. data/lib/bigcommerce/resources/tax/tax_class.rb +15 -0
  106. data/lib/bigcommerce/resources/webhooks/webhook.rb +22 -0
  107. data/lib/bigcommerce/subresource_actions.rb +43 -0
  108. data/lib/bigcommerce/version.rb +1 -4
  109. data/spec/bigcommerce/bigcommerce_spec.rb +76 -0
  110. data/spec/bigcommerce/unit/actions_spec.rb +151 -0
  111. data/spec/bigcommerce/unit/exception_spec.rb +53 -0
  112. data/spec/bigcommerce/unit/middleware/auth_spec.rb +18 -0
  113. data/spec/bigcommerce/unit/middleware/http_exception_spec.rb +40 -0
  114. data/spec/bigcommerce/unit/request_spec.rb +180 -0
  115. data/spec/bigcommerce/unit/resources/content/blog_post_spec.rb +12 -0
  116. data/spec/bigcommerce/unit/resources/content/blog_tag_spec.rb +12 -0
  117. data/spec/bigcommerce/unit/resources/content/redirect_spec.rb +12 -0
  118. data/spec/bigcommerce/unit/resources/customers/customer_address_spec.rb +21 -0
  119. data/spec/bigcommerce/unit/resources/customers/customer_group_spec.rb +12 -0
  120. data/spec/bigcommerce/unit/resources/customers/customer_spec.rb +12 -0
  121. data/spec/bigcommerce/unit/resources/geography/country_spec.rb +12 -0
  122. data/spec/bigcommerce/unit/resources/geography/state_spec.rb +21 -0
  123. data/spec/bigcommerce/unit/resources/marketing/coupon_spec.rb +12 -0
  124. data/spec/bigcommerce/unit/resources/orders/order_product_spec.rb +21 -0
  125. data/spec/bigcommerce/unit/resources/orders/order_shipping_address_spec.rb +21 -0
  126. data/spec/bigcommerce/unit/resources/orders/order_spec.rb +13 -0
  127. data/spec/bigcommerce/unit/resources/orders/shipment_spec.rb +21 -0
  128. data/spec/bigcommerce/unit/resources/payments/payment_method_spec.rb +23 -0
  129. data/spec/bigcommerce/unit/resources/products/brand_spec.rb +12 -0
  130. data/spec/bigcommerce/unit/resources/products/bulk_pricing_rule_spec.rb +21 -0
  131. data/spec/bigcommerce/unit/resources/products/category_spec.rb +12 -0
  132. data/spec/bigcommerce/unit/resources/products/configurable_field_spec.rb +21 -0
  133. data/spec/bigcommerce/unit/resources/products/custom_field_spec.rb +21 -0
  134. data/spec/bigcommerce/unit/resources/products/google_product_search_mapping_spec.rb +14 -0
  135. data/spec/bigcommerce/unit/resources/products/option_set_spec.rb +12 -0
  136. data/spec/bigcommerce/unit/resources/products/option_spec.rb +12 -0
  137. data/spec/bigcommerce/unit/resources/products/product_image_spec.rb +21 -0
  138. data/spec/bigcommerce/unit/resources/products/product_review_spec.rb +14 -0
  139. data/spec/bigcommerce/unit/resources/products/product_rule_spec.rb +21 -0
  140. data/spec/bigcommerce/unit/resources/products/product_spec.rb +13 -0
  141. data/spec/bigcommerce/unit/resources/products/product_video_spec.rb +21 -0
  142. data/spec/bigcommerce/unit/resources/products/sku_spec.rb +21 -0
  143. data/spec/bigcommerce/unit/resources/resource_spec.rb +4 -0
  144. data/spec/bigcommerce/unit/resources/store_info/store_information_spec.rb +12 -0
  145. data/spec/bigcommerce/unit/resources/system/time_spec.rb +12 -0
  146. data/spec/bigcommerce/unit/version_spec.rb +7 -0
  147. data/spec/spec_helper.rb +9 -25
  148. metadata +203 -127
  149. data/lib/big_commerce.rb +0 -1
  150. data/lib/bigcommerce/api.rb +0 -473
  151. data/lib/bigcommerce/connection.rb +0 -171
  152. data/lib/bigcommerce/product.rb +0 -13
  153. data/lib/bigcommerce/resource.rb +0 -50
  154. data/spec/big_commerce_spec.rb +0 -9
  155. data/spec/integration/orders_spec.rb +0 -18
  156. data/spec/support/integration_context.rb +0 -13
  157. data/spec/support/mock_api_context.rb +0 -10
  158. data/spec/unit/api_request_spec.rb +0 -34
  159. data/spec/unit/api_spec.rb +0 -49
  160. data/spec/unit/connection_spec.rb +0 -23
  161. data/spec/unit/date_time_spec.rb +0 -31
  162. data/spec/unit/version_spec.rb +0 -13
@@ -0,0 +1,31 @@
1
+ # Product Image
2
+ # Images associated with a product.
3
+ # https://developer.bigcommerce.com/api/stores/v2/products/images
4
+
5
+ module Bigcommerce
6
+ class ProductImage < Resource
7
+ include Bigcommerce::SubresourceActions.new uri: 'products/%d/images/%d'
8
+
9
+ property :id
10
+ property :count
11
+ property :product_id
12
+ property :image_file
13
+ property :is_thumbnail
14
+ property :sort_order
15
+ property :zoom_url
16
+ property :thumbnail_url
17
+ property :standard_url
18
+ property :tiny_url
19
+ property :is_sample
20
+ property :description
21
+ property :date_created
22
+
23
+ def self.count(product_id)
24
+ get "products/#{product_id}/images/count"
25
+ end
26
+
27
+ def self.count_all
28
+ get 'products/images/count'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ # Product Option
2
+ # Options associated directly with a product.
3
+ # https://developer.bigcommerce.com/api/stores/v2/products/options
4
+
5
+ module Bigcommerce
6
+ class ProductOption < Resource
7
+ include Bigcommerce::SubresourceActions.new(
8
+ uri: 'products/%d/options/%d',
9
+ disable: [:create, :update, :destroy, :destroy_all])
10
+
11
+ property :id
12
+ property :option_id
13
+ property :display_name
14
+ property :sort_order
15
+ property :is_required
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ # Product Review
2
+ # Options associated directly with a product.
3
+ # https://developer.bigcommerce.com/api/stores/v2/products/reviews
4
+
5
+ module Bigcommerce
6
+ class ProductReview < Resource
7
+ include Bigcommerce::Request.new 'products/%d/reviews'
8
+
9
+ property :id
10
+ property :product_id
11
+ property :author
12
+ property :date_created
13
+ property :rating
14
+ property :title
15
+ property :review
16
+ property :status
17
+
18
+ def self.all(product_id)
19
+ get path.build(product_id)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ # Product Rule
2
+ # Rules that modify the default behaviour of products.
3
+ # https://developer.bigcommerce.com/api/stores/v2/products/rules
4
+
5
+ module Bigcommerce
6
+ class ProductRule < Resource
7
+ include Bigcommerce::SubresourceActions.new uri: 'products/%d/rules/%d'
8
+
9
+ property :id
10
+ property :count
11
+ property :product_id
12
+ property :sort_order
13
+ property :is_enabled
14
+ property :is_stop
15
+ property :price_adjuster
16
+ property :weight_adjuster
17
+ property :is_purchasing_disabled
18
+ property :purchasing_disabled_message
19
+ property :is_purchasing_hidden
20
+ property :image_file
21
+ property :conditions
22
+
23
+ def self.count(product_id)
24
+ get "products/#{product_id}/rules/count"
25
+ end
26
+
27
+ def self.count_all
28
+ get 'products/rules/count'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ # Product Video
2
+ # Embedded videos displayed on product listings.
3
+ # https://developer.bigcommerce.com/api/stores/v2/products/videos
4
+
5
+ module Bigcommerce
6
+ class ProductVideo < Resource
7
+ include Bigcommerce::SubresourceActions.new uri: 'products/%d/videos/%s'
8
+
9
+ property :id
10
+ property :product_id
11
+ property :count
12
+ property :url
13
+ property :sort_order
14
+ property :name
15
+
16
+ def self.count(product_id)
17
+ get "products/#{product_id}/videos/count"
18
+ end
19
+
20
+ def self.count_all
21
+ get 'products/videos/count'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ # SKU
2
+ # Stock Keeping Unit identifiers associated with products.
3
+ # https://developer.bigcommerce.com/api/stores/v2/products/skus
4
+
5
+ module Bigcommerce
6
+ class Sku < Resource
7
+ include Bigcommerce::SubresourceActions.new uri: 'products/%d/skus/%d'
8
+
9
+ property :id
10
+ property :product_id
11
+ property :sku
12
+ property :cost_price
13
+ property :count
14
+ property :upc
15
+ property :inventory_level
16
+ property :intentory_warning_level
17
+ property :bin_picking_number
18
+ property :options
19
+ property :inventory_warning_level
20
+
21
+ def self.count_all
22
+ get 'products/skus/count'
23
+ end
24
+
25
+ def self.count(product_id)
26
+ get "products/#{product_id}/skus/count"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ require 'bigcommerce/request'
2
+ require 'bigcommerce/resource_actions'
3
+ require 'bigcommerce/subresource_actions'
4
+
5
+ module Bigcommerce
6
+ class Resource < Hashie::Trash
7
+ include Hashie::Extensions::MethodAccess
8
+ include Hashie::Extensions::IgnoreUndeclared
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ # Shipping Method
2
+ # List of enabled shipping methods.
3
+ # https://developer.bigcommerce.com/api/stores/v2/shipping/methods
4
+
5
+ module Bigcommerce
6
+ class ShippingMethod < Resource
7
+ include Bigcommerce::ResourceActions.new(
8
+ uri: 'shipping/methods/%d',
9
+ disable: [:create, :update, :destroy, :destroy_all])
10
+
11
+ property :id
12
+ property :name
13
+ property :method_name
14
+ end
15
+ end
@@ -0,0 +1,37 @@
1
+ # Store Information
2
+ # Metadata that describes the store.
3
+ # https://developer.bigcommerce.com/api/stores/v2/store_information
4
+
5
+ module Bigcommerce
6
+ class StoreInfo < Resource
7
+ include Bigcommerce::Request.new 'store'
8
+
9
+ property :id
10
+ property :domain
11
+ property :name
12
+ property :address
13
+ property :phone
14
+ property :admin_email
15
+ property :order_email
16
+ property :language
17
+ property :currency
18
+ property :currency_symbol
19
+ property :decimal_separator
20
+ property :thousands_separator
21
+ property :decimal_places
22
+ property :dimension_decimal_places
23
+ property :dimension_decimal_token
24
+ property :dimension_thousands_token
25
+ property :currency_symbol_location
26
+ property :is_price_entered_with_tax
27
+ property :active_comparison_modules
28
+ property :weight_units
29
+ property :dimension_units
30
+ property :plan_name
31
+ property :logo
32
+
33
+ def self.info
34
+ get path.build
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ # Time
2
+ # Timestamp ping to check the system status.
3
+ # https://developer.bigcommerce.com/api/stores/v2/time
4
+
5
+ module Bigcommerce
6
+ class System < Resource
7
+ include Bigcommerce::Request.new 'time'
8
+
9
+ property :time
10
+
11
+ def self.time
12
+ get path.build
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # Tax Class
2
+ # Tax classes are used to apply different tax rates for specific types
3
+ # of products and orders.
4
+ # https://developer.bigcommerce.com/api/stores/v2/tax_classes
5
+
6
+ module Bigcommerce
7
+ class TaxClass < Resource
8
+ include Bigcommerce::ResourceActions.new(
9
+ uri: 'tax_classes/%d',
10
+ disable: [:create, :update, :destroy, :destroy_all])
11
+
12
+ property :id
13
+ property :name
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ # Webhook
2
+ # Register and manage webhooks that connect events from a store to
3
+ # external URLs.
4
+ # https://developer.bigcommerce.com/api/stores/v2/webhooks
5
+
6
+ module Bigcommerce
7
+ class Webhook < Resource
8
+ include Bigcommerce::ResourceActions.new(
9
+ uri: 'hooks/%d',
10
+ disable: [:destroy_all])
11
+
12
+ property :id
13
+ property :client_id
14
+ property :store_hash
15
+ property :scope
16
+ property :destination
17
+ property :headers
18
+ property :is_active
19
+ property :created_at
20
+ property :update_at
21
+ end
22
+ end
@@ -0,0 +1,43 @@
1
+ module Bigcommerce
2
+ class SubresourceActions < ResourceActions
3
+ def included(base)
4
+ base.send(:include, Request.new(options[:uri]))
5
+ base.extend(ClassMethods)
6
+ options[:disable_methods] ||= []
7
+ methods = ClassMethods.public_instance_methods & options[:disable_methods]
8
+ methods.each { |name| base.send(:remove_method, name) }
9
+ end
10
+
11
+ module ClassMethods
12
+ def all(parent_id, params = {})
13
+ fail ArgumentError if parent_id.nil?
14
+ get path.build(parent_id), params
15
+ end
16
+
17
+ def find(parent_id, resource_id)
18
+ fail ArgumentError if [parent_id, resource_id].any?(&:nil?)
19
+ get path.build([parent_id, resource_id])
20
+ end
21
+
22
+ def create(parent_id, params)
23
+ fail ArgumentError if parent_id.nil?
24
+ post path.build(parent_id), params
25
+ end
26
+
27
+ def update(parent_id, resource_id, params)
28
+ fail ArgumentError if [parent_id, resource_id].any?(&:nil?)
29
+ put path.build([parent_id, resource_id]), params
30
+ end
31
+
32
+ def destroy(parent_id, resource_id)
33
+ fail ArgumentError if [parent_id, resource_id].any?(&:nil?)
34
+ delete path.build([parent_id, resource_id])
35
+ end
36
+
37
+ def destroy_all(parent_id)
38
+ fail ArgumentError if parent_id.nil?
39
+ delete path.build(parent_id)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,6 +1,3 @@
1
1
  module Bigcommerce
2
- major = 0
3
- minor = 10
4
- patch = 0
5
- VERSION = [major, minor, patch].join('.') unless defined? Bigcommerce::VERSION
2
+ VERSION = '1.0.0.beta'
6
3
  end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bigcommerce do
4
+ let(:middleware) do
5
+ api.instance_variable_get('@builder').instance_variable_get('@handlers')
6
+ end
7
+
8
+ it 'should return a faraday object when configured' do
9
+ Bigcommerce.configure do |config|
10
+ config.url = 'http://foobar.com'
11
+ config.auth = 'legacy'
12
+ config.api_key = '214789175'
13
+ config.username = 'admin'
14
+ end
15
+ expect(Bigcommerce.api).to be_a_kind_of(Faraday::Connection)
16
+ end
17
+
18
+ describe '.build_connection' do
19
+ context 'when using legacy' do
20
+ let(:api) do
21
+ Bigcommerce.configure do |config|
22
+ config.url = 'http://foobar.com'
23
+ config.auth = 'legacy'
24
+ config.api_key = '214789175'
25
+ config.username = 'admin'
26
+ end
27
+ end
28
+
29
+ it 'should have the correct auth middleware' do
30
+ expect(middleware).to include(Faraday::Request::BasicAuthentication)
31
+ end
32
+ end
33
+
34
+ context 'when not using legacy' do
35
+ let(:api) do
36
+ Bigcommerce.configure do |config|
37
+ config.access_token = 'jksdgkjbhksjdb'
38
+ config.client_id = 'negskjgdjkbg'
39
+ end
40
+ end
41
+
42
+ it 'should have the correct auth middleware' do
43
+ expect(middleware).to include(Bigcommerce::Middleware::Auth)
44
+ end
45
+ end
46
+ end
47
+
48
+ describe 'multiple configurations' do
49
+ it 'should use the configuration for the most recently defined' do
50
+ Bigcommerce.configure do |config|
51
+ config.access_token = 'jksdgkjbhksjdb'
52
+ config.client_id = 'negskjgdjkbg'
53
+ end
54
+
55
+ Bigcommerce.configure do |config|
56
+ config.url = 'http://foobar.com'
57
+ config.auth = 'legacy'
58
+ config.api_key = '214789175'
59
+ config.username = 'admin'
60
+ end
61
+
62
+ expect(Bigcommerce.api.instance_variable_get('@builder')
63
+ .instance_variable_get('@handlers'))
64
+ .to include(Faraday::Request::BasicAuthentication)
65
+
66
+ Bigcommerce.configure do |config|
67
+ config.access_token = 'jksdgkjbhksjdb'
68
+ config.client_id = 'negskjgdjkbg'
69
+ end
70
+
71
+ expect(Bigcommerce.api.instance_variable_get('@builder')
72
+ .instance_variable_get('@handlers'))
73
+ .to include(Bigcommerce::Middleware::Auth)
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,151 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bigcommerce::ResourceActions do
4
+ before do
5
+ module Bigcommerce
6
+ class DummyClass
7
+ include ResourceActions.new(uri: 'http://foo.bar/%d')
8
+ end
9
+ end
10
+ @klass = Bigcommerce::DummyClass
11
+ end
12
+
13
+ let(:params) do
14
+ { page: 1 }
15
+ end
16
+
17
+ it 'should have options' do
18
+ mod = Bigcommerce::ResourceActions.new(
19
+ uri: 'http://foo.bar',
20
+ disable: [:find,:all]
21
+ )
22
+ options = {
23
+ uri: 'http://foo.bar',
24
+ disable: [:find,:all]
25
+ }
26
+ expect(mod._options).to eq options
27
+ end
28
+
29
+ describe '.all' do
30
+ it 'should make a get request to the correct route with query params' do
31
+ expect(@klass).to receive(:get).with('http://foo.bar', page: 1)
32
+ @klass.all(params)
33
+ end
34
+
35
+ it 'should make a get request to the correct route' do
36
+ expect(@klass).to receive(:get).with('http://foo.bar', {})
37
+ params.delete(:params)
38
+ @klass.all
39
+ end
40
+ end
41
+
42
+ describe '.find' do
43
+ it 'should make a get request to the correct route' do
44
+ expect(@klass).to receive(:get).with('http://foo.bar/1')
45
+ @klass.find(1)
46
+ end
47
+ end
48
+
49
+ describe '.create' do
50
+ it 'should make a post request to the correct route with params' do
51
+ expect(@klass).to receive(:post).with('http://foo.bar', page: 1)
52
+ @klass.create(params)
53
+ end
54
+ end
55
+
56
+ describe '.update' do
57
+ it 'should make a put request to the correct route with params' do
58
+ expect(@klass).to receive(:put).with('http://foo.bar/1', page: 1)
59
+ @klass.update(1, params)
60
+ end
61
+ end
62
+
63
+ describe '.destroy' do
64
+ it 'should make a delete request to the correct route with params' do
65
+ expect(@klass).to receive(:delete).with('http://foo.bar/1')
66
+ @klass.destroy(1)
67
+ end
68
+ end
69
+
70
+ describe '.destroy_all' do
71
+ it 'should make a delete request to the correct route with params' do
72
+ expect(@klass).to receive(:delete).with('http://foo.bar')
73
+ @klass.destroy_all
74
+ end
75
+ end
76
+ end
77
+
78
+ describe Bigcommerce::SubresourceActions do
79
+ before do
80
+ module Bigcommerce
81
+ class DummyClass
82
+ include SubresourceActions.new(uri: 'http://foo.bar/%d/%d')
83
+ end
84
+ end
85
+ @klass = Bigcommerce::DummyClass
86
+ end
87
+
88
+ let(:params) do
89
+ { page: 1 }
90
+ end
91
+
92
+ it 'should have options' do
93
+ mod = Bigcommerce::SubresourceActions.new(
94
+ uri: 'http://foo.bar',
95
+ disable: [:find,:all]
96
+ )
97
+ options = {
98
+ uri: 'http://foo.bar',
99
+ disable: [:find,:all]
100
+ }
101
+ expect(mod._options).to eq options
102
+ end
103
+
104
+ describe '.all' do
105
+ it 'should make a get request to the correct route with query params' do
106
+ expect(@klass).to receive(:get).with('http://foo.bar/1', page: 1)
107
+ @klass.all(1, params)
108
+ end
109
+
110
+ it 'should make a get request to the correct route' do
111
+ expect(@klass).to receive(:get).with('http://foo.bar/1', {})
112
+ params.delete(:params)
113
+ @klass.all(1)
114
+ end
115
+ end
116
+
117
+ describe '.find' do
118
+ it 'should make a get request to the correct route' do
119
+ expect(@klass).to receive(:get).with('http://foo.bar/1/2')
120
+ @klass.find(1,2)
121
+ end
122
+ end
123
+
124
+ describe '.create' do
125
+ it 'should make a post request to the correct route with params' do
126
+ expect(@klass).to receive(:post).with('http://foo.bar/1', page: 1)
127
+ @klass.create(1, params)
128
+ end
129
+ end
130
+
131
+ describe '.update' do
132
+ it 'should make a put request to the correct route with params' do
133
+ expect(@klass).to receive(:put).with('http://foo.bar/1/2', page: 1)
134
+ @klass.update(1, 2, params)
135
+ end
136
+ end
137
+
138
+ describe '.destroy' do
139
+ it 'should make a delete request to the correct route with params' do
140
+ expect(@klass).to receive(:delete).with('http://foo.bar/1/2')
141
+ @klass.destroy(1, 2)
142
+ end
143
+ end
144
+
145
+ describe '.destroy_all' do
146
+ it 'should make a delete request to the correct route with params' do
147
+ expect(@klass).to receive(:delete).with('http://foo.bar/1')
148
+ @klass.destroy_all(1)
149
+ end
150
+ end
151
+ end