Module: Sms77::Hooks::Validator
- Defined in:
- lib/sms77/hooks.rb
Class Method Summary collapse
- .event_type?(str) ⇒ Boolean
- .is_action?(str) ⇒ Boolean
- .request_method?(str) ⇒ Boolean
- .subscribe(params) ⇒ Object
- .target_url?(str) ⇒ Boolean
- .unsubscribe(params) ⇒ Object
- .validate(params) ⇒ Object
Class Method Details
.event_type?(str) ⇒ Boolean
55 56 57 |
# File 'lib/sms77/hooks.rb', line 55 def self.event_type?(str) Sms77::Util::in_module_constants?(str, Sms77::Hooks::EventType) end |
.is_action?(str) ⇒ Boolean
51 52 53 |
# File 'lib/sms77/hooks.rb', line 51 def self.is_action?(str) Sms77::Util::in_module_constants?(str, Sms77::Hooks::Action) end |
.request_method?(str) ⇒ Boolean
59 60 61 |
# File 'lib/sms77/hooks.rb', line 59 def self.request_method?(str) Sms77::Util::in_module_constants?(str, Sms77::Hooks::RequestMethod) end |
.subscribe(params) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/sms77/hooks.rb', line 39 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 |
.target_url?(str) ⇒ Boolean
63 64 65 |
# File 'lib/sms77/hooks.rb', line 63 def self.target_url?(str) Sms77::Util::is_valid_url?(str) end |
.unsubscribe(params) ⇒ Object
47 48 49 |
# File 'lib/sms77/hooks.rb', line 47 def self.unsubscribe(params) Sms77::Util::is_positive_integer?(params[:id]) end |
.validate(params) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sms77/hooks.rb', line 27 def self.validate(params) action = params[:action] raise "Unknown action #{action}" unless Sms77::Hooks::Validator::is_action?(action) if Sms77::Hooks::Action::SUBSCRIBE == action raise 'Parameter validation failed' unless Sms77::Hooks::Validator::subscribe(params) elsif Sms77::Hooks::Action::UNSUBSCRIBE == action raise 'ID must be a positive integer' unless Sms77::Hooks::Validator::unsubscribe(params) end end |