class Dsx::Dml::Writer

Public Class Methods

new(params) click to toggle source
# File lib/dsx/writer.rb, line 15
def initialize(params)
  if(params.key?(:address) && params.key?(:user) && params.key?(:password))
    @address = params[:address]
    @user = params[:user]
    @password = encrypt(params[:password])
    @doc_label = (params.key? :doc_label) ? params[:doc_label] : 'rb_dsx_dml'
    
    # @key = SecureRandom::uuid()
    # @salt = SecureRandom::uuid()
    # @vector = SecureRandom::uuid()
    
  else
    raise 'Incomplete DSX credentials'
  end
end

Public Instance Methods

curl(string_or_object) click to toggle source

Alternative to Net::SFTP.

# File lib/dsx/writer.rb, line 44
def curl(string_or_object)
  data = format(string_or_object)
  Dir.mktmpdir do |tmpdir|
    file = Tempfile.new(["^Imp_#{@doc_label}_#{Time.now.utc.to_i}_", '.txt'], tmpdir)
    file.write data
    file.close()
    result = `curl -s -S -u #{@user}:#{@password} -T #{file.path} -w "okay\n" sftp://#{@address}/`
    file.unlink()
  end
  
  dynamic_return(string_or_object)
end
net_sftp(string_or_object) click to toggle source

params: {address: server_address, user: user, password: password}

# File lib/dsx/writer.rb, line 32
def net_sftp(string_or_object)
  data = format(string_or_object)
  Net::SFTP::start(@address, @user, :password => @password) do |sftp|
    sftp.file.open("/^Imp_#{@doc_label}_#{Time.now.utc.to_i}_#{SecureRandom::hex(4)}.txt", 'w') do |file|
      file.write data
    end
  end
  
  dynamic_return(string_or_object)
end

Private Instance Methods

decrypt(value) click to toggle source
# File lib/dsx/writer.rb, line 87
def decrypt(value)
  return value
end
dynamic_return(string_or_object) click to toggle source
# File lib/dsx/writer.rb, line 59
def dynamic_return (string_or_object)
  if (string_or_object.is_a? String)
    return this
  else
    return string_or_object
  end
end
encrypt(value) click to toggle source
# File lib/dsx/writer.rb, line 83
def encrypt(value)
  return value
end
format(string_or_object) click to toggle source
# File lib/dsx/writer.rb, line 67
def format(string_or_object)
  if(string_or_object.respond_to?(:to_s))
    return string_or_object.to_s()
  elsif(string_or_object.respond_to?(:to_string))
    return string_or_object.to_string()
  else
    # Really most things will respond to to_s. Might need special casing, though.
  end
end
password() click to toggle source
# File lib/dsx/writer.rb, line 79
def password
  decrypt(@password)
end