navi_client 1.0.1 → 1.0.2

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
- SHA256:
3
- metadata.gz: acc1ca10c112e0fd575ea62e64a3e7fa6e2388a337502a0f3c0e1befca457867
4
- data.tar.gz: ab131ee64ac2b5d96da0bf1ea4ace7b3550e6a134ee59e9c1f60f086e7f9bd89
2
+ SHA1:
3
+ metadata.gz: 07a660e29a51bd335bf13e164ef1d265cbc72fa4
4
+ data.tar.gz: 55144c6419251828e9ff25266d534a03d5fe8e74
5
5
  SHA512:
6
- metadata.gz: 6a52b5fcfd91329adc0cccfe6afc1b59a248b4d5bafbfc7d79611c8318fb170e579b38bc99ca91f3cfab00478bce110505614364b9503680969b06cd85c1de21
7
- data.tar.gz: d26f357c8e466144ea6687adf6d4e4d0985491d2be352e74b8b580812fd4d6f211a63c1ac411cfe8beb8cd89c877eb5f32a55daa2c9552fa638a135a028918a6
6
+ metadata.gz: c5a41ada36cc8242359d68c622c3c097cabf3510a85af4b836456a48c58b6bec5b250a75f6aad1fcae702aa0cb962788a1f62baf59e5f940dde80bd7b12da8d7
7
+ data.tar.gz: 76e6b2e83e89a590b5e88bd7e3cdc22ffc59da0dbaa9c2f1bf94aa464a114e033cbfa2391ece9264f200d1661574435b567b4539329ab24d303045438b5daf83
data/lib/client.rb CHANGED
@@ -9,7 +9,8 @@ module Client
9
9
  # login to the navi-cloud and get the authentication token
10
10
  #
11
11
  def login
12
- provider_url = "http://localhost:3008/oauth/token"
12
+ url = "#{@sso_web_url/oauth/token}"
13
+ provider_url = url
13
14
  @token = HTTParty.post(provider_url,
14
15
  body: {
15
16
  client_id: config["uid"], # get from sso_web application
@@ -69,20 +70,16 @@ module Client
69
70
  @logger.debug "\nProcessing #{message_ids.count} mails.\n"
70
71
  end
71
72
  end
72
-
73
73
  message_ids.each_with_index do |message_id, i|
74
74
  # fetch all the email contents
75
75
  data = imap.fetch(message_id, "RFC822")
76
-
77
76
  data.each do |d|
78
77
  msg = d.attr['RFC822']
79
78
  # instantiate a Mail object to avoid further IMAP parameters nightmares
80
79
  mail = Mail.read_from_string msg
81
80
 
82
81
  # call the block with mail object as param
83
- start = (i == 0)
84
- last = (i == message_ids-1)
85
- process_email_block.call mail, start, last
82
+ process_email_block.call mail
86
83
 
87
84
  # mark as read
88
85
  if @mark_as_read
@@ -119,7 +116,10 @@ module Client
119
116
 
120
117
  # We're out, which means there are some emails ready for us.
121
118
  # Go do a search for UNSEEN and fetch them.
122
- retrieve_emails(imap, search_condition, folder) { |mail| process_email mail }
119
+ filenames = []
120
+ retrieve_emails(imap, search_condition, folder) { |mail| filenames << process_email mail }
121
+ self.send_request(filenames)
122
+
123
123
  @logger.debug "Process Completed." if @debug
124
124
 
125
125
  rescue SignalException => e
@@ -143,7 +143,18 @@ module Client
143
143
  end
144
144
  end
145
145
 
146
- def process_email(mail, start, last)
146
+ def send_request(in_filenames = [])
147
+ download_path = config['download_path']
148
+ filename = download_path + "inputs/" + (Time.now.to_f * 1000).to_s
149
+
150
+ File.open(filename, 'w') do |f|
151
+ in_filenames.each { |element| f.puts(element) }
152
+ end
153
+
154
+ HttpService::NaviAI.start(filename, @client_type, @token)
155
+ end
156
+
157
+ def process_email(mail)
147
158
  meta = Hash.new
148
159
  custom_uid = (Time.now.to_f * 1000).to_s + "_" + mail.__id__.to_s
149
160
 
@@ -155,18 +166,15 @@ module Client
155
166
 
156
167
  if mail.multipart?
157
168
  for i in 0...mail.parts.length
158
- m = @local_flag ? download_local(mail, custom_uid) : download_s3(mail, custom_uid)
169
+ m = download(mail, custom_uid)
159
170
  meta.merge!(m) unless m.nil?
160
171
  end
161
172
  else
162
- m = @local_flag ? download_local(mail, custom_uid) : download_s3(mail, custom_uid)
173
+ m = download(mail, custom_uid)
163
174
  meta.merge!(m) unless m.nil?
164
175
  end
165
176
 
166
- meta_file_path = save(meta, "meta/#{custom_uid}")
167
- pid = Process.spawn(@cmd+" -f=#{meta_file_path} -t=#{@token}")
168
-
169
- HTTPService::NaviAI.start(start, last)
177
+ save(meta, "meta/#{custom_uid}")
170
178
  end
171
179
 
172
180
  def save(data={}, filename)
@@ -3,7 +3,7 @@ require Gem::Specification.find_by_name("navi_client").gem_dir+"/lib/client"
3
3
  module NaviClient
4
4
  class Cloud
5
5
  include Client
6
- def initialize
6
+ def initialize(sso_web_url = "http://localhost:3008/")
7
7
  # flag to print Ruby library debug info (very detailed)
8
8
  @net_imap_debug = false
9
9
 
@@ -19,7 +19,6 @@ module NaviClient
19
19
 
20
20
  # naviai command
21
21
  @cmd = 'naviai'
22
-
23
22
  # authentication token received from sso_web used to authenticate the request to database_api
24
23
  @token = nil
25
24
  end
@@ -2,16 +2,19 @@ require "httparty"
2
2
 
3
3
  GO_SERVER_URL = 'http://localhost:9090'
4
4
 
5
- CLIENT_TYPE = 'locallockbox'
6
-
7
5
  module HTTPService
8
6
  class NaviAI
9
7
 
10
- def self.start(start_time, end_time)
8
+ def self.start(file_path, client_type, token)
9
+ if client_type == 'local'
10
+ go_url = 'http://localhost:9090'
11
+ else
12
+ go_url = ''
13
+ end
11
14
  HTTParty.post(GO_SERVER_URL, body: {
12
- client_type: CLIENT_TYPE,
13
- start_time: start_time,
14
- end_time: end_time
15
+ client_type: client_type,
16
+ list_meta_path: file_path,
17
+ token: token
15
18
  })
16
19
  end
17
20
  end
@@ -2,7 +2,7 @@ require Gem::Specification.find_by_name("navi_client").gem_dir+"/lib/client"
2
2
  module NaviClient
3
3
  class Local
4
4
  include Client
5
- def initialize
5
+ def initialize(sso_web_url = 'http://localhost:3008')
6
6
  # flag to print Ruby library debug info (very detailed)
7
7
  @net_imap_debug = false
8
8
 
@@ -16,9 +16,9 @@ module NaviClient
16
16
  mkdir_if_not_exist(config['client_log_file'])
17
17
  @logger = Logger.new(config['client_log_file'])
18
18
 
19
+ @sso_web_url = sso_web_url
19
20
  # naviai command
20
21
  @cmd = 'naviai'
21
-
22
22
  # authentication token received from sso_web used to authenticate the request to database_api
23
23
  @token = nil
24
24
  end
@@ -1,3 +1,3 @@
1
1
  module NaviClient
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,80 +1,80 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: navi_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Surya
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
  date: 2017-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: bundler
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - "~>"
17
18
  - !ruby/object:Gem::Version
18
19
  version: '1.11'
19
- name: bundler
20
- prerelease: false
21
20
  type: :development
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.11'
27
27
  - !ruby/object:Gem::Dependency
28
+ name: rake
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - "~>"
31
32
  - !ruby/object:Gem::Version
32
33
  version: '10.0'
33
- name: rake
34
- prerelease: false
35
34
  type: :development
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
+ name: rspec
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
45
  - - "~>"
45
46
  - !ruby/object:Gem::Version
46
47
  version: '3.0'
47
- name: rspec
48
- prerelease: false
49
48
  type: :development
49
+ prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
+ name: httparty
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
59
  - - ">="
59
60
  - !ruby/object:Gem::Version
60
61
  version: '0'
61
- name: httparty
62
- prerelease: false
63
62
  type: :runtime
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
+ name: mail
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
72
73
  - - ">="
73
74
  - !ruby/object:Gem::Version
74
75
  version: '0'
75
- name: mail
76
- prerelease: false
77
76
  type: :runtime
77
+ prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
@@ -87,7 +87,6 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - ".DS_Store"
91
90
  - ".gitignore"
92
91
  - ".rspec"
93
92
  - ".travis.yml"
@@ -110,7 +109,7 @@ homepage: http://navihq.com
110
109
  licenses:
111
110
  - MIT
112
111
  metadata: {}
113
- post_install_message:
112
+ post_install_message:
114
113
  rdoc_options: []
115
114
  require_paths:
116
115
  - lib
@@ -125,9 +124,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
124
  - !ruby/object:Gem::Version
126
125
  version: '0'
127
126
  requirements: []
128
- rubyforge_project:
129
- rubygems_version: 2.6.11
130
- signing_key:
127
+ rubyforge_project:
128
+ rubygems_version: 2.6.12
129
+ signing_key:
131
130
  specification_version: 4
132
131
  summary: Write a short summary, because Rubygems requires one.
133
132
  test_files: []
data/.DS_Store DELETED
Binary file