module Bearcat class Client < Footrest::Client module OutcomeImports def import_outcomes(file_path, params={}) params = params.with_indifferent_access params['attachment'] = Faraday::UploadIO.new(file_path, 'text/csv') url = "api/v1/#{outcome_import_context_slug(params)}" url += "group/#{params[:group]}/" if params[:group].present? params.delete(:group) post(url, params) end def outcome_import_status(id, params={}) params = params.with_indifferent_access get("api/v1/#{outcome_import_context_slug(params)}#{id}", params) end def outcome_import_created_group_ids(id, params={}) params = params.with_indifferent_access get("api/v1/#{outcome_import_context_slug(params)}#{id}/created_group_ids", params) end protected def outcome_import_context_slug(params) context_hash = params.select { |k, _| k == "account" || k == "course" } if context_hash.keys.count > 1 raise ArgumentError, "cannot have account and course in params" elsif context_hash.empty? "accounts/self/outcome_imports/" else context_hash_key = context_hash.keys.first case context_hash_key when 'account' params.delete(:account) "accounts/#{context_hash[context_hash_key]}/outcome_imports/" when 'course' params.delete(:course) "courses/#{context_hash[context_hash_key]}/outcome_imports/" end end end end end end