require 'bearcat/api_array'

module Catalogcat
  class ApiArray < Bearcat::ApiArray
    def self.array_key(response)
      key = nil
      if response.env[:method] == :get
        path = response.env[:url].path
        key = 'courses' if path =~ %r{.*/courses}
        key = 'course' if path =~ %r{.*/courses/[0-9]*}
        key = 'catalogs' if path =~ %r{.*/catalogs}
        key = 'enrollments' if path =~ %r{.*/enrollments}
        key = 'order' if path =~ %r{.*/order/[0-9]*}
        key = 'completed_certificates' if path =~ %r{.*/completed_certificates}
        key = 'user_registrations' if path =~ %r{.*/user_registrations}
      end
      key.present? ? key : super(response)
    end
  end
end