multiwoven-integrations 0.1.63 → 0.1.64

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d27c9915ed80faa33f88467a0dddfaeda4c5c91560ca7b94ba9970ece2430bb5
4
- data.tar.gz: abefc5bb7771864fe8d1e4b6aee4810fa4f36e8db507c634f99d2546cae46df1
3
+ metadata.gz: a04192999a6c02ae4dd3cf752c22f602d9ed196e3a293f67c53727b89ec0ce3a
4
+ data.tar.gz: 955cab0486157d96c00ba540de776dd9d32687366ddd260bfa4e9a81c95e017d
5
5
  SHA512:
6
- metadata.gz: e39874d8fce8e065b862a460b84e7e35ca8cef3c1a897a507c6590feb39d45c4ec5a1b4c4ee206f9b7ce8e5763a5cfe77ea4b60ed4861e9f97b83c75ce40f37d
7
- data.tar.gz: 251d70c151bc3bcb39bc5d3e20464dbc351353dd814b370f45631b3f58ae586ba1e21ab277d67b89943ad5905623a1aa0eb64629ebd0049ec6a774374fe55d41
6
+ metadata.gz: 30a2e1bbd87278e54f40ce5c8d07630d4b4e4b3a1b7f077c5f1bfdf9e00d37dd402bbe3fbcfa477cf7fd331929a9f2e41d8506e7ac9388e3403ae73e2b474be3
7
+ data.tar.gz: 77840062ae81f7efa968919d7377a0e324c6b7720ffe3f237996a55c850e8f7dc68f2a241086780ea4d22d66a2b3c3a5d57e3045aa6c921a909d6e2a36584acc
@@ -39,27 +39,58 @@ module Multiwoven::Integrations::Destination
39
39
  file_path = generate_file_path(sync_config)
40
40
  local_file_name = generate_local_file_name(sync_config)
41
41
  csv_content = generate_csv_content(records)
42
+ records_size = records.size
42
43
  write_success = 0
43
- write_failure = 0
44
44
 
45
+ case connection_config[:format][:compression_type]
46
+ when CompressionType.enum("zip")
47
+ write_success = write_compressed_data(connection_config, file_path, local_file_name, csv_content, records_size)
48
+ when CompressionType.enum("un_compressed")
49
+ write_success = write_uncompressed_data(connection_config, file_path, local_file_name, csv_content, records_size)
50
+ else
51
+ raise ArgumentError, "Unsupported compression type: #{connection_config[:format][:compression_type]}"
52
+ end
53
+ write_failure = records.size - write_success
54
+ tracking_message(write_success, write_failure)
55
+ rescue StandardError => e
56
+ handle_exception(
57
+ "SFTP:WRITE:EXCEPTION",
58
+ "error",
59
+ e
60
+ )
61
+ end
62
+
63
+ def write_compressed_data(connection_config, file_path, local_file_name, csv_content, records_size)
64
+ write_success = 0
65
+ Tempfile.create([local_file_name, ".zip"]) do |tempfile|
66
+ Zip::File.open(tempfile.path, Zip::File::CREATE) do |zipfile|
67
+ zipfile.get_output_stream("#{local_file_name}.csv") { |f| f.write(csv_content) }
68
+ end
69
+ with_sftp_client(connection_config) do |sftp|
70
+ sftp.upload!(tempfile.path, file_path)
71
+ write_success = records_size
72
+ rescue StandardError => e
73
+ handle_exception("SFTP:RECORD:WRITE:EXCEPTION", "error", e)
74
+ write_success = 0
75
+ end
76
+ end
77
+ write_success
78
+ end
79
+
80
+ def write_uncompressed_data(connection_config, file_path, local_file_name, csv_content, records_size)
81
+ write_success = 0
45
82
  Tempfile.create([local_file_name, ".csv"]) do |tempfile|
46
83
  tempfile.write(csv_content)
47
84
  tempfile.close
48
85
  with_sftp_client(connection_config) do |sftp|
49
86
  sftp.upload!(tempfile.path, file_path)
50
- write_success += records.size
87
+ write_success = records_size
51
88
  rescue StandardError => e
52
89
  handle_exception("SFTP:RECORD:WRITE:EXCEPTION", "error", e)
53
- write_failure += records.size
90
+ write_success = 0
54
91
  end
55
92
  end
56
- tracking_message(write_success, write_failure)
57
- rescue StandardError => e
58
- handle_exception(
59
- "SFTP:WRITE:EXCEPTION",
60
- "error",
61
- e
62
- )
93
+ write_success
63
94
  end
64
95
 
65
96
  def clear_all_records(sync_config)
@@ -82,7 +113,13 @@ module Multiwoven::Integrations::Destination
82
113
  def generate_file_path(sync_config)
83
114
  connection_specification = sync_config.destination.connection_specification.with_indifferent_access
84
115
  timestamp = Time.now.strftime("%Y%m%d-%H%M%S")
85
- file_name = "#{connection_specification[:file_name]}_#{timestamp}.csv"
116
+ format = connection_specification[:format]
117
+ extension = if format[:compression_type] == "un_compressed"
118
+ format[:format_type]
119
+ else
120
+ format[:compression_type]
121
+ end
122
+ file_name = "#{connection_specification[:file_name]}_#{timestamp}.#{extension}"
86
123
  File.join(connection_specification[:destination_path], file_name)
87
124
  end
88
125
 
@@ -4,7 +4,7 @@
4
4
  "connection_specification": {
5
5
  "$schema": "http://json-schema.org/draft-07/schema#",
6
6
  "title": "SFTP",
7
- "required": ["host", "username", "password", "destination_path"],
7
+ "required": ["host", "username", "password", "destination_path", "format" ],
8
8
  "properties": {
9
9
  "host": {
10
10
  "title": "Host",
@@ -45,6 +45,28 @@
45
45
  "type": "string",
46
46
  "description": "Name of the file to be written.",
47
47
  "order": 5
48
+ },
49
+ "format": {
50
+ "title": "Output Format",
51
+ "type": "object",
52
+ "description": "Format of the data output.",
53
+ "order": 6,
54
+ "required": ["format_type"],
55
+ "properties": {
56
+ "format_type": {
57
+ "title": "File Format Type",
58
+ "type": "string",
59
+ "enum": ["csv"],
60
+ "default": "csv"
61
+ },
62
+ "compression_type": {
63
+ "title": "Compression Type",
64
+ "description": "Whether the output files should be compressed.",
65
+ "type": "string",
66
+ "enum": ["un_compressed", "zip"],
67
+ "default": "un_compressed"
68
+ }
69
+ }
48
70
  }
49
71
  }
50
72
  }
@@ -26,6 +26,8 @@ module Multiwoven
26
26
  LogLevel = Types::String.enum("fatal", "error", "warn", "info", "debug", "trace")
27
27
  RequestRateLimitingUnit = Types::String.default("minute").enum("minute", "hour", "day")
28
28
  SchemaMode = Types::String.enum("schema", "schemaless")
29
+ FileFormatType = Types::String.enum("csv")
30
+ CompressionType = Types::String.enum("un_compressed", "zip")
29
31
 
30
32
  class ProtocolModel < Dry::Struct
31
33
  extend Multiwoven::Integrations::Core::Utils
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Multiwoven
4
4
  module Integrations
5
- VERSION = "0.1.63"
5
+ VERSION = "0.1.64"
6
6
 
7
7
  ENABLED_SOURCES = %w[
8
8
  Snowflake
@@ -22,6 +22,7 @@ require "stripe"
22
22
  require "net/sftp"
23
23
  require "csv"
24
24
  require "securerandom"
25
+ require "zip"
25
26
 
26
27
  # Service
27
28
  require_relative "integrations/config"
@@ -49,6 +49,7 @@ Gem::Specification.new do |spec|
49
49
  spec.add_runtime_dependency "restforce"
50
50
  spec.add_runtime_dependency "ruby-limiter"
51
51
  spec.add_runtime_dependency "ruby-odbc"
52
+ spec.add_runtime_dependency "rubyzip"
52
53
  spec.add_runtime_dependency "sequel"
53
54
  spec.add_runtime_dependency "slack-ruby-client"
54
55
  spec.add_runtime_dependency "stripe"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multiwoven-integrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.63
4
+ version: 0.1.64
5
5
  platform: ruby
6
6
  authors:
7
7
  - Subin T P
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-30 00:00:00.000000000 Z
11
+ date: 2024-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -234,6 +234,20 @@ dependencies:
234
234
  - - ">="
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: rubyzip
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :runtime
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
237
251
  - !ruby/object:Gem::Dependency
238
252
  name: sequel
239
253
  requirement: !ruby/object:Gem::Requirement