module RequestRepeater

Constants

VERSION

Public Class Methods

logger() click to toggle source
# File lib/request_repeater.rb, line 15
def self.logger
  @logger ||= Logger.new(STDOUT)
end
logger=(logger) click to toggle source
# File lib/request_repeater.rb, line 19
def self.logger=(logger)
  @logger = logger
end
run() click to toggle source
# File lib/request_repeater.rb, line 23
def self.run
  if ENV['URL']
    endpoints = [Endpoint.new(url: ENV['URL'], sleepfor: ENV['SLEEPFOR'] || self._default_sleep)]
  elsif ENV['URLS']
    endpoints = _json_to_endpoints(ENV['URLS'])
  else
    raise ArgumentError, 'You must specify URL or URLS envirement variable'
  end

  endpoints.each { |e| e.executed }

  RequestRepeater::RequestMaker.new(endpoints).run
end
sleeptime(miliseconds) click to toggle source
# File lib/request_repeater.rb, line 11
def self.sleeptime(miliseconds)
  miliseconds / 1000.0
end

Private Class Methods

_default_sleep() click to toggle source
# File lib/request_repeater.rb, line 45
def self._default_sleep
  1000
end
_json_to_endpoints(json_string) click to toggle source
# File lib/request_repeater.rb, line 38
def self._json_to_endpoints(json_string)
  JSON
    .parse(json_string)
    .fetch('urls')
    .map { |url_options| Endpoint.new(url: url_options.fetch('url'), sleepfor: url_options['sleepfor'] || url_options['sleep'] || self._default_sleep) }
end