Class: Zoom::Utils
- Inherits:
-
Object
- Object
- Zoom::Utils
- Defined in:
- lib/zoom/utils.rb
Class Method Summary collapse
- .argument_error(name) ⇒ Object
- .build_error(response) ⇒ Object
- .exclude_argument_error(name) ⇒ Object
- .extract_options!(array) ⇒ Object
- .parse_response(http_response) ⇒ Object
- .process_datetime_params!(params) ⇒ Object
- .raise_if_error!(response) ⇒ 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 |
.build_error(response) ⇒ Object
24 25 26 27 28 |
# File 'lib/zoom/utils.rb', line 24 def build_error(response) error_hash = { base: response['message']} error_hash[response['message']] = response['errors'] if response['errors'] error_hash 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
34 35 36 37 |
# File 'lib/zoom/utils.rb', line 34 def (array) params = array.last.is_a?(::Hash) ? array.pop : {} process_datetime_params!(params) end |
.parse_response(http_response) ⇒ Object
30 31 32 |
# File 'lib/zoom/utils.rb', line 30 def parse_response(http_response) raise_if_error!(http_response.parsed_response) || http_response.code end |
.process_datetime_params!(params) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/zoom/utils.rb', line 44 def process_datetime_params!(params) params.each do |key, value| case key when Symbol, String params[key] = value.is_a?(Time) ? value.strftime('%FT%TZ') : value when Hash process_datetime_params!(params[key]) end end params end |
.raise_if_error!(response) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/zoom/utils.rb', line 14 def raise_if_error!(response) return response unless response&.key?('code') code = response['code'] raise AuthenticationError, build_error(response) if code == 124 error_hash = build_error(response) raise Error.new(error_hash, error_hash) if code >= 300 end |
.validate_password(password) ⇒ Object
39 40 41 42 |
# File 'lib/zoom/utils.rb', line 39 def validate_password(password) password_regex = /\A[a-zA-Z0-9@-_*]{0,10}\z/ raise(Error , 'Invalid Password') unless password[password_regex].nil? end |