Class: Zoom::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/zoom/utils.rb

Class Method Summary collapse

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



31
32
33
34
35
# File 'lib/zoom/utils.rb', line 31

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



41
42
43
44
# File 'lib/zoom/utils.rb', line 41

def extract_options!(array)
  params = array.last.is_a?(::Hash) ? array.pop : {}
  process_datetime_params!(params)
end

.parse_response(http_response) ⇒ Object



37
38
39
# File 'lib/zoom/utils.rb', line 37

def parse_response(http_response)
  raise_if_error!(http_response.parsed_response, http_response.code) || http_response.code
end

.process_datetime_params!(params) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/zoom/utils.rb', line 51

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, http_code = 200) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/zoom/utils.rb', line 14

def raise_if_error!(response, http_code=200)
  return response unless response.is_a?(Hash) && response.key?('code')

  code = response['code']
  error_hash = build_error(response)

  raise AuthenticationError, error_hash if code == 124
  raise BadRequest, error_hash if code == 400
  raise Unauthorized, error_hash if code == 401
  raise Forbidden, error_hash if code == 403
  raise NotFound, error_hash if code == 404
  raise Conflict, error_hash if code == 409
  raise TooManyRequests, error_hash if code == 429
  raise InternalServerError, error_hash if code == 500
  raise Error.new(error_hash, error_hash)
end

.validate_password(password) ⇒ Object

Raises:



46
47
48
49
# File 'lib/zoom/utils.rb', line 46

def validate_password(password)
  password_regex = /\A[a-zA-Z0-9@-_*]{0,10}\z/
  raise(Error , 'Invalid Password') unless password[password_regex].nil?
end