bearcat 1.0.0 → 1.5.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. checksums.yaml +7 -0
  2. data/bearcat.gemspec +15 -5
  3. data/lib/badgrcat/api_array.rb +25 -0
  4. data/lib/badgrcat/client/methods.rb +54 -0
  5. data/lib/badgrcat/client.rb +53 -0
  6. data/lib/badgrcat/version.rb +3 -0
  7. data/lib/bearcat/api_array.rb +132 -65
  8. data/lib/bearcat/client/account_reports.rb +6 -14
  9. data/lib/bearcat/client/accounts.rb +18 -6
  10. data/lib/bearcat/client/analytics.rb +12 -0
  11. data/lib/bearcat/client/assignment_groups.rb +15 -0
  12. data/lib/bearcat/client/assignments.rb +17 -9
  13. data/lib/bearcat/client/blueprint_courses.rb +25 -0
  14. data/lib/bearcat/client/calendar_events.rb +9 -17
  15. data/lib/bearcat/client/canvas_files.rb +0 -2
  16. data/lib/bearcat/client/conferences.rb +3 -8
  17. data/lib/bearcat/client/content_exports.rb +39 -0
  18. data/lib/bearcat/client/content_migrations.rb +54 -0
  19. data/lib/bearcat/client/conversations.rb +3 -8
  20. data/lib/bearcat/client/courses.rb +25 -14
  21. data/lib/bearcat/client/custom_gradebook_columns.rb +21 -0
  22. data/lib/bearcat/client/discussions.rb +10 -4
  23. data/lib/bearcat/client/enrollments.rb +9 -25
  24. data/lib/bearcat/client/external_tools.rb +18 -0
  25. data/lib/bearcat/client/file_helper.rb +36 -30
  26. data/lib/bearcat/client/files.rb +9 -0
  27. data/lib/bearcat/client/folders.rb +24 -0
  28. data/lib/bearcat/client/graph_ql.rb +17 -0
  29. data/lib/bearcat/client/group_categories.rb +18 -0
  30. data/lib/bearcat/client/group_memberships.rb +14 -0
  31. data/lib/bearcat/client/groups.rb +10 -2
  32. data/lib/bearcat/client/learning_outcomes.rb +17 -0
  33. data/lib/bearcat/client/logins.rb +20 -0
  34. data/lib/bearcat/client/module_items.rb +18 -0
  35. data/lib/bearcat/client/modules.rb +12 -7
  36. data/lib/bearcat/client/o_auth2.rb +18 -9
  37. data/lib/bearcat/client/outcome_groups.rb +2 -4
  38. data/lib/bearcat/client/outcome_imports.rb +48 -0
  39. data/lib/bearcat/client/outcomes.rb +4 -7
  40. data/lib/bearcat/client/pages.rb +15 -0
  41. data/lib/bearcat/client/progresses.rb +9 -0
  42. data/lib/bearcat/client/quizzes.rb +13 -9
  43. data/lib/bearcat/client/reports.rb +37 -17
  44. data/lib/bearcat/client/roles.rb +15 -0
  45. data/lib/bearcat/client/rubric.rb +17 -0
  46. data/lib/bearcat/client/rubric_assessment.rb +13 -0
  47. data/lib/bearcat/client/rubric_association.rb +13 -0
  48. data/lib/bearcat/client/search.rb +9 -0
  49. data/lib/bearcat/client/sections.rb +10 -17
  50. data/lib/bearcat/client/sis_imports.rb +6 -12
  51. data/lib/bearcat/client/submissions.rb +53 -21
  52. data/lib/bearcat/client/tabs.rb +12 -0
  53. data/lib/bearcat/client/users.rb +32 -13
  54. data/lib/bearcat/client.rb +111 -45
  55. data/lib/bearcat/client_module.rb +103 -0
  56. data/lib/bearcat/rate_limiting/increment_bucket.lua +33 -0
  57. data/lib/bearcat/rate_limiting/redis_script.rb +164 -0
  58. data/lib/bearcat/rate_limiting.rb +69 -0
  59. data/lib/bearcat/redis_connection.rb +106 -0
  60. data/lib/bearcat/spec_helpers.rb +125 -0
  61. data/lib/bearcat/version.rb +1 -1
  62. data/lib/bearcat.rb +49 -0
  63. data/lib/catalogcat/api_array.rb +22 -0
  64. data/lib/catalogcat/client/catalogs.rb +21 -0
  65. data/lib/catalogcat/client/certificates.rb +17 -0
  66. data/lib/catalogcat/client/courses.rb +25 -0
  67. data/lib/catalogcat/client/email_domain_sets.rb +17 -0
  68. data/lib/catalogcat/client/enrollments.rb +25 -0
  69. data/lib/catalogcat/client/orders.rb +13 -0
  70. data/lib/catalogcat/client/user_registrations.rb +9 -0
  71. data/lib/catalogcat/client.rb +26 -0
  72. data/lib/catalogcat/version.rb +3 -0
  73. data/lib/catalogcat.rb +14 -0
  74. data/spec/bearcat/api_array_spec.rb +112 -0
  75. data/spec/bearcat/client/accounts_spec.rb +71 -1
  76. data/spec/bearcat/client/analytics_spec.rb +22 -0
  77. data/spec/bearcat/client/assignment_groups_spec.rb +47 -0
  78. data/spec/bearcat/client/assignments_spec.rb +43 -0
  79. data/spec/bearcat/client/blueprint_courses_spec.rb +43 -0
  80. data/spec/bearcat/client/canvas_files_spec.rb +1 -2
  81. data/spec/bearcat/client/content_exports_spec.rb +68 -0
  82. data/spec/bearcat/client/content_migrations_spec.rb +94 -0
  83. data/spec/bearcat/client/courses_spec.rb +81 -2
  84. data/spec/bearcat/client/custom_gradebook_columns_spec.rb +66 -0
  85. data/spec/bearcat/client/discussions_spec.rb +73 -0
  86. data/spec/bearcat/client/enrollments_spec.rb +10 -0
  87. data/spec/bearcat/client/external_tools_spec.rb +106 -0
  88. data/spec/bearcat/client/files_spec.rb +15 -0
  89. data/spec/bearcat/client/folders_spec.rb +18 -0
  90. data/spec/bearcat/client/graph_ql_spec.rb +35 -0
  91. data/spec/bearcat/client/group_categories_spec.rb +45 -0
  92. data/spec/bearcat/client/group_membership_spec.rb +14 -0
  93. data/spec/bearcat/client/group_memberships_spec.rb +36 -0
  94. data/spec/bearcat/client/groups_spec.rb +46 -0
  95. data/spec/bearcat/client/learning_outcomes_spec.rb +25 -0
  96. data/spec/bearcat/client/module_items_spec.rb +60 -0
  97. data/spec/bearcat/client/modules_spec.rb +38 -1
  98. data/spec/bearcat/client/o_auth2_spec.rb +3 -3
  99. data/spec/bearcat/client/pages_spec.rb +17 -0
  100. data/spec/bearcat/client/quizzes_spec.rb +41 -4
  101. data/spec/bearcat/client/reports_spec.rb +40 -1
  102. data/spec/bearcat/client/roles_spec.rb +24 -0
  103. data/spec/bearcat/client/rubric_assessment_spec.rb +47 -0
  104. data/spec/bearcat/client/rubric_association_spec.rb +39 -0
  105. data/spec/bearcat/client/rubric_spec.rb +45 -0
  106. data/spec/bearcat/client/search_spec.rb +16 -0
  107. data/spec/bearcat/client/sections_spec.rb +12 -0
  108. data/spec/bearcat/client/submissions_spec.rb +47 -2
  109. data/spec/bearcat/client/users_spec.rb +43 -0
  110. data/spec/bearcat/client_spec.rb +1 -4
  111. data/spec/bearcat/rate_limiting_spec.rb +62 -0
  112. data/spec/bearcat/stub_bearcat_spec.rb +15 -0
  113. data/spec/fixtures/access_token.json +3 -0
  114. data/spec/fixtures/account_admin_create.json +14 -0
  115. data/spec/fixtures/account_admin_delete.json +15 -0
  116. data/spec/fixtures/account_admins.json +54 -0
  117. data/spec/fixtures/account_courses.json +48 -0
  118. data/spec/fixtures/account_grading_standards.json +20 -0
  119. data/spec/fixtures/account_groups.json +42 -0
  120. data/spec/fixtures/account_role.json +34 -0
  121. data/spec/fixtures/account_roles.json +35 -0
  122. data/spec/fixtures/account_sis_imports.json +39 -0
  123. data/spec/fixtures/account_sub_accounts.json +17 -0
  124. data/spec/fixtures/accounts.json +13 -0
  125. data/spec/fixtures/assignment.json +32 -0
  126. data/spec/fixtures/assignment_group.json +7 -0
  127. data/spec/fixtures/assignment_groups.json +16 -0
  128. data/spec/fixtures/blueprint_migration.json +12 -0
  129. data/spec/fixtures/blueprint_subscriptions.json +5 -0
  130. data/spec/fixtures/blueprint_template.json +7 -0
  131. data/spec/fixtures/blueprint_update_assocations_success.json +3 -0
  132. data/spec/fixtures/communication_channels.json +10 -0
  133. data/spec/fixtures/content_export.json +9 -0
  134. data/spec/fixtures/content_migration_files/content_migration.json +13 -0
  135. data/spec/fixtures/course_copy.json +18 -0
  136. data/spec/fixtures/course_files.json +38 -0
  137. data/spec/fixtures/course_folder.json +21 -0
  138. data/spec/fixtures/course_folders.json +44 -0
  139. data/spec/fixtures/course_grading_standards.json +20 -0
  140. data/spec/fixtures/course_settings.json +33 -0
  141. data/spec/fixtures/create_course_discussion.json +44 -0
  142. data/spec/fixtures/created_group.json +37 -0
  143. data/spec/fixtures/created_group_category.json +15 -0
  144. data/spec/fixtures/created_group_membership.json +8 -0
  145. data/spec/fixtures/created_module.json +13 -0
  146. data/spec/fixtures/custom_gradebook_columns/column_data.json +4 -0
  147. data/spec/fixtures/custom_gradebook_columns/custom_gradebook_column.json +7 -0
  148. data/spec/fixtures/custom_gradebook_columns/custom_gradebook_columns.json +16 -0
  149. data/spec/fixtures/custom_gradebook_columns/gradebook_column_progress.json +14 -0
  150. data/spec/fixtures/dashboard.json +6 -0
  151. data/spec/fixtures/delete_course.json +3 -0
  152. data/spec/fixtures/delete_group_category.json +3 -0
  153. data/spec/fixtures/deleted_group.json +37 -0
  154. data/spec/fixtures/department_level_participation.json +73 -0
  155. data/spec/fixtures/department_level_statistics.json +10 -0
  156. data/spec/fixtures/discussion_entries.json +21 -0
  157. data/spec/fixtures/discussion_entry_replies.json +21 -0
  158. data/spec/fixtures/discussion_topic.json +49 -0
  159. data/spec/fixtures/discussion_topics.json +51 -0
  160. data/spec/fixtures/edited_group.json +129 -0
  161. data/spec/fixtures/edited_group_category.json +15 -0
  162. data/spec/fixtures/enrollment_terms.json +1 -1
  163. data/spec/fixtures/external_tool.json +55 -0
  164. data/spec/fixtures/external_tools.json +57 -0
  165. data/spec/fixtures/file.csv +5 -0
  166. data/spec/fixtures/gradebook_history.json +52 -0
  167. data/spec/fixtures/graph_ql_scores.json +33 -0
  168. data/spec/fixtures/group.json +15 -0
  169. data/spec/fixtures/group_categories.json +28 -0
  170. data/spec/fixtures/group_category.json +13 -0
  171. data/spec/fixtures/group_category_groups.json +20 -0
  172. data/spec/fixtures/group_membership.json +7 -0
  173. data/spec/fixtures/learning_outcome.json +32 -0
  174. data/spec/fixtures/merge_user.json +8 -0
  175. data/spec/fixtures/module.json +15 -0
  176. data/spec/fixtures/module_item.json +15 -0
  177. data/spec/fixtures/module_items.json +47 -0
  178. data/spec/fixtures/ok.json +3 -0
  179. data/spec/fixtures/outcome_result.json +13 -0
  180. data/spec/fixtures/pages.json +40 -0
  181. data/spec/fixtures/progress.json +13 -0
  182. data/spec/fixtures/quizzes/course_quiz_questions.json +59 -0
  183. data/spec/fixtures/quizzes/quiz_assignment_override.json +31 -0
  184. data/spec/fixtures/reactivate_enrollment.json +20 -0
  185. data/spec/fixtures/rubric.json +13 -0
  186. data/spec/fixtures/rubric_assessment.json +32 -0
  187. data/spec/fixtures/rubric_association.json +13 -0
  188. data/spec/fixtures/search_find_recipients.json +10 -0
  189. data/spec/fixtures/update_section.json +1 -1
  190. data/spec/fixtures/user_details.json +16 -0
  191. data/spec/fixtures/user_logins.json +9 -0
  192. data/spec/helper.rb +2 -0
  193. metadata +336 -43
@@ -1,15 +1,10 @@
1
1
  module Bearcat
2
2
  class Client < Footrest::Client
3
3
  module Conferences
4
+ extend ClientModule
4
5
 
5
- def course_conferences(course)
6
- get("/api/v1/courses/#{course.to_s}/conferences")
7
- end
8
-
9
- def group_conferences(section)
10
- get("/api/v1/groups/#{section.to_s}/conferences")
11
- end
12
-
6
+ get :course_conferences, "/api/v1/courses/:course/conferences"
7
+ get :group_conferences, "/api/v1/groups/:section/conferences"
13
8
  end
14
9
  end
15
10
  end
@@ -0,0 +1,39 @@
1
+ module Bearcat
2
+ class Client < Footrest::Client
3
+ module ContentExports
4
+
5
+ def create_content_export(id, type, params = {})
6
+ post("/api/v1/#{type}/#{id}/content_exports", params)
7
+ end
8
+
9
+ def create_course_export(id, params = {})
10
+ create_content_export(id, 'courses', params)
11
+ end
12
+
13
+ def create_group_export(id, params = {})
14
+ create_content_export(id, 'groups', params)
15
+ end
16
+
17
+ def create_user_export(id, params = {})
18
+ create_content_export(id, 'users', params)
19
+ end
20
+
21
+ def get_content_export(id, export_id, type, params = {})
22
+ get("/api/v1/#{type}/#{id}/content_exports/#{export_id}", params)
23
+ end
24
+
25
+ def get_course_export(course_id, export_id, params = {})
26
+ get_content_export(course_id, export_id, 'courses', params)
27
+ end
28
+
29
+ def get_group_export(group_id, export_id, params = {})
30
+ get_content_export(group_id, export_id, 'groups', params)
31
+ end
32
+
33
+ def get_user_export(user_id, export_id, params = {})
34
+ get_content_export(user_id, export_id, 'users', params)
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,54 @@
1
+ module Bearcat
2
+ class Client < Footrest::Client
3
+ module ContentMigrations
4
+
5
+ def upload_content_package(api_path, file_path, params = {})
6
+ response = post(api_path, params)
7
+ pre_attachment = response['pre_attachment']
8
+ confirmation_url = post_file(pre_attachment['upload_url'], pre_attachment['upload_params'], file_path)
9
+ confirm_file_upload(confirmation_url)
10
+ end
11
+
12
+ def get_content_migration(id, migration_id, type, params = {})
13
+ get("/api/v1/#{type}/#{id}/content_migrations/#{migration_id}", params)
14
+ end
15
+
16
+ def get_account_content_migration(account_id, migration_id, params = {})
17
+ get_content_migration(account_id, migration_id, 'accounts', params = {})
18
+ end
19
+
20
+ def get_course_content_migration(course_id, migration_id, params = {})
21
+ get_content_migration(course_id, migration_id, 'courses', params = {})
22
+ end
23
+
24
+ def get_group_content_migration(group_id, migration_id, params = {})
25
+ get_content_migration(group_id, migration_id, 'groups', params = {})
26
+ end
27
+
28
+ def get_user_content_migration(user_id, migration_id, params = {})
29
+ get_content_migration(user_id, migration_id, 'users', params = {})
30
+ end
31
+
32
+ def create_content_migration_with_type(id, type, params = {})
33
+ post("/api/v1/#{type}/#{id}/content_migrations", params)
34
+ end
35
+
36
+ def create_account_content_migration(account_id, params = {})
37
+ create_content_migration_with_type(account_id, 'accounts', params)
38
+ end
39
+
40
+ def create_course_content_migration(course_id, params = {})
41
+ create_content_migration_with_type(course_id, 'courses', params)
42
+ end
43
+
44
+ def create_group_content_migration(group_id, params = {})
45
+ create_content_migration_with_type(group_id, 'groups', params)
46
+ end
47
+
48
+ def create_user_content_migration(user_id, params = {})
49
+ create_content_migration_with_type(user_id, 'users', params)
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -1,15 +1,10 @@
1
1
  module Bearcat
2
2
  class Client < Footrest::Client
3
3
  module Conversations
4
+ extend ClientModule
4
5
 
5
- def create_conversation(params = {})
6
- post("/api/v1/conversations", params)
7
- end
8
-
9
- def delete_conversation(conversation)
10
- delete("/api/v1/conversations/#{conversation.to_s}")
11
- end
12
-
6
+ post :create_conversation, "/api/v1/conversations"
7
+ delete :delete_conversation, "/api/v1/conversations/:conversation"
13
8
  end
14
9
  end
15
10
  end
@@ -1,28 +1,39 @@
1
1
  module Bearcat
2
2
  class Client < Footrest::Client
3
3
  module Courses
4
+ extend ClientModule
4
5
 
5
- def course(course, params={})
6
- get("/api/v1/courses/#{course}", params)
7
- end
6
+ post :create_course, "/api/v1/accounts/:account_id/courses"
7
+ get :list_users_courses, "/api/v1/courses"
8
8
 
9
- def create_course(account_id, params={})
10
- post("/api/v1/accounts/#{account_id}/courses", params)
11
- end
9
+ prefix "/api/v1/courses/:course/" do
10
+ get :course
11
+ put :update_course
12
+ delete :delete_course, defaults: { event: "delete" }
13
+ get :list_course_users, "users"
14
+ post :course_quiz_extensions, "quiz_extensions"
15
+ get :course_outcome_results, "outcome_results"
16
+
17
+ get :course_grading_standards, "grading_standards"
18
+ get :course_grading_standard, "grading_standards/:grading_standard_id"
19
+ get :course_gradebook_history, "gradebook_history/feed"
12
20
 
13
- def update_course(course, params={})
14
- put("/api/v1/courses/#{course}", params)
21
+ # Performs effectively the same operation as #create_content_migration, but without the need to specify a file to be uploaded
22
+ post :copy_course, "content_migrations"
23
+
24
+ get :course_settings, 'settings'
15
25
  end
16
26
 
17
- def list_course_users(course, params={})
18
- get("/api/v1/courses/#{course}/users", params)
27
+ def create_content_migration_with_both_responses(course, file_path, params={})
28
+ content_migration_response = post("/api/v1/courses/#{course}/content_migrations", params)
29
+ pre_attachment = content_migration_response['pre_attachment']
30
+ confirmation_url = post_file(pre_attachment['upload_url'], pre_attachment['upload_params'], file_path)
31
+ [content_migration_response, confirm_file_upload(confirmation_url)]
19
32
  end
20
33
 
21
34
  def create_content_migration(course, file_path, params={})
22
- response = post("/api/v1/courses/#{course}/content_migrations", params)
23
- pre_attachment = response['pre_attachment']
24
- confirmation_url = post_file(pre_attachment['upload_url'], pre_attachment['upload_params'], file_path)
25
- confirm_file_upload(confirmation_url)
35
+ content_migration_response, file_upload_response = create_content_migration_with_both_responses(course, file_path, params)
36
+ file_upload_response
26
37
  end
27
38
  end
28
39
  end
@@ -0,0 +1,21 @@
1
+ module Bearcat
2
+ class Client < Footrest::Client
3
+ module CustomGradebookColumns
4
+ extend ClientModule
5
+
6
+ put :bulk_update_gradebook_columns_data, "/api/v1/courses/:course/custom_gradebook_column_data"
7
+
8
+ prefix "/api/v1/courses/:course/custom_gradebook_columns/" do
9
+ get :custom_gradebook_columns
10
+ post :create_gradebook_columns
11
+
12
+ prefix ":gradebook_column/" do
13
+ put :update_gradebook_columns
14
+ delete :delete_gradebook_columns
15
+ get :gradebook_columns_data, "data"
16
+ put :update_gradebook_columns_data, "data/:student"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,11 +1,17 @@
1
1
  module Bearcat
2
2
  class Client < Footrest::Client
3
3
  module Discussions
4
+ extend ClientModule
4
5
 
5
- def create_group_discussion(group_id, params = {})
6
- post("/api/v1/groups/#{group_id}/discussion_topics", params)
7
- end
8
-
6
+ post :create_group_discussion, "/api/v1/groups/:group/discussion_topics"
7
+ post :create_course_discussion, "/api/v1/courses/:course/discussion_topics"
8
+ get :group_discussions, "/api/v1/groups/:group/discussion_topics"
9
+ get :course_discussions, "/api/v1/courses/:course/discussion_topics"
10
+ get :course_discussion, "/api/v1/courses/:course/discussion_topics/:discussion_topic"
11
+ get :group_discussion_entries, "/api/v1/groups/:group/discussion_topics/:discussion/entries"
12
+ get :course_discussion_entries, "/api/v1/courses/:course/discussion_topics/:discussion/entries"
13
+ get :group_discussion_entry_replies, "/api/v1/groups/:group/discussion_topics/:discussion/entries/:entry/replies"
14
+ get :course_discussion_entry_replies, "/api/v1/courses/:course/discussion_topics/:discussion/entries/:entry/replies"
9
15
  end
10
16
  end
11
17
  end
@@ -1,31 +1,15 @@
1
1
  module Bearcat
2
2
  class Client < Footrest::Client
3
3
  module Enrollments
4
-
5
- def user_enrollments(user, params={})
6
- get("/api/v1/users/#{user.to_s}/enrollments", params)
7
- end
8
-
9
- def course_enrollments(course, params={})
10
- get("/api/v1/courses/#{course.to_s}/enrollments", params)
11
- end
12
-
13
- def section_enrollments(section, params={})
14
- get("/api/v1/sections/#{section.to_s}/enrollments", params)
15
- end
16
-
17
- def enroll_in_section(section, params={})
18
- post("/api/v1/sections/#{section.to_s}/enrollments", params)
19
- end
20
-
21
- def enroll_in_course(course, params={})
22
- post("/api/v1/courses/#{course.to_s}/enrollments", params)
23
- end
24
-
25
- def conclude_enrollment(course, enrollment, params={})
26
- delete("/api/v1/courses/#{course}/enrollments/#{enrollment}", params)
27
- end
28
-
4
+ extend ClientModule
5
+
6
+ get :user_enrollments, "/api/v1/users/:user/enrollments"
7
+ get :course_enrollments, "/api/v1/courses/:course/enrollments"
8
+ get :section_enrollments, "/api/v1/sections/:section/enrollments"
9
+ post :enroll_in_section, "/api/v1/sections/:section/enrollments"
10
+ post :enroll_in_course, "/api/v1/courses/:course/enrollments"
11
+ delete :conclude_enrollment, "/api/v1/courses/:course/enrollments/:enrollment"
12
+ put :reactivate_enrollment, "/api/v1/courses/:course/enrollments/:enrollment/reactivate"
29
13
  end
30
14
  end
31
15
  end
@@ -0,0 +1,18 @@
1
+ module Bearcat
2
+ class Client < Footrest::Client
3
+ module ExternalTools
4
+ extend ClientModule
5
+
6
+ context_types %i[course account] do |ct|
7
+ prefix "/api/v1/#{ct}s/:#{ct}/external_tools/" do
8
+ get :"#{ct}_external_tools"
9
+ post :"create_#{ct}_external_tool"
10
+
11
+ get :"#{ct}_external_tool", ":tool"
12
+ put :"edit_#{ct}_external_tool", ":tool"
13
+ delete :"delete_#{ct}_external_tool", ":tool"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,37 +1,43 @@
1
- module FileHelper
1
+ module Bearcat
2
+ class Client < Footrest::Client
3
+ module FileHelper
4
+ def file_params(file_path)
5
+ {
6
+ size: File.open(file_path).size,
7
+ name: File.basename(file_path)
8
+ }.with_indifferent_access
9
+ end
2
10
 
3
- def file_params(file_path)
4
- {
5
- size: File.open(file_path).size,
6
- name: File.basename(file_path)
7
- }
8
- end
9
-
10
- def declare_file(api_path, params)
11
- post(api_path, params)
12
- end
11
+ def declare_file(api_path, params)
12
+ post(api_path, params)
13
+ end
13
14
 
14
- def post_file(url, params, file_path)
15
- params['Filename'] = File.basename(file_path)
16
- params['file'] = Faraday::UploadIO.new(file_path, params['content-type'])
17
- response = upload_connection.post(url, params)
18
- if [302, 303].include? response.status #success if it is a redirect
19
- response.headers['Location']
20
- else
21
- raise 'FailedFileUpload'
22
- end
23
- end
15
+ def post_file(url, params, file_path)
16
+ params['Filename'] = File.basename(file_path)
17
+ params['file'] = Faraday::UploadIO.new(file_path, params['content-type'])
18
+ response = upload_connection.post(url, params)
19
+ if [201, 302, 303].include? response.status #success if it is a redirect or 201
20
+ response.headers['Location']
21
+ else
22
+ raise 'FailedFileUpload'
23
+ end
24
+ end
24
25
 
25
- def confirm_file_upload(url)
26
- uri = URI(url)
27
- post(uri.path, CGI::parse(uri.query))
28
- end
26
+ def confirm_file_upload(url)
27
+ uri = URI(url)
28
+ uri.scheme = uri.host = uri.port = nil
29
+ get(uri.to_s)
30
+ end
29
31
 
30
- def upload_connection
31
- Faraday.new do |f|
32
- f.request :multipart
33
- f.request :url_encoded
34
- f.adapter :net_http
32
+ def upload_connection
33
+ Faraday.new do |f|
34
+ f.options[:open_timeout] = ENV.fetch('FARADAY_OPEN_TIMEOUT', 60).to_i
35
+ f.options[:timeout] = ENV.fetch('FARADAY_TIMEOUT', 60).to_i
36
+ f.request :multipart
37
+ f.request :url_encoded
38
+ f.adapter :net_http
39
+ end
40
+ end
35
41
  end
36
42
  end
37
43
  end
@@ -0,0 +1,9 @@
1
+ module Bearcat
2
+ class Client < Footrest::Client
3
+ module Files
4
+ extend ClientModule
5
+
6
+ get :list_course_files, "/api/v1/courses/:course/files"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ module Bearcat
2
+ class Client < Footrest::Client
3
+ module Folders
4
+ extend ClientModule
5
+
6
+ context_types %i[course user group] do |ct|
7
+ prefix "/api/v1/#{ct}s/:#{ct}/folders/" do
8
+ get :"list_#{ct}_folders"
9
+ post :"create_#{ct}_folder"
10
+ get :"get_#{ct}_folder", ":folder"
11
+ get :"resolve_path_for_#{ct}", "by_path/:full_path"
12
+ end
13
+ end
14
+
15
+ prefix "/api/v1/folders/:folder/" do
16
+ put :update_folder
17
+ delete :delete_folder
18
+ end
19
+
20
+ post :copy_folder, "/api/v1/folders/:destination_folder/copy_folder"
21
+ post :copy_file_to_folder, "/api/v1/folders/:destination_folder/copy_file"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ module Bearcat
2
+ class Client < Footrest::Client
3
+ # Request body format should be: { query: "query string" }. More info in README.md
4
+ module GraphQL
5
+
6
+ def graphql_query(query)
7
+ if query.is_a?(String)
8
+ query = {
9
+ query: query
10
+ }
11
+ end
12
+ post('/api/graphql', query)
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module Bearcat
2
+ class Client < Footrest::Client
3
+ module GroupCategories
4
+ extend ClientModule
5
+
6
+ prefix "/api/v1/:context/:id/group_categories/" do
7
+ get :list_group_categories
8
+ post :create_group_category
9
+ end
10
+
11
+ prefix "/api/v1/group_categories/:id/" do
12
+ get :group_category
13
+ put :edit_group_category
14
+ delete :delete_group_category
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ module Bearcat
2
+ class Client < Footrest::Client
3
+ module GroupMemberships
4
+ extend ClientModule
5
+
6
+ prefix "/api/v1/groups/:group/" do
7
+ get :group_membership, "memberships/:group_membership"
8
+ get :list_group_memberships, "memberships"
9
+ post :create_group_membership, "memberships"
10
+ delete :delete_group_membership, ":context/:context_id"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,11 +1,19 @@
1
1
  module Bearcat
2
2
  class Client < Footrest::Client
3
3
  module Groups
4
+ extend ClientModule
4
5
 
5
- def course_groups(course)
6
- get("/api/v1/courses/#{course.to_s}/groups")
6
+ prefix "/api/v1/groups/:group/" do
7
+ get :group
8
+ put :edit_group
9
+ delete :delete_group
7
10
  end
8
11
 
12
+ get :course_groups, "/api/v1/courses/:course/groups"
13
+ get :account_groups, "/api/v1/accounts/:account/groups"
14
+
15
+ get :category_groups, "/api/v1/group_categories/:group_category/groups"
16
+ post :create_group, "/api/v1/group_categories/:group_category/groups"
9
17
  end
10
18
  end
11
19
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bearcat
4
+ class Client < Footrest::Client
5
+ module LearningOutcomes
6
+
7
+ def learning_outcome(outcome, params={})
8
+ get("/api/v1/outcomes/#{outcome}", params)
9
+ end
10
+
11
+ def update_learning_outcome(outcome, params={})
12
+ put("/api/v1/outcomes/#{outcome}", params)
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ module Bearcat
2
+ class Client < Footrest::Client
3
+ module Logins
4
+ extend ClientModule
5
+
6
+ post :reset_password, "/api/v1/users/reset_password"
7
+
8
+ prefix "/api/v1/accounts/:account/logins/" do
9
+ get :account_logins
10
+ post :create_login
11
+ put :update_login, ":id"
12
+ end
13
+
14
+ prefix "/api/v1/users/:user/logins/" do
15
+ get :user_logins
16
+ delete :delete_login, ":id"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ module Bearcat
2
+ class Client < Footrest::Client
3
+ module ModuleItems
4
+ extend ClientModule
5
+
6
+ prefix "/api/v1/courses/:course/modules/:module/items/" do
7
+ get :list_module_items
8
+ post :create_module_item
9
+
10
+ prefix ":module_item/" do
11
+ get :module_item
12
+ put :update_module_item
13
+ delete :delete_module_item
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,15 +1,20 @@
1
1
  module Bearcat
2
2
  class Client < Footrest::Client
3
3
  module Modules
4
+ extend ClientModule
4
5
 
5
- def course_modules(course, params = {})
6
- get("/api/v1/courses/#{course.to_s}/modules", params)
7
- end
6
+ prefix "/api/v1/courses/:course/" do
7
+ prefix "modules/" do
8
+ get :course_modules
9
+ post :create_module
8
10
 
9
- def course_module_item_sequence(course, params = {})
10
- get("/api/v1/courses/#{course}/module_item_sequence", params)
11
- end
11
+ get :course_module, ":context_module_id"
12
+ put :update_module, ":module_id"
13
+ delete :delete_module, ":module_id"
14
+ end
12
15
 
16
+ get :course_module_item_sequence, "module_item_sequence"
17
+ end
13
18
  end
14
19
  end
15
- end
20
+ end
@@ -2,31 +2,40 @@ module Bearcat
2
2
  class Client < Footrest::Client
3
3
  module OAuth2
4
4
 
5
- def auth_redirect_url(client_id, redirect_uri, scopes = nil, response_type='code')
5
+ def auth_redirect_url(client_id, redirect_uri, opts = {})
6
+ opts[:response_type] ||= 'code'
7
+
6
8
  fullpath('login/oauth2/auth')
7
9
  uri = URI.parse(fullpath('login/oauth2/auth'))
8
10
  query = [
9
11
  ['client_id', client_id],
10
12
  ['redirect_uri', redirect_uri],
11
- ['response_type', response_type]
13
+ ['response_type', opts[:response_type]]
12
14
  ]
13
- query << ['scopes', scopes] if scopes
15
+ query << ['state', opts[:state]] if opts[:state]
16
+ query << ['scopes', opts[:scope]] if opts[:scope]
14
17
  uri.query = URI.encode_www_form(query)
15
18
  uri.to_s
16
19
  end
17
20
 
18
- def retrieve_token(client_id, redirect_url, client_secret, code)
19
- body = post('/login/oauth2/token', {
21
+ def retrieve_token(client_id, redirect_url, client_secret, code, grant_type = 'authorization_code')
22
+ token_params = {
20
23
  client_id: client_id,
21
24
  redirect_url: redirect_url,
22
25
  client_secret: client_secret,
23
- code: code
24
- })
26
+ grant_type: grant_type
27
+ }
28
+ if grant_type == 'authorization_code'
29
+ token_params[:code] = code
30
+ elsif grant_type == 'refresh_token'
31
+ token_params[:refresh_token] = code
32
+ end
33
+ body = post('/login/oauth2/token', token_params)
25
34
  config[:token] = body['access_token']
26
35
  set_connection(config)
27
- config[:token]
36
+ body
28
37
  end
29
38
 
30
39
  end
31
40
  end
32
- end
41
+ end
@@ -1,6 +1,7 @@
1
1
  module Bearcat
2
2
  class Client < Footrest::Client
3
3
  module OutcomeGroups
4
+ extend ClientModule
4
5
 
5
6
  def show_outcome_group(outcome_group_id, params={})
6
7
  get("#{outcomes_context_slug(params)}#{outcome_group_id}")
@@ -61,21 +62,18 @@ module Bearcat
61
62
  end
62
63
 
63
64
  private
65
+
64
66
  def account_slug(account_id)
65
67
  "accounts/#{account_id}/outcome_groups/"
66
68
  end
67
69
 
68
-
69
- private
70
70
  def course_slug(course_id)
71
71
  "courses/#{course_id}/outcome_groups/"
72
72
  end
73
73
 
74
- private
75
74
  def global_slug
76
75
  "global/outcome_groups/"
77
76
  end
78
-
79
77
  end
80
78
  end
81
79
  end