Class: IronBank::LocalRecords

Inherits:
Object
  • Object
show all
Defined in:
lib/iron_bank/local_records.rb

Overview

Utility class to save records locally.

Constant Summary collapse

RESOURCE_QUERY_FIELDS =
{
  "Product"                   => ["*"],
  "ProductRatePlan"           => ["*", "Product.Id"],
  "ProductRatePlanCharge"     => ["*", "ProductRatePlan.Id"],
  "ProductRatePlanChargeTier" => ["*", "ProductRatePlanCharge.Id"]
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.directoryObject



16
17
18
# File 'lib/iron_bank/local_records.rb', line 16

def self.directory
  IronBank.configuration.export_directory
end

.exportObject



20
21
22
23
# File 'lib/iron_bank/local_records.rb', line 20

def self.export
  FileUtils.mkdir_p(directory)
  RESOURCE_QUERY_FIELDS.each_key { |resource| new(resource).save_file }
end

Instance Method Details

#save_fileObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/iron_bank/local_records.rb', line 25

def save_file
  until completed? || max_query?
    IronBank.logger.info(export_query_info)
    sleep backoff_time
  end

  # rubocop:disable Style/FileWrite
  File.open(file_path, "w") do |file|
    file.write(export.content.force_encoding("UTF-8"))
  end
  # rubocop:enable Style/FileWrite
end