Centralize sdk_object_to_hash logic in DataHelpers module and update all references for improved reusability and consistency. Add error handling for partial and failed SnapTrade account linking. (#741)

Co-authored-by: luckyPipewrench <luckypipewrench@proton.me>
This commit is contained in:
LPW
2026-01-22 16:19:44 -05:00
committed by GitHub
parent bf76d6b88d
commit 9858b36dc7
6 changed files with 41 additions and 52 deletions

View File

@@ -1,5 +1,6 @@
class SnaptradeItem::Importer
include SyncStats::Collector
include SnaptradeAccount::DataHelpers
attr_reader :snaptrade_item, :snaptrade_provider, :sync
@@ -53,22 +54,6 @@ class SnaptradeItem::Importer
private
# Convert SnapTrade SDK objects to hashes
# SDK objects don't have to_h but do have to_json
def sdk_object_to_hash(obj)
return obj if obj.is_a?(Hash)
if obj.respond_to?(:to_json)
JSON.parse(obj.to_json)
elsif obj.respond_to?(:to_h)
obj.to_h
else
obj
end
rescue JSON::ParserError, TypeError
obj.respond_to?(:to_h) ? obj.to_h : {}
end
# Extract activities array from API response
# get_account_activities returns a paginated object with .data accessor
# This handles both paginated responses and plain arrays