mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user