veeqo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.hound.yml +3 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +629 -0
  6. data/.sample.pryrc +4 -0
  7. data/.travis.yml +5 -0
  8. data/Gemfile +4 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +574 -0
  11. data/Rakefile +6 -0
  12. data/bin/console +10 -0
  13. data/bin/rspec +17 -0
  14. data/bin/setup +8 -0
  15. data/lib/veeqo.rb +16 -0
  16. data/lib/veeqo/actions/base.rb +13 -0
  17. data/lib/veeqo/actions/delete.rb +11 -0
  18. data/lib/veeqo/actions/find.rb +11 -0
  19. data/lib/veeqo/actions/list.rb +11 -0
  20. data/lib/veeqo/allocation.rb +32 -0
  21. data/lib/veeqo/base.rb +26 -0
  22. data/lib/veeqo/company.rb +17 -0
  23. data/lib/veeqo/configuration.rb +17 -0
  24. data/lib/veeqo/customer.rb +24 -0
  25. data/lib/veeqo/delivery_method.rb +19 -0
  26. data/lib/veeqo/errors.rb +30 -0
  27. data/lib/veeqo/errors/forbidden.rb +9 -0
  28. data/lib/veeqo/errors/request_error.rb +15 -0
  29. data/lib/veeqo/errors/server_error.rb +9 -0
  30. data/lib/veeqo/errors/unauthorized.rb +9 -0
  31. data/lib/veeqo/order.rb +25 -0
  32. data/lib/veeqo/product.rb +25 -0
  33. data/lib/veeqo/purchase_order.rb +11 -0
  34. data/lib/veeqo/request.rb +89 -0
  35. data/lib/veeqo/response.rb +27 -0
  36. data/lib/veeqo/shipment.rb +30 -0
  37. data/lib/veeqo/store.rb +19 -0
  38. data/lib/veeqo/supplier.rb +19 -0
  39. data/lib/veeqo/version.rb +3 -0
  40. data/lib/veeqo/warehouse.rb +19 -0
  41. data/spec/fixtures/allocation_created.json +554 -0
  42. data/spec/fixtures/company.json +3 -0
  43. data/spec/fixtures/customer.json +4 -0
  44. data/spec/fixtures/customer_created.json +15 -0
  45. data/spec/fixtures/customers.json +38 -0
  46. data/spec/fixtures/delivery_method.json +3 -0
  47. data/spec/fixtures/delivery_method_created.json +4 -0
  48. data/spec/fixtures/delivery_methods.json +5 -0
  49. data/spec/fixtures/empty.json +0 -0
  50. data/spec/fixtures/order.json +3 -0
  51. data/spec/fixtures/order_created.json +554 -0
  52. data/spec/fixtures/orders.json +5 -0
  53. data/spec/fixtures/ping.json +3 -0
  54. data/spec/fixtures/product.json +4 -0
  55. data/spec/fixtures/product_created.json +137 -0
  56. data/spec/fixtures/products.json +5 -0
  57. data/spec/fixtures/purchase_orders.json +177 -0
  58. data/spec/fixtures/shipment_created.json +19 -0
  59. data/spec/fixtures/store.json +3 -0
  60. data/spec/fixtures/store_created.json +4 -0
  61. data/spec/fixtures/stores.json +5 -0
  62. data/spec/fixtures/supplier.json +3 -0
  63. data/spec/fixtures/supplier_created.json +4 -0
  64. data/spec/fixtures/suppliers.json +5 -0
  65. data/spec/fixtures/warehouse.json +3 -0
  66. data/spec/fixtures/warehouse_created.json +4 -0
  67. data/spec/fixtures/warehouses.json +5 -0
  68. data/spec/spec_helper.rb +15 -0
  69. data/spec/support/fake_veeqo_api.rb +408 -0
  70. data/spec/veeqo/actions/list_spec.rb +38 -0
  71. data/spec/veeqo/allocation_spec.rb +49 -0
  72. data/spec/veeqo/base_spec.rb +23 -0
  73. data/spec/veeqo/company_spec.rb +23 -0
  74. data/spec/veeqo/configuration_spec.rb +24 -0
  75. data/spec/veeqo/customer_spec.rb +77 -0
  76. data/spec/veeqo/delivery_method_spec.rb +65 -0
  77. data/spec/veeqo/order_spec.rb +93 -0
  78. data/spec/veeqo/product_spec.rb +82 -0
  79. data/spec/veeqo/purchase_order_spec.rb +14 -0
  80. data/spec/veeqo/request_spec.rb +40 -0
  81. data/spec/veeqo/shipment_spec.rb +38 -0
  82. data/spec/veeqo/store_spec.rb +61 -0
  83. data/spec/veeqo/supplier_spec.rb +61 -0
  84. data/spec/veeqo/warehouse_spec.rb +61 -0
  85. data/veeqo.gemspec +26 -0
  86. metadata +198 -0
@@ -0,0 +1,38 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Veeqo::Actions::List do
4
+ describe ".list" do
5
+ context "without any filter arguments" do
6
+ it "retrieves the list of all items" do
7
+ stub_veeqo_product_list_api
8
+
9
+ items = TestProduct.list
10
+
11
+ expect(items.count).to eq(1)
12
+ expect(items.first.id).not_to be_nil
13
+ end
14
+ end
15
+
16
+ context "with custom filter arguments" do
17
+ it "retrieves the list of filterred item" do
18
+ filters = { page: 1, page_size: 10 }
19
+
20
+ stub_veeqo_product_list_api(filters)
21
+ items = TestProduct.list(filters)
22
+
23
+ expect(items.count).to eq(1)
24
+ expect(items.first.id).not_to be_nil
25
+ end
26
+ end
27
+ end
28
+
29
+ class TestProduct < Veeqo::Base
30
+ include Veeqo::Actions::List
31
+
32
+ private
33
+
34
+ def end_point
35
+ "products"
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,49 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Veeqo::Allocation do
4
+ describe ".create" do
5
+ it "creates a new allocation" do
6
+ stub_veeqo_allocation_create_api(allocation_attributes)
7
+ allocation = Veeqo::Allocation.create(allocation_attributes)
8
+
9
+ expect(allocation.id).not_to be_nil
10
+ expect(allocation.line_items.first.sellable.id).to eq(1226615)
11
+ end
12
+ end
13
+
14
+ describe ".update" do
15
+ it "updates an existing allocation" do
16
+ allocation_id = 123_456
17
+
18
+ stub_veeqo_allocation_update_api(allocation_id, allocation_attributes)
19
+ allocation_update = Veeqo::Allocation.update(
20
+ allocation_id, allocation_attributes
21
+ )
22
+
23
+ expect(allocation_update.successful?).to be_truthy
24
+ end
25
+ end
26
+
27
+ describe ".delete" do
28
+ it "deletes the specified allocation" do
29
+ order_id = 123_456
30
+ allocation_id = 456_789
31
+
32
+ stub_veeqo_allocation_delete_api(order_id, allocation_id)
33
+ allocation_delete = Veeqo::Allocation.delete(order_id, allocation_id)
34
+
35
+ expect(allocation_delete.successful?).to be_truthy
36
+ end
37
+ end
38
+
39
+ def allocation_attributes
40
+ {
41
+ order_id: 447452,
42
+ warehouse_id: 5,
43
+ line_items: [{
44
+ sellable_id: 1226615,
45
+ quantity: 1,
46
+ }],
47
+ }
48
+ end
49
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Veeqo::Base do
4
+ describe ".method_missing" do
5
+ context "with existing instance method" do
6
+ it "creates a new instace and invoke the method" do
7
+ expect(InheritedBase.valid?).to be_truthy
8
+ end
9
+ end
10
+
11
+ context "with non existing instance method" do
12
+ it "raise an default method error" do
13
+ expect { InheritedBase.invalid_method }.to raise_error(NoMethodError)
14
+ end
15
+ end
16
+ end
17
+
18
+ class InheritedBase < Veeqo::Base
19
+ def valid?
20
+ true
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Veeqo::Company do
4
+ describe ".find" do
5
+ it "retrieves the current company" do
6
+ stub_veeqo_company_find_api
7
+ company = Veeqo::Company.find
8
+
9
+ expect(company.name).not_to be_nil
10
+ end
11
+ end
12
+
13
+ describe ".update" do
14
+ it "updates the current company with new attributes" do
15
+ new_attributes = { name: "ACME" }
16
+
17
+ stub_veeqo_company_update_api(new_attributes)
18
+ company_update = Veeqo::Company.update(new_attributes)
19
+
20
+ expect(company_update.successful?).to be_truthy
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Veeqo::Configuration do
4
+ describe ".configuration" do
5
+ it "returns the client configuration object" do
6
+ veeqo_api_host = "api.veeqo.com"
7
+ configuration = Veeqo.configuration
8
+
9
+ expect(configuration.api_host).to eq(veeqo_api_host)
10
+ end
11
+ end
12
+
13
+ describe ".configure" do
14
+ it "allows user to cofigure their keys" do
15
+ veeqo_api_key = "VEEQO_API_KEY"
16
+
17
+ Veeqo.configure do |config|
18
+ config.api_key = veeqo_api_key
19
+ end
20
+
21
+ expect(Veeqo.configuration.api_key).to eq(veeqo_api_key)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,77 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Veeqo::Customer do
4
+ describe ".list" do
5
+ it "retrieves the list of all customers" do
6
+ filters = { page: 1, page_size: 12 }
7
+
8
+ stub_veeqo_customer_list_api(filters)
9
+ customers = Veeqo::Customer.list(filters)
10
+
11
+ expect(customers.count).to eq(1)
12
+ expect(customers.first.id).not_to be_nil
13
+ end
14
+ end
15
+
16
+ describe ".find" do
17
+ it "retrives the details for a customer" do
18
+ customer_id = 123
19
+
20
+ stub_veeqo_customer_find_api(customer_id)
21
+ customer = Veeqo::Customer.find(customer_id)
22
+
23
+ expect(customer.id).to eq(123)
24
+ expect(customer.email).not_to be_nil
25
+ end
26
+ end
27
+
28
+ describe ".create" do
29
+ it "creates a new customer" do
30
+ stub_veeqo_customer_create_api(customer_attributes)
31
+ customer = Veeqo::Customer.create(customer_attributes)
32
+
33
+ expect(customer.id).to eq(123)
34
+ expect(customer.email).to eq(customer_attributes[:email])
35
+ end
36
+ end
37
+
38
+ describe ".update" do
39
+ it "updates the customer with new attributes" do
40
+ customer_id = 123
41
+ new_attributes = { email: "customer@example.com" }
42
+
43
+ stub_veeqo_customer_update_api(customer_id, new_attributes)
44
+ customer_update = Veeqo::Customer.update(customer_id, new_attributes)
45
+
46
+ expect(customer_update.successful?).to be_truthy
47
+ end
48
+ end
49
+
50
+ describe ".delete" do
51
+ it "deletes the specified customer" do
52
+ customer_id = 123
53
+
54
+ stub_veeqo_customer_delete_api(customer_id)
55
+ customer_deletion = Veeqo::Customer.delete(customer_id)
56
+
57
+ expect(customer_deletion.successful?).to be_truthy
58
+ end
59
+ end
60
+
61
+ def customer_attributes
62
+ {
63
+ email: "customer@example.com",
64
+ phone: "01792 720740",
65
+ mobile: "07329023903",
66
+ billing_address: {
67
+ first_name: "John",
68
+ last_name: "Doe",
69
+ company: "FooBar Ltd",
70
+ address1: "221 High Street Lane",
71
+ city: "Swansea",
72
+ country: "GB",
73
+ zip: "SA1 1NW",
74
+ },
75
+ }
76
+ end
77
+ end
@@ -0,0 +1,65 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Veeqo::DeliveryMethod do
4
+ describe ".list" do
5
+ it "retrieves all the develiery methods" do
6
+ filters = { page: 1, page_size: 12 }
7
+
8
+ stub_veeqo_delivery_method_list_api(filters)
9
+ delivery_methods = Veeqo::DeliveryMethod.list(filters)
10
+
11
+ expect(delivery_methods.count).to eq(1)
12
+ expect(delivery_methods.first.id).not_to be_nil
13
+ end
14
+ end
15
+
16
+ describe ".find" do
17
+ it "retrieves the details for a delivery method" do
18
+ delivery_method_id = 123
19
+
20
+ stub_veeqo_delivery_method_find_api(delivery_method_id)
21
+ delivery_method = Veeqo::DeliveryMethod.find(delivery_method_id)
22
+
23
+ expect(delivery_method.name).not_to be_nil
24
+ end
25
+ end
26
+
27
+ describe ".create" do
28
+ it "creates a new deliver method" do
29
+ attributes = { name: "Next Day Delivery" }
30
+
31
+ stub_veeqo_delivery_method_create_api(attributes)
32
+ delivery_method = Veeqo::DeliveryMethod.create(attributes)
33
+
34
+ expect(delivery_method.id).not_to be_nil
35
+ expect(delivery_method.name).to eq(attributes[:name])
36
+ end
37
+ end
38
+
39
+ describe ".update" do
40
+ it "updates a delivery method with new attributes" do
41
+ delivery_method_id = 123
42
+ new_attributes = { name: "Next Day Delivery" }
43
+
44
+ stub_veeqo_delivery_method_update_api(delivery_method_id, new_attributes)
45
+ delivery_method_update = Veeqo::DeliveryMethod.update(
46
+ delivery_method_id, new_attributes
47
+ )
48
+
49
+ expect(delivery_method_update.successful?).to be_truthy
50
+ end
51
+ end
52
+
53
+ describe ".delete" do
54
+ it "deletes a specific delivery method" do
55
+ delivery_method_id = 123
56
+
57
+ stub_veeqo_delivery_method_delete_api(delivery_method_id)
58
+ delivery_method_deletion = Veeqo::DeliveryMethod.delete(
59
+ delivery_method_id,
60
+ )
61
+
62
+ expect(delivery_method_deletion.successful?).to be_truthy
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,93 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Veeqo::Order do
4
+ describe ".list" do
5
+ it "retrives the all of the orders" do
6
+ filters = { page: "2", page_size: "25" }
7
+
8
+ stub_veeqo_order_list_api(filters)
9
+ orders = Veeqo::Order.list(filters)
10
+
11
+ expect(orders.count).to eq(1)
12
+ expect(orders.first.id).to eq(123)
13
+ end
14
+ end
15
+
16
+ describe ".find" do
17
+ it "retrieves a specific order" do
18
+ order_id = 123
19
+ stub_veeqo_order_find_api(order_id)
20
+ order = Veeqo::Order.find(order_id)
21
+
22
+ expect(order.number).not_to be_nil
23
+ end
24
+ end
25
+
26
+ describe ".create" do
27
+ it "creates a new order" do
28
+ stub_veeqo_order_create_api(order_attributes)
29
+ order = Veeqo::Order.create(order_attributes)
30
+
31
+ expect(order.id).not_to be_nil
32
+ expect(order.deliver_to.first_name).to eq("Sky")
33
+ expect(order.payment.payment_type).not_to be_nil
34
+ end
35
+ end
36
+
37
+ describe ".update" do
38
+ it "updates the order with new attributes" do
39
+ order_id = 123
40
+ new_attributes = { number: "Inv #123" }
41
+
42
+ stub_veeqo_order_update_api(order_id, new_attributes)
43
+ order_update = Veeqo::Order.update(order_id, new_attributes)
44
+
45
+ expect(order_update.successful?).to be_truthy
46
+ end
47
+ end
48
+
49
+ describe ".delete" do
50
+ it "deletes a specific order" do
51
+ order_id = 123
52
+ stub_veeqo_order_delete_api(order_id)
53
+ order_delete = Veeqo::Order.delete(order_id)
54
+
55
+ expect(order_delete.successful?).to be_truthy
56
+ end
57
+ end
58
+
59
+ def order_attributes
60
+ {
61
+ channel_id: "3525",
62
+ customer_id: "516208",
63
+ delivery_method_id: "92298",
64
+ deliver_to_attributes: {
65
+ address1: "294 queenstown road",
66
+ city: "london",
67
+ country: "GB",
68
+ customer_id: "516208",
69
+ first_name: "Sky",
70
+ last_name: "Schonhuber",
71
+ phone: "07734450718",
72
+ state: "london",
73
+ zip: "sw8 4lt",
74
+ },
75
+ deliver_to_id: "1086864",
76
+ line_items_attributes: [
77
+ {
78
+ price_per_unit: "13.99",
79
+ quantity: "1",
80
+ sellable_id: "1226615",
81
+ tax_rate: "0",
82
+ },
83
+ ],
84
+ payment_attributes: {
85
+ payment_type: "bank_transfer",
86
+ reference_number: "123456789",
87
+ },
88
+ send_notification_email: "false",
89
+ total_discounts: "0",
90
+ total_tax: "0",
91
+ }
92
+ end
93
+ end
@@ -0,0 +1,82 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Veeqo::Product do
4
+ describe ".list" do
5
+ it "retrieve the lists of products" do
6
+ product_filters = { page_size: 10 }
7
+
8
+ stub_veeqo_product_list_api(product_filters)
9
+ products = Veeqo::Product.list(product_filters)
10
+
11
+ expect(products.count).to eq(1)
12
+ expect(products.first.id).not_to be_nil
13
+ end
14
+ end
15
+
16
+ describe ".find" do
17
+ it "retrieves the specific product" do
18
+ product_id = 123
19
+
20
+ stub_veeqo_product_find_api(product_id)
21
+ product = Veeqo::Product.find(product_id)
22
+
23
+ expect(product.id).to eq(product_id)
24
+ expect(product.title).not_to be_nil
25
+ end
26
+ end
27
+
28
+ describe ".create" do
29
+ it "creates a new product" do
30
+ stub_veeqo_product_create_api(product_attributes)
31
+ product = Veeqo::Product.create(product_attributes)
32
+
33
+ expect(product.id).not_to be_nil
34
+ expect(product.title).to eq("T-Shirt")
35
+ end
36
+ end
37
+
38
+ describe ".update" do
39
+ it "updates the product with new attributes" do
40
+ product_id = 123
41
+ new_attributes = { title: "Best T Shirt" }
42
+
43
+ stub_veeqo_product_update_api(product_id, new_attributes)
44
+ product_update = Veeqo::Product.update(product_id, new_attributes)
45
+
46
+ expect(product_update.successful?).to be_truthy
47
+ end
48
+ end
49
+
50
+ describe ".delete" do
51
+ it "deletes the specific product" do
52
+ product_id = 123
53
+ stub_veeqo_product_delete_api(product_id)
54
+ product_delete = Veeqo::Product.delete(product_id)
55
+
56
+ expect(product_delete.successful?).to be_truthy
57
+ end
58
+ end
59
+
60
+ def product_attributes
61
+ {
62
+ title: "T Shirt",
63
+ variants: [
64
+ {
65
+ cost_price: "10",
66
+ min_reorder_level: "0",
67
+ price: "15",
68
+ quantity_to_reorder: "0",
69
+ sku_code: "t-shirt-large",
70
+ tax_rate: "0",
71
+ title: "Large",
72
+ },
73
+ ],
74
+ images: [
75
+ {
76
+ display_position: "1",
77
+ src: "http://veeqo.com/t-shirt.jpg",
78
+ },
79
+ ],
80
+ }
81
+ end
82
+ end