buckybox-api 1.6.2 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.gitlab-ci.yml +20 -0
- data/.rubocop.yml +29 -0
- data/.simplecov +1 -0
- data/Gemfile +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +1 -0
- data/Rakefile +1 -1
- data/buckybox-api.gemspec +12 -10
- data/fixtures/authenticate_customer.yml +60 -0
- data/fixtures/box.yml +63 -0
- data/fixtures/boxes.yml +70 -0
- data/fixtures/create_or_update_customer.yml +62 -0
- data/fixtures/create_order.yml +62 -0
- data/fixtures/customer.yml +60 -0
- data/fixtures/customers.yml +60 -0
- data/fixtures/delivery_service.yml +60 -0
- data/fixtures/delivery_services.yml +60 -0
- data/fixtures/webstore.yml +78 -0
- data/lib/buckybox/api.rb +70 -37
- data/spec/lib/buckybox/api_spec.rb +35 -25
- data/spec/spec_helper.rb +14 -6
- metadata +58 -18
@@ -0,0 +1,60 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.buckybox.com/v1/customers/8859?embed=address
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Api-Key:
|
11
|
+
- "<API-Key>"
|
12
|
+
Api-Secret:
|
13
|
+
- "<API-Secret>"
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Date:
|
20
|
+
- Thu, 11 Aug 2016 11:17:12 GMT
|
21
|
+
Content-Type:
|
22
|
+
- application/json; charset=utf-8
|
23
|
+
Transfer-Encoding:
|
24
|
+
- chunked
|
25
|
+
Connection:
|
26
|
+
- keep-alive
|
27
|
+
X-Ua-Compatible:
|
28
|
+
- IE=Edge,chrome=1
|
29
|
+
Etag:
|
30
|
+
- '"c5a90bcbc9b7c787061a869fa26a0566"'
|
31
|
+
Cache-Control:
|
32
|
+
- max-age=0, private, must-revalidate
|
33
|
+
Vary:
|
34
|
+
- Origin
|
35
|
+
Content-Security-Policy:
|
36
|
+
- default-src 'none'; connect-src 'self' api.buckybox.com *.google-analytics.com
|
37
|
+
*.intercomcdn.com *.intercom.io wss://*.intercom.io; form-action 'self' www.paypal.com;
|
38
|
+
frame-ancestors 'none'; img-src 'self' *.google-analytics.com *.pingdom.net
|
39
|
+
*.pingdom.com *.intercomcdn.com *.intercomassets.com *.intercom.io *.tile.openstreetmap.org;
|
40
|
+
script-src 'self' 'unsafe-inline' 'unsafe-eval' *.google-analytics.com *.pingdom.net
|
41
|
+
js-agent.newrelic.com bam.nr-data.net *.intercomcdn.com *.intercom.io; style-src
|
42
|
+
'self' 'unsafe-inline'; report-uri https://api.buckybox.com/v1/csp-report
|
43
|
+
Strict-Transport-Security:
|
44
|
+
- max-age=631138519
|
45
|
+
X-Content-Type-Options:
|
46
|
+
- nosniff
|
47
|
+
X-Download-Options:
|
48
|
+
- noopen
|
49
|
+
X-Frame-Options:
|
50
|
+
- DENY
|
51
|
+
X-Permitted-Cross-Domain-Policies:
|
52
|
+
- none
|
53
|
+
X-Xss-Protection:
|
54
|
+
- 1; mode=block
|
55
|
+
body:
|
56
|
+
encoding: UTF-8
|
57
|
+
string: '{"id":8859,"first_name":"Joe","last_name":"Dalton","name":"Joe Dalton","email":"joe@buckybox.com","delivery_service_id":492,"halted?":false,"discount?":false,"discount":0.0,"number":"0437","account_balance":"-153.40","webstore_id":"fantastic-vege-people","webstore_name":"Fantastic Organic Demo","address":{"address_1":"1 My Street","address_2":null,"suburb":null,"city":"London","postcode":"XXX123","delivery_note":null,"home_phone":"007","mobile_phone":null,"work_phone":null}}'
|
58
|
+
http_version:
|
59
|
+
recorded_at: Thu, 11 Aug 2016 11:17:12 GMT
|
60
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,60 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.buckybox.com/v1/customers?email=joe@buckybox.com
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Api-Key:
|
11
|
+
- "<API-Key>"
|
12
|
+
Api-Secret:
|
13
|
+
- "<API-Secret>"
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Date:
|
20
|
+
- Thu, 11 Aug 2016 11:17:12 GMT
|
21
|
+
Content-Type:
|
22
|
+
- application/json; charset=utf-8
|
23
|
+
Transfer-Encoding:
|
24
|
+
- chunked
|
25
|
+
Connection:
|
26
|
+
- keep-alive
|
27
|
+
X-Ua-Compatible:
|
28
|
+
- IE=Edge,chrome=1
|
29
|
+
Etag:
|
30
|
+
- '"c7629f19a7f202c452bcb56a91d6cf38"'
|
31
|
+
Cache-Control:
|
32
|
+
- max-age=0, private, must-revalidate
|
33
|
+
Vary:
|
34
|
+
- Origin
|
35
|
+
Content-Security-Policy:
|
36
|
+
- default-src 'none'; connect-src 'self' api.buckybox.com *.google-analytics.com
|
37
|
+
*.intercomcdn.com *.intercom.io wss://*.intercom.io; form-action 'self' www.paypal.com;
|
38
|
+
frame-ancestors 'none'; img-src 'self' *.google-analytics.com *.pingdom.net
|
39
|
+
*.pingdom.com *.intercomcdn.com *.intercomassets.com *.intercom.io *.tile.openstreetmap.org;
|
40
|
+
script-src 'self' 'unsafe-inline' 'unsafe-eval' *.google-analytics.com *.pingdom.net
|
41
|
+
js-agent.newrelic.com bam.nr-data.net *.intercomcdn.com *.intercom.io; style-src
|
42
|
+
'self' 'unsafe-inline'; report-uri https://api.buckybox.com/v1/csp-report
|
43
|
+
Strict-Transport-Security:
|
44
|
+
- max-age=631138519
|
45
|
+
X-Content-Type-Options:
|
46
|
+
- nosniff
|
47
|
+
X-Download-Options:
|
48
|
+
- noopen
|
49
|
+
X-Frame-Options:
|
50
|
+
- DENY
|
51
|
+
X-Permitted-Cross-Domain-Policies:
|
52
|
+
- none
|
53
|
+
X-Xss-Protection:
|
54
|
+
- 1; mode=block
|
55
|
+
body:
|
56
|
+
encoding: UTF-8
|
57
|
+
string: '[{"id":8859,"first_name":"Joe","last_name":"Dalton","name":"Joe Dalton","email":"joe@buckybox.com","delivery_service_id":492,"halted?":false,"discount?":false,"discount":0.0,"number":"0437","account_balance":"-153.40","webstore_id":"fantastic-vege-people","webstore_name":"Fantastic Organic Demo"}]'
|
58
|
+
http_version:
|
59
|
+
recorded_at: Thu, 11 Aug 2016 11:17:12 GMT
|
60
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,60 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.buckybox.com/v1/delivery_services/91
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Api-Key:
|
11
|
+
- "<API-Key>"
|
12
|
+
Api-Secret:
|
13
|
+
- "<API-Secret>"
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Date:
|
20
|
+
- Thu, 11 Aug 2016 11:17:16 GMT
|
21
|
+
Content-Type:
|
22
|
+
- application/json; charset=utf-8
|
23
|
+
Transfer-Encoding:
|
24
|
+
- chunked
|
25
|
+
Connection:
|
26
|
+
- keep-alive
|
27
|
+
X-Ua-Compatible:
|
28
|
+
- IE=Edge,chrome=1
|
29
|
+
Etag:
|
30
|
+
- '"29f029d7c4388719ac8fdd17a6f4c836"'
|
31
|
+
Cache-Control:
|
32
|
+
- max-age=0, private, must-revalidate
|
33
|
+
Vary:
|
34
|
+
- Origin
|
35
|
+
Content-Security-Policy:
|
36
|
+
- default-src 'none'; connect-src 'self' api.buckybox.com *.google-analytics.com
|
37
|
+
*.intercomcdn.com *.intercom.io wss://*.intercom.io; form-action 'self' www.paypal.com;
|
38
|
+
frame-ancestors 'none'; img-src 'self' *.google-analytics.com *.pingdom.net
|
39
|
+
*.pingdom.com *.intercomcdn.com *.intercomassets.com *.intercom.io *.tile.openstreetmap.org;
|
40
|
+
script-src 'self' 'unsafe-inline' 'unsafe-eval' *.google-analytics.com *.pingdom.net
|
41
|
+
js-agent.newrelic.com bam.nr-data.net *.intercomcdn.com *.intercom.io; style-src
|
42
|
+
'self' 'unsafe-inline'; report-uri https://api.buckybox.com/v1/csp-report
|
43
|
+
Strict-Transport-Security:
|
44
|
+
- max-age=631138519
|
45
|
+
X-Content-Type-Options:
|
46
|
+
- nosniff
|
47
|
+
X-Download-Options:
|
48
|
+
- noopen
|
49
|
+
X-Frame-Options:
|
50
|
+
- DENY
|
51
|
+
X-Permitted-Cross-Domain-Policies:
|
52
|
+
- none
|
53
|
+
X-Xss-Protection:
|
54
|
+
- 1; mode=block
|
55
|
+
body:
|
56
|
+
encoding: UTF-8
|
57
|
+
string: '{"id":91,"name":"Courier (All Regions)","instructions":"Choose this Route for all regions outside of X, X and X\r\n\r\nWe delivery at 10:00 - 14:00.\r\nIf you''re not home, we will leave the box out of direct sunlight.","name_days_and_fee":"Courier (All Regions) - Mon, Tue, Wed, Thu, Fri - £5.00","pickup_point":false,"start_dates":[["Mon - Aug 15, 2016","2016-08-15",{"data-weekday":"mon"}],["Tue - Aug 16, 2016","2016-08-16",{"data-weekday":"tue"}],["Wed - Aug 17, 2016","2016-08-17",{"data-weekday":"wed"}],["Thu - Aug 18, 2016","2016-08-18",{"data-weekday":"thu"}],["Fri - Aug 19, 2016","2016-08-19",{"data-weekday":"fri"}],["Mon - Aug 22, 2016","2016-08-22",{"data-weekday":"mon"}],["Tue - Aug 23, 2016","2016-08-23",{"data-weekday":"tue"}],["Wed - Aug 24, 2016","2016-08-24",{"data-weekday":"wed"}],["Thu - Aug 25, 2016","2016-08-25",{"data-weekday":"thu"}],["Fri - Aug 26, 2016","2016-08-26",{"data-weekday":"fri"}],["Mon - Aug 29, 2016","2016-08-29",{"data-weekday":"mon"}],["Tue - Aug 30, 2016","2016-08-30",{"data-weekday":"tue"}],["Wed - Aug 31, 2016","2016-08-31",{"data-weekday":"wed"}],["Thu - Sep 1, 2016","2016-09-01",{"data-weekday":"thu"}],["Fri - Sep 2, 2016","2016-09-02",{"data-weekday":"fri"}],["Mon - Sep 5, 2016","2016-09-05",{"data-weekday":"mon"}],["Tue - Sep 6, 2016","2016-09-06",{"data-weekday":"tue"}],["Wed - Sep 7, 2016","2016-09-07",{"data-weekday":"wed"}],["Thu - Sep 8, 2016","2016-09-08",{"data-weekday":"thu"}],["Fri - Sep 9, 2016","2016-09-09",{"data-weekday":"fri"}],["Mon - Sep 12, 2016","2016-09-12",{"data-weekday":"mon"}],["Tue - Sep 13, 2016","2016-09-13",{"data-weekday":"tue"}],["Wed - Sep 14, 2016","2016-09-14",{"data-weekday":"wed"}],["Thu - Sep 15, 2016","2016-09-15",{"data-weekday":"thu"}],["Fri - Sep 16, 2016","2016-09-16",{"data-weekday":"fri"}],["Mon - Sep 19, 2016","2016-09-19",{"data-weekday":"mon"}],["Tue - Sep 20, 2016","2016-09-20",{"data-weekday":"tue"}],["Wed - Sep 21, 2016","2016-09-21",{"data-weekday":"wed"}],["Thu - Sep 22, 2016","2016-09-22",{"data-weekday":"thu"}],["Fri - Sep 23, 2016","2016-09-23",{"data-weekday":"fri"}],["Mon - Sep 26, 2016","2016-09-26",{"data-weekday":"mon"}],["Tue - Sep 27, 2016","2016-09-27",{"data-weekday":"tue"}],["Wed - Sep 28, 2016","2016-09-28",{"data-weekday":"wed"}],["Thu - Sep 29, 2016","2016-09-29",{"data-weekday":"thu"}],["Fri - Sep 30, 2016","2016-09-30",{"data-weekday":"fri"}],["Mon - Oct 3, 2016","2016-10-03",{"data-weekday":"mon"}],["Tue - Oct 4, 2016","2016-10-04",{"data-weekday":"tue"}],["Wed - Oct 5, 2016","2016-10-05",{"data-weekday":"wed"}],["Thu - Oct 6, 2016","2016-10-06",{"data-weekday":"thu"}],["Fri - Oct 7, 2016","2016-10-07",{"data-weekday":"fri"}],["Mon - Oct 10, 2016","2016-10-10",{"data-weekday":"mon"}],["Tue - Oct 11, 2016","2016-10-11",{"data-weekday":"tue"}],["Wed - Oct 12, 2016","2016-10-12",{"data-weekday":"wed"}],["Thu - Oct 13, 2016","2016-10-13",{"data-weekday":"thu"}],["Fri - Oct 14, 2016","2016-10-14",{"data-weekday":"fri"}],["Mon - Oct 17, 2016","2016-10-17",{"data-weekday":"mon"}],["Tue - Oct 18, 2016","2016-10-18",{"data-weekday":"tue"}],["Wed - Oct 19, 2016","2016-10-19",{"data-weekday":"wed"}],["Thu - Oct 20, 2016","2016-10-20",{"data-weekday":"thu"}],["Fri - Oct 21, 2016","2016-10-21",{"data-weekday":"fri"}],["Mon - Oct 24, 2016","2016-10-24",{"data-weekday":"mon"}],["Tue - Oct 25, 2016","2016-10-25",{"data-weekday":"tue"}],["Wed - Oct 26, 2016","2016-10-26",{"data-weekday":"wed"}],["Thu - Oct 27, 2016","2016-10-27",{"data-weekday":"thu"}],["Fri - Oct 28, 2016","2016-10-28",{"data-weekday":"fri"}],["Mon - Oct 31, 2016","2016-10-31",{"data-weekday":"mon"}],["Tue - Nov 1, 2016","2016-11-01",{"data-weekday":"tue"}],["Wed - Nov 2, 2016","2016-11-02",{"data-weekday":"wed"}],["Thu - Nov 3, 2016","2016-11-03",{"data-weekday":"thu"}],["Fri - Nov 4, 2016","2016-11-04",{"data-weekday":"fri"}],["Mon - Nov 7, 2016","2016-11-07",{"data-weekday":"mon"}],["Tue - Nov 8, 2016","2016-11-08",{"data-weekday":"tue"}],["Wed - Nov 9, 2016","2016-11-09",{"data-weekday":"wed"}],["Thu - Nov 10, 2016","2016-11-10",{"data-weekday":"thu"}],["Fri - Nov 11, 2016","2016-11-11",{"data-weekday":"fri"}],["Mon - Nov 14, 2016","2016-11-14",{"data-weekday":"mon"}],["Tue - Nov 15, 2016","2016-11-15",{"data-weekday":"tue"}],["Wed - Nov 16, 2016","2016-11-16",{"data-weekday":"wed"}],["Thu - Nov 17, 2016","2016-11-17",{"data-weekday":"thu"}],["Fri - Nov 18, 2016","2016-11-18",{"data-weekday":"fri"}],["Mon - Nov 21, 2016","2016-11-21",{"data-weekday":"mon"}],["Tue - Nov 22, 2016","2016-11-22",{"data-weekday":"tue"}],["Wed - Nov 23, 2016","2016-11-23",{"data-weekday":"wed"}],["Thu - Nov 24, 2016","2016-11-24",{"data-weekday":"thu"}],["Fri - Nov 25, 2016","2016-11-25",{"data-weekday":"fri"}],["Mon - Nov 28, 2016","2016-11-28",{"data-weekday":"mon"}],["Tue - Nov 29, 2016","2016-11-29",{"data-weekday":"tue"}],["Wed - Nov 30, 2016","2016-11-30",{"data-weekday":"wed"}],["Thu - Dec 1, 2016","2016-12-01",{"data-weekday":"thu"}],["Fri - Dec 2, 2016","2016-12-02",{"data-weekday":"fri"}],["Mon - Dec 5, 2016","2016-12-05",{"data-weekday":"mon"}],["Tue - Dec 6, 2016","2016-12-06",{"data-weekday":"tue"}],["Wed - Dec 7, 2016","2016-12-07",{"data-weekday":"wed"}],["Thu - Dec 8, 2016","2016-12-08",{"data-weekday":"thu"}],["Fri - Dec 9, 2016","2016-12-09",{"data-weekday":"fri"}],["Mon - Dec 12, 2016","2016-12-12",{"data-weekday":"mon"}],["Tue - Dec 13, 2016","2016-12-13",{"data-weekday":"tue"}],["Wed - Dec 14, 2016","2016-12-14",{"data-weekday":"wed"}],["Thu - Dec 15, 2016","2016-12-15",{"data-weekday":"thu"}],["Fri - Dec 16, 2016","2016-12-16",{"data-weekday":"fri"}],["Mon - Dec 19, 2016","2016-12-19",{"data-weekday":"mon"}],["Tue - Dec 20, 2016","2016-12-20",{"data-weekday":"tue"}],["Wed - Dec 21, 2016","2016-12-21",{"data-weekday":"wed"}],["Thu - Dec 22, 2016","2016-12-22",{"data-weekday":"thu"}],["Fri - Dec 23, 2016","2016-12-23",{"data-weekday":"fri"}],["Mon - Dec 26, 2016","2016-12-26",{"data-weekday":"mon"}],["Tue - Dec 27, 2016","2016-12-27",{"data-weekday":"tue"}],["Wed - Dec 28, 2016","2016-12-28",{"data-weekday":"wed"}],["Thu - Dec 29, 2016","2016-12-29",{"data-weekday":"thu"}],["Fri - Dec 30, 2016","2016-12-30",{"data-weekday":"fri"}],["Mon - Jan 2, 2017","2017-01-02",{"data-weekday":"mon"}],["Tue - Jan 3, 2017","2017-01-03",{"data-weekday":"tue"}],["Wed - Jan 4, 2017","2017-01-04",{"data-weekday":"wed"}],["Thu - Jan 5, 2017","2017-01-05",{"data-weekday":"thu"}],["Fri - Jan 6, 2017","2017-01-06",{"data-weekday":"fri"}],["Mon - Jan 9, 2017","2017-01-09",{"data-weekday":"mon"}],["Tue - Jan 10, 2017","2017-01-10",{"data-weekday":"tue"}],["Wed - Jan 11, 2017","2017-01-11",{"data-weekday":"wed"}],["Thu - Jan 12, 2017","2017-01-12",{"data-weekday":"thu"}],["Fri - Jan 13, 2017","2017-01-13",{"data-weekday":"fri"}],["Mon - Jan 16, 2017","2017-01-16",{"data-weekday":"mon"}],["Tue - Jan 17, 2017","2017-01-17",{"data-weekday":"tue"}],["Wed - Jan 18, 2017","2017-01-18",{"data-weekday":"wed"}],["Thu - Jan 19, 2017","2017-01-19",{"data-weekday":"thu"}],["Fri - Jan 20, 2017","2017-01-20",{"data-weekday":"fri"}],["Mon - Jan 23, 2017","2017-01-23",{"data-weekday":"mon"}],["Tue - Jan 24, 2017","2017-01-24",{"data-weekday":"tue"}],["Wed - Jan 25, 2017","2017-01-25",{"data-weekday":"wed"}],["Thu - Jan 26, 2017","2017-01-26",{"data-weekday":"thu"}],["Fri - Jan 27, 2017","2017-01-27",{"data-weekday":"fri"}],["Mon - Jan 30, 2017","2017-01-30",{"data-weekday":"mon"}],["Tue - Jan 31, 2017","2017-01-31",{"data-weekday":"tue"}],["Wed - Feb 1, 2017","2017-02-01",{"data-weekday":"wed"}],["Thu - Feb 2, 2017","2017-02-02",{"data-weekday":"thu"}],["Fri - Feb 3, 2017","2017-02-03",{"data-weekday":"fri"}],["Mon - Feb 6, 2017","2017-02-06",{"data-weekday":"mon"}],["Tue - Feb 7, 2017","2017-02-07",{"data-weekday":"tue"}],["Wed - Feb 8, 2017","2017-02-08",{"data-weekday":"wed"}],["Thu - Feb 9, 2017","2017-02-09",{"data-weekday":"thu"}],["Fri - Feb 10, 2017","2017-02-10",{"data-weekday":"fri"}]],"sun":false,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":false,"fee":"5.00","dates_grid":[[["Sun",0],["Mon",1],["Tue",2],["Wed",3],["Thu",4],["Fri",5],["Sat",6]],[["Sun",7],["Mon",8],["Tue",9],["Wed",10],["Thu",11],["Fri",12],["Sat",13]],[["Sun",14],["Mon",15],["Tue",16],["Wed",17],["Thu",18],["Fri",19],["Sat",20]],[["Sun",21],["Mon",22],["Tue",23],["Wed",24],["Thu",25],["Fri",26],["Sat",27]]],"cache_key":"6436c74901143c290941d608607651c95f292d3649b425bd0582ffddf6ae942c"}'
|
58
|
+
http_version:
|
59
|
+
recorded_at: Thu, 11 Aug 2016 11:17:16 GMT
|
60
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,60 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.buckybox.com/v1/delivery_services
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Api-Key:
|
11
|
+
- "<API-Key>"
|
12
|
+
Api-Secret:
|
13
|
+
- "<API-Secret>"
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Date:
|
20
|
+
- Thu, 11 Aug 2016 11:17:15 GMT
|
21
|
+
Content-Type:
|
22
|
+
- application/json; charset=utf-8
|
23
|
+
Transfer-Encoding:
|
24
|
+
- chunked
|
25
|
+
Connection:
|
26
|
+
- keep-alive
|
27
|
+
X-Ua-Compatible:
|
28
|
+
- IE=Edge,chrome=1
|
29
|
+
Etag:
|
30
|
+
- '"065c3ed18478f4c8e4dc72d24ad1c1e8"'
|
31
|
+
Cache-Control:
|
32
|
+
- max-age=0, private, must-revalidate
|
33
|
+
Vary:
|
34
|
+
- Origin
|
35
|
+
Content-Security-Policy:
|
36
|
+
- default-src 'none'; connect-src 'self' api.buckybox.com *.google-analytics.com
|
37
|
+
*.intercomcdn.com *.intercom.io wss://*.intercom.io; form-action 'self' www.paypal.com;
|
38
|
+
frame-ancestors 'none'; img-src 'self' *.google-analytics.com *.pingdom.net
|
39
|
+
*.pingdom.com *.intercomcdn.com *.intercomassets.com *.intercom.io *.tile.openstreetmap.org;
|
40
|
+
script-src 'self' 'unsafe-inline' 'unsafe-eval' *.google-analytics.com *.pingdom.net
|
41
|
+
js-agent.newrelic.com bam.nr-data.net *.intercomcdn.com *.intercom.io; style-src
|
42
|
+
'self' 'unsafe-inline'; report-uri https://api.buckybox.com/v1/csp-report
|
43
|
+
Strict-Transport-Security:
|
44
|
+
- max-age=631138519
|
45
|
+
X-Content-Type-Options:
|
46
|
+
- nosniff
|
47
|
+
X-Download-Options:
|
48
|
+
- noopen
|
49
|
+
X-Frame-Options:
|
50
|
+
- DENY
|
51
|
+
X-Permitted-Cross-Domain-Policies:
|
52
|
+
- none
|
53
|
+
X-Xss-Protection:
|
54
|
+
- 1; mode=block
|
55
|
+
body:
|
56
|
+
encoding: UTF-8
|
57
|
+
string: '[{"id":91,"name":"Courier (All Regions)","instructions":"Choose this Route for all regions outside of X, X and X\r\n\r\nWe delivery at 10:00 - 14:00.\r\nIf you''re not home, we will leave the box out of direct sunlight.","name_days_and_fee":"Courier (All Regions) - Mon, Tue, Wed, Thu, Fri - £5.00","pickup_point":false,"start_dates":[["Mon - Aug 15, 2016","2016-08-15",{"data-weekday":"mon"}],["Tue - Aug 16, 2016","2016-08-16",{"data-weekday":"tue"}],["Wed - Aug 17, 2016","2016-08-17",{"data-weekday":"wed"}],["Thu - Aug 18, 2016","2016-08-18",{"data-weekday":"thu"}],["Fri - Aug 19, 2016","2016-08-19",{"data-weekday":"fri"}],["Mon - Aug 22, 2016","2016-08-22",{"data-weekday":"mon"}],["Tue - Aug 23, 2016","2016-08-23",{"data-weekday":"tue"}],["Wed - Aug 24, 2016","2016-08-24",{"data-weekday":"wed"}],["Thu - Aug 25, 2016","2016-08-25",{"data-weekday":"thu"}],["Fri - Aug 26, 2016","2016-08-26",{"data-weekday":"fri"}],["Mon - Aug 29, 2016","2016-08-29",{"data-weekday":"mon"}],["Tue - Aug 30, 2016","2016-08-30",{"data-weekday":"tue"}],["Wed - Aug 31, 2016","2016-08-31",{"data-weekday":"wed"}],["Thu - Sep 1, 2016","2016-09-01",{"data-weekday":"thu"}],["Fri - Sep 2, 2016","2016-09-02",{"data-weekday":"fri"}],["Mon - Sep 5, 2016","2016-09-05",{"data-weekday":"mon"}],["Tue - Sep 6, 2016","2016-09-06",{"data-weekday":"tue"}],["Wed - Sep 7, 2016","2016-09-07",{"data-weekday":"wed"}],["Thu - Sep 8, 2016","2016-09-08",{"data-weekday":"thu"}],["Fri - Sep 9, 2016","2016-09-09",{"data-weekday":"fri"}],["Mon - Sep 12, 2016","2016-09-12",{"data-weekday":"mon"}],["Tue - Sep 13, 2016","2016-09-13",{"data-weekday":"tue"}],["Wed - Sep 14, 2016","2016-09-14",{"data-weekday":"wed"}],["Thu - Sep 15, 2016","2016-09-15",{"data-weekday":"thu"}],["Fri - Sep 16, 2016","2016-09-16",{"data-weekday":"fri"}],["Mon - Sep 19, 2016","2016-09-19",{"data-weekday":"mon"}],["Tue - Sep 20, 2016","2016-09-20",{"data-weekday":"tue"}],["Wed - Sep 21, 2016","2016-09-21",{"data-weekday":"wed"}],["Thu - Sep 22, 2016","2016-09-22",{"data-weekday":"thu"}],["Fri - Sep 23, 2016","2016-09-23",{"data-weekday":"fri"}],["Mon - Sep 26, 2016","2016-09-26",{"data-weekday":"mon"}],["Tue - Sep 27, 2016","2016-09-27",{"data-weekday":"tue"}],["Wed - Sep 28, 2016","2016-09-28",{"data-weekday":"wed"}],["Thu - Sep 29, 2016","2016-09-29",{"data-weekday":"thu"}],["Fri - Sep 30, 2016","2016-09-30",{"data-weekday":"fri"}],["Mon - Oct 3, 2016","2016-10-03",{"data-weekday":"mon"}],["Tue - Oct 4, 2016","2016-10-04",{"data-weekday":"tue"}],["Wed - Oct 5, 2016","2016-10-05",{"data-weekday":"wed"}],["Thu - Oct 6, 2016","2016-10-06",{"data-weekday":"thu"}],["Fri - Oct 7, 2016","2016-10-07",{"data-weekday":"fri"}],["Mon - Oct 10, 2016","2016-10-10",{"data-weekday":"mon"}],["Tue - Oct 11, 2016","2016-10-11",{"data-weekday":"tue"}],["Wed - Oct 12, 2016","2016-10-12",{"data-weekday":"wed"}],["Thu - Oct 13, 2016","2016-10-13",{"data-weekday":"thu"}],["Fri - Oct 14, 2016","2016-10-14",{"data-weekday":"fri"}],["Mon - Oct 17, 2016","2016-10-17",{"data-weekday":"mon"}],["Tue - Oct 18, 2016","2016-10-18",{"data-weekday":"tue"}],["Wed - Oct 19, 2016","2016-10-19",{"data-weekday":"wed"}],["Thu - Oct 20, 2016","2016-10-20",{"data-weekday":"thu"}],["Fri - Oct 21, 2016","2016-10-21",{"data-weekday":"fri"}],["Mon - Oct 24, 2016","2016-10-24",{"data-weekday":"mon"}],["Tue - Oct 25, 2016","2016-10-25",{"data-weekday":"tue"}],["Wed - Oct 26, 2016","2016-10-26",{"data-weekday":"wed"}],["Thu - Oct 27, 2016","2016-10-27",{"data-weekday":"thu"}],["Fri - Oct 28, 2016","2016-10-28",{"data-weekday":"fri"}],["Mon - Oct 31, 2016","2016-10-31",{"data-weekday":"mon"}],["Tue - Nov 1, 2016","2016-11-01",{"data-weekday":"tue"}],["Wed - Nov 2, 2016","2016-11-02",{"data-weekday":"wed"}],["Thu - Nov 3, 2016","2016-11-03",{"data-weekday":"thu"}],["Fri - Nov 4, 2016","2016-11-04",{"data-weekday":"fri"}],["Mon - Nov 7, 2016","2016-11-07",{"data-weekday":"mon"}],["Tue - Nov 8, 2016","2016-11-08",{"data-weekday":"tue"}],["Wed - Nov 9, 2016","2016-11-09",{"data-weekday":"wed"}],["Thu - Nov 10, 2016","2016-11-10",{"data-weekday":"thu"}],["Fri - Nov 11, 2016","2016-11-11",{"data-weekday":"fri"}],["Mon - Nov 14, 2016","2016-11-14",{"data-weekday":"mon"}],["Tue - Nov 15, 2016","2016-11-15",{"data-weekday":"tue"}],["Wed - Nov 16, 2016","2016-11-16",{"data-weekday":"wed"}],["Thu - Nov 17, 2016","2016-11-17",{"data-weekday":"thu"}],["Fri - Nov 18, 2016","2016-11-18",{"data-weekday":"fri"}],["Mon - Nov 21, 2016","2016-11-21",{"data-weekday":"mon"}],["Tue - Nov 22, 2016","2016-11-22",{"data-weekday":"tue"}],["Wed - Nov 23, 2016","2016-11-23",{"data-weekday":"wed"}],["Thu - Nov 24, 2016","2016-11-24",{"data-weekday":"thu"}],["Fri - Nov 25, 2016","2016-11-25",{"data-weekday":"fri"}],["Mon - Nov 28, 2016","2016-11-28",{"data-weekday":"mon"}],["Tue - Nov 29, 2016","2016-11-29",{"data-weekday":"tue"}],["Wed - Nov 30, 2016","2016-11-30",{"data-weekday":"wed"}],["Thu - Dec 1, 2016","2016-12-01",{"data-weekday":"thu"}],["Fri - Dec 2, 2016","2016-12-02",{"data-weekday":"fri"}],["Mon - Dec 5, 2016","2016-12-05",{"data-weekday":"mon"}],["Tue - Dec 6, 2016","2016-12-06",{"data-weekday":"tue"}],["Wed - Dec 7, 2016","2016-12-07",{"data-weekday":"wed"}],["Thu - Dec 8, 2016","2016-12-08",{"data-weekday":"thu"}],["Fri - Dec 9, 2016","2016-12-09",{"data-weekday":"fri"}],["Mon - Dec 12, 2016","2016-12-12",{"data-weekday":"mon"}],["Tue - Dec 13, 2016","2016-12-13",{"data-weekday":"tue"}],["Wed - Dec 14, 2016","2016-12-14",{"data-weekday":"wed"}],["Thu - Dec 15, 2016","2016-12-15",{"data-weekday":"thu"}],["Fri - Dec 16, 2016","2016-12-16",{"data-weekday":"fri"}],["Mon - Dec 19, 2016","2016-12-19",{"data-weekday":"mon"}],["Tue - Dec 20, 2016","2016-12-20",{"data-weekday":"tue"}],["Wed - Dec 21, 2016","2016-12-21",{"data-weekday":"wed"}],["Thu - Dec 22, 2016","2016-12-22",{"data-weekday":"thu"}],["Fri - Dec 23, 2016","2016-12-23",{"data-weekday":"fri"}],["Mon - Dec 26, 2016","2016-12-26",{"data-weekday":"mon"}],["Tue - Dec 27, 2016","2016-12-27",{"data-weekday":"tue"}],["Wed - Dec 28, 2016","2016-12-28",{"data-weekday":"wed"}],["Thu - Dec 29, 2016","2016-12-29",{"data-weekday":"thu"}],["Fri - Dec 30, 2016","2016-12-30",{"data-weekday":"fri"}],["Mon - Jan 2, 2017","2017-01-02",{"data-weekday":"mon"}],["Tue - Jan 3, 2017","2017-01-03",{"data-weekday":"tue"}],["Wed - Jan 4, 2017","2017-01-04",{"data-weekday":"wed"}],["Thu - Jan 5, 2017","2017-01-05",{"data-weekday":"thu"}],["Fri - Jan 6, 2017","2017-01-06",{"data-weekday":"fri"}],["Mon - Jan 9, 2017","2017-01-09",{"data-weekday":"mon"}],["Tue - Jan 10, 2017","2017-01-10",{"data-weekday":"tue"}],["Wed - Jan 11, 2017","2017-01-11",{"data-weekday":"wed"}],["Thu - Jan 12, 2017","2017-01-12",{"data-weekday":"thu"}],["Fri - Jan 13, 2017","2017-01-13",{"data-weekday":"fri"}],["Mon - Jan 16, 2017","2017-01-16",{"data-weekday":"mon"}],["Tue - Jan 17, 2017","2017-01-17",{"data-weekday":"tue"}],["Wed - Jan 18, 2017","2017-01-18",{"data-weekday":"wed"}],["Thu - Jan 19, 2017","2017-01-19",{"data-weekday":"thu"}],["Fri - Jan 20, 2017","2017-01-20",{"data-weekday":"fri"}],["Mon - Jan 23, 2017","2017-01-23",{"data-weekday":"mon"}],["Tue - Jan 24, 2017","2017-01-24",{"data-weekday":"tue"}],["Wed - Jan 25, 2017","2017-01-25",{"data-weekday":"wed"}],["Thu - Jan 26, 2017","2017-01-26",{"data-weekday":"thu"}],["Fri - Jan 27, 2017","2017-01-27",{"data-weekday":"fri"}],["Mon - Jan 30, 2017","2017-01-30",{"data-weekday":"mon"}],["Tue - Jan 31, 2017","2017-01-31",{"data-weekday":"tue"}],["Wed - Feb 1, 2017","2017-02-01",{"data-weekday":"wed"}],["Thu - Feb 2, 2017","2017-02-02",{"data-weekday":"thu"}],["Fri - Feb 3, 2017","2017-02-03",{"data-weekday":"fri"}],["Mon - Feb 6, 2017","2017-02-06",{"data-weekday":"mon"}],["Tue - Feb 7, 2017","2017-02-07",{"data-weekday":"tue"}],["Wed - Feb 8, 2017","2017-02-08",{"data-weekday":"wed"}],["Thu - Feb 9, 2017","2017-02-09",{"data-weekday":"thu"}],["Fri - Feb 10, 2017","2017-02-10",{"data-weekday":"fri"}]],"sun":false,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":false,"fee":"5.00","dates_grid":[[["Sun",0],["Mon",1],["Tue",2],["Wed",3],["Thu",4],["Fri",5],["Sat",6]],[["Sun",7],["Mon",8],["Tue",9],["Wed",10],["Thu",11],["Fri",12],["Sat",13]],[["Sun",14],["Mon",15],["Tue",16],["Wed",17],["Thu",18],["Fri",19],["Sat",20]],[["Sun",21],["Mon",22],["Tue",23],["Wed",24],["Thu",25],["Fri",26],["Sat",27]]],"cache_key":"6436c74901143c290941d608607651c95f292d3649b425bd0582ffddf6ae942c"}]'
|
58
|
+
http_version:
|
59
|
+
recorded_at: Thu, 11 Aug 2016 11:17:15 GMT
|
60
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,78 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.buckybox.com/v1/webstore
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Api-Key:
|
11
|
+
- "<API-Key>"
|
12
|
+
Api-Secret:
|
13
|
+
- "<API-Secret>"
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Date:
|
20
|
+
- Thu, 11 Aug 2016 11:17:12 GMT
|
21
|
+
Content-Type:
|
22
|
+
- application/json; charset=utf-8
|
23
|
+
Transfer-Encoding:
|
24
|
+
- chunked
|
25
|
+
Connection:
|
26
|
+
- keep-alive
|
27
|
+
X-Ua-Compatible:
|
28
|
+
- IE=Edge,chrome=1
|
29
|
+
Etag:
|
30
|
+
- '"a5fe3a149c12381fff3c8266e8e9b532"'
|
31
|
+
Cache-Control:
|
32
|
+
- max-age=0, private, must-revalidate
|
33
|
+
Vary:
|
34
|
+
- Origin
|
35
|
+
Content-Security-Policy:
|
36
|
+
- default-src 'none'; connect-src 'self' api.buckybox.com *.google-analytics.com
|
37
|
+
*.intercomcdn.com *.intercom.io wss://*.intercom.io; form-action 'self' www.paypal.com;
|
38
|
+
frame-ancestors 'none'; img-src 'self' *.google-analytics.com *.pingdom.net
|
39
|
+
*.pingdom.com *.intercomcdn.com *.intercomassets.com *.intercom.io *.tile.openstreetmap.org;
|
40
|
+
script-src 'self' 'unsafe-inline' 'unsafe-eval' *.google-analytics.com *.pingdom.net
|
41
|
+
js-agent.newrelic.com bam.nr-data.net *.intercomcdn.com *.intercom.io; style-src
|
42
|
+
'self' 'unsafe-inline'; report-uri https://api.buckybox.com/v1/csp-report
|
43
|
+
Strict-Transport-Security:
|
44
|
+
- max-age=631138519
|
45
|
+
X-Content-Type-Options:
|
46
|
+
- nosniff
|
47
|
+
X-Download-Options:
|
48
|
+
- noopen
|
49
|
+
X-Frame-Options:
|
50
|
+
- DENY
|
51
|
+
X-Permitted-Cross-Domain-Policies:
|
52
|
+
- none
|
53
|
+
X-Xss-Protection:
|
54
|
+
- 1; mode=block
|
55
|
+
body:
|
56
|
+
encoding: UTF-8
|
57
|
+
string: '{"name":"Fantastic Organic Demo","locale":"en","currency":"GBP","time_zone":"London","city":"London","sidebar_description":"The
|
58
|
+
Fantastic Vege People are a mythic being from Bucky Box Land.\r\n\r\nThey''re
|
59
|
+
an example of how easy it is to operate local food distribution enterprises. \r\n\r\nHere''s
|
60
|
+
to catalysing a local food revolution!\r\nOur boxes are Nom Nom Nom.\r\n\r\nYou
|
61
|
+
can customise any information in these fields from within the admin console
|
62
|
+
in the Settings Page.\r\n\r\n<a href=\"https://store.buckybox.com/\" target=\"_blank\">Bucky
|
63
|
+
Box Global Directory</a>","facebook_url":"www.facebook.com/buckybox","phone":"","email":"demo@buckybox.com","line_items":[{"created_at":"2013-10-18T00:36:20+01:00","distributor_id":18,"id":2497,"name":"Apple
|
64
|
+
(Pacific Rose)","updated_at":"2013-10-18T00:36:20+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":240,"name":"Apple
|
65
|
+
(Red)","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":237,"name":"Banana
|
66
|
+
(Fairtrade)","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2013-12-16T00:33:00+00:00","distributor_id":18,"id":4036,"name":"Basi2","updated_at":"2013-12-16T00:33:00+00:00"},{"created_at":"2012-08-27T05:20:09+01:00","distributor_id":18,"id":247,"name":"Beetroot","updated_at":"2012-08-27T05:20:09+01:00"},{"created_at":"2012-09-14T13:50:37+01:00","distributor_id":18,"id":270,"name":"Bok
|
67
|
+
Choy","updated_at":"2012-09-14T13:50:37+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":228,"name":"Broccoli","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-09-14T13:50:37+01:00","distributor_id":18,"id":268,"name":"Broccoliflower","updated_at":"2012-09-14T13:50:37+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":241,"name":"Butternut
|
68
|
+
Squash","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":226,"name":"Cabbage","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":227,"name":"Carrot","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":242,"name":"Celeriac","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":243,"name":"Celery","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":229,"name":"Chard","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":231,"name":"Coriander","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":236,"name":"Orange","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-08-27T05:20:09+01:00","distributor_id":18,"id":246,"name":"Peas","updated_at":"2012-08-27T05:20:09+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":244,"name":"Plum","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":234,"name":"Potato","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":238,"name":"Pumpkin","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":230,"name":"Rocket","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":225,"name":"Silverbeet","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-08-27T05:20:09+01:00","distributor_id":18,"id":249,"name":"Spinach","updated_at":"2012-08-27T05:20:09+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":245,"name":"Sugar
|
69
|
+
Snaps","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":235,"name":"Sweet
|
70
|
+
Potato","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-08-27T05:20:08+01:00","distributor_id":18,"id":233,"name":"Tomato","updated_at":"2012-08-27T05:20:08+01:00"},{"created_at":"2012-09-14T13:50:37+01:00","distributor_id":18,"id":269,"name":"Yams","updated_at":"2012-09-14T13:50:37+01:00"}],"payment_options":[["Cash
|
71
|
+
on Delivery","cash_on_delivery"],["Bank Deposit","bank_deposit"],["PayPal","paypal"]],"email_customer_on_new_webstore_order":true,"paypal_email":"pp@buckybox.com","ga_tracking_id":"","require_phone":true,"require_address_1":true,"require_address_2":false,"require_suburb":false,"require_city":false,"require_postcode":false,"require_delivery_note":false,"collect_phone":true,"collect_delivery_note":true,"active":true,"bank_information":{"bank_name":"The
|
72
|
+
Community Bank","account_name":"Vege People","account_number":"Sort Code:
|
73
|
+
112233\nAccount Number: 1234567","customer_message":"Please make payment <strong>3
|
74
|
+
days</strong> before your delivery to allow time for bank deposits to register."},"id":"fantastic-vege-people","company_logo":"//my.buckybox.com/system/uploads/distributor/company_logo/18/banner_bucky-demo.jpg","company_team_image":"//my.buckybox.com/system/uploads/distributor/company_team_image/18/photo_bucky-demo.jpg","cod_payment_message":"Please
|
75
|
+
place full payment in the mailbox"}'
|
76
|
+
http_version:
|
77
|
+
recorded_at: Thu, 11 Aug 2016 11:17:12 GMT
|
78
|
+
recorded_with: VCR 3.0.3
|
data/lib/buckybox/api.rb
CHANGED
@@ -1,29 +1,42 @@
|
|
1
1
|
require "cgi"
|
2
|
-
require "httparty"
|
3
2
|
require "crazy_money"
|
4
|
-
require "
|
3
|
+
require "hashie/mash"
|
4
|
+
require "oj"
|
5
|
+
require "typhoeus"
|
5
6
|
|
6
7
|
module BuckyBox
|
7
8
|
class API
|
8
9
|
ResponseError = Class.new(Exception) # generic error
|
9
|
-
NotFoundError = Class.new(
|
10
|
+
NotFoundError = Class.new(ResponseError)
|
10
11
|
|
11
12
|
ENDPOINTS = {
|
12
13
|
production: "https://api.buckybox.com/v1",
|
13
14
|
staging: "https://api-staging.buckybox.com/v1",
|
14
15
|
development: "http://api.buckybox.local:3000/v1",
|
15
|
-
test: "
|
16
|
+
test: "https://api.buckybox.com/v1",
|
16
17
|
}.freeze
|
17
18
|
|
19
|
+
class Response < Hashie::Mash
|
20
|
+
def initialize(hash)
|
21
|
+
unless hash.is_a?(Hash)
|
22
|
+
raise ArgumentError, "#{hash.inspect} must be a Hash"
|
23
|
+
end
|
24
|
+
|
25
|
+
super(hash, nil) do |object, key|
|
26
|
+
raise NoMethodError, "undefined method `#{key}' for #{object}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
18
31
|
class CachedResponse
|
19
|
-
attr_reader :response
|
32
|
+
attr_reader :response
|
20
33
|
|
21
34
|
def initialize(response)
|
22
35
|
@response, @cached_at = response, epoch
|
23
36
|
end
|
24
37
|
|
25
38
|
def expired?
|
26
|
-
epoch - cached_at > 60 # NOTE: cache responses for 60 seconds
|
39
|
+
epoch - @cached_at > 60 # NOTE: cache responses for 60 seconds
|
27
40
|
end
|
28
41
|
|
29
42
|
private def epoch
|
@@ -31,19 +44,20 @@ module BuckyBox
|
|
31
44
|
end
|
32
45
|
end
|
33
46
|
|
34
|
-
|
35
|
-
|
36
|
-
|
47
|
+
def self.fixtures_path
|
48
|
+
File.expand_path("../../../fixtures", __FILE__)
|
49
|
+
end
|
37
50
|
|
38
51
|
def initialize(headers)
|
39
|
-
|
52
|
+
@headers = headers.freeze
|
53
|
+
@endpoint = ENDPOINTS.fetch(ENV.fetch("RAILS_ENV", :production).to_sym)
|
40
54
|
end
|
41
55
|
|
42
|
-
def boxes(params = {embed: "images"}, options = {})
|
56
|
+
def boxes(params = { embed: "images" }, options = {})
|
43
57
|
query :get, "/boxes", params, options, price: CrazyMoney
|
44
58
|
end
|
45
59
|
|
46
|
-
def box(id, params = {embed: "extras,images,box_items"}, options = {})
|
60
|
+
def box(id, params = { embed: "extras,images,box_items" }, options = {})
|
47
61
|
query :get, "/boxes/#{id}", params, options, price: CrazyMoney
|
48
62
|
end
|
49
63
|
|
@@ -72,9 +86,9 @@ module BuckyBox
|
|
72
86
|
end
|
73
87
|
|
74
88
|
def create_or_update_customer(json_customer)
|
75
|
-
customer =
|
89
|
+
customer = Oj.load(json_customer)
|
76
90
|
|
77
|
-
if customer[
|
91
|
+
if customer["id"]
|
78
92
|
query :put, "/customers/#{customer['id']}", json_customer # TODO: replace by :patch
|
79
93
|
else
|
80
94
|
query :post, "/customers", json_customer
|
@@ -91,13 +105,21 @@ module BuckyBox
|
|
91
105
|
|
92
106
|
private
|
93
107
|
|
94
|
-
def
|
95
|
-
|
96
|
-
|
97
|
-
message
|
98
|
-
|
99
|
-
|
108
|
+
def handle_error!(response)
|
109
|
+
parsed_response = parse_response(response)
|
110
|
+
message = if parsed_response
|
111
|
+
parsed_response["message"] || parsed_response
|
112
|
+
else
|
113
|
+
"Empty response"
|
100
114
|
end
|
115
|
+
|
116
|
+
message = "Error #{response.code} - #{message}"
|
117
|
+
|
118
|
+
raise exception_type(response.code), message
|
119
|
+
end
|
120
|
+
|
121
|
+
def parse_response(response)
|
122
|
+
Oj.load(response.body)
|
101
123
|
end
|
102
124
|
|
103
125
|
def exception_type(http_code)
|
@@ -106,32 +128,43 @@ module BuckyBox
|
|
106
128
|
}.fetch(http_code, ResponseError)
|
107
129
|
end
|
108
130
|
|
109
|
-
def query(
|
110
|
-
options = {
|
111
|
-
|
112
|
-
}.merge(options)
|
113
|
-
|
114
|
-
hash = query_cache(type, uri, params, types)
|
131
|
+
def query(method, path, params = {}, options = {}, types = {})
|
132
|
+
options = { as_object: true }.merge(options)
|
133
|
+
hash = query_cache(method, path, params, types)
|
115
134
|
|
116
135
|
if options[:as_object]
|
117
|
-
|
136
|
+
if hash.is_a?(Array)
|
137
|
+
hash.map { |item| Response.new(item) }
|
138
|
+
else
|
139
|
+
Response.new(hash)
|
140
|
+
end
|
118
141
|
else
|
119
142
|
hash
|
120
143
|
end.freeze
|
121
144
|
end
|
122
145
|
|
123
|
-
def query_cache(
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
146
|
+
def query_cache(method, path, params, types)
|
147
|
+
uri = [@endpoint, path].join
|
148
|
+
|
149
|
+
query_fresh = lambda do
|
150
|
+
params_key = (method == :get ? :params : :body)
|
151
|
+
|
152
|
+
response = Typhoeus::Request.new(
|
153
|
+
uri,
|
154
|
+
headers: @headers,
|
155
|
+
method: method,
|
156
|
+
params_key => params,
|
157
|
+
accept_encoding: "gzip",
|
158
|
+
).run
|
159
|
+
|
160
|
+
handle_error!(response) unless response.success?
|
161
|
+
parsed_response = parse_response(response)
|
129
162
|
add_types(parsed_response, types)
|
130
|
-
|
163
|
+
end
|
131
164
|
|
132
|
-
if
|
165
|
+
if method == :get # NOTE: only cache GET method
|
133
166
|
@cache ||= {}
|
134
|
-
cache_key = [
|
167
|
+
cache_key = [@headers.hash, uri, to_query(params)].join
|
135
168
|
cached_response = @cache[cache_key]
|
136
169
|
|
137
170
|
if cached_response && !cached_response.expired?
|
@@ -163,7 +196,7 @@ module BuckyBox
|
|
163
196
|
|
164
197
|
def to_query(hash)
|
165
198
|
if hash.empty?
|
166
|
-
|
199
|
+
""
|
167
200
|
else
|
168
201
|
hash.map do |key, value|
|
169
202
|
"#{CGI.escape(key.to_s)}=#{CGI.escape(value)}"
|