navi_client 1.3.9 → 1.3.10

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: b8c3281c7fe9cefc025a5f027e1628704c3e3f48ad3e44d9d78145f44811af9b
4
- data.tar.gz: 363af32e8f32120620fe5997c045c11960cdb526ca1c840cb9ef644b21868176
3
+ metadata.gz: c39405cc2df043a2ad2f08b61a1d9adc164c3e3a6bc3fa881b7b54918de68e68
4
+ data.tar.gz: b3375b30526ee1f0cdcb44b5c1c71a1b6d24346a4aa408f499d06ead7b18eb09
5
5
  SHA512:
6
- metadata.gz: 45d8b5a96116df63b3752d3fb2ac6d37e2a4fb294519f991c554d21c3d3e62b258ea33289412d59ccc512ff10f88cf5d2eb7f7f737fce1b1bc0b860349d1f71b
7
- data.tar.gz: dcb3be86e1b65c41da9e11bcfe1cabb73a518611fd22c62ddf0079ebea4c2573639d3db2af2dc2a2f3a4d3a06c52ee8bdcc3615a78343f4fcb302feb8f453e21
6
+ metadata.gz: 2aa50a52ec8b545d07dbd3557708a0e27998a2030dd54ca82530cc7534da3ba30120862b9a430f60bcd9ad30a5519c3f803a17cb38be51310805ceb9f232386a
7
+ data.tar.gz: bc3b28178f50df47807f706abde054a809320ba21806ccf3255834285683612f6dba8200e0e627762d62cc33ae2b2c8a71738d84a6f315b4cb095b7854fe4e06
data/lib/client.rb CHANGED
@@ -33,7 +33,7 @@ module Client
33
33
  #
34
34
  # connect the app with imap server
35
35
  #
36
- def imap_connection(server, username, password)
36
+ def imap_connection(server, username, password, exitOnFail = true)
37
37
  # connect to IMAP server
38
38
  imap = Net::IMAP.new server, ssl: true, certs: nil, verify: false
39
39
 
@@ -48,7 +48,7 @@ module Client
48
48
  unless capabilities.include? "IDLE" || @debug
49
49
  @logger.info "'IDLE' IMAP capability not available in server: #{server}"
50
50
  imap.disconnect
51
- exit
51
+ exit if exitOnFail
52
52
  end
53
53
  end
54
54
 
@@ -60,6 +60,8 @@ module Client
60
60
  @errors = {exception: e}
61
61
  rescue Net::IMAP::BadResponseError => e
62
62
  @errors = {exception: e}
63
+ rescue
64
+ @errors = {exception: e}
63
65
  end
64
66
 
65
67
  # return IMAP connection handler
@@ -113,6 +115,8 @@ module Client
113
115
  imap.store(message_id, "+FLAGS", [:Seen])
114
116
  end
115
117
  end
118
+ rescue Errno::ECONNREFUSED => e
119
+ raise e
116
120
  rescue => e
117
121
 
118
122
  unless logger.nil?
@@ -56,6 +56,14 @@ module NaviClient
56
56
  @token = "Token: #{token}##{config['username']}"
57
57
  end
58
58
 
59
+ def override_logger(logger)
60
+ @logger = logger
61
+ end
62
+
63
+ def set_token(token)
64
+ @token = token
65
+ end
66
+
59
67
  ##
60
68
  # Downloads the email content from imap-server and save it to the download_path
61
69
  #
@@ -81,11 +89,19 @@ module NaviClient
81
89
  #
82
90
  def save(data={}, filename)
83
91
  download_path = config['download_path'] + config['username'] + '/'
92
+ temp_path = config['download_path'] + config['username'] + '/inputs/temp'
84
93
  filepath = download_path + filename + ".yml"
85
94
 
86
95
  mkdir_if_not_exist(filepath)
96
+ mkdir_if_not_exist(temp_path)
97
+ File.open(filepath, 'w') do |f|
98
+ f.puts(data.to_yaml)
99
+ end
100
+
101
+ File.open(temp_path, 'a') do |f|
102
+ f.puts(filepath)
103
+ end
87
104
 
88
- File.write(filepath, data.to_yaml)
89
105
  return filepath
90
106
  end
91
107
 
@@ -97,13 +113,21 @@ module NaviClient
97
113
  download_path = config['download_path']
98
114
  filename = download_path + config['username'] + "/inputs/" + (Time.now.to_f * 1000).to_s
99
115
 
116
+ filename_temp = download_path + config['username'] + "/inputs/temp"
117
+
100
118
  mkdir_if_not_exist(filename)
101
119
 
102
120
  File.open(filename, 'w') do |f|
103
121
  in_filenames.each { |element| f.puts(element) }
104
122
  end
105
123
 
124
+ # this step might not be required as it is done in the prev download step
125
+ File.open(filename_temp, 'w') do |f|
126
+ in_filenames.each { |element| f.puts(element) }
127
+ end
128
+
106
129
  HTTPService::NaviAI.start(filepath: filename, client_type: @client_type, token: @token, email: config['username'])
130
+ FileUtils.rm_f filename_temp if File.file? filename_temp
107
131
  end
108
132
  end
109
133
 
@@ -194,5 +218,17 @@ module NaviClient
194
218
  def update_config(data)
195
219
  File.write(CONFIG_PATH, YAML.dump(data))
196
220
  end
221
+
222
+ def parse_prev_failed_emails
223
+ file = @download_path + 'inputs/temp'
224
+ if File.file? file
225
+ @logger.debug "Parsing previously fetched emails"
226
+ HTTPService::NaviAI.start(filepath: file, client_type: @client_type, token: @token, email: @current_user_email )
227
+ FileUtils.rm_f file
228
+ @logger.debug "Complete Ok..."
229
+ end
230
+
231
+ end
232
+
197
233
  end
198
234
  end
@@ -1,3 +1,3 @@
1
1
  module NaviClient
2
- VERSION = "1.3.9"
2
+ VERSION = "1.3.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: navi_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.9
4
+ version: 1.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sujit
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2018-04-03 00:00:00.000000000 Z
13
+ date: 2018-04-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler