Class: Zoom::Utils
- Inherits:
-
Object
- Object
- Zoom::Utils
- Defined in:
- lib/zoom/utils.rb
Class Method Summary collapse
- .argument_error(name) ⇒ Object
- .exclude_argument_error(name) ⇒ Object
-
.extract_options!(array) ⇒ Object
Dynamically defines bang methods for Actions modules def define_bang_methods(klass) klass.instance_methods.each do |m| klass.send(:define_method, “#m!”) do |*args| response = send(m, *args) Utils.raise_if_error!(response) end end end.
- .parse_response(http_response) ⇒ Object
- .permit_params(params, options) ⇒ Object
- .process_datetime_params!(params, options) ⇒ Object
- .raise_if_error!(response) ⇒ Object
- .require_params(params, options) ⇒ Object
- .validate_password(password) ⇒ Object
Class Method Details
.argument_error(name) ⇒ Object
6 7 8 |
# File 'lib/zoom/utils.rb', line 6 def argument_error(name) name ? ArgumentError.new("You must provide #{name}") : ArgumentError.new end |
.exclude_argument_error(name) ⇒ Object
10 11 12 |
# File 'lib/zoom/utils.rb', line 10 def exclude_argument_error(name) name ? ArgumentError.new("Unrecognized parameter #{name}") : ArgumentError.new end |
.extract_options!(array) ⇒ Object
Dynamically defines bang methods for Actions modules def define_bang_methods(klass)
klass.instance_methods.each do |m|
klass.send(:define_method, "#{m}!") do |*args|
response = send(m, *args)
Utils.raise_if_error!(response)
end
end
end
53 54 55 |
# File 'lib/zoom/utils.rb', line 53 def (array) array.last.is_a?(::Hash) ? array.pop : {} end |
.parse_response(http_response) ⇒ Object
25 26 27 |
# File 'lib/zoom/utils.rb', line 25 def parse_response(http_response) raise_if_error!(http_response.parsed_response) || http_response.code end |
.permit_params(params, options) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/zoom/utils.rb', line 36 def permit_params(params, ) params = [params] unless params.is_a? Array .keys.each do |key| raise exclude_argument_error(key.to_s) unless params.include?(key) end end |
.process_datetime_params!(params, options) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/zoom/utils.rb', line 62 def process_datetime_params!(params, ) params = [params] unless params.is_a? Array params.each do |param| if [param] && [param].kind_of?(Time) [param] = [param].strftime('%FT%TZ') end end end |
.raise_if_error!(response) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/zoom/utils.rb', line 14 def raise_if_error!(response) if response&.[]('code') && response['code'] >= 300 error_hash = { base: response['message']} raise Error, error_hash unless response['errors'] error_hash[response['message']] = response['errors'] raise Error, error_hash else response end end |
.require_params(params, options) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/zoom/utils.rb', line 29 def require_params(params, ) params = [params] unless params.is_a? Array params.each do |param| raise argument_error(param.to_s) unless [param] end end |
.validate_password(password) ⇒ Object
57 58 59 60 |
# File 'lib/zoom/utils.rb', line 57 def validate_password(password) password_regex = /\A[a-zA-Z0-9@-_*]{0,10}\z/ raise(Error , 'Invalid Password') unless password[password_regex].nil? end |