Module: SevenApi::Journal::Validator
- Defined in:
- lib/seven_api/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
35 36 37 |
# File 'lib/seven_api/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
31 32 33 |
# File 'lib/seven_api/journal.rb', line 31 def self.is_type?(str) SevenApi::Util::in_module_constants?(str, SevenApi::Journal::Type) end |
.subscribe(params) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/seven_api/journal.rb', line 23 def self.subscribe(params) { :request_method => SevenApi::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/seven_api/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 SevenApi::Journal::Validator::is_type?(type) raise "Wrong date_from #{date_from}" unless SevenApi::Journal::Validator::is_date?(date_from) raise "Wrong date_to #{date_to}" unless SevenApi::Journal::Validator::is_date?(date_to) end |