Class: Dsx::Dml::Writer
- Inherits:
-
Object
- Object
- Dsx::Dml::Writer
- Defined in:
- lib/dsx/writer.rb
Instance Method Summary collapse
-
#curl(string_or_object) ⇒ Object
Alternative to Net::SFTP.
-
#initialize(params) ⇒ Writer
constructor
A new instance of Writer.
-
#net_sftp(string_or_object) ⇒ Object
params: server_address, user: user, password: password.
Constructor Details
#initialize(params) ⇒ Writer
Returns a new instance of Writer.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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 |
Instance Method Details
#curl(string_or_object) ⇒ Object
Alternative to Net::SFTP.
44 45 46 47 48 49 50 51 52 53 54 55 |
# 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) ⇒ Object
params: server_address, user: user, password: password
32 33 34 35 36 37 38 39 40 41 |
# 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 |