require 'zoom'
require 'zoom_gateway'

unless Rails.env.test?
  Zoom.configure do |c|
    c.api_key = ENV['ZOOM_API_KEY']
    c.api_secret = ENV['ZOOM_API_SECRET']
  end
end

class Zoom::APIError < StandardError
  attr_reader :status_code
  def initialize(status_code)
    super
    @status_code = status_code
  end
end

module RaiseErrorsWithCodes
  def raise_if_error!(response)
    if response&.[]('code') && (response['code'] >= 300 || response['code'] == 124)
      raise Zoom::APIError.new(response['code']), response['message']
    else
      super
    end
  end
end
Zoom::Utils.singleton_class.send :prepend, RaiseErrorsWithCodes