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,4 @@
1
+ Veeqo.configure do |config|
2
+ config.api_host = "https://api.veeqo.com"
3
+ config.api_key = "SECRET_API_KEY"
4
+ end
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in veeqo.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Abu Nashir
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,574 @@
1
+ # Veeqo
2
+
3
+ [![Build
4
+ Status](https://travis-ci.org/abunashir/veeqo.svg?branch=master)](https://travis-ci.org/abunashir/veeqo)
5
+ [![Code
6
+ Climate](https://codeclimate.com/github/abunashir/veeqo/badges/gpa.svg)](https://codeclimate.com/github/abunashir/veeqo)
7
+
8
+ The Ruby Interface to the Veeqo API
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem "veeqo"
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ ```sh
21
+ bundle install
22
+ ```
23
+
24
+ ## Configure
25
+
26
+ Follow [these simple steps] to get up and running with the Veeqo API. Once you
27
+ have your API key then you can configure it by adding an initializer with the
28
+ following code
29
+
30
+ ```ruby
31
+ Veeqo.configure do |config|
32
+ config.api_key = "SECRET_API_KEY"
33
+ end
34
+ ```
35
+
36
+ Or
37
+
38
+ ```ruby
39
+ Veeqo.configuration.api_key = "SECRET_API_KEY"
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ ### Order
45
+
46
+ Resources related to the orders in the API.
47
+
48
+ #### List orders
49
+
50
+ ```ruby
51
+ Veeqo::Order.list(
52
+ page: 1,
53
+ page_size: 25,
54
+ since_id: since_id,
55
+ status: "awaiting_fulfillment",
56
+ created_at_min: "2017-01-01 11:10:01",
57
+ updated_at_min: "2017-01-01 11:10:01",
58
+ )
59
+ ```
60
+
61
+ #### Create a new order
62
+
63
+ ```ruby
64
+ # Create a new order for customer
65
+ #
66
+ # Please pay close attention to the argumetns construction.
67
+ # Some attrbitues require some nested attributes, that's why
68
+ # we've extracted those to make it easier to understand, but
69
+ # you don't have to do it unelss you prefer a clean code :)
70
+
71
+ Veeqo::Order.create(
72
+ channel_id: store_id,
73
+ customer_id: customer_id,
74
+ delivery_method_id: deliver_method_id,
75
+ deliver_to_id: deliver_to_id,
76
+ total_discounts: 0,
77
+ total_tax: 0,
78
+ due_date: "",
79
+ send_notification_email: false,
80
+ deliver_to_attributes: deliver_to_attributes,
81
+ line_items_attributes: [line_item_one_attributes]
82
+ payment_attributes: payment_attributes,
83
+ )
84
+
85
+ # Delivery Attributes
86
+ #
87
+ # This includes the details attributes to specify the
88
+ # delivery details for that specific order.
89
+
90
+ deliver_to_attributes = {
91
+ address1: "294 queenstown road",
92
+ address2: "",
93
+ city: "london",
94
+ company: "",
95
+ country: "GB",
96
+ customer_id: customer_id,
97
+ first_name: "Sky",
98
+ last_name: "Schonhuber",
99
+ phone: "07734450718",
100
+ state: "london",
101
+ zip: "sw8 4lt",
102
+ }
103
+
104
+ # Line Item Attributes
105
+ #
106
+ # This includes the details about a specific
107
+ # Line items for the new order
108
+
109
+ line_item_one_attributes = {
110
+ price_per_unit: 13.99,
111
+ quantity: "1",
112
+ sellable_id: 1226615,
113
+ tax_rate: 0
114
+ }
115
+
116
+ # Payment Attributes
117
+ #
118
+ # Include the payment details with the order
119
+
120
+ payment_attributes = {
121
+ payment_type: "bank_transfer",
122
+ reference_number: "123456789",
123
+ }
124
+ ```
125
+
126
+ #### View an order details
127
+
128
+ ```ruby
129
+ Veeqo::Order.find(order_id)
130
+ ```
131
+
132
+ #### Update order details
133
+
134
+ ```ruby
135
+ Veeqo::Order.update(order_id, new_attributes)
136
+ ```
137
+
138
+ #### Delete an order
139
+
140
+ ```ruby
141
+ Veeqo::Order.delete(order_id)
142
+ ```
143
+
144
+ ### Allocation
145
+
146
+ Resources related to the allocations in the API. This allocates a set of stock
147
+ item to a specific order. To allocate stock to an order, the item must be added
148
+ as a line item within that order and not be allocated already.
149
+
150
+ #### Create a new allocation
151
+
152
+ ```ruby
153
+ Veeqo::Allocation.create(
154
+ order_id: 123_456,
155
+ warehouse_id: 456_789,
156
+ line_items: [{
157
+ quantity: 1,
158
+ sellable_id: 123_456,
159
+ }],
160
+ )
161
+ ```
162
+
163
+ #### Update a allocation details
164
+
165
+ ```ruby
166
+ Veeqo::Allocation.update(
167
+ allocation_id,
168
+ order_id: 123_456,
169
+ warehouse_id: 456_789,
170
+ line_items: [{
171
+ quantity: 2,
172
+ sellable_id: 123_456,
173
+ }],
174
+ )
175
+ ```
176
+
177
+ #### Delete an existing allocation
178
+
179
+ ```ruby
180
+ Veeqo::Allocation.delete(order_id, allocation_id)
181
+ ```
182
+
183
+ ### Product
184
+
185
+ Resources related to the products in the API.
186
+
187
+ #### List all products
188
+
189
+ ```ruby
190
+ Veeqo::Product.list(
191
+ since_id: 123_45, page: 1, page_size: 12
192
+ )
193
+ ```
194
+
195
+ #### Create a new product
196
+
197
+ ```ruby
198
+ # Create a new product
199
+ #
200
+ # Pay close attension to the argument constructions. It
201
+ # simlify the process, and the `variants` and `images`
202
+ # supports mutiple item, and we can pass those as an
203
+ # array, please check the example bellow for inspiration
204
+
205
+ Veeqo::Product.create(
206
+ title: "T Shirt",
207
+ description: "The best t-shirt!",
208
+ estimated_delivery: 3,
209
+ notes: "This is a limited addtion!",
210
+ variants: [variant_one_attributes],
211
+ images: [image_one_attributes],
212
+ )
213
+
214
+ # Variant attributes
215
+ variant_one_attributes = {
216
+ cost_price: "10",
217
+ min_reorder_level: "0",
218
+ price: "15",
219
+ quantity_to_reorder: "0",
220
+ sku_code: "t-shirt-large",
221
+ tax_rate: "0",
222
+ title: "Large",
223
+ }
224
+
225
+ # Image attributes
226
+ image_one_attributes = {
227
+ display_position: "1"
228
+ src: "http://veeqo.com/t-shirt.jpg",
229
+ }
230
+ ```
231
+
232
+ #### View a product details
233
+
234
+ ```ruby
235
+ Veeqo::Product.find(product_id)
236
+ ```
237
+
238
+ #### Update product details
239
+
240
+ ```ruby
241
+ Veeqo::Product.update(product_id, new_attributes)
242
+ ```
243
+
244
+ #### Delete a product
245
+
246
+ ```ruby
247
+ Veeqo::Product.delete(product_id)
248
+ ```
249
+
250
+ ### Purchase Orders
251
+
252
+ Resources related to the purchase orders in the API.
253
+
254
+ #### List purchase orders
255
+
256
+ ```ruby
257
+ Veeqo::PurchaseOrder.list(
258
+ page: 1, page_size: 12, show_complete: false
259
+ )
260
+ ```
261
+
262
+ ### Suppliers
263
+
264
+ Resources related to the suppliers in the API.
265
+
266
+ #### List all suppliers
267
+
268
+ ```ruby
269
+ Veeqo::Supplier.list(page: 1, page_size: 12)
270
+ ```
271
+
272
+ #### Create a new supplier
273
+
274
+ ```ruby
275
+ Veeqo::Supplier.create(name: "ACME")
276
+ ```
277
+
278
+ #### View a supplier details
279
+
280
+ ```ruby
281
+ Veeqo::Supplier.find(supplier_id)
282
+ ```
283
+
284
+ #### Update a supplier details
285
+
286
+ ```ruby
287
+ Veeqo::Supplier.update(supplier_id, new_attributes_hash)
288
+ ```
289
+
290
+ #### Delete a supplier
291
+
292
+ ```ruby
293
+ Veeqo::Supplier.delete(supplier_id)
294
+ ```
295
+
296
+ ### Company
297
+
298
+ Information about current company
299
+
300
+ #### View company details
301
+
302
+ ```ruby
303
+ Veeqo::Company.find
304
+ ```
305
+
306
+ #### Update company details
307
+
308
+ ```ruby
309
+ Veeqo::Company.update(new_attributes_hash)
310
+ ```
311
+
312
+ ### Warehouse
313
+
314
+ Resources related to the warehouses in the API.
315
+
316
+ #### List all warehouses
317
+
318
+ ```ruby
319
+ Veeqo::Warehouse.list(page: 1, page_size: 12)
320
+ ```
321
+
322
+ #### Create a new warehouse
323
+
324
+ ```ruby
325
+ Veeqo::Warehouse.create(name: "My Warehouse")
326
+ ```
327
+
328
+ #### View a warehouse details
329
+
330
+ ```ruby
331
+ Veeqo::Warehouse.find(warehouse_id)
332
+ ```
333
+
334
+ #### Update a warehouse details
335
+
336
+ ```ruby
337
+ Veeqo::Warehouse.update(warehouse_id, new_attributes_hash)
338
+ ```
339
+
340
+ #### Delete a warehouse
341
+
342
+ ```ruby
343
+ Veeqo::Warehouse.delete(warehouse_id)
344
+ ```
345
+
346
+ ### Customer
347
+
348
+ Resources related to the customers in the API.
349
+
350
+ #### List all customers
351
+
352
+ ```ruby
353
+ Veeqo::Customer.list(page: 1, page_size: 12)
354
+ ```
355
+
356
+ #### Create a customer
357
+
358
+ ```ruby
359
+ Veeqo::Customer.create(
360
+ email: "customer@example.com",
361
+ phone: "01792 720740",
362
+ mobile: "07329023903",
363
+ billing_address_attributes: {
364
+ first_name: "John",
365
+ last_name: "Doe",
366
+ company: "FooBar Ltd",
367
+ address1: "221 High Street Lane",
368
+ city: "Swansea",
369
+ country: "GB",
370
+ zip: "SA1 1NW",
371
+ }
372
+ )
373
+ ```
374
+
375
+ #### View a customer details
376
+
377
+ ```ruby
378
+ Veeqo::Customer.find(customer_id)
379
+ ```
380
+
381
+ #### Update a customer details
382
+
383
+ ```ruby
384
+ Veeqo::Customer.update(
385
+ customer_id, new_attributes_hash
386
+ )
387
+ ```
388
+
389
+ #### Delete a customer
390
+
391
+ ```ruby
392
+ Veeqo::Customer.delete(customer_id)
393
+ ```
394
+
395
+ ### Store
396
+
397
+ Resources related to the stores in the API.
398
+
399
+ #### List all stores
400
+
401
+ ```ruby
402
+ Veeqo::Store.list(page: 1, page_size: 12)
403
+ ```
404
+
405
+ #### Create a new store
406
+
407
+ ```ruby
408
+ Veeqo::Store.create(name: "Phone", type_code: "direct")
409
+ ```
410
+
411
+ #### View a store details
412
+
413
+ ```ruby
414
+ Veeqo::Store.find(store_id)
415
+ ```
416
+
417
+ #### Update a store details
418
+
419
+ ```ruby
420
+ Veeqo::Store.update(store_id, new_attributes_hash)
421
+ ```
422
+
423
+ #### Delete a store
424
+
425
+ ```ruby
426
+ Veeqo::Store.delete(store_id)
427
+ ```
428
+
429
+ ### Delivery Method
430
+
431
+ Resources related to the delivery methods in the API
432
+
433
+ #### List all delivery methods
434
+
435
+ ```ruby
436
+ Veeqo::DeliveryMethod.list(page: 1, page_size: 12)
437
+ ```
438
+
439
+ #### Create a delivery method
440
+
441
+ ```ruby
442
+ Veeqo::DeliveryMethod.create(name: "Next Day Delivery")
443
+ ```
444
+
445
+ #### View a delivery method details
446
+
447
+ ```ruby
448
+ Veeqo::DeliveryMethod.find(delivery_method_id)
449
+ ```
450
+
451
+ #### Update a delivery method
452
+
453
+ ```ruby
454
+ Veeqo::DeliveryMethod.update(delivery_method_id, new_attributes_hash)
455
+ ```
456
+
457
+ #### Delete a delivery method
458
+
459
+ ```ruby
460
+ Veeqo::DeliveryMethod.delete(delivery_method_id)
461
+ ```
462
+
463
+ ### Shipment
464
+
465
+ Information about creating shipments in the API. Please follow the [shipment doc]
466
+ regarding the `carrier_id` or other details.
467
+
468
+ #### Create a shipment
469
+
470
+ ```ruby
471
+ # Create a new shipment
472
+ #
473
+ # Please pay close attention to the construciton of
474
+ # the arugments, This simplified some attrbitues, so
475
+ # the developer does not need to worry about the too
476
+ # much details on how it needs to structured.
477
+
478
+ Veeqo::Shipment.create(
479
+ order_id: 1,
480
+ allocation_id: 1,
481
+ shipment: {
482
+ carrier_id: 3,
483
+ notify_customer: false,
484
+ update_remote_order: false,
485
+ tracking_number: "12345679ABC",
486
+ },
487
+ )
488
+ ```
489
+
490
+ #### Delete a shipment
491
+
492
+ ```ruby
493
+ Veeqo::Shipment.delete(shipment_id)
494
+ ```
495
+
496
+ ## Development
497
+
498
+ We are following Sandi Metz's Rules for this gem, you can read the
499
+ [description of the rules here] (http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers).
500
+ All new code should follow these rules. If you make changes in a pre-existing
501
+ file that violates these rules you should fix the violations as part of your
502
+ contribution.
503
+
504
+ ### Setup
505
+
506
+ Clone the repository.
507
+
508
+ ```sh
509
+ git clone https://github.com/abunashir/veeqo
510
+ ```
511
+
512
+ Setup your environment.
513
+
514
+ ```sh
515
+ bin/setup
516
+ ```
517
+
518
+ Run the test suite
519
+
520
+ ```sh
521
+ bin/rspec
522
+ ```
523
+
524
+ ### Play Box
525
+
526
+ The API Play Box provides an interactive console so we can easily test out the
527
+ actual API interaction. But before moving forward let's configure the key and
528
+ API host (In case you wanna test on a mock server).
529
+
530
+ Setup the client configuration.
531
+
532
+ ```sh
533
+ cp .sample.pryrc .pryrc
534
+ vim .pryrc
535
+ ```
536
+
537
+ Start the console.
538
+
539
+ ```sh
540
+ bin/console
541
+ ```
542
+
543
+ Start playing with it.
544
+
545
+ ```ruby
546
+ Veeqo::Order.list
547
+ ```
548
+
549
+ ## Contributing
550
+
551
+ First, thank you for contributing! We love pull requests from everyone. By
552
+ participating in this project, you hereby grant the right to grant or transfer
553
+ an unlimited number of non exclusive licenses or sub-licenses to third parties,
554
+ under the copyright covering the contribution to use the contribution by all
555
+ means.
556
+
557
+ Here are a few technical guidelines to follow:
558
+
559
+ 1. Open an [issue][issues] to discuss a new feature.
560
+ 1. Write tests to support your new feature.
561
+ 1. Make sure the entire test suite passes locally and on CI.
562
+ 1. Open a Pull Request.
563
+ 1. [Squash your commits][squash] after receiving feedback.
564
+ 1. Party!
565
+
566
+ [issues]: https://github.com/abunashir/veeqo/issues
567
+ [squash]: https://github.com/thoughtbot/guides/tree/master/protocol/git#write-a-feature
568
+
569
+ ## License
570
+
571
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
572
+
573
+ [these simple steps]: http://docs.veeqo.apiary.io/#introduction/getting-started
574
+ [shipment doc]: http://docs.veeqo.apiary.io/#reference/shipments