-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into td/ffs-2110-update-fl…
…ow-use-new-database * origin/main: FFS-2336: First sketch of multi-provider search (#442)
- Loading branch information
Showing
11 changed files
with
177 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ [email protected] | |
ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=primary | ||
ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=deterministic | ||
ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=derivationsalt | ||
SUPPORTED_PROVIDERS=pinwheel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module ResponseObjects | ||
SearchResult = Struct.new(:provider_name, :provider_options, :name, :logo_url, keyword_init: true) do | ||
def self.from_pinwheel(response_body) | ||
new( | ||
provider_name: :pinwheel, | ||
provider_options: { | ||
response_type: response_body["response_type"], | ||
provider_id: response_body["id"] | ||
}, | ||
name: response_body["name"], | ||
logo_url: response_body["logo_url"] | ||
) | ||
end | ||
|
||
def self.from_argyle(response_body) | ||
new( | ||
provider_name: :argyle, | ||
provider_options: { | ||
response_type: response_body["kind"], | ||
provider_id: response_body["id"] | ||
}, | ||
name: response_body["name"], | ||
logo_url: response_body["logo_url"] | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
require "faraday" | ||
|
||
class ArgyleService | ||
ENVIRONMENTS = { | ||
sandbox: { | ||
base_url: "https://api-sandbox.argyle.com/v2", | ||
api_key_id: ENV["ARGYLE_API_TOKEN_SANDBOX_ID"], | ||
api_key_secret: ENV["ARGYLE_API_TOKEN_SANDBOX_SECRET"] | ||
} | ||
} | ||
|
||
def initialize(environment, api_key_id = nil, api_key_secret = nil) | ||
@api_key_id = api_key_id || ENVIRONMENTS.fetch(environment.to_sym)[:api_key_id] | ||
@api_key_secret = api_key_secret || ENVIRONMENTS.fetch(environment.to_sym)[:api_key_secret] | ||
@environment = ENVIRONMENTS.fetch(environment.to_sym) { |env| raise KeyError.new("ArgyleService unknown environment: #{env}") } | ||
|
||
client_options = { | ||
request: { | ||
open_timeout: 5, | ||
timeout: 5, | ||
params_encoder: Faraday::FlatParamsEncoder | ||
}, | ||
url: @environment[:base_url] | ||
} | ||
@http = Faraday.new(client_options) do |conn| | ||
conn.set_basic_auth @api_key_id, @api_key_secret | ||
conn.response :raise_error | ||
conn.response :json, content_type: "application/json" | ||
conn.response :logger, | ||
Rails.logger, | ||
headers: true, | ||
bodies: true, | ||
log_level: :debug | ||
end | ||
end | ||
|
||
# Fetch all Argyle items | ||
def items(query = nil) | ||
@http.get("items", { q: query }).body | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class ProviderSearchService | ||
SUPPORTED_PROVIDERS = (ENV["SUPPORTED_PROVIDERS"] || "pinwheel")&.split(",")&.map(&:to_sym) | ||
|
||
def initialize(client_agency_id) | ||
@client_agency_config = site_config[client_agency_id] | ||
end | ||
|
||
def search(query = "") | ||
SUPPORTED_PROVIDERS.map do |provider| | ||
case provider | ||
when :pinwheel | ||
PinwheelService.new(@client_agency_config.pinwheel_environment).fetch_items(q: query)["data"].map do |result| | ||
ResponseObjects::SearchResult.from_pinwheel(result) | ||
end | ||
when :argyle | ||
ArgyleService.new(@client_agency_config.argyle_environment).items(query)["results"].map do |result| | ||
ResponseObjects::SearchResult.from_argyle(result) | ||
end | ||
end | ||
end.flatten | ||
end | ||
|
||
private | ||
|
||
def site_config | ||
Rails.application.config.client_agencies | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe ProviderSearchService, type: :service do | ||
include PinwheelApiHelper | ||
let(:service) { ProviderSearchService.new("sandbox") } | ||
|
||
describe "#search" do | ||
around do |ex| | ||
stub_environment_variable("SUPPORTED_PROVIDERS", "pinwheel", &ex) | ||
end | ||
|
||
before do | ||
stub_request_items_response | ||
end | ||
|
||
it "returns results from all enabled providers" do | ||
results = service.search("test") | ||
expect(results.length).to eq(1) | ||
end | ||
|
||
it "returns results with correct structure" do | ||
results = service.search("test") | ||
result = results.first | ||
|
||
expect(result).to have_attributes( | ||
provider_name: :pinwheel, | ||
provider_options: a_hash_including(:response_type, :provider_id), | ||
name: a_kind_of(String), | ||
logo_url: a_kind_of(String) | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters