Module: Sms77::Journal::Validator
- Defined in:
- lib/sms77/journal.rb
Class Method Summary collapse
- .is_date?(date) ⇒ Boolean
- .is_type?(str) ⇒ Boolean
- .subscribe(params) ⇒ Object
- .validate(params) ⇒ Object
Class Method Details
.is_date?(date) ⇒ Boolean
34 35 36 |
# File 'lib/sms77/journal.rb', line 34 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
30 31 32 |
# File 'lib/sms77/journal.rb', line 30 def self.is_type?(str) Sms77::Util::in_module_constants?(str, Sms77::Journal::Type) end |
.subscribe(params) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/sms77/journal.rb', line 22 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
12 13 14 15 16 17 18 19 20 |
# File 'lib/sms77/journal.rb', line 12 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 |