module Bearcat class Client < Footrest::Client module OutcomeGroups def show_outcome_group(outcome_group_id, params={}) get("#{outcomes_context_slug(params)}#{outcome_group_id}") end def update_outcome_group(outcome_group_id, params={}) put("#{outcomes_context_slug(params)}#{outcome_group_id}", params) end def delete_outcome_group(outcome_group_id, params={}) delete("#{outcomes_context_slug(params)}#{outcome_group_id}") end def list_linked_outcomes(outcome_group_id, params={}) get("#{outcomes_context_slug(params)}#{outcome_group_id}/outcomes") end def create_outcome_in_group(outcome_group_id, params={}) post("#{outcomes_context_slug(params)}#{outcome_group_id}/outcomes", params) end def link_outcome(outcome_group_id, outcome_id, params={}) put("#{outcomes_context_slug(params)}#{outcome_group_id}/outcomes/#{outcome_id}") end def unlink_outcome(outcome_group_id, outcome_id, params={}) delete("#{outcomes_context_slug(params)}#{outcome_group_id}/outcomes/#{outcome_id}") end def list_subgroups(outcome_group_id, params={}) get("#{outcomes_context_slug(params)}#{outcome_group_id}/subgroups") end def create_subgroup(outcome_group_id, params={}) post("#{outcomes_context_slug(params)}#{outcome_group_id}/subgroups", params) end def import_outcome_group(outcome_group_id, params={}) post("#{outcomes_context_slug(params)}#{outcome_group_id}/import", params) end def outcomes_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? return "#{config.prefix}#{global_slug}" else context_hash_key = context_hash.keys.first case context_hash_key when 'account' "#{config.prefix}#{account_slug(context_hash[context_hash_key])}" when 'course' "#{config.prefix}#{course_slug(context_hash[context_hash_key])}" end end end private def account_slug(account_id) "accounts/#{account_id}/outcome_groups/" end private def course_slug(course_id) "courses/#{course_id}/outcome_groups/" end private def global_slug "global/outcome_groups/" end end end end