Class: DIDWW::Resource::Export

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Includes:
Callback::CONST, HasStatusHelpers
Defined in:
lib/didww/resource/export.rb

Constant Summary collapse

STATUS_PENDING =
'pending'
STATUS_PROCESSING =
'processing'
STATUS_COMPLETED =
'completed'
STATUSES =
[
  STATUS_PENDING,
  STATUS_PROCESSING,
  STATUS_COMPLETED
].freeze
EXPORT_TYPE_CDR_IN =
'cdr_in'
EXPORT_TYPE_CDR_OUT =
'cdr_out'
EXPORT_TYPES =
[
  EXPORT_TYPE_CDR_IN,
  EXPORT_TYPE_CDR_OUT
].freeze

Constants included from Callback::CONST

Callback::CONST::CALLBACK_METHODS, Callback::CONST::CALLBACK_METHOD_GET, Callback::CONST::CALLBACK_METHOD_POST

Instance Method Summary collapse

Methods included from HasStatusHelpers

included

Methods inherited from Base

#as_json_api

Constructor Details

#initialize(params = {}) ⇒ Export

Type: String Description: Customer-supplied reference. Max 100 characters. (API 2026-04-16)



67
68
69
# File 'lib/didww/resource/export.rb', line 67

def initialize(params = {})
  super params.reverse_merge(filters: {})
end

Instance Method Details

#csvObject



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/didww/resource/export.rb', line 80

def csv
  file = download
  return unless file
  gz = Zlib::GzipReader.new(file)
  begin
    StringIO.new(gz.read)
  ensure
    gz.close unless gz.closed?
    file.close if file.respond_to?(:close) && !file.closed?
  end
end

#downloadObject



71
72
73
74
75
76
77
78
# File 'lib/didww/resource/export.rb', line 71

def download
  return unless url.present?
  Down::Http.new(headers: {
    'Api-Key' => DIDWW::Client.api_key,
    'X-DIDWW-API-Version' => DIDWW::Client.api_version,
    'User-Agent' => "didww-v3 Ruby gem v#{DIDWW::VERSION}"
  }).open(url)
end