From dfc4418377499264d46edab4e00d492c60f06f9a Mon Sep 17 00:00:00 2001 From: Daniele Palombo Date: Wed, 27 Sep 2017 17:05:06 +0200 Subject: [PATCH 1/3] Use nebulab shipwire that have adjust and warehouses support --- Gemfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Gemfile b/Gemfile index ed8041e..80c1889 100644 --- a/Gemfile +++ b/Gemfile @@ -18,4 +18,6 @@ gem 'mysql2' gem 'sqlite3' gem 'pg' +gem 'shipwire', github: 'nebulab/shipwire' + gemspec From 5f24a7acbddb5c7a0791919d5f22f77c6d543e49 Mon Sep 17 00:00:00 2001 From: Daniele Palombo Date: Wed, 27 Sep 2017 17:08:57 +0200 Subject: [PATCH 2/3] Add rate controller This action call rate on shipwire and return the rates options with the related shipments. --- .../spree/shipwire/rate_controller.rb | 59 +++++++++++++++++++ config/routes.rb | 4 ++ 2 files changed, 63 insertions(+) create mode 100644 app/controllers/spree/shipwire/rate_controller.rb diff --git a/app/controllers/spree/shipwire/rate_controller.rb b/app/controllers/spree/shipwire/rate_controller.rb new file mode 100644 index 0000000..fc019e8 --- /dev/null +++ b/app/controllers/spree/shipwire/rate_controller.rb @@ -0,0 +1,59 @@ +module Spree + module Shipwire + class RateController < StoreController + respond_to :json + + def create + rates = shipwire_rate(rate_params) + + if rates.empty? + render json: { error: 'Rate not found' }, status: :not_found + elsif rates.map{ |r| r['serviceOptions'].any? }.none? + render json: { error: 'Service not found' }, status: :not_found + else + render json: { rates: rates } + end + rescue StandardError => e + render json: { error: e.message }, status: :internal_server_error + end + + private + + def shipwire_rate(rate_params) + rate = ::Shipwire::Rate.new.find(rate_params) + raise rate.error_report unless rate.ok? + rate.body['resource']['rates'] + end + + def rate_params + { + order: { + shipTo: order_shipwire_json[:shipTo], + items: order_shipwire_json[:items] + }, + options: { + currency: order_shipwire_json[:options][:currency], + canSplit: order_shipwire_json[:options][:canSplit], + expectedShipDate: expected_ship_date + } + } + end + + def expected_ship_date + ship_date = params[:expectedShipDate] || nil + return if ship_date.nil? + + process_after_date = DateTime.strptime(ship_date).to_datetime.to_s + process_after_date if process_after_date > DateTime.current + end + + def order + @order ||= current_order || Order.incomplete.find_by(guest_token: params[:order_guest_token]) + end + + def order_shipwire_json + @order_shipwire_json ||= order.to_shipwire + end + end + end +end diff --git a/config/routes.rb b/config/routes.rb index 620478a..a2ee375 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,6 +11,10 @@ end end + namespace :shipwire do + resources :rate, only: :create + end + namespace :shipwire_webhooks do resources :stock, only: :create From eba3305dfe3e4c98a16bf74f3dd4f67c0ee5bab8 Mon Sep 17 00:00:00 2001 From: Daniele Palombo Date: Wed, 27 Sep 2017 17:09:23 +0200 Subject: [PATCH 3/3] Add spec for rate api controller --- spec/controllers/spree/shipwire/rate_spec.rb | 99 ++++++++ .../cassettes/shipwire/extract_rate.yml | 240 ++++++++++++++++++ .../shipwire/extract_rate_next_week.yml | 96 +++++++ 3 files changed, 435 insertions(+) create mode 100644 spec/controllers/spree/shipwire/rate_spec.rb create mode 100644 spec/support/cassettes/shipwire/extract_rate.yml create mode 100644 spec/support/cassettes/shipwire/extract_rate_next_week.yml diff --git a/spec/controllers/spree/shipwire/rate_spec.rb b/spec/controllers/spree/shipwire/rate_spec.rb new file mode 100644 index 0000000..aa0eb26 --- /dev/null +++ b/spec/controllers/spree/shipwire/rate_spec.rb @@ -0,0 +1,99 @@ +RSpec.describe Spree::Shipwire::RateController, type: :controller do + controller Spree::Shipwire::RateController do + end + + let(:shipwire_product) { sw_product_factory.in_stock } + let(:product) { create(:product, sku: shipwire_product['sku']) } + let(:order) { create(:order_with_line_items, line_items_attributes: [product: variant.product] ) } + + let(:variant) do + product.master.tap { |master| master.update_attributes(shipwire_id: shipwire_product['id']) } + end + + let(:rate_params) { { order_guest_token: order.guest_token } } + + subject { post :create, params: rate_params } + + context 'when receive rate information', vcr: { cassette_name: 'shipwire/extract_rate' } do + let(:json_response) { JSON.parse(response.body) } + let(:service_options) { json_response['rates'].first } + + it 'return service options info' do + subject + + expect(json_response).to include 'rates' + + expect(json_response['rates'].count).to eq 1 + json_response['rates'].each do |service_options| + expect(service_options['serviceOptions'].count).to eq 3 + + service_options['serviceOptions'].each do |service_option| + expect(service_option).to include 'serviceLevelCode', + 'serviceLevelName' + + shipment = service_option['shipments'].first + + expect(shipment).to include 'expectedDeliveryMaxDate', + 'expectedDeliveryMinDate', + 'expectedShipDate', + 'warehouseName', + 'carrier', + 'cost' + end + end + end + + context 'stub the rate api' do + before do + allow(Shipwire::Rate).to receive(:new).and_return shipwire_api + subject + end + + context 'expected ship date' do + RSpec::Matchers.define :expected_ship_date do |expected_ship_date| + match { |hash| hash[:options][:expectedShipDate] == expected_ship_date } + end + + let(:shipwire_api) { double('ShipwireApi', find: true) } + + it 'is nil' do + expect(shipwire_api).to have_received(:find).with(expected_ship_date(nil)) + end + + context 'is in the future' do + let(:expectedShipDate) { (DateTime.current + 2.weeks).to_s } + let(:rate_params) do + { + order_guest_token: order.guest_token, + expectedShipDate: expectedShipDate + } + end + + it 'expectedShipDate is setted' do + expect(shipwire_api).to have_received(:find).with(expected_ship_date(expectedShipDate)) + end + end + end + + context 'with empty services' do + context 'no service available' do + let(:shipwire_rate) do + { + resource: { + rates: [{ 'serviceOptions': [] }] + } + }.deep_stringify_keys + end + + let(:shipwire_response) { double('ShipwireResponse', ok?: true, body: shipwire_rate ) } + let(:shipwire_api) { double('ShipwireApi', find: shipwire_response) } + + it 'return not found' do + subject + expect(response).to have_http_status(:not_found) + end + end + end + end + end +end diff --git a/spec/support/cassettes/shipwire/extract_rate.yml b/spec/support/cassettes/shipwire/extract_rate.yml new file mode 100644 index 0000000..3dfac4d --- /dev/null +++ b/spec/support/cassettes/shipwire/extract_rate.yml @@ -0,0 +1,240 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.beta.shipwire.com/api/v3/products?classification=baseProduct&limit=1&sku=product-in-stock&status=instock + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Faraday v0.9.2 + Authorization: + - "" + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Date: + - Wed, 27 Sep 2017 09:14:25 GMT + Server: + - Apache + X-Process-Time-Seconds: + - '1.210979' + X-Request-Id: + - 213e55db80f4feaea40894638b06ca76 + Vary: + - Accept-Encoding + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + P3p: + - policyref="/w3c/p3p.xml", CP="COM CNT INT NAV PUR STA UNI CAO DSP CUR o i + OUR IND" + Content-Length: + - '582' + Content-Type: + - application/json + body: + encoding: ASCII-8BIT + string: '{"status":200,"message":"Successful","resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products?classification=baseProduct&limit=1&sku=product-in-stock&status=instock&offset=0","resource":{"offset":0,"total":1,"previous":null,"next":null,"items":[{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products\/baseProducts\/276038","resource":{"id":276038,"externalId":null,"sku":"product-in-stock","upc":null,"ean":null,"description":"description","hsCode":null,"countryOfOrigin":"US","htsCode":null,"eccn":null,"creationDate":"2017-09-26T03:10:18-07:00","archivedDate":null,"status":"instock","storageConfiguration":"INDIVIDUAL_ITEM","batteryConfiguration":"NOBATTERY","classification":"baseProduct","category":"FURNITURE_&_APPLIANCES","itemCount":1,"vendorId":null,"vendorExternalId":null,"dimensions":{"resourceLocation":null},"values":{"resourceLocation":null},"alternateNames":{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products\/baseProducts\/276038\/alternateNames?classification=baseProduct&limit=1&sku=product-in-stock&status=instock&offset=0"},"alternateDescriptions":{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products\/baseProducts\/276038\/alternateDescriptions?classification=baseProduct&limit=1&sku=product-in-stock&status=instock&offset=0"},"extendedAttributes":{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products\/baseProducts\/276038\/extendedAttributes?classification=baseProduct&limit=1&sku=product-in-stock&status=instock&offset=0"},"technicalData":{"resourceLocation":null},"flags":{"resourceLocation":null},"enqueuedDimensions":{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products\/baseProducts\/276038\/enqueuedDimensions?classification=baseProduct&limit=1&sku=product-in-stock&status=instock&offset=0"},"innerPack":{"resourceLocation":null},"masterCase":{"resourceLocation":null},"pallet":{"resourceLocation":null}}}]}}' + http_version: + recorded_at: Wed, 27 Sep 2017 09:14:27 GMT +- request: + method: post + uri: https://api.beta.shipwire.com/api/v3/rate + body: + encoding: UTF-8 + string: '{"order":{"shipTo":{"name":"John ","company":"Company","address1":"A + Different Road","address2":"Northwest","city":"Herndon","state":null,"postalCode":"10012","country":"US","phone":"555-555-0199","email":"email6@example.com"},"items":[{"sku":"product-in-stock","quantity":1,"commercialInvoiceValue":"10.0","commercialInvoiceValueCurrency":"USD"}]},"options":{"currency":"USD","canSplit":1,"expectedShipDate":null}}' + headers: + User-Agent: + - Faraday v0.9.2 + Authorization: + - "" + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Date: + - Tue, 16 Jan 2018 17:32:42 GMT + Server: + - Apache + X-Process-Time-Seconds: + - '1.507741' + X-Request-Id: + - 53c9f6f24a82437bf49068138cd0b2b4 + Vary: + - Accept-Encoding + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + P3p: + - policyref="/w3c/p3p.xml", CP="COM CNT INT NAV PUR STA UNI CAO DSP CUR o i + OUR IND" + Content-Length: + - '765' + Content-Type: + - application/json + body: + encoding: ASCII-8BIT + string: '{"status":200,"message":"Successful","warnings":[{"type":"warning","code":"addressVerification","message":"Could + not verify shipping address"}],"resourceLocation":null,"resource":{"groupBy":"all","rates":[{"serviceOptions":[{"serviceLevelCode":"GD","serviceLevelName":"Ground","shipments":[{"warehouseName":"Philadelphia","warehouseId":12,"warehouseExternalId":"1","carrier":{"code":"USPS + PMFPE","name":"USPS","description":"USPS Priority Mail Flat Rate Padded Envelope","properties":["trackable"]},"cost":{"currency":"USD","type":"total","name":"Total","amount":8.17,"converted":false,"originalCost":8.17,"originalCurrency":"USD"},"subtotals":[{"currency":"USD","type":"shipping","name":"Shipping","amount":8.17,"converted":false,"originalCost":8.17,"originalCurrency":"USD"},{"currency":"USD","type":"insurance","name":"Insurance","amount":0,"converted":false,"originalCost":0,"originalCurrency":"USD"},{"currency":"USD","type":"packaging","name":"Packaging","amount":0,"converted":false,"originalCost":0,"originalCurrency":"USD"},{"currency":"USD","type":"handling","name":"Handling","amount":0,"converted":false,"originalCost":0,"originalCurrency":"USD"}],"pieces":[{"length":{"amount":10.5,"units":"in"},"width":{"amount":7.5,"units":"in"},"height":{"amount":1,"units":"in"},"weight":{"amount":1.1,"units":"lbs","type":"total"},"subweights":[{"amount":0.1,"units":"lbs","type":"packaging"},{"amount":0,"units":"lbs","type":"voidFill"},{"amount":1,"units":"lbs","type":"products"}],"contents":[{"sku":"product-in-stock","quantity":1}]}],"expectedShipDate":"2018-01-16T09:32:42-08:00","expectedDeliveryMinDate":"2018-01-18T09:32:42-08:00","expectedDeliveryMaxDate":"2018-01-19T09:32:42-08:00"}]},{"serviceLevelCode":"2D","serviceLevelName":"Second + Day","shipments":[{"warehouseName":"Philadelphia","warehouseId":12,"warehouseExternalId":"1","carrier":{"code":"FDX + 2D","name":"FDX","description":"FedEx 2Day","properties":["trackable"]},"cost":{"currency":"USD","type":"total","name":"Total","amount":23.07,"converted":false,"originalCost":23.07,"originalCurrency":"USD"},"subtotals":[{"currency":"USD","type":"shipping","name":"Shipping","amount":23.07,"converted":false,"originalCost":23.07,"originalCurrency":"USD"},{"currency":"USD","type":"insurance","name":"Insurance","amount":0,"converted":false,"originalCost":0,"originalCurrency":"USD"},{"currency":"USD","type":"packaging","name":"Packaging","amount":0,"converted":false,"originalCost":0,"originalCurrency":"USD"},{"currency":"USD","type":"handling","name":"Handling","amount":0,"converted":false,"originalCost":0,"originalCurrency":"USD"}],"pieces":[{"length":{"amount":10,"units":"in"},"width":{"amount":5.5,"units":"in"},"height":{"amount":1,"units":"in"},"weight":{"amount":1.1,"units":"lbs","type":"total"},"subweights":[{"amount":0.1,"units":"lbs","type":"packaging"},{"amount":0,"units":"lbs","type":"voidFill"},{"amount":1,"units":"lbs","type":"products"}],"contents":[{"sku":"product-in-stock","quantity":1}]}],"expectedShipDate":"2018-01-16T09:32:42-08:00","expectedDeliveryMinDate":"2018-01-18T09:32:42-08:00","expectedDeliveryMaxDate":"2018-01-18T09:32:42-08:00"}]},{"serviceLevelCode":"1D","serviceLevelName":"Next + Day","shipments":[{"warehouseName":"Philadelphia","warehouseId":12,"warehouseExternalId":"1","carrier":{"code":"USPS + XP","name":"USPS","description":"USPS Express Mail","properties":["trackable"]},"cost":{"currency":"USD","type":"total","name":"Total","amount":25.28,"converted":false,"originalCost":25.28,"originalCurrency":"USD"},"subtotals":[{"currency":"USD","type":"shipping","name":"Shipping","amount":25.28,"converted":false,"originalCost":25.28,"originalCurrency":"USD"},{"currency":"USD","type":"insurance","name":"Insurance","amount":0,"converted":false,"originalCost":0,"originalCurrency":"USD"},{"currency":"USD","type":"packaging","name":"Packaging","amount":0,"converted":false,"originalCost":0,"originalCurrency":"USD"},{"currency":"USD","type":"handling","name":"Handling","amount":0,"converted":false,"originalCost":0,"originalCurrency":"USD"}],"pieces":[{"length":{"amount":10,"units":"in"},"width":{"amount":5.5,"units":"in"},"height":{"amount":1,"units":"in"},"weight":{"amount":1.1,"units":"lbs","type":"total"},"subweights":[{"amount":0.1,"units":"lbs","type":"packaging"},{"amount":0,"units":"lbs","type":"voidFill"},{"amount":1,"units":"lbs","type":"products"}],"contents":[{"sku":"product-in-stock","quantity":1}]}],"expectedShipDate":"2018-01-16T09:32:42-08:00","expectedDeliveryMinDate":"2018-01-17T09:32:42-08:00","expectedDeliveryMaxDate":"2018-01-17T09:32:42-08:00"}]}]}]}}' + http_version: + recorded_at: Tue, 16 Jan 2018 17:32:44 GMT +- request: + method: get + uri: https://api.beta.shipwire.com/api/v3/products?classification=baseProduct&limit=1&sku=product-in-stock + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Faraday v0.9.2 + Authorization: + - "" + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Date: + - Tue, 16 Jan 2018 17:32:52 GMT + Server: + - Apache + X-Process-Time-Seconds: + - '0.234403' + X-Request-Id: + - 500f12473d23b22c68bdd24a46f662bb + Vary: + - Accept-Encoding + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + P3p: + - policyref="/w3c/p3p.xml", CP="COM CNT INT NAV PUR STA UNI CAO DSP CUR o i + OUR IND" + Content-Length: + - '575' + Content-Type: + - application/json + body: + encoding: ASCII-8BIT + string: '{"status":200,"message":"Successful","resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products?classification=baseProduct&limit=1&sku=product-in-stock&offset=0","resource":{"offset":0,"total":1,"previous":null,"next":null,"items":[{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products\/baseProducts\/276038","resource":{"id":276038,"externalId":null,"sku":"product-in-stock","upc":null,"ean":null,"description":"description","hsCode":null,"countryOfOrigin":"US","htsCode":null,"eccn":null,"creationDate":"2017-09-26T03:10:18-07:00","archivedDate":null,"status":"instock","storageConfiguration":"INDIVIDUAL_ITEM","batteryConfiguration":"NOBATTERY","classification":"baseProduct","category":"FURNITURE_&_APPLIANCES","itemCount":1,"vendorId":null,"vendorExternalId":null,"dimensions":{"resourceLocation":null},"values":{"resourceLocation":null},"alternateNames":{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products\/baseProducts\/276038\/alternateNames?classification=baseProduct&limit=1&sku=product-in-stock&offset=0"},"alternateDescriptions":{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products\/baseProducts\/276038\/alternateDescriptions?classification=baseProduct&limit=1&sku=product-in-stock&offset=0"},"extendedAttributes":{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products\/baseProducts\/276038\/extendedAttributes?classification=baseProduct&limit=1&sku=product-in-stock&offset=0"},"technicalData":{"resourceLocation":null},"flags":{"resourceLocation":null},"enqueuedDimensions":{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products\/baseProducts\/276038\/enqueuedDimensions?classification=baseProduct&limit=1&sku=product-in-stock&offset=0"},"innerPack":{"resourceLocation":null},"masterCase":{"resourceLocation":null},"pallet":{"resourceLocation":null}}}]}}' + http_version: + recorded_at: Tue, 16 Jan 2018 17:32:52 GMT +- request: + method: get + uri: https://api.beta.shipwire.com/api/v3.1/warehouses?type=SHIPWIRE_ANYWHERE + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Faraday v0.9.2 + Authorization: + - "" + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Date: + - Tue, 16 Jan 2018 17:32:53 GMT + Server: + - Apache + X-Process-Time-Seconds: + - '0.211100' + X-Request-Id: + - e4880271b27995bd94f1a9937975b2cc + Vary: + - Accept-Encoding + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + P3p: + - policyref="/w3c/p3p.xml", CP="COM CNT INT NAV PUR STA UNI CAO DSP CUR o i + OUR IND" + Content-Length: + - '638' + Content-Type: + - application/json + body: + encoding: ASCII-8BIT + string: '{"status":200,"message":"Successful","resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3.1\/warehouses?type=SHIPWIRE_ANYWHERE&offset=0&limit=20","resource":{"offset":0,"total":2,"previous":null,"next":null,"items":[{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3.1\/warehouses\/10294","resource":{"id":10294,"externalId":null,"name":"Test","code":"TEST1","vendorId":null,"vendorExternalId":null,"isActive":1,"address":{"resourceLocation":null,"resource":{"address1":"2465 + Danforth Street","address2":"","address3":"","city":"Hamtramck","state":"MI","postalCode":"48212","country":"US","continent":"NORTH_AMERICA","name":"TEST","email":"","phone":"320-333-3334","fax":""}},"latitude":42.4081,"longitude":-83.0583,"isRoutable":0,"generatesLabels":1,"type":"SHIPWIRE + ANYWHERE","labelFormat":"8.5x11","returnWarehouseId":null,"returnWarehouseExternalId":null,"seedWithTypicalContainers":null,"physicalWarehouseId":null,"containers":{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3.1\/warehouses\/10294\/containers?type=SHIPWIRE_ANYWHERE&offset=0&limit=20"},"carriers":null}},{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3.1\/warehouses\/10295","resource":{"id":10295,"externalId":null,"name":"Test2","code":"TEST21","vendorId":null,"vendorExternalId":null,"isActive":1,"address":{"resourceLocation":null,"resource":{"address1":"479 + Steiner Street","address2":"","address3":"","city":"San Francisco","state":"CA","postalCode":"94117","country":"US","continent":"NORTH_AMERICA","name":"floyd + test2","email":"","phone":"333-456-7890","fax":""}},"latitude":37.7712,"longitude":-122.441,"isRoutable":0,"generatesLabels":1,"type":"SHIPWIRE + ANYWHERE","labelFormat":"8.5x11","returnWarehouseId":null,"returnWarehouseExternalId":null,"seedWithTypicalContainers":null,"physicalWarehouseId":null,"containers":{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3.1\/warehouses\/10295\/containers?type=SHIPWIRE_ANYWHERE&offset=0&limit=20"},"carriers":null}}]}}' + http_version: + recorded_at: Tue, 16 Jan 2018 17:32:54 GMT +- request: + method: post + uri: https://api.beta.shipwire.com/api/v3/stock/adjust + body: + encoding: UTF-8 + string: '{"sku":"product-in-stock","quantity":50,"warehouseId":10294,"reason":"Init + for test"}' + headers: + User-Agent: + - Faraday v0.9.2 + Authorization: + - "" + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Date: + - Tue, 16 Jan 2018 17:32:54 GMT + Server: + - Apache + X-Process-Time-Seconds: + - '0.268724' + X-Request-Id: + - 421171d4386a35013c2a1200c9182300 + Vary: + - Accept-Encoding + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + P3p: + - policyref="/w3c/p3p.xml", CP="COM CNT INT NAV PUR STA UNI CAO DSP CUR o i + OUR IND" + Content-Length: + - '360' + Content-Type: + - application/json + body: + encoding: ASCII-8BIT + string: '{"status":200,"message":"Successful","resourceLocation":null,"resource":{"offset":0,"total":1,"previous":null,"next":null,"items":[{"resourceLocation":null,"resource":{"productId":276038,"productExternalId":null,"vendorId":null,"vendorExternalId":null,"sku":"product-in-stock","isBundle":0,"isAlias":0,"warehouseRegion":"TEST1","warehouseId":10294,"physicalWarehouseId":null,"warehouseExternalId":null,"pending":41,"good":50,"reserved":92,"backordered":0,"shipping":46,"shipped":30,"creating":0,"consuming":0,"consumed":null,"created":0,"damaged":0,"returned":0,"inreview":0,"availableDate":null,"shippedLastDay":0,"shippedLastWeek":0,"shippedLast4Weeks":0,"orderedLastDay":0,"orderedLastWeek":0,"orderedLast4Weeks":0}}]}}' + http_version: + recorded_at: Tue, 16 Jan 2018 17:32:55 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/support/cassettes/shipwire/extract_rate_next_week.yml b/spec/support/cassettes/shipwire/extract_rate_next_week.yml new file mode 100644 index 0000000..0b4db5b --- /dev/null +++ b/spec/support/cassettes/shipwire/extract_rate_next_week.yml @@ -0,0 +1,96 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.beta.shipwire.com/api/v3/products?classification=baseProduct&limit=1&sku=product-in-stock&status=instock + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Faraday v0.9.2 + Authorization: + - "" + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Date: + - Wed, 27 Sep 2017 09:14:34 GMT + Server: + - Apache + X-Process-Time-Seconds: + - '1.006467' + X-Request-Id: + - 4d0d6648fe8bd3c7d1c5fcb2e801d706 + Vary: + - Accept-Encoding + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + P3p: + - policyref="/w3c/p3p.xml", CP="COM CNT INT NAV PUR STA UNI CAO DSP CUR o i + OUR IND" + Content-Length: + - '582' + Content-Type: + - application/json + body: + encoding: ASCII-8BIT + string: '{"status":200,"message":"Successful","resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products?classification=baseProduct&limit=1&sku=product-in-stock&status=instock&offset=0","resource":{"offset":0,"total":1,"previous":null,"next":null,"items":[{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products\/baseProducts\/276038","resource":{"id":276038,"externalId":null,"sku":"product-in-stock","upc":null,"ean":null,"description":"description","hsCode":null,"countryOfOrigin":"US","htsCode":null,"eccn":null,"creationDate":"2017-09-26T03:10:18-07:00","archivedDate":null,"status":"instock","storageConfiguration":"INDIVIDUAL_ITEM","batteryConfiguration":"NOBATTERY","classification":"baseProduct","category":"FURNITURE_&_APPLIANCES","itemCount":1,"vendorId":null,"vendorExternalId":null,"dimensions":{"resourceLocation":null},"values":{"resourceLocation":null},"alternateNames":{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products\/baseProducts\/276038\/alternateNames?classification=baseProduct&limit=1&sku=product-in-stock&status=instock&offset=0"},"alternateDescriptions":{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products\/baseProducts\/276038\/alternateDescriptions?classification=baseProduct&limit=1&sku=product-in-stock&status=instock&offset=0"},"extendedAttributes":{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products\/baseProducts\/276038\/extendedAttributes?classification=baseProduct&limit=1&sku=product-in-stock&status=instock&offset=0"},"technicalData":{"resourceLocation":null},"flags":{"resourceLocation":null},"enqueuedDimensions":{"resourceLocation":"https:\/\/api.beta.shipwire.com\/api\/v3\/products\/baseProducts\/276038\/enqueuedDimensions?classification=baseProduct&limit=1&sku=product-in-stock&status=instock&offset=0"},"innerPack":{"resourceLocation":null},"masterCase":{"resourceLocation":null},"pallet":{"resourceLocation":null}}}]}}' + http_version: + recorded_at: Wed, 27 Sep 2017 09:14:36 GMT +- request: + method: post + uri: https://api.beta.shipwire.com/api/v3/rate + body: + encoding: UTF-8 + string: '{"order":{"shipTo":{"name":"John ","company":"Company","address1":"A + Different Road","address2":"Northwest","city":"Herndon","state":null,"postalCode":"00296","country":"US","phone":"555-555-0199","email":"jackeline.crooks@thompsondietrich.co.uk"},"items":[{"sku":"product-in-stock","quantity":1,"commercialInvoiceValue":"10.0","commercialInvoiceValueCurrency":"USD"}]},"options":{"currency":"USD","canSplit":1,"expectedShipDate":"2017-10-11T09:14:36+00:00"}}' + headers: + User-Agent: + - Faraday v0.9.2 + Authorization: + - "" + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Date: + - Wed, 27 Sep 2017 09:14:37 GMT + Server: + - Apache + X-Process-Time-Seconds: + - '2.981863' + X-Request-Id: + - 5247796a7a96f566d75d6f3f6d0d2487 + Vary: + - Accept-Encoding + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + P3p: + - policyref="/w3c/p3p.xml", CP="COM CNT INT NAV PUR STA UNI CAO DSP CUR o i + OUR IND" + Content-Length: + - '621' + Content-Type: + - application/json + body: + encoding: ASCII-8BIT + string: '{"status":200,"message":"Successful","warnings":[{"type":"warning","code":"addressVerification","message":"Could + not verify shipping address"}],"resourceLocation":null,"resource":{"groupBy":"all","rates":[{"serviceOptions":[{"serviceLevelCode":"GD","serviceLevelName":"Ground","shipments":[{"warehouseName":"Philadelphia","warehouseId":12,"warehouseExternalId":"1","carrier":{"code":"USPS + PMFPE","name":"USPS","description":"USPS Priority Mail Flat Rate Padded Envelope","properties":["trackable"]},"cost":{"currency":"USD","type":"total","name":"Total","amount":7.48,"converted":false,"originalCost":7.48,"originalCurrency":"USD"},"subtotals":[{"currency":"USD","type":"shipping","name":"Shipping","amount":7.48,"converted":false,"originalCost":7.48,"originalCurrency":"USD"},{"currency":"USD","type":"insurance","name":"Insurance","amount":0,"converted":false,"originalCost":0,"originalCurrency":"USD"},{"currency":"USD","type":"packaging","name":"Packaging","amount":0,"converted":false,"originalCost":0,"originalCurrency":"USD"},{"currency":"USD","type":"handling","name":"Handling","amount":0,"converted":false,"originalCost":0,"originalCurrency":"USD"}],"pieces":[{"length":{"amount":10.5,"units":"in"},"width":{"amount":7.5,"units":"in"},"height":{"amount":1,"units":"in"},"weight":{"amount":1.1,"units":"lbs","type":"total"},"subweights":[{"amount":0.1,"units":"lbs","type":"packaging"},{"amount":0,"units":"lbs","type":"voidFill"},{"amount":1,"units":"lbs","type":"products"}],"contents":[{"sku":"product-in-stock","quantity":1}]}],"expectedShipDate":"2017-10-11T00:00:00+00:00","expectedDeliveryMinDate":"2017-10-13T00:00:00+00:00","expectedDeliveryMaxDate":"2017-10-16T00:00:00+00:00"}]}]}]}}' + http_version: + recorded_at: Wed, 27 Sep 2017 09:14:40 GMT +recorded_with: VCR 3.0.3