-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FFS-2336: First sketch of multi-provider search #442
Merged
allthesignals
merged 11 commits into
main
from
wmg/2336-implement-multi-provider-search
Feb 12, 2025
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f7fda9e
First sketch of multi-provider search
allthesignals d5c0d09
Refactor Provider Search Service
allthesignals 372799a
Merge branch 'main' into wmg/2336-implement-multi-provider-search
allthesignals 0fa9163
Keyed by symbol
allthesignals 5afa813
Basic test
allthesignals fcb2f28
Extract provider result into response objects
allthesignals c518401
Merge branch 'main' into wmg/2336-implement-multi-provider-search
allthesignals f9a21c3
Add terraform configuration
allthesignals 5f110fa
Merge branch 'main' into wmg/2336-implement-multi-provider-search
allthesignals cb32bd9
Resolve conflicts
allthesignals 3b782ad
Lint infra
allthesignals File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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,68 @@ | ||
class ProviderSearchService | ||
PROVIDER_RESULT = Struct.new(:provider_name, :provider_options, :name, :logo_url, keyword_init: true) | ||
|
||
SUPPORTED_PROVIDERS = (ENV["SUPPORTED_PROVIDERS"] || "pinwheel")&.split(",")&.map(&:to_sym) | ||
|
||
def initialize(client_agency_id) | ||
client_agency_config = site_config[client_agency_id] | ||
|
||
@providers = SUPPORTED_PROVIDERS.map do |provider| | ||
case provider | ||
when :pinwheel | ||
PinwheelAdapter.new(client_agency_config.pinwheel_environment) | ||
when :argyle | ||
ArgyleAdapter.new(client_agency_config.argyle_environment) | ||
end | ||
end | ||
end | ||
|
||
def search(query = "") | ||
@providers.map { |provider| provider.query(query) }.flatten | ||
end | ||
|
||
private | ||
|
||
def site_config | ||
Rails.application.config.sites | ||
end | ||
|
||
class PinwheelAdapter | ||
def initialize(environment) | ||
@pinwheel = PinwheelService.new(environment) | ||
end | ||
|
||
def query(query) | ||
@pinwheel.fetch_items(q: query)["data"].map do |result| | ||
PROVIDER_RESULT.new( | ||
provider_name: :pinwheel, | ||
provider_options: { | ||
response_type: result["response_type"], | ||
provider_id: result["id"] | ||
}, | ||
name: result["name"], | ||
logo_url: result["logo_url"] | ||
) | ||
end | ||
end | ||
end | ||
|
||
class ArgyleAdapter | ||
def initialize(environment) | ||
@argyle = ArgyleService.new(environment) | ||
end | ||
|
||
def query(query) | ||
@argyle.items(query)["results"].map do |result| | ||
PROVIDER_RESULT.new( | ||
provider_name: :argyle, | ||
provider_options: { | ||
response_type: result["kind"], | ||
provider_id: result["id"] | ||
}, | ||
name: result["name"], | ||
logo_url: result["logo_url"] | ||
) | ||
end | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now after doing all of this I wonder if it makes sense just to have the services themselves assume a common interface. I don't know if you'd enforce it. There's no reason why |
||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the memory implications of instantiating this every time? It's only really used for looking up some values specific to the partner agency configuration...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's only used in once place so it doesn't really matter right now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory implications are probably not too bad, since GC should clear it out automatically after the method runs. There is a tiny performance hit in allocating and then GCing it, but whatever, not worth worrying about.