module SolidusBling class Seller < ApplicationRecord validates :name, presence: true validates :external_id, presence: true belongs_to :account def self.upsert_sellers account account.check_token BlingApi.configure { |config| config.access_token = account.access_token } sellers = BlingApi::Seller.get_sellers upsert_sellers = sellers.map { |seller| { name: seller[:nome], external_id: seller[:id], account_id: account.id } } SolidusBling::Seller.upsert_all(upsert_sellers, unique_by: :external_id) end def self.default find_by(default: true) end end end