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



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
# File 'lib/zoom/utils.rb', line 34

def extract_options!(array)
  array.last.is_a?(::Hash) ? array.pop : {}
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, options) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/zoom/utils.rb', line 43

def process_datetime_params!(params, options)
  params = [params] unless params.is_a? Array
  params.each do |param|
    if options[param] && options[param].kind_of?(Time)
      options[param] = options[param].strftime('%FT%TZ')
    end
  end
  options
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

Raises:



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

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