Skip to content

Commit

Permalink
Add identity; remove ARes
Browse files Browse the repository at this point in the history
  • Loading branch information
allthesignals committed Feb 14, 2025
1 parent 7868994 commit 36209d7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 31 deletions.
1 change: 0 additions & 1 deletion app/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ gem "pdf-reader", "~> 2.12.0"
gem "net-imap", "0.4.19" # Fixing CVE-2025-25186

gem "maybe_later"
gem "activeresource"

group :development, :test do
gem "brakeman", "~> 5.2"
Expand Down
9 changes: 0 additions & 9 deletions app/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,10 @@ GEM
globalid (>= 0.3.6)
activemodel (7.1.5.1)
activesupport (= 7.1.5.1)
activemodel-serializers-xml (1.0.3)
activemodel (>= 5.0.0.a)
activesupport (>= 5.0.0.a)
builder (~> 3.1)
activerecord (7.1.5.1)
activemodel (= 7.1.5.1)
activesupport (= 7.1.5.1)
timeout (>= 0.4.0)
activeresource (6.1.4)
activemodel (>= 6.0)
activemodel-serializers-xml (~> 1.0)
activesupport (>= 6.0)
activestorage (7.1.5.1)
actionpack (= 7.1.5.1)
activejob (= 7.1.5.1)
Expand Down Expand Up @@ -526,7 +518,6 @@ PLATFORMS

DEPENDENCIES
actioncable-enhanced-postgresql-adapter
activeresource
aws-actionmailer-ses
aws-sdk-rails
aws-sdk-s3
Expand Down
15 changes: 15 additions & 0 deletions app/app/models/response_objects/identity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
IDENTITY_FIELDS = %i[
account_id
full_name
]

module ResponseObjects
Identity = Struct.new(*IDENTITY_FIELDS, keyword_init: true) do
def self.from_pinwheel(response_body)
new(
account_id: response_body["account_id"],
full_name: response_body["full_name"],
)
end
end
end
17 changes: 1 addition & 16 deletions app/app/services/pinwheel_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,6 @@ class PinwheelService
}
]

# Base class for wrapping responses from Pinwheel to allow accessing the data
# via dot-notation.
class ResponseObject < ActiveResource::Base
def initialize(*params, environment:)
# ActiveResource requires us to set the `site` (the API base url) on the
# class. Since Pinwheel's API base URL's differ per-environment, let's
# set the value dynamically as these records are instantiated.
self.class.site = environment[:base_url]
super(*params)
end
end
# Employment = Class.new(ResponseObject)
Identity = Class.new(ResponseObject)
Income = Class.new(ResponseObject)

def initialize(environment, api_key = nil)
@api_key = api_key || ENVIRONMENTS.fetch(environment.to_sym)[:api_key]
@environment = ENVIRONMENTS.fetch(environment.to_sym) { |env| raise KeyError.new("PinwheelService unknown environment: #{env}") }
Expand Down Expand Up @@ -174,7 +159,7 @@ def fetch_employment(account_id:)
def fetch_identity(account_id:)
json = @http.get(build_url("#{ACCOUNTS_ENDPOINT}/#{account_id}/identity")).body

Identity.new(json["data"], environment: @environment)
ResponseObjects::Identity.from_pinwheel(json["data"])
end

def fetch_income(account_id:)
Expand Down
5 changes: 1 addition & 4 deletions app/spec/helpers/cbv/pinwheel_data_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
end

let(:identities) do
PinwheelService::Identity.new(
load_relative_json_file('request_identity_response.json')['data'],
environment: PinwheelService::ENVIRONMENTS[:sandbox]
)
ResponseObjects::Identity.from_pinwheel(load_relative_json_file('request_identity_response.json')['data'])
end

let!(:cbv_flow) { create(:cbv_flow, :with_pinwheel_account) }
Expand Down
2 changes: 1 addition & 1 deletion app/spec/support/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def stub_identities(account_id = SecureRandom.uuid)
]
}

PinwheelService::Identity.new(fields, environment: PinwheelService::ENVIRONMENTS[:sandbox])
ResponseObjects::Identity.from_pinwheel(fields)
end
end

Expand Down

0 comments on commit 36209d7

Please sign in to comment.