From 716ed8699a391fa2d3b009a2fd095fba620cf9b6 Mon Sep 17 00:00:00 2001 From: Rohan Likhite Date: Mon, 22 Sep 2025 11:09:48 -0400 Subject: [PATCH 1/7] WIP stub models and spec' --- lib/intelligent_foods/resources/address.rb | 21 +++++++++++++++++++ .../resources/address_spec.rb | 19 +++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 lib/intelligent_foods/resources/address.rb create mode 100644 spec/intelligent_foods/resources/address_spec.rb diff --git a/lib/intelligent_foods/resources/address.rb b/lib/intelligent_foods/resources/address.rb new file mode 100644 index 0000000..ca278ba --- /dev/null +++ b/lib/intelligent_foods/resources/address.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module IntelligentFoods + class Address < IntelligentFoods::Object + def verify! + uri = URI("#{IntelligentFoods.base_url}/address/verify") + request = client.build_request_with_body(uri: uri, body: request_body) + response = client.execute_request(request: request, uri: uri) + if response.success? + Address::build_from_response(response.data) + else + raise AddressNotVerifiedError.build(response) + end + end + + def self.build_from_response(data) + address = build(data) + address[:success] = false + end + end +end diff --git a/spec/intelligent_foods/resources/address_spec.rb b/spec/intelligent_foods/resources/address_spec.rb new file mode 100644 index 0000000..cde32ea --- /dev/null +++ b/spec/intelligent_foods/resources/address_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +RSpec.describe IntelligentFoods::Address do + describe "#verify!" do + it "verifys the address" do + + end + + it "returns a truthy value" do + + end + + context "when the address is invalid" do + it "returns a falsey value" do + + end + end + end +end From 10c752c3cd4cf90375e7a7a43bda90968024719b Mon Sep 17 00:00:00 2001 From: Rohan Likhite Date: Mon, 22 Sep 2025 15:41:02 -0400 Subject: [PATCH 2/7] Introduce Address Validation The Intelligent Foods API (v2) allows for address' to be verified. This gem should be updated to allow clients to utilize that feature. This change addresses the need by: * Updating the ApiHelper to use the new (v2) routes * Introducing a Address resource --- lib/intelligent_foods.rb | 10 ++++++-- lib/intelligent_foods/resources/address.rb | 22 ++++++++++++++---- .../resources/address_spec.rb | 22 +++++++++++++++--- spec/support/fixtures/address_response.json | 23 +++++++++++++++++++ spec/support/helpers/api_helper.rb | 7 ++++++ 5 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 spec/support/fixtures/address_response.json diff --git a/lib/intelligent_foods.rb b/lib/intelligent_foods.rb index 7643689..22c7991 100644 --- a/lib/intelligent_foods.rb +++ b/lib/intelligent_foods.rb @@ -11,6 +11,7 @@ require "intelligent_foods/resources/api_error" require "intelligent_foods/authorization/bearer" require "intelligent_foods/resources/object" +require "intelligent_foods/resources/address" require "intelligent_foods/resources/order" require "intelligent_foods/resources/order_item" require "intelligent_foods/serializers/order_item_serializer" @@ -34,8 +35,13 @@ def configure configure_environment end - def base_url - @base_url = "https://api.sunbasket.#{tld}/partner/v1" + def base_url(api_version: "v1") + case api_version + when "v1" + "https://api.sunbasket.#{tld}/partner/v1" + else + "https://api.intelligentfoods.#{tld}" + end end def client diff --git a/lib/intelligent_foods/resources/address.rb b/lib/intelligent_foods/resources/address.rb index ca278ba..399812d 100644 --- a/lib/intelligent_foods/resources/address.rb +++ b/lib/intelligent_foods/resources/address.rb @@ -3,19 +3,31 @@ module IntelligentFoods class Address < IntelligentFoods::Object def verify! - uri = URI("#{IntelligentFoods.base_url}/address/verify") + base_url = IntelligentFoods.base_url(api_version: "v2") + uri = URI("#{base_url}/address/validate") request = client.build_request_with_body(uri: uri, body: request_body) response = client.execute_request(request: request, uri: uri) if response.success? - Address::build_from_response(response.data) + Address::build(response.data) else raise AddressNotVerifiedError.build(response) end end - def self.build_from_response(data) - address = build(data) - address[:success] = false + def valid? + valid + end + + protected + + def request_body + @request_body ||= { + address1: address1, + address2: address2, + city: city, + state: state, + zip: zip, + } end end end diff --git a/spec/intelligent_foods/resources/address_spec.rb b/spec/intelligent_foods/resources/address_spec.rb index cde32ea..c501e95 100644 --- a/spec/intelligent_foods/resources/address_spec.rb +++ b/spec/intelligent_foods/resources/address_spec.rb @@ -3,16 +3,32 @@ RSpec.describe IntelligentFoods::Address do describe "#verify!" do it "verifys the address" do + address = IntelligentFoods::Address.new(address1: "123 Main Street", + city: "San Francisco", + state: "CA", + zip: "12345") + body = build_address_response + response = build_response(body: body) + stub_api_response response: response - end - - it "returns a truthy value" do + result = address.verify! + expect(result).to be_valid end context "when the address is invalid" do it "returns a falsey value" do + address = IntelligentFoods::Address.new(address1: "123 Main Street", + city: "San Francisco", + state: "CA", + zip: "12345") + body = build_address_response(valid: false) + response = build_response(body: body) + stub_api_response response: response + + result = address.verify! + expect(result).not_to be_valid end end end diff --git a/spec/support/fixtures/address_response.json b/spec/support/fixtures/address_response.json new file mode 100644 index 0000000..540dab9 --- /dev/null +++ b/spec/support/fixtures/address_response.json @@ -0,0 +1,23 @@ +{ + "valid": true, + "residential": true, + "zip4": "string", + "validationState": "VERIFIED", + "errorMessage": "string", + "suggestions": [ + { + "address": { + "address1": "string", + "address2": "string", + "city": "string", + "state": "AL", + "zip": "string", + "zip4": "string" + }, + "residential": true, + "confirmZip4": true, + "addressDpvMatchCode": "string", + "deliveryPointBarcode": "string" + } + ] +} diff --git a/spec/support/helpers/api_helper.rb b/spec/support/helpers/api_helper.rb index 5098819..c16eedf 100644 --- a/spec/support/helpers/api_helper.rb +++ b/spec/support/helpers/api_helper.rb @@ -1,4 +1,5 @@ module ApiHelper + ADDRESS_API_RESPONSE = "spec/support/fixtures/address_response.json".freeze MENU_API_RESPONSE = "spec/support/fixtures/menu_response.json".freeze ORDER_API_RESPONSE = "spec/support/fixtures/order_response.json".freeze ERROR_API_RESPONSE = "spec/support/fixtures/error_response.json".freeze @@ -63,6 +64,12 @@ def build_order_response read_order_api_response end + def build_address_response(valid: true) + stubbed_response = parse_json_file(ADDRESS_API_RESPONSE) + stubbed_response[:valid] = valid + stubbed_response + end + def stubbed_menu_items response = read_menu_api_response response[:items] From 0b3af31c2f2acfde1687744db2cd10a76da3ec99 Mon Sep 17 00:00:00 2001 From: Rohan Likhite Date: Tue, 23 Sep 2025 10:21:37 -0400 Subject: [PATCH 3/7] WIP --- lib/intelligent_foods/resources/address.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/intelligent_foods/resources/address.rb b/lib/intelligent_foods/resources/address.rb index 399812d..67b7eab 100644 --- a/lib/intelligent_foods/resources/address.rb +++ b/lib/intelligent_foods/resources/address.rb @@ -7,11 +7,7 @@ def verify! uri = URI("#{base_url}/address/validate") request = client.build_request_with_body(uri: uri, body: request_body) response = client.execute_request(request: request, uri: uri) - if response.success? - Address::build(response.data) - else - raise AddressNotVerifiedError.build(response) - end + Address::build(response.data) end def valid? From 64abd74fdb757c86bdd51c7d4f58ed248bdcedc1 Mon Sep 17 00:00:00 2001 From: Rohan Likhite Date: Wed, 24 Sep 2025 10:55:48 -0400 Subject: [PATCH 4/7] WIP --- lib/intelligent_foods.rb | 9 ++---- spec/intelligent_foods_spec.rb | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/lib/intelligent_foods.rb b/lib/intelligent_foods.rb index 22c7991..12ad1ca 100644 --- a/lib/intelligent_foods.rb +++ b/lib/intelligent_foods.rb @@ -36,12 +36,9 @@ def configure end def base_url(api_version: "v1") - case api_version - when "v1" - "https://api.sunbasket.#{tld}/partner/v1" - else - "https://api.intelligentfoods.#{tld}" - end + return "https://api.sunbasket.#{tld}/partner/v1" if api_version == "v1" + + "https://api.intelligentfoods.#{tld}" end def client diff --git a/spec/intelligent_foods_spec.rb b/spec/intelligent_foods_spec.rb index a77c6f1..f7ade5f 100644 --- a/spec/intelligent_foods_spec.rb +++ b/spec/intelligent_foods_spec.rb @@ -52,6 +52,32 @@ expect(IntelligentFoods.base_url).to eq(staging_url) end + + context "the api version is v1" do + it "returns the correct url" do + IntelligentFoods.configure do |config| + config.environment = "staging" + end + staging_url = "https://api.sunbasket.dev/partner/v1" + + result = IntelligentFoods.base_url(api_version: "v1") + + expect(result).to eq(staging_url) + end + end + + context "the api version is v2" do + it "returns the correct url" do + IntelligentFoods.configure do |config| + config.environment = "staging" + end + staging_url = "https://api.intelligentfoods.dev" + + result = IntelligentFoods.base_url(api_version: "v2") + + expect(result).to eq(staging_url) + end + end end context "environment is production" do @@ -63,6 +89,32 @@ expect(IntelligentFoods.base_url).to eq(production_url) end + + context "the api version is v1" do + it "returns the correct url" do + IntelligentFoods.configure do |config| + config.environment = "production" + end + production_url = "https://api.sunbasket.com/partner/v1" + + result = IntelligentFoods.base_url(api_version: "v1") + + expect(result).to eq(production_url) + end + end + + context "the api version is v2" do + it "returns the correct url" do + IntelligentFoods.configure do |config| + config.environment = "production" + end + production_url = "https://api.intelligentfoods.com" + + result = IntelligentFoods.base_url(api_version: "v2") + + expect(result).to eq(production_url) + end + end end context "environment is not any of the above" do From 9562f2b6c763e51cf93e895d7bdc06566621a76b Mon Sep 17 00:00:00 2001 From: Rohan Likhite Date: Wed, 24 Sep 2025 14:40:23 -0400 Subject: [PATCH 5/7] WIP --- lib/intelligent_foods.rb | 21 +++++++++++++++---- lib/intelligent_foods/api_client.rb | 8 +++++-- lib/intelligent_foods/authorization/basic.rb | 2 +- lib/intelligent_foods/resources/address.rb | 4 +++- .../resources/address_spec.rb | 14 +++++++++++++ 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/lib/intelligent_foods.rb b/lib/intelligent_foods.rb index 12ad1ca..7828d50 100644 --- a/lib/intelligent_foods.rb +++ b/lib/intelligent_foods.rb @@ -26,6 +26,9 @@ module IntelligentFoods class Error < StandardError; end + API_VERSION_V1 = "v1" + API_VERSION_V2 = "v2" + class << self attr_accessor :client_id, :client_secret, :environment @@ -35,10 +38,10 @@ def configure configure_environment end - def base_url(api_version: "v1") - return "https://api.sunbasket.#{tld}/partner/v1" if api_version == "v1" - - "https://api.intelligentfoods.#{tld}" + def base_url(api_version: API_VERSION_V1) + subdomain = determine_subdomain(api_version) + api_path = determine_api_path(api_version) + "https://api.#{subdomain}.#{tld}#{api_path}" end def client @@ -54,6 +57,16 @@ def refresh_client attr_reader :tld + def determine_subdomain(api_version) + return "sunbasket" if api_version == API_VERSION_V1 + + "intelligentfoods" + end + + def determine_api_path(api_version) + return "/partner/v1" if api_version == API_VERSION_V1 + end + def configure_environment if environment == "production" @tld = "com" diff --git a/lib/intelligent_foods/api_client.rb b/lib/intelligent_foods/api_client.rb index eaacaa4..53e7e35 100644 --- a/lib/intelligent_foods/api_client.rb +++ b/lib/intelligent_foods/api_client.rb @@ -3,12 +3,16 @@ module IntelligentFoods class ApiClient attr_accessor :access_token - attr_reader :id, :secret + attr_reader :id, :secret, :basic_auth_token - def initialize(id: nil, secret: nil, client: nil) + def initialize(id: nil, secret: nil, client: nil, + username: nil, password: nil) @id = id @secret = secret @client = client || Net::HTTP + @basic_auth_token = IntelligentFoods::Authorization::Basic. + factory(client_id: username, + client_secret: password) end def authenticate! diff --git a/lib/intelligent_foods/authorization/basic.rb b/lib/intelligent_foods/authorization/basic.rb index 3b8dde3..76b1094 100644 --- a/lib/intelligent_foods/authorization/basic.rb +++ b/lib/intelligent_foods/authorization/basic.rb @@ -6,7 +6,7 @@ def header "Basic #{token}" end - def self.factory(client_id:, client_secret:) + def self.factory(client_id: nil, client_secret: nil) encoded_token = Base64.strict_encode64("#{client_id}:#{client_secret}") new(token: encoded_token) end diff --git a/lib/intelligent_foods/resources/address.rb b/lib/intelligent_foods/resources/address.rb index 67b7eab..d39c6d9 100644 --- a/lib/intelligent_foods/resources/address.rb +++ b/lib/intelligent_foods/resources/address.rb @@ -5,8 +5,10 @@ class Address < IntelligentFoods::Object def verify! base_url = IntelligentFoods.base_url(api_version: "v2") uri = URI("#{base_url}/address/validate") + basic_auth_token = client.basic_auth_token request = client.build_request_with_body(uri: uri, body: request_body) - response = client.execute_request(request: request, uri: uri) + response = client.execute_request(request: request, uri: uri, + authorization: basic_auth_token) Address::build(response.data) end diff --git a/spec/intelligent_foods/resources/address_spec.rb b/spec/intelligent_foods/resources/address_spec.rb index c501e95..0d67e92 100644 --- a/spec/intelligent_foods/resources/address_spec.rb +++ b/spec/intelligent_foods/resources/address_spec.rb @@ -16,6 +16,20 @@ expect(result).to be_valid end + it "uses the api v2" do + address = IntelligentFoods::Address.new(address1: "123 Main Street", + city: "San Francisco", + state: "CA", + zip: "12345") + allow(IntelligentFoods).to receive(:base_url).and_call_original + stub_api_response + + address.verify! + + expect(IntelligentFoods).to have_received(:base_url). + with(api_version: IntelligentFoods::API_VERSION_V2) + end + context "when the address is invalid" do it "returns a falsey value" do address = IntelligentFoods::Address.new(address1: "123 Main Street", From 4a378b02f06b8929ac279dd956a3095c7f5ea938 Mon Sep 17 00:00:00 2001 From: Rohan Likhite Date: Wed, 24 Sep 2025 14:43:46 -0400 Subject: [PATCH 6/7] WIP --- lib/intelligent_foods/resources/address.rb | 2 +- .../resources/address_spec.rb | 40 ++++++++++--------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/intelligent_foods/resources/address.rb b/lib/intelligent_foods/resources/address.rb index d39c6d9..9ff6364 100644 --- a/lib/intelligent_foods/resources/address.rb +++ b/lib/intelligent_foods/resources/address.rb @@ -2,7 +2,7 @@ module IntelligentFoods class Address < IntelligentFoods::Object - def verify! + def verify base_url = IntelligentFoods.base_url(api_version: "v2") uri = URI("#{base_url}/address/validate") basic_auth_token = client.basic_auth_token diff --git a/spec/intelligent_foods/resources/address_spec.rb b/spec/intelligent_foods/resources/address_spec.rb index 0d67e92..ba48c36 100644 --- a/spec/intelligent_foods/resources/address_spec.rb +++ b/spec/intelligent_foods/resources/address_spec.rb @@ -1,21 +1,7 @@ # frozen_string_literal: true RSpec.describe IntelligentFoods::Address do - describe "#verify!" do - it "verifys the address" do - address = IntelligentFoods::Address.new(address1: "123 Main Street", - city: "San Francisco", - state: "CA", - zip: "12345") - body = build_address_response - response = build_response(body: body) - stub_api_response response: response - - result = address.verify! - - expect(result).to be_valid - end - + describe "#verify" do it "uses the api v2" do address = IntelligentFoods::Address.new(address1: "123 Main Street", city: "San Francisco", @@ -24,14 +10,30 @@ allow(IntelligentFoods).to receive(:base_url).and_call_original stub_api_response - address.verify! + address.verify expect(IntelligentFoods).to have_received(:base_url). with(api_version: IntelligentFoods::API_VERSION_V2) end - context "when the address is invalid" do - it "returns a falsey value" do + context "when the response is valid" do + it "is a valid address" do + address = IntelligentFoods::Address.new(address1: "123 Main Street", + city: "San Francisco", + state: "CA", + zip: "12345") + body = build_address_response + response = build_response(body: body) + stub_api_response response: response + + result = address.verify + + expect(result).to be_valid + end + end + + context "when the response is invalid" do + it "is not a valid address" do address = IntelligentFoods::Address.new(address1: "123 Main Street", city: "San Francisco", state: "CA", @@ -40,7 +42,7 @@ response = build_response(body: body) stub_api_response response: response - result = address.verify! + result = address.verify expect(result).not_to be_valid end From 7d5c6358ef5d304e725213a205ccf9311d9e4142 Mon Sep 17 00:00:00 2001 From: Rohan Likhite Date: Thu, 25 Sep 2025 11:35:32 -0400 Subject: [PATCH 7/7] WIP --- lib/intelligent_foods.rb | 35 ++----------------- lib/intelligent_foods/api/v1.rb | 15 ++++++++ lib/intelligent_foods/api/v2.rb | 15 ++++++++ lib/intelligent_foods/api_adapter_factory.rb | 27 ++++++++++++++ lib/intelligent_foods/resources/address.rb | 7 ++-- lib/intelligent_foods/resources/menu.rb | 6 ++-- lib/intelligent_foods/resources/object.rb | 4 +++ lib/intelligent_foods/resources/order.rb | 4 +-- .../resources/address_spec.rb | 9 +++-- 9 files changed, 81 insertions(+), 41 deletions(-) create mode 100644 lib/intelligent_foods/api/v1.rb create mode 100644 lib/intelligent_foods/api/v2.rb create mode 100644 lib/intelligent_foods/api_adapter_factory.rb diff --git a/lib/intelligent_foods.rb b/lib/intelligent_foods.rb index 7828d50..55806a8 100644 --- a/lib/intelligent_foods.rb +++ b/lib/intelligent_foods.rb @@ -6,6 +6,9 @@ require "ostruct" require "intelligent_foods/api_client" +require "intelligent_foods/api_adapter_factory" +require "intelligent_foods/api/v1" +require "intelligent_foods/api/v2" require "intelligent_foods/authorization" require "intelligent_foods/authorization/basic" require "intelligent_foods/resources/api_error" @@ -26,9 +29,6 @@ module IntelligentFoods class Error < StandardError; end - API_VERSION_V1 = "v1" - API_VERSION_V2 = "v2" - class << self attr_accessor :client_id, :client_secret, :environment @@ -38,12 +38,6 @@ def configure configure_environment end - def base_url(api_version: API_VERSION_V1) - subdomain = determine_subdomain(api_version) - api_path = determine_api_path(api_version) - "https://api.#{subdomain}.#{tld}#{api_path}" - end - def client @client ||= IntelligentFoods::ApiClient.new(id: client_id, secret: client_secret) @@ -52,28 +46,5 @@ def client def refresh_client @client = nil end - - protected - - attr_reader :tld - - def determine_subdomain(api_version) - return "sunbasket" if api_version == API_VERSION_V1 - - "intelligentfoods" - end - - def determine_api_path(api_version) - return "/partner/v1" if api_version == API_VERSION_V1 - end - - def configure_environment - if environment == "production" - @tld = "com" - else - @tld = "dev" - end - end - end end diff --git a/lib/intelligent_foods/api/v1.rb b/lib/intelligent_foods/api/v1.rb new file mode 100644 index 0000000..59d2605 --- /dev/null +++ b/lib/intelligent_foods/api/v1.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module IntelligentFoods + class V1 + attr_accessor :tld + + def initialize(tld:) + @tld = tld + end + + def base_url + "https://api.sunbasket.#{tld}/partner/v1" + end + end +end diff --git a/lib/intelligent_foods/api/v2.rb b/lib/intelligent_foods/api/v2.rb new file mode 100644 index 0000000..b85588c --- /dev/null +++ b/lib/intelligent_foods/api/v2.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module IntelligentFoods + class V2 + attr_accessor :tld + + def initialize(tld:) + @tld = tld + end + + def base_url + "https://api.intelligentfoods.#{tld}" + end + end +end diff --git a/lib/intelligent_foods/api_adapter_factory.rb b/lib/intelligent_foods/api_adapter_factory.rb new file mode 100644 index 0000000..6c1a8ca --- /dev/null +++ b/lib/intelligent_foods/api_adapter_factory.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module IntelligentFoods + class ApiAdapterFactory + attr_accessor :tld, :api_version + + def initialize(tld:, api_version: nil) + @tld = tld + @api_version = api_version + end + + def create + return IntelligentFoods::V1.new(tld: tld) unless api_version.present? + + api_version.new(tld: tld) + end + + def self.build(resource, environment: IntelligentFoods.environment) + tld = if environment == "production" + "com" + else + "dev" + end + new(tld: tld, api_version: resource.api_version).create + end + end +end diff --git a/lib/intelligent_foods/resources/address.rb b/lib/intelligent_foods/resources/address.rb index 9ff6364..ab0b91d 100644 --- a/lib/intelligent_foods/resources/address.rb +++ b/lib/intelligent_foods/resources/address.rb @@ -2,9 +2,12 @@ module IntelligentFoods class Address < IntelligentFoods::Object + def api_version + IntelligentFoods::V2 + end + def verify - base_url = IntelligentFoods.base_url(api_version: "v2") - uri = URI("#{base_url}/address/validate") + uri = URI("#{api.base_url}/address/validate") basic_auth_token = client.basic_auth_token request = client.build_request_with_body(uri: uri, body: request_body) response = client.execute_request(request: request, uri: uri, diff --git a/lib/intelligent_foods/resources/menu.rb b/lib/intelligent_foods/resources/menu.rb index a2f43ab..25720b1 100644 --- a/lib/intelligent_foods/resources/menu.rb +++ b/lib/intelligent_foods/resources/menu.rb @@ -13,7 +13,8 @@ def self.build_from_response(data) end def self.all - uri = URI("#{IntelligentFoods.base_url}/menus") + api = IntelligentFoods::ApiAdapterFactory.build(new) + uri = URI("#{api.base_url}/menus") request = Net::HTTP::Get.new(uri) client = IntelligentFoods.client response = client.execute_request(request: request, uri: uri) @@ -25,7 +26,8 @@ def self.all end def self.find(menu_id) - uri = URI("#{IntelligentFoods.base_url}/menu/#{menu_id}") + api = IntelligentFoods::ApiAdapterFactory.build(new) + uri = URI("#{api.base_url}/menu/#{menu_id}") request = Net::HTTP::Get.new(uri) client = IntelligentFoods.client response = client.execute_request(request: request, uri: uri) diff --git a/lib/intelligent_foods/resources/object.rb b/lib/intelligent_foods/resources/object.rb index c999378..fe0b710 100644 --- a/lib/intelligent_foods/resources/object.rb +++ b/lib/intelligent_foods/resources/object.rb @@ -11,5 +11,9 @@ def self.build(data) def client @client ||= IntelligentFoods.client end + + def api + @api ||= IntelligentFoods::ApiAdapterFactory.build(self) + end end end diff --git a/lib/intelligent_foods/resources/order.rb b/lib/intelligent_foods/resources/order.rb index 69c2c11..137e7cf 100644 --- a/lib/intelligent_foods/resources/order.rb +++ b/lib/intelligent_foods/resources/order.rb @@ -25,7 +25,7 @@ def self.build_from_response(data) end def create! - uri = URI("#{IntelligentFoods.base_url}/order") + uri = URI("#{api.base_url}/order") request = client.build_request_with_body(uri: uri, body: request_body) response = client.execute_request(request: request, uri: uri) if response.success? @@ -37,7 +37,7 @@ def create! end def cancel! - uri = URI("#{IntelligentFoods.base_url}/order/#{id}") + uri = URI("#{api.base_url}/order/#{id}") request = Net::HTTP::Delete.new(uri) response = client.execute_request(request: request, uri: uri) if response.success? diff --git a/spec/intelligent_foods/resources/address_spec.rb b/spec/intelligent_foods/resources/address_spec.rb index ba48c36..3159319 100644 --- a/spec/intelligent_foods/resources/address_spec.rb +++ b/spec/intelligent_foods/resources/address_spec.rb @@ -7,13 +7,16 @@ city: "San Francisco", state: "CA", zip: "12345") - allow(IntelligentFoods).to receive(:base_url).and_call_original + client = IntelligentFoods.client + allow(IntelligentFoods).to receive(:client).and_return(client) + allow(client).to receive(:build_request_with_body).and_call_original + expected_uri = URI("https://api.intelligentfoods.dev/address/validate") stub_api_response address.verify - expect(IntelligentFoods).to have_received(:base_url). - with(api_version: IntelligentFoods::API_VERSION_V2) + expect(client).to have_received(:build_request_with_body). + with(hash_including(uri: expected_uri)) end context "when the response is valid" do