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
- .parse_response(http_response) ⇒ Object
- .process_datetime_params!(params) ⇒ Object
- .raise_error(response, http_code = nil) ⇒ 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
44 45 46 47 |
# File 'lib/zoom/utils.rb', line 44 def (array) params = array.last.is_a?(::Hash) ? array.pop : {} process_datetime_params!(params) end |
.parse_response(http_response) ⇒ Object
39 40 41 42 |
# File 'lib/zoom/utils.rb', line 39 def parse_response(http_response) return http_response.parsed_response || http_response.code if http_response.success? raise_error(http_response.parsed_response, http_response.code) end |
.process_datetime_params!(params) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/zoom/utils.rb', line 54 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_error(response, http_code = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/zoom/utils.rb', line 14 def raise_error(response, http_code=nil) code = response['code'] = response['message'] errors = response['errors'] case http_code when 400 raise BadRequest.new(, code, errors) when 401 raise Unauthorized.new(, code, errors) when 403 raise Forbidden.new(, code, errors) when 404 raise NotFound.new(, code, errors) when 409 raise Conflict.new(, code, errors) when 429 raise TooManyRequests.new(, code, errors) when 500 raise InternalServerError.new(, code, errors) else raise Error.new(, code, errors) end end |
.validate_password(password) ⇒ Object
49 50 51 52 |
# File 'lib/zoom/utils.rb', line 49 def validate_password(password) password_regex = /\A[a-zA-Z0-9@-_*]{0,10}\z/ raise(Error , 'Invalid Password') unless password[password_regex].nil? end |