Module: Sms77::Journal::Validator

Defined in:
lib/sms77/journal.rb

Class Method Summary collapse

Class Method Details

.is_date?(date) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/sms77/journal.rb', line 35

def self.is_date?(date)
  date.is_a?(NilClass) || date.match(/[\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1])/)
end

.is_type?(str) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/sms77/journal.rb', line 31

def self.is_type?(str)
  Sms77::Util::in_module_constants?(str, Sms77::Journal::Type)
end

.subscribe(params) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/sms77/journal.rb', line 23

def self.subscribe(params)
  { :request_method => Sms77::Hooks::RequestMethod::POST }.merge!(params)

  self.event_type?(params[:event_type]) &&
    self.request_method?(params[:request_method]) &&
    self.target_url?(params[:target_url])
end

.validate(params) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/sms77/journal.rb', line 13

def self.validate(params)
  type = params[:type]
  date_from = params[:date_from]
  date_to = params[:date_to]

  raise "Unknown type #{type}" unless Sms77::Journal::Validator::is_type?(type)
  raise "Wrong date_from #{date_from}" unless Sms77::Journal::Validator::is_date?(date_from)
  raise "Wrong date_to #{date_to}" unless Sms77::Journal::Validator::is_date?(date_to)
end