vend 0.0.4

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 (65) hide show
  1. data/.gitignore +6 -0
  2. data/.travis.yml +4 -0
  3. data/Gemfile +6 -0
  4. data/README.rdoc +8 -0
  5. data/Rakefile +18 -0
  6. data/example.rb +51 -0
  7. data/lib/vend.rb +24 -0
  8. data/lib/vend/base.rb +200 -0
  9. data/lib/vend/base_factory.rb +34 -0
  10. data/lib/vend/client.rb +82 -0
  11. data/lib/vend/exception.rb +35 -0
  12. data/lib/vend/http_client.rb +119 -0
  13. data/lib/vend/logable.rb +9 -0
  14. data/lib/vend/null_logger.rb +9 -0
  15. data/lib/vend/pagination_info.rb +30 -0
  16. data/lib/vend/resource/customer.rb +11 -0
  17. data/lib/vend/resource/outlet.rb +7 -0
  18. data/lib/vend/resource/payment_type.rb +7 -0
  19. data/lib/vend/resource/product.rb +12 -0
  20. data/lib/vend/resource/register.rb +7 -0
  21. data/lib/vend/resource/register_sale.rb +19 -0
  22. data/lib/vend/resource/register_sale_product.rb +21 -0
  23. data/lib/vend/resource/tax.rb +7 -0
  24. data/lib/vend/resource/user.rb +7 -0
  25. data/lib/vend/resource_collection.rb +132 -0
  26. data/lib/vend/scope.rb +27 -0
  27. data/lib/vend/version.rb +3 -0
  28. data/spec/integration/customer_spec.rb +33 -0
  29. data/spec/integration/outlet_spec.rb +15 -0
  30. data/spec/integration/payment_types_spec.rb +15 -0
  31. data/spec/integration/product_spec.rb +76 -0
  32. data/spec/integration/register_sale_spec.rb +35 -0
  33. data/spec/integration/register_spec.rb +16 -0
  34. data/spec/integration/tax_spec.rb +16 -0
  35. data/spec/integration/user_spec.rb +16 -0
  36. data/spec/mock_responses/customers.find_by_email.json +44 -0
  37. data/spec/mock_responses/customers.json +20 -0
  38. data/spec/mock_responses/outlets.json +14 -0
  39. data/spec/mock_responses/payment_types.json +7 -0
  40. data/spec/mock_responses/products.active.since.json +184 -0
  41. data/spec/mock_responses/products.json +115 -0
  42. data/spec/mock_responses/products/page/1.json +130 -0
  43. data/spec/mock_responses/products/page/2.json +130 -0
  44. data/spec/mock_responses/register_sales.find_by_state.json +324 -0
  45. data/spec/mock_responses/register_sales.json +158 -0
  46. data/spec/mock_responses/register_sales/2e658bce-9627-bc27-d77d-6c9ba2e8216e.json +158 -0
  47. data/spec/mock_responses/registers.json +32 -0
  48. data/spec/mock_responses/taxes.json +7 -0
  49. data/spec/mock_responses/users.json +17 -0
  50. data/spec/spec_helper.rb +16 -0
  51. data/spec/support/matchers/have_attributes.rb +11 -0
  52. data/spec/support/shared_examples/integration.rb +79 -0
  53. data/spec/support/shared_examples/logger.rb +25 -0
  54. data/spec/vend/base_factory_spec.rb +48 -0
  55. data/spec/vend/base_spec.rb +348 -0
  56. data/spec/vend/client_spec.rb +93 -0
  57. data/spec/vend/http_client_spec.rb +129 -0
  58. data/spec/vend/null_logger_spec.rb +5 -0
  59. data/spec/vend/pagination_info_spec.rb +48 -0
  60. data/spec/vend/resource/register_sale_product_spec.rb +27 -0
  61. data/spec/vend/resource/register_sale_spec.rb +24 -0
  62. data/spec/vend/resource_collection_spec.rb +312 -0
  63. data/spec/vend/scope_spec.rb +41 -0
  64. data/vend.gemspec +26 -0
  65. metadata +179 -0
@@ -0,0 +1,3 @@
1
+ module Vend #:nodoc:
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vend::Resource::Customer do
4
+
5
+ let(:expected_attributes) do
6
+ {
7
+ 'id' => '6cbfbc20-3d5f-11e0-8697-4040f540b50a',
8
+ 'customer_code' => 'WALKIN',
9
+ 'name' => ''
10
+ }
11
+ end
12
+
13
+ let(:client) do
14
+ Vend::Client.new('foo', 'bar', 'baz')
15
+ end
16
+
17
+ let(:expected_collection_length) { 1 }
18
+
19
+ specify { client.Customer.should respond_to(:find_by_email) }
20
+ specify { client.Customer.should respond_to(:find_by_name) }
21
+
22
+ it "returns a collection of customers from a search" do
23
+ stub_request(:get, "https://bar:baz@foo.vendhq.com/api/customers?email=foo@example.com").
24
+ to_return(:status => 200, :body => get_mock_response('customers.find_by_email.json'))
25
+
26
+ collection = client.Customer.find_by_email('foo@example.com')
27
+ collection.first.should be_a Vend::Resource::Customer
28
+ collection.first.email.should == 'foo@example.com'
29
+ end
30
+
31
+ it_should_behave_like "a resource with a collection GET endpoint"
32
+
33
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vend::Resource::Outlet do
4
+
5
+ let(:expected_attributes) do
6
+ {
7
+ 'id' => '6cb5c88c-3d5f-11e0-8697-4040f540b50a',
8
+ 'name' => 'Main Outlet',
9
+ }
10
+ end
11
+
12
+ let(:expected_collection_length) { 1 }
13
+
14
+ it_should_behave_like "a resource with a collection GET endpoint"
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vend::Resource::PaymentType do
4
+
5
+ let(:expected_attributes) do
6
+ {
7
+ 'id' => '6cde3ba0-3d5f-11e0-8697-4040f540b50a',
8
+ 'name' => 'Cash'
9
+ }
10
+ end
11
+
12
+ let(:expected_collection_length) { 1 }
13
+
14
+ it_should_behave_like "a resource with a collection GET endpoint"
15
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vend::Resource::Product do
4
+
5
+ let(:expected_attributes) do
6
+ {
7
+ 'id' => '6cc53042-3d5f-11e0-8697-4040f540b50a',
8
+ 'handle' => 'tshirt',
9
+ 'supply_price' => 2.00,
10
+ 'name' => 'T-shirt (Demo)'
11
+ }
12
+ end
13
+
14
+ let(:expected_collection_length) { 2 }
15
+
16
+ it_should_behave_like "a resource with a collection GET endpoint"
17
+ it_should_behave_like "a resource with a DELETE endpoint"
18
+
19
+ describe "pagination" do
20
+
21
+ let(:username) {"foo"}
22
+ let(:password) {"bar"}
23
+ let(:store) {"baz"}
24
+
25
+ let(:client) do
26
+ Vend::Client.new(store, username, password)
27
+ end
28
+
29
+ before do
30
+ stub_request( :get,
31
+ "https://#{username}:#{password}@#{store}.vendhq.com/api/products"
32
+ ).to_return(
33
+ :status => 200, :body => get_mock_response('products/page/1.json')
34
+ )
35
+ stub_request( :get,
36
+ "https://#{username}:#{password}@#{store}.vendhq.com/api/products/page/2"
37
+ ).to_return(
38
+ :status => 200, :body => get_mock_response('products/page/2.json')
39
+ )
40
+ end
41
+
42
+ it "returns paginated results" do
43
+ client.Product.all.count.should == 4
44
+ end
45
+
46
+ it "returns the first result" do
47
+ collection = client.Product.all
48
+ end
49
+ end
50
+
51
+ describe "chaining" do
52
+ let(:username) {"foo"}
53
+ let(:password) {"bar"}
54
+ let(:store) {"baz"}
55
+
56
+ let(:timestamp) { Time.new(2012,7,5,11,12,13) }
57
+
58
+ let(:client) do
59
+ Vend::Client.new(store, username, password)
60
+ end
61
+
62
+ before do
63
+ stub_request( :get,
64
+ "https://#{username}:#{password}@#{store}.vendhq.com/api/products/active/1/since/2012-07-05+11:12:13"
65
+ ).to_return(
66
+ :status => 200, :body => get_mock_response('products.active.since.json')
67
+ )
68
+ end
69
+
70
+ it "allows scope chaining" do
71
+ client.Product.active(1).since(timestamp).count.should == 3
72
+ end
73
+
74
+
75
+ end
76
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vend::Resource::RegisterSale do
4
+
5
+ let(:expected_attributes) do
6
+ {
7
+ 'id' => '98ce3dbf-e862-c811-fa93-10f6db3a8f66',
8
+ 'register_id' => '6cbe2342-3d5f-11e0-8697-4040f540b50a',
9
+ 'market_id' => '1'
10
+ }
11
+ end
12
+
13
+ let(:client) do
14
+ Vend::Client.new('foo', 'bar', 'baz')
15
+ end
16
+
17
+ let(:id) { '2e658bce-9627-bc27-d77d-6c9ba2e8216e' }
18
+
19
+ let(:expected_collection_length) { 1 }
20
+
21
+ it_should_behave_like "a resource with a singular GET endpoint"
22
+ it_should_behave_like "a resource with a collection GET endpoint"
23
+
24
+ specify "register_sales are findable by state" do
25
+ client.RegisterSale.should respond_to(:find_by_state)
26
+
27
+ stub_request(:get, "https://bar:baz@foo.vendhq.com/api/register_sales?status[]=OPEN&status[]=CLOSED").
28
+ to_return(:status => 200, :body => get_mock_response('register_sales.find_by_state.json'))
29
+
30
+ collection = client.RegisterSale.find_by_state([:OPEN, :CLOSED])
31
+ collection.first.should be_a Vend::Resource::RegisterSale
32
+ collection.first.id.should == "8dd57077-c158-f7db-d582-6785f43c9d72"
33
+ collection.first.register_sale_products.count.should == 2
34
+ end
35
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vend::Resource::Register do
4
+
5
+ let(:expected_attributes) do
6
+ {
7
+ 'id' => '6cbe2342-3d5f-11e0-8697-4040f540b50a',
8
+ 'receipt_header' => '<h1>Trineo Dev Account<h1>',
9
+ 'name' => 'Main Register'
10
+ }
11
+ end
12
+
13
+ let(:expected_collection_length) { 1 }
14
+
15
+ it_should_behave_like "a resource with a collection GET endpoint"
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vend::Resource::Tax do
4
+
5
+ let(:expected_attributes) do
6
+ {
7
+ 'id' => '53b3501c-887c-102d-8a4b-a9cf13f17faa',
8
+ 'default' => 1,
9
+ 'rate' => 0.15
10
+ }
11
+ end
12
+
13
+ let(:expected_collection_length) { 1 }
14
+
15
+ it_should_behave_like "a resource with a collection GET endpoint"
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vend::Resource::User do
4
+
5
+ let(:expected_attributes) do
6
+ {
7
+ 'id' => '6ce4286c-3d5f-11e0-8697-4040f540b50a',
8
+ 'username' => 'user@example.com',
9
+ 'name' => 'A cashier'
10
+ }
11
+ end
12
+
13
+ let(:expected_collection_length) { 2 }
14
+
15
+ it_should_behave_like "a resource with a collection GET endpoint"
16
+ end
@@ -0,0 +1,44 @@
1
+ {
2
+ "customers" : [ {
3
+ "id": "7bb8d1c7-58f5-11e1-8cd4-4040dde94e2e",
4
+ "name": "Foo Bar",
5
+ "customer_code": "Foo-9F7N",
6
+ "customer_group_id": "6cbee822-3d5f-11e0-8697-4040f540b50a",
7
+ "customer_group_name": "All Customers",
8
+ "first_name": "Foo",
9
+ "last_name": "Bar",
10
+ "company_name": "",
11
+ "phone": "",
12
+ "mobile": "",
13
+ "fax": "",
14
+ "email": "foo@example.com",
15
+ "twitter": "",
16
+ "website" : "",
17
+ "physical_address1": "",
18
+ "physical_address2": "",
19
+ "physical_suburb": "",
20
+ "physical_city": "",
21
+ "physical_postcode": "",
22
+ "physical_state": "",
23
+ "physical_country_id": "NZ",
24
+ "postal_address1": "",
25
+ "postal_address2": "",
26
+ "postal_suburb": "",
27
+ "postal_city": "",
28
+ "postal_postcode": "",
29
+ "postal_state": "",
30
+ "postal_country_id" : "NZ", "updated_at": "2012-02-16 23:22:54",
31
+ "deleted_at": "",
32
+ "balance": "0.000",
33
+ "year_to_date": "0.00000",
34
+ "points": "0",
35
+ "custom_field_1": "",
36
+ "custom_field_2": "",
37
+ "custom_field_3": "",
38
+ "custom_field_4": "",
39
+ "contact": {
40
+ "company_name": "",
41
+ "phone": "",
42
+ "email": "foo@example.com" }
43
+ } ]
44
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "customers" : [ {
3
+ "id": "6cbfbc20-3d5f-11e0-8697-4040f540b50a",
4
+ "name": "",
5
+ "customer_code": "WALKIN",
6
+ "customer_group_id": "6cbee822-3d5f-11e0-8697-4040f540b50a",
7
+ "customer_group_name": "All Customers",
8
+ "updated_at": "2011-02-21 02:08:07",
9
+ "deleted_at": "",
10
+ "balance": "0.000",
11
+ "year_to_date": "0.00000",
12
+ "points": "0",
13
+ "custom_field_1": "",
14
+ "custom_field_2": "",
15
+ "custom_field_3": "",
16
+ "custom_field_4": "",
17
+ "contact": {
18
+ }
19
+ } ]
20
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "outlets" : [ {
3
+ "id": "6cb5c88c-3d5f-11e0-8697-4040f540b50a",
4
+ "name": "Main Outlet",
5
+ "email": "",
6
+ "physical_address1": "",
7
+ "physical_address2": "",
8
+ "physical_suburb": "",
9
+ "physical_city": "",
10
+ "physical_postcode": "",
11
+ "physical_state": "",
12
+ "physical_country_id" : ""
13
+ } ]
14
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "payment_types": [{
3
+ "id": "6cde3ba0-3d5f-11e0-8697-4040f540b50a",
4
+ "name": "Cash",
5
+ "payment_type_id": "1",
6
+ "config": {} } ]
7
+ }
@@ -0,0 +1,184 @@
1
+ {
2
+ "products" : [
3
+ {
4
+ "variant_option_three_value" : "",
5
+ "variant_option_three_name" : "",
6
+ "account_code_purchase" : "",
7
+ "id" : "92a6ea40-c975-11e1-8d73-4040782fde00",
8
+ "variant_source_id" : "",
9
+ "variant_option_two_value" : "",
10
+ "image_large" : "https://trineodev.vendhq.com/images/placeholder/product/no-image-white-original.png",
11
+ "source_id" : "",
12
+ "brand_name" : "",
13
+ "active" : true,
14
+ "name" : "malc dummy product 0",
15
+ "description" : "",
16
+ "price_book_entries" : [
17
+ {
18
+ "valid_from" : "",
19
+ "max_units" : "",
20
+ "product_id" : "92a6ea40-c975-11e1-8d73-4040782fde00",
21
+ "customer_group_id" : "6cbee822-3d5f-11e0-8697-4040f540b50a",
22
+ "id" : "92baa2ae-c975-11e1-8d73-4040782fde00",
23
+ "valid_to" : "",
24
+ "outlet_id" : "",
25
+ "display_retail_price_tax_inclusive" : "1",
26
+ "price_book_name" : "General price book (All)",
27
+ "tax" : 16.1,
28
+ "outlet_name" : "",
29
+ "customer_group_name" : "All Customers",
30
+ "tax_rate" : "0.15",
31
+ "price_book_id" : "6cc0a162-3d5f-11e0-8697-4040f540b50a",
32
+ "tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
33
+ "type" : "BASE",
34
+ "price" : 107.35,
35
+ "tax_name" : "NZ GST",
36
+ "min_units" : ""
37
+ }
38
+ ],
39
+ "tax_rate" : 0.15,
40
+ "handle" : "malc_dummy_0",
41
+ "updated_at" : "2012-07-09 03:24:20",
42
+ "price" : 107.35,
43
+ "type" : "",
44
+ "account_code_sales" : "",
45
+ "sku" : "MD1",
46
+ "brand_id" : "",
47
+ "variant_option_one_name" : "",
48
+ "supplier_code" : "",
49
+ "inventory" : [],
50
+ "supply_price" : "0.00",
51
+ "display_retail_price_tax_inclusive" : "1",
52
+ "tax" : 16.1,
53
+ "tags" : "",
54
+ "image" : "https://trineodev.vendhq.com/images/placeholder/product/no-image-white-thumb.png",
55
+ "variant_option_one_value" : "",
56
+ "supplier_name" : "",
57
+ "deleted_at" : "",
58
+ "variant_parent_id" : "",
59
+ "tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
60
+ "tax_name" : "NZ GST",
61
+ "variant_option_two_name" : ""
62
+ },
63
+ {
64
+ "variant_option_three_value" : "",
65
+ "variant_option_three_name" : "",
66
+ "account_code_purchase" : "",
67
+ "id" : "c89d0384-c975-11e1-8d73-4040782fde00",
68
+ "variant_source_id" : "",
69
+ "variant_option_two_value" : "",
70
+ "image_large" : "https://trineodev.vendhq.com/images/placeholder/product/no-image-white-original.png",
71
+ "source_id" : "",
72
+ "brand_name" : "",
73
+ "active" : true,
74
+ "name" : "malc dummy product 1",
75
+ "description" : "",
76
+ "price_book_entries" : [
77
+ {
78
+ "valid_from" : "",
79
+ "max_units" : "",
80
+ "product_id" : "c89d0384-c975-11e1-8d73-4040782fde00",
81
+ "customer_group_id" : "6cbee822-3d5f-11e0-8697-4040f540b50a",
82
+ "id" : "c8afc654-c975-11e1-8d73-4040782fde00",
83
+ "valid_to" : "",
84
+ "outlet_id" : "",
85
+ "display_retail_price_tax_inclusive" : "1",
86
+ "price_book_name" : "General price book (All)",
87
+ "tax" : 16.1,
88
+ "outlet_name" : "",
89
+ "customer_group_name" : "All Customers",
90
+ "tax_rate" : "0.15",
91
+ "price_book_id" : "6cc0a162-3d5f-11e0-8697-4040f540b50a",
92
+ "tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
93
+ "type" : "BASE",
94
+ "price" : 107.35,
95
+ "tax_name" : "NZ GST",
96
+ "min_units" : ""
97
+ }
98
+ ],
99
+ "tax_rate" : 0.15,
100
+ "handle" : "malc_dummy_1",
101
+ "updated_at" : "2012-07-09 03:25:51",
102
+ "price" : 107.35,
103
+ "type" : "",
104
+ "account_code_sales" : "",
105
+ "sku" : "MD1",
106
+ "brand_id" : "",
107
+ "variant_option_one_name" : "",
108
+ "supplier_code" : "",
109
+ "inventory" : [],
110
+ "supply_price" : "0.00",
111
+ "display_retail_price_tax_inclusive" : "1",
112
+ "tax" : 16.1,
113
+ "tags" : "",
114
+ "image" : "https://trineodev.vendhq.com/images/placeholder/product/no-image-white-thumb.png",
115
+ "variant_option_one_value" : "",
116
+ "supplier_name" : "",
117
+ "deleted_at" : "",
118
+ "variant_parent_id" : "",
119
+ "tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
120
+ "tax_name" : "NZ GST",
121
+ "variant_option_two_name" : ""
122
+ },
123
+ {
124
+ "variant_option_three_value" : "",
125
+ "variant_option_three_name" : "",
126
+ "account_code_purchase" : "",
127
+ "id" : "c9ae81bf-c975-11e1-8d73-4040782fde00",
128
+ "variant_source_id" : "",
129
+ "variant_option_two_value" : "",
130
+ "image_large" : "https://trineodev.vendhq.com/images/placeholder/product/no-image-white-original.png",
131
+ "source_id" : "",
132
+ "brand_name" : "",
133
+ "active" : true,
134
+ "name" : "malc dummy product 2",
135
+ "description" : "",
136
+ "price_book_entries" : [
137
+ {
138
+ "valid_from" : "",
139
+ "max_units" : "",
140
+ "product_id" : "c9ae81bf-c975-11e1-8d73-4040782fde00",
141
+ "customer_group_id" : "6cbee822-3d5f-11e0-8697-4040f540b50a",
142
+ "id" : "c9cd8cea-c975-11e1-8d73-4040782fde00",
143
+ "valid_to" : "",
144
+ "outlet_id" : "",
145
+ "display_retail_price_tax_inclusive" : "1",
146
+ "price_book_name" : "General price book (All)",
147
+ "tax" : 16.1,
148
+ "outlet_name" : "",
149
+ "customer_group_name" : "All Customers",
150
+ "tax_rate" : "0.15",
151
+ "price_book_id" : "6cc0a162-3d5f-11e0-8697-4040f540b50a",
152
+ "tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
153
+ "type" : "BASE",
154
+ "price" : 107.35,
155
+ "tax_name" : "NZ GST",
156
+ "min_units" : ""
157
+ }
158
+ ],
159
+ "tax_rate" : 0.15,
160
+ "handle" : "malc_dummy_2",
161
+ "updated_at" : "2012-07-09 03:25:53",
162
+ "price" : 107.35,
163
+ "type" : "",
164
+ "account_code_sales" : "",
165
+ "sku" : "MD2",
166
+ "brand_id" : "",
167
+ "variant_option_one_name" : "",
168
+ "supplier_code" : "",
169
+ "inventory" : [],
170
+ "supply_price" : "0.00",
171
+ "display_retail_price_tax_inclusive" : "1",
172
+ "tax" : 16.1,
173
+ "tags" : "",
174
+ "image" : "https://trineodev.vendhq.com/images/placeholder/product/no-image-white-thumb.png",
175
+ "variant_option_one_value" : "",
176
+ "supplier_name" : "",
177
+ "deleted_at" : "",
178
+ "variant_parent_id" : "",
179
+ "tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
180
+ "tax_name" : "NZ GST",
181
+ "variant_option_two_name" : ""
182
+ }
183
+ ]
184
+ }