Class: NaviClient::Local

Inherits:
Object
  • Object
show all
Includes:
Client
Defined in:
lib/local/navi_local_client.rb

Instance Method Summary collapse

Methods included from Client

#config, #encrypt, #idle_loop, #imap_connection, #logger, #login, #mkdir_if_not_exist, #process_email, #retrieve_emails, #save, #send_request, #shutdown, #time_now

Constructor Details

#initialize(sso_web_url = 'http://localhost:3008') ⇒ Local

Returns a new instance of Local.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/local/navi_local_client.rb', line 5

def initialize(sso_web_url = 'http://localhost:3008')
  # flag to print Ruby library debug info (very detailed)
  @net_imap_debug = false

  # flag to mark email as read after gets downloaded.
  @mark_as_read = false

  # flag to turn on/off debug mode.
  @debug = false

  # override the log file
  mkdir_if_not_exist(config['client_log_file'])
  @logger = Logger.new(config['client_log_file'])

  @sso_web_url = sso_web_url
  # naviai command
  @cmd = 'naviai'
  # authentication token received from sso_web used to authenticate the request to database_api
  @token = nil
end

Instance Method Details

#download(message, custom_uid) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/local/navi_local_client.rb', line 26

def download(message, custom_uid)
  download_path = config['download_path']
  if ['text/plain', 'text/html'].include? message.mime_type

    h = Hash.new
    out_file = download_path + message.mime_type + "/"+custom_uid
    mkdir_if_not_exist(out_file)

    File.open(out_file, 'w') { |file| file.write(encrypt(message.decoded)) }
    key = message.mime_type.split("/").join("_")

    h[key] = out_file
    return h
  end
end