Module: BotHelpers::Tests

Defined in:
lib/mail_runner/bot_helpers/tests.rb

Overview

series of initial command validation tests on launch.

Class Method Summary collapse

Class Method Details

.all_args_included?(args) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
11
12
# File 'lib/mail_runner/bot_helpers/tests.rb', line 3

def self.all_args_included?(args)
  if args[:mailbox].nil? or args[:webhook].nil?
    raise ArgumentError, 'You must include mailbox & webhook minimum. Archive argument is optional. Add -h to see help.' 
  end
  #if args.size > 3
  # raise ArgumentError, 'You can only include mailbox, webhook & Archive argument. 3 max! Add -h to see help.' 
  #end
    #?test format of mailbox?
    #? test valid webhook format?
end

.soft_test_webhook(url) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/mail_runner/bot_helpers/tests.rb', line 32

def self.soft_test_webhook(url) 
  begin
    response = RestClient.head url
    MailRunner.manager_bot.update_webhook_status("live")
    $logger.info("ManagerBot") {"webhook status: live"}
  rescue 
  end
end

.test_mailbox(path) ⇒ Object



14
15
16
17
18
# File 'lib/mail_runner/bot_helpers/tests.rb', line 14

def self.test_mailbox (path)
  unless File.file?(path)
    raise ArgumentError, 'ERROR: Mailbox not valid' 
  end
end

.test_webhook(url) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mail_runner/bot_helpers/tests.rb', line 20

def self.test_webhook(url) 
  begin
    response = RestClient.head url
    MailRunner.manager_bot.update_webhook_status("live")
  rescue 
    raise ArgumentError, "ERROR: \nMake sure the server is running and the webhook exists.\nNOTE:  Server must respond to http HEAD method.\nSee README.md for proper setup.\n"
  end
  unless response.code == 200
    raise ArgumentError, "ERROR: Invalid Webhook. NOTE, Must respond to http HEAD method."
  end
end