bearcat 1.6.10 → 1.6.12

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 (263) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +0 -0
  3. data/lib/badgrcat/api_array.rb +0 -0
  4. data/lib/badgrcat/client.rb +15 -2
  5. data/lib/badgrcat/version.rb +0 -0
  6. data/lib/bearcat/client/account_reports.rb +0 -0
  7. data/lib/bearcat/client/analytics.rb +0 -0
  8. data/lib/bearcat/client/assignment_groups.rb +0 -0
  9. data/lib/bearcat/client/assignments.rb +0 -0
  10. data/lib/bearcat/client/blueprint_courses.rb +0 -0
  11. data/lib/bearcat/client/calendar_events.rb +0 -0
  12. data/lib/bearcat/client/canvas_files.rb +0 -0
  13. data/lib/bearcat/client/conferences.rb +0 -0
  14. data/lib/bearcat/client/content_exports.rb +0 -0
  15. data/lib/bearcat/client/content_migrations.rb +0 -0
  16. data/lib/bearcat/client/conversations.rb +0 -0
  17. data/lib/bearcat/client/custom_gradebook_columns.rb +0 -0
  18. data/lib/bearcat/client/discussions.rb +0 -0
  19. data/lib/bearcat/client/enrollments.rb +0 -0
  20. data/lib/bearcat/client/external_tools.rb +0 -0
  21. data/lib/bearcat/client/file_helper.rb +0 -0
  22. data/lib/bearcat/client/files.rb +0 -0
  23. data/lib/bearcat/client/folders.rb +0 -0
  24. data/lib/bearcat/client/group_categories.rb +0 -0
  25. data/lib/bearcat/client/group_memberships.rb +0 -0
  26. data/lib/bearcat/client/groups.rb +0 -0
  27. data/lib/bearcat/client/learning_outcomes.rb +0 -0
  28. data/lib/bearcat/client/logins.rb +0 -0
  29. data/lib/bearcat/client/module_items.rb +0 -0
  30. data/lib/bearcat/client/modules.rb +0 -0
  31. data/lib/bearcat/client/o_auth2.rb +0 -0
  32. data/lib/bearcat/client/outcome_groups.rb +0 -0
  33. data/lib/bearcat/client/outcome_imports.rb +0 -0
  34. data/lib/bearcat/client/outcomes.rb +0 -0
  35. data/lib/bearcat/client/progresses.rb +0 -0
  36. data/lib/bearcat/client/quizzes.rb +0 -0
  37. data/lib/bearcat/client/roles.rb +0 -0
  38. data/lib/bearcat/client/rubric.rb +0 -0
  39. data/lib/bearcat/client/rubric_assessment.rb +0 -0
  40. data/lib/bearcat/client/rubric_association.rb +0 -0
  41. data/lib/bearcat/client/search.rb +0 -0
  42. data/lib/bearcat/client/sections.rb +0 -0
  43. data/lib/bearcat/client/sis_imports.rb +0 -0
  44. data/lib/bearcat/client/tabs.rb +0 -0
  45. data/lib/bearcat/client_module.rb +0 -0
  46. data/lib/bearcat/rate_limiting/functions.lua +11 -0
  47. data/lib/bearcat/rate_limiting/increment_bucket.lua +0 -0
  48. data/lib/bearcat/rate_limiting/redis_script.rb +0 -0
  49. data/lib/bearcat/rate_limiting.rb +0 -0
  50. data/lib/bearcat/version.rb +1 -1
  51. data/lib/catalogcat/api_array.rb +1 -1
  52. data/lib/catalogcat/client/catalogs.rb +0 -0
  53. data/lib/catalogcat/client/certificates.rb +0 -0
  54. data/lib/catalogcat/client/courses.rb +0 -0
  55. data/lib/catalogcat/client/email_domain_sets.rb +0 -0
  56. data/lib/catalogcat/client/enrollments.rb +0 -0
  57. data/lib/catalogcat/client/orders.rb +0 -0
  58. data/lib/catalogcat/client/user_registrations.rb +1 -1
  59. data/lib/catalogcat/client.rb +0 -0
  60. data/lib/catalogcat/version.rb +0 -0
  61. data/lib/catalogcat.rb +0 -0
  62. data/spec/badgrcat/client_spec.rb +151 -0
  63. data/spec/bearcat/api_array_spec.rb +0 -0
  64. data/spec/bearcat/client/analytics_spec.rb +0 -0
  65. data/spec/bearcat/client/assignment_groups_spec.rb +0 -0
  66. data/spec/bearcat/client/assignments_spec.rb +0 -0
  67. data/spec/bearcat/client/blueprint_courses_spec.rb +0 -0
  68. data/spec/bearcat/client/calendar_events_spec.rb +0 -0
  69. data/spec/bearcat/client/canvas_files_spec.rb +0 -0
  70. data/spec/bearcat/client/conferences_spec.rb +0 -0
  71. data/spec/bearcat/client/content_exports_spec.rb +0 -0
  72. data/spec/bearcat/client/content_migrations_spec.rb +0 -0
  73. data/spec/bearcat/client/conversations_spec.rb +0 -0
  74. data/spec/bearcat/client/courses_spec.rb +0 -0
  75. data/spec/bearcat/client/custom_gradebook_columns_spec.rb +0 -0
  76. data/spec/bearcat/client/discussions_spec.rb +0 -0
  77. data/spec/bearcat/client/enrollments_spec.rb +0 -0
  78. data/spec/bearcat/client/external_tools_spec.rb +0 -0
  79. data/spec/bearcat/client/files_spec.rb +0 -0
  80. data/spec/bearcat/client/folders_spec.rb +0 -0
  81. data/spec/bearcat/client/graph_ql_spec.rb +0 -0
  82. data/spec/bearcat/client/group_categories_spec.rb +0 -0
  83. data/spec/bearcat/client/group_membership_spec.rb +0 -0
  84. data/spec/bearcat/client/group_memberships_spec.rb +0 -0
  85. data/spec/bearcat/client/groups_spec.rb +0 -0
  86. data/spec/bearcat/client/learning_outcomes_spec.rb +0 -0
  87. data/spec/bearcat/client/module_items_spec.rb +0 -0
  88. data/spec/bearcat/client/modules_spec.rb +0 -0
  89. data/spec/bearcat/client/new_quizzes_spec.rb +111 -0
  90. data/spec/bearcat/client/o_auth2_spec.rb +0 -0
  91. data/spec/bearcat/client/outcome_groups_spec.rb +0 -0
  92. data/spec/bearcat/client/outcomes_spec.rb +0 -0
  93. data/spec/bearcat/client/quizzes_spec.rb +0 -0
  94. data/spec/bearcat/client/roles_spec.rb +0 -0
  95. data/spec/bearcat/client/rubric_assessment_spec.rb +0 -0
  96. data/spec/bearcat/client/rubric_association_spec.rb +0 -0
  97. data/spec/bearcat/client/rubric_spec.rb +0 -0
  98. data/spec/bearcat/client/search_spec.rb +0 -0
  99. data/spec/bearcat/client/sections_spec.rb +0 -0
  100. data/spec/bearcat/client/submissions_spec.rb +0 -0
  101. data/spec/bearcat/client/users_spec.rb +0 -0
  102. data/spec/bearcat/rate_limiting_spec.rb +0 -0
  103. data/spec/bearcat/stub_bearcat_spec.rb +0 -0
  104. data/spec/bearcat_spec.rb +0 -0
  105. data/spec/fixtures/access_token.json +0 -0
  106. data/spec/fixtures/account_admin_create.json +0 -0
  107. data/spec/fixtures/account_admin_delete.json +0 -0
  108. data/spec/fixtures/account_admins.json +0 -0
  109. data/spec/fixtures/account_courses.json +0 -0
  110. data/spec/fixtures/account_grading_standards.json +0 -0
  111. data/spec/fixtures/account_groups.json +0 -0
  112. data/spec/fixtures/account_reports.json +0 -0
  113. data/spec/fixtures/account_reports_index.json +0 -0
  114. data/spec/fixtures/account_reports_result_success.json +0 -0
  115. data/spec/fixtures/account_reports_start_result.json +0 -0
  116. data/spec/fixtures/account_role.json +0 -0
  117. data/spec/fixtures/account_roles.json +0 -0
  118. data/spec/fixtures/account_sis_imports.json +0 -0
  119. data/spec/fixtures/account_sub_accounts.json +0 -0
  120. data/spec/fixtures/account_user.json +0 -0
  121. data/spec/fixtures/account_users.json +0 -0
  122. data/spec/fixtures/accounts.json +0 -0
  123. data/spec/fixtures/add_custom_user_data.json +0 -0
  124. data/spec/fixtures/add_user.json +0 -0
  125. data/spec/fixtures/assignment.json +0 -0
  126. data/spec/fixtures/assignment_group.json +0 -0
  127. data/spec/fixtures/assignment_groups.json +0 -0
  128. data/spec/fixtures/assignment_section_override.json +0 -0
  129. data/spec/fixtures/assignments.json +0 -0
  130. data/spec/fixtures/bearcat.jpg +0 -0
  131. data/spec/fixtures/blueprint_migration.json +0 -0
  132. data/spec/fixtures/blueprint_subscriptions.json +0 -0
  133. data/spec/fixtures/blueprint_template.json +0 -0
  134. data/spec/fixtures/blueprint_update_assocations_success.json +0 -0
  135. data/spec/fixtures/calendar_event.json +0 -0
  136. data/spec/fixtures/calendar_events.json +0 -0
  137. data/spec/fixtures/canvas_files/declare_file.json +0 -0
  138. data/spec/fixtures/canvas_files/upload_success.json +0 -0
  139. data/spec/fixtures/cc.imscc +0 -0
  140. data/spec/fixtures/communication_channels.json +0 -0
  141. data/spec/fixtures/conclude_enrollment.json +0 -0
  142. data/spec/fixtures/content_export.json +0 -0
  143. data/spec/fixtures/content_migration_files/content_migration.json +0 -0
  144. data/spec/fixtures/content_migration_files/response.json +0 -0
  145. data/spec/fixtures/content_migration_files/upload_success.json +0 -0
  146. data/spec/fixtures/conversation.json +0 -0
  147. data/spec/fixtures/course.json +0 -0
  148. data/spec/fixtures/course_conferences.json +0 -0
  149. data/spec/fixtures/course_copy.json +0 -0
  150. data/spec/fixtures/course_enrollments.json +0 -0
  151. data/spec/fixtures/course_files.json +0 -0
  152. data/spec/fixtures/course_folder.json +0 -0
  153. data/spec/fixtures/course_folders.json +0 -0
  154. data/spec/fixtures/course_grading_standards.json +0 -0
  155. data/spec/fixtures/course_groups.json +0 -0
  156. data/spec/fixtures/course_sections.json +0 -0
  157. data/spec/fixtures/course_settings.json +0 -0
  158. data/spec/fixtures/course_students.json +0 -0
  159. data/spec/fixtures/create_course_discussion.json +0 -0
  160. data/spec/fixtures/create_group_discussion.json +0 -0
  161. data/spec/fixtures/create_outcome_in_group.json +0 -0
  162. data/spec/fixtures/create_section.json +0 -0
  163. data/spec/fixtures/created_assignment.json +0 -0
  164. data/spec/fixtures/created_course.json +0 -0
  165. data/spec/fixtures/created_group.json +0 -0
  166. data/spec/fixtures/created_group_category.json +0 -0
  167. data/spec/fixtures/created_group_membership.json +0 -0
  168. data/spec/fixtures/created_module.json +0 -0
  169. data/spec/fixtures/custom_data.json +0 -0
  170. data/spec/fixtures/custom_food_data.json +0 -0
  171. data/spec/fixtures/custom_gradebook_columns/column_data.json +0 -0
  172. data/spec/fixtures/custom_gradebook_columns/custom_gradebook_column.json +0 -0
  173. data/spec/fixtures/custom_gradebook_columns/custom_gradebook_columns.json +0 -0
  174. data/spec/fixtures/custom_gradebook_columns/gradebook_column_progress.json +0 -0
  175. data/spec/fixtures/dashboard.json +0 -0
  176. data/spec/fixtures/delete_course.json +0 -0
  177. data/spec/fixtures/delete_custom_data_scope.json +0 -0
  178. data/spec/fixtures/delete_group_category.json +0 -0
  179. data/spec/fixtures/delete_section.json +0 -0
  180. data/spec/fixtures/deleted_conversation.json +0 -0
  181. data/spec/fixtures/deleted_group.json +0 -0
  182. data/spec/fixtures/department_level_participation.json +0 -0
  183. data/spec/fixtures/department_level_statistics.json +0 -0
  184. data/spec/fixtures/discussion_entries.json +0 -0
  185. data/spec/fixtures/discussion_entry_replies.json +0 -0
  186. data/spec/fixtures/discussion_topic.json +0 -0
  187. data/spec/fixtures/discussion_topics.json +0 -0
  188. data/spec/fixtures/edited_group.json +0 -0
  189. data/spec/fixtures/edited_group_category.json +0 -0
  190. data/spec/fixtures/enroll_student.json +0 -0
  191. data/spec/fixtures/enrollment_terms.json +0 -0
  192. data/spec/fixtures/external_tool.json +0 -0
  193. data/spec/fixtures/external_tools.json +0 -0
  194. data/spec/fixtures/file.csv +0 -0
  195. data/spec/fixtures/gradebook_history.json +0 -0
  196. data/spec/fixtures/graph_ql_scores.json +0 -0
  197. data/spec/fixtures/group.json +0 -0
  198. data/spec/fixtures/group_categories.json +0 -0
  199. data/spec/fixtures/group_category.json +0 -0
  200. data/spec/fixtures/group_category_groups.json +0 -0
  201. data/spec/fixtures/group_conferences.json +0 -0
  202. data/spec/fixtures/group_membership.json +0 -0
  203. data/spec/fixtures/learning_outcome.json +0 -0
  204. data/spec/fixtures/link_unlink_outcome.json +0 -0
  205. data/spec/fixtures/merge_user.json +0 -0
  206. data/spec/fixtures/module.json +0 -0
  207. data/spec/fixtures/module_item.json +0 -0
  208. data/spec/fixtures/module_item_sequence.json +0 -0
  209. data/spec/fixtures/module_items.json +0 -0
  210. data/spec/fixtures/modules.json +0 -0
  211. data/spec/fixtures/new_quizzes/new_quiz_item_categorization.json +44 -0
  212. data/spec/fixtures/new_quizzes/new_quiz_item_essay.json +29 -0
  213. data/spec/fixtures/new_quizzes/new_quiz_item_file_upload.json +32 -0
  214. data/spec/fixtures/new_quizzes/new_quiz_item_fill_in_multiple_blanks.json +65 -0
  215. data/spec/fixtures/new_quizzes/new_quiz_item_formula.json +50 -0
  216. data/spec/fixtures/new_quizzes/new_quiz_item_hot_spot.json +42 -0
  217. data/spec/fixtures/new_quizzes/new_quiz_item_matching.json +52 -0
  218. data/spec/fixtures/new_quizzes/new_quiz_item_multiple_answer.json +38 -0
  219. data/spec/fixtures/new_quizzes/new_quiz_item_numeric.json +30 -0
  220. data/spec/fixtures/new_quizzes/new_quiz_item_ordering.json +40 -0
  221. data/spec/fixtures/new_quizzes/new_quiz_item_short_answer.json +31 -0
  222. data/spec/fixtures/new_quizzes/new_quiz_item_stimulus.json +26 -0
  223. data/spec/fixtures/new_quizzes/new_quiz_item_true_false.json +29 -0
  224. data/spec/fixtures/no_custom_data.json +0 -0
  225. data/spec/fixtures/ok.json +0 -0
  226. data/spec/fixtures/outcome_group_import.json +0 -0
  227. data/spec/fixtures/outcome_groups.json +0 -0
  228. data/spec/fixtures/outcome_result.json +0 -0
  229. data/spec/fixtures/outcome_subgroup.json +0 -0
  230. data/spec/fixtures/outcome_subgroups.json +0 -0
  231. data/spec/fixtures/outcomes.json +0 -0
  232. data/spec/fixtures/paged_body.json +0 -0
  233. data/spec/fixtures/pages.json +0 -0
  234. data/spec/fixtures/progress.json +0 -0
  235. data/spec/fixtures/quizzes/course_quiz.json +0 -0
  236. data/spec/fixtures/quizzes/course_quiz_questions.json +0 -0
  237. data/spec/fixtures/quizzes/course_quizzes.json +0 -0
  238. data/spec/fixtures/quizzes/quiz_assignment_override.json +0 -0
  239. data/spec/fixtures/quizzes/quiz_extension.json +0 -0
  240. data/spec/fixtures/reactivate_enrollment.json +0 -0
  241. data/spec/fixtures/report_history.json +0 -0
  242. data/spec/fixtures/report_list.json +0 -0
  243. data/spec/fixtures/report_status.json +0 -0
  244. data/spec/fixtures/rubric.json +0 -0
  245. data/spec/fixtures/rubric_assessment.json +0 -0
  246. data/spec/fixtures/rubric_association.json +0 -0
  247. data/spec/fixtures/search_find_recipients.json +0 -0
  248. data/spec/fixtures/section.json +0 -0
  249. data/spec/fixtures/section_enrollments.json +0 -0
  250. data/spec/fixtures/single_account.json +0 -0
  251. data/spec/fixtures/start_report.json +0 -0
  252. data/spec/fixtures/submissions/submission.json +0 -0
  253. data/spec/fixtures/update_outcome.json +0 -0
  254. data/spec/fixtures/update_outcome_group.json +0 -0
  255. data/spec/fixtures/update_section.json +0 -0
  256. data/spec/fixtures/updated_course.json +0 -0
  257. data/spec/fixtures/user_avatars.json +0 -0
  258. data/spec/fixtures/user_details.json +0 -0
  259. data/spec/fixtures/user_enrollments.json +0 -0
  260. data/spec/fixtures/user_logins.json +0 -0
  261. data/spec/fixtures/user_page_views.json +0 -0
  262. data/spec/fixtures/user_profile.json +0 -0
  263. metadata +31 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6da81a40773d9eba82a151acdfbca17550ae9a707b6089f31a1df74f5e9c8abd
4
- data.tar.gz: 0f6de89595ede0206490f91d7490311e29d4206c42f35b21e8f35e36ea3dabd1
3
+ metadata.gz: f52b8360f7ce34fd388a13bb54935a02f659eb85f283d99f2afcfadb8c2ad2fa
4
+ data.tar.gz: d22ffcf503be32f35771341fc2183bde298a1f9802172efba7ba5d1813ec7725
5
5
  SHA512:
6
- metadata.gz: fd621b13dbecaeabadce71ddc403836f40d78e62439db93dd0066fd7f823a761b469250ba51692d5ea68368d6632cab5da7faf45da55b2c8077777c85167d696
7
- data.tar.gz: 35497af71785998f52ac54d9f5729b56777d76f94f882878aecd21d33281b5058f0df4a9ba6db414fe87c179c002bb6599ffab18d9d80a8bbf73e98220fe2d82
6
+ metadata.gz: 947870a0adcbde03d22ed11db07c853f03d7236376d04b9f4a138e7f3033c65470ea68c9216f0689361af969560c575675940a6d15e7a59c1d6f570318060ae7
7
+ data.tar.gz: 200a1712dbb4449d892fa8821efecf6208fc72f931205fd9ff48b6f955cccfbcc6d62cf365a41cd5042927705ce36ee7b2e78216f271632225ac14dd3b62d68a
data/Rakefile CHANGED
File without changes
File without changes
@@ -10,6 +10,17 @@ module Badgrcat
10
10
  include "Badgrcat::Client::#{mname}".constantize
11
11
  end
12
12
 
13
+ attr_reader :access_token, :refresh_token, :expires_in
14
+
15
+ def initialize(options = {}, &block)
16
+ super
17
+ @refresh_token = config[:refresh_token] if config[:refresh_token].present?
18
+ if config[:access_token].present?
19
+ connection.headers[:authorization] = "Bearer #{config[:access_token]}"
20
+ connection.headers['Content-Type'] = 'application/json'
21
+ end
22
+ end
23
+
13
24
  # Override Footrest request for ApiArray support
14
25
  def request(method, &block)
15
26
  response = begin
@@ -44,6 +55,7 @@ module Badgrcat
44
55
 
45
56
  def authenticate!
46
57
  connection.headers[:authorization] = nil
58
+ connection.headers['Content-Type'] = nil
47
59
 
48
60
  auth_url = config[:auth_url]
49
61
 
@@ -71,10 +83,11 @@ module Badgrcat
71
83
  authresp = connection.send(:post, auth_url, tok_params)
72
84
  authdata = authresp.body
73
85
 
86
+ @access_token = authdata["access_token"]
74
87
  @refresh_token = authdata["refresh_token"].presence || @refresh_token
75
- connection.headers[:authorization] = "#{authdata['token_type']} #{authdata['access_token']}"
88
+ @expires_in = authdata["expires_in"]
76
89
 
77
- # Set content type as application/json
90
+ connection.headers[:authorization] = "#{authdata['token_type']} #{@access_token}"
78
91
  connection.headers['Content-Type'] = "application/json"
79
92
  end
80
93
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,11 @@
1
+ #!lua name=bearcat_rate_limiting
2
+
3
+ local function checkin_time(keys, args)
4
+ local return_time = args[1]
5
+ local true_remaining = args[2]
6
+
7
+ local hash = keys[1]
8
+ return redis.call('HGET', hash, '_last_modified_')
9
+ end
10
+
11
+ redis.register_function('my_hset', my_hset)
File without changes
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module Bearcat
2
- VERSION = '1.6.10' unless defined?(Bearcat::VERSION)
2
+ VERSION = '1.6.12' unless defined?(Bearcat::VERSION)
3
3
  end
@@ -13,7 +13,7 @@ module Catalogcat
13
13
  key = 'order' if path =~ %r{.*/order/[0-9]*}
14
14
  key = 'orders' if path =~ %r{.*/orders}
15
15
  key = 'completed_certificates' if path =~ %r{.*/completed_certificates}
16
- key = 'user_registrations' if path =~ %r{.*/user_registrations}
16
+ key = 'users' if path =~ %r{.*/users}
17
17
  key = 'email_domain_sets' if path =~ %r{.*/email_domain_sets}
18
18
  end
19
19
  key.present? ? key : super(response)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -2,7 +2,7 @@ module Catalogcat
2
2
  class Client < Footrest::Client
3
3
  module UserRegistrations
4
4
  def list_user_registrations(params = {})
5
- get("/api/v1/user_registrations", params)
5
+ get("/api/v1/users", { registered_in_catalog: true }.merge(params))
6
6
  end
7
7
  end
8
8
  end
File without changes
File without changes
data/lib/catalogcat.rb CHANGED
File without changes
@@ -0,0 +1,151 @@
1
+ require 'helper'
2
+ require 'badgrcat/client'
3
+
4
+ describe Badgrcat::Client do
5
+ let(:auth_url) { 'http://localhost:3000/o/token' }
6
+ let(:token_response) do
7
+ {
8
+ 'access_token' => 'new_access_token',
9
+ 'refresh_token' => 'new_refresh_token',
10
+ 'expires_in' => 86400,
11
+ 'token_type' => 'Bearer'
12
+ }
13
+ end
14
+
15
+ before do
16
+ stub_request(:post, auth_url)
17
+ .to_return(status: 200, body: token_response.to_json, headers: { 'Content-Type' => 'application/json' })
18
+ end
19
+
20
+ describe '#authenticate!' do
21
+ context 'with username/password credentials' do
22
+ let(:client) do
23
+ Badgrcat::Client.new(
24
+ prefix: 'http://localhost:3000',
25
+ auth_url: auth_url,
26
+ username: 'user@example.com',
27
+ password: 'password123'
28
+ )
29
+ end
30
+
31
+ it 'exposes token attributes' do
32
+ client.authenticate!
33
+
34
+ expect(client.access_token).to eq('new_access_token')
35
+ expect(client.refresh_token).to eq('new_refresh_token')
36
+ expect(client.expires_in).to eq(86400)
37
+ end
38
+
39
+ it 'sends username and password in the auth request' do
40
+ client.authenticate!
41
+
42
+ expect(WebMock).to have_requested(:post, auth_url)
43
+ .with(body: hash_including(username: 'user@example.com', password: 'password123'))
44
+ end
45
+
46
+ it 'sets the authorization header' do
47
+ client.authenticate!
48
+
49
+ expect(client.connection.headers[:authorization]).to eq('Bearer new_access_token')
50
+ end
51
+ end
52
+
53
+ context 'with a refresh token from config' do
54
+ let(:client) do
55
+ Badgrcat::Client.new(
56
+ prefix: 'http://localhost:3000',
57
+ auth_url: auth_url,
58
+ refresh_token: 'stored_refresh_token'
59
+ )
60
+ end
61
+
62
+ it 'sends the refresh token in the auth request' do
63
+ client.authenticate!
64
+
65
+ expect(WebMock).to have_requested(:post, auth_url)
66
+ .with(body: hash_including(grant_type: 'refresh_token', refresh_token: 'stored_refresh_token'))
67
+ end
68
+
69
+ it 'does not send username or password' do
70
+ client.authenticate!
71
+
72
+ expect(WebMock).not_to have_requested(:post, auth_url)
73
+ .with(body: hash_including(:username))
74
+ end
75
+
76
+ it 'exposes updated token attributes after auth' do
77
+ client.authenticate!
78
+
79
+ expect(client.access_token).to eq('new_access_token')
80
+ expect(client.refresh_token).to eq('new_refresh_token')
81
+ expect(client.expires_in).to eq(86400)
82
+ end
83
+ end
84
+
85
+ context 'when both refresh token and credentials are provided' do
86
+ let(:client) do
87
+ Badgrcat::Client.new(
88
+ prefix: 'http://localhost:3000',
89
+ auth_url: auth_url,
90
+ username: 'user@example.com',
91
+ password: 'password123',
92
+ refresh_token: 'stored_refresh_token'
93
+ )
94
+ end
95
+
96
+ it 'uses the refresh token' do
97
+ client.authenticate!
98
+
99
+ expect(WebMock).to have_requested(:post, auth_url)
100
+ .with(body: hash_including(grant_type: 'refresh_token', refresh_token: 'stored_refresh_token'))
101
+ end
102
+ end
103
+
104
+ context 'on subsequent auth calls' do
105
+ let(:client) do
106
+ Badgrcat::Client.new(
107
+ prefix: 'http://localhost:3000',
108
+ auth_url: auth_url,
109
+ username: 'user@example.com',
110
+ password: 'password123'
111
+ )
112
+ end
113
+
114
+ it 'uses the refresh token obtained from the first auth call' do
115
+ client.authenticate!
116
+ expect(client.refresh_token).to eq('new_refresh_token')
117
+
118
+ client.authenticate!
119
+ expect(client.refresh_token).to eq('new_refresh_token')
120
+ expect(client.access_token).to eq('new_access_token')
121
+
122
+ expect(WebMock).to have_requested(:post, auth_url)
123
+ .with(body: hash_including(grant_type: 'refresh_token', refresh_token: 'new_refresh_token'))
124
+ end
125
+ end
126
+
127
+ context 'when the response omits a refresh token' do
128
+ let(:token_response) do
129
+ {
130
+ 'access_token' => 'another_access_token',
131
+ 'refresh_token' => nil,
132
+ 'expires_in' => 86400,
133
+ 'token_type' => 'Bearer'
134
+ }
135
+ end
136
+
137
+ let(:client) do
138
+ Badgrcat::Client.new(
139
+ prefix: 'http://localhost:3000',
140
+ auth_url: auth_url,
141
+ refresh_token: 'original_refresh_token'
142
+ )
143
+ end
144
+
145
+ it 'keeps the existing refresh token' do
146
+ client.authenticate!
147
+ expect(client.refresh_token).to eq('original_refresh_token')
148
+ end
149
+ end
150
+ end
151
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -83,6 +83,117 @@ describe Bearcat::Client::NewQuizzes do
83
83
  expect { @client.delete_new_quiz_item('1', '1', '1') }.not_to raise_error
84
84
  end
85
85
 
86
+ # Item types
87
+ it 'returns a true/false item' do
88
+ stub_get(@client, '/api/quiz/v1/courses/1/quizzes/1/items/2').to_return(json_response('new_quizzes/new_quiz_item_true_false.json'))
89
+ item = @client.new_quiz_item('1', '1', '2')
90
+ item['entry']['interaction_type_slug'].should == 'true-false'
91
+ item['entry']['interaction_data']['true_choice'].should == 'True'
92
+ item['entry']['interaction_data']['false_choice'].should == 'False'
93
+ item['entry']['scoring_data']['value'].should == true
94
+ end
95
+
96
+ it 'returns a matching item' do
97
+ stub_get(@client, '/api/quiz/v1/courses/1/quizzes/1/items/3').to_return(json_response('new_quizzes/new_quiz_item_matching.json'))
98
+ item = @client.new_quiz_item('1', '1', '3')
99
+ item['entry']['interaction_type_slug'].should == 'matching'
100
+ item['entry']['interaction_data']['questions'].count.should == 4
101
+ item['entry']['interaction_data']['answers'].count.should == 5
102
+ item['entry']['scoring_data']['value'].should be_a(Hash)
103
+ item['entry']['scoring_data']['value']['q1'].should == 'Mammal'
104
+ item['entry']['scoring_algorithm'].should == 'PartialDeep'
105
+ end
106
+
107
+ it 'returns a categorization item' do
108
+ stub_get(@client, '/api/quiz/v1/courses/1/quizzes/1/items/4').to_return(json_response('new_quizzes/new_quiz_item_categorization.json'))
109
+ item = @client.new_quiz_item('1', '1', '4')
110
+ item['entry']['interaction_type_slug'].should == 'categorization'
111
+ item['entry']['interaction_data']['categories'].count.should == 2
112
+ item['entry']['interaction_data']['choices'].count.should == 3
113
+ end
114
+
115
+ it 'returns a rich-fill-blank item' do
116
+ stub_get(@client, '/api/quiz/v1/courses/1/quizzes/1/items/5').to_return(json_response('new_quizzes/new_quiz_item_fill_in_multiple_blanks.json'))
117
+ item = @client.new_quiz_item('1', '1', '5')
118
+ item['entry']['interaction_type_slug'].should == 'rich-fill-blank'
119
+ item['entry']['interaction_data']['blanks'].count.should == 2
120
+ item['entry']['interaction_data']['blanks'].first['answer_type'].should == 'openEntry'
121
+ item['entry']['interaction_data']['blanks'].last['answer_type'].should == 'dropdown'
122
+ item['entry']['scoring_algorithm'].should == 'MultipleMethods'
123
+ end
124
+
125
+ it 'returns a multi-answer item' do
126
+ stub_get(@client, '/api/quiz/v1/courses/1/quizzes/1/items/6').to_return(json_response('new_quizzes/new_quiz_item_multiple_answer.json'))
127
+ item = @client.new_quiz_item('1', '1', '6')
128
+ item['entry']['interaction_type_slug'].should == 'multi-answer'
129
+ item['entry']['scoring_data']['value'].count.should == 3
130
+ item['entry']['scoring_algorithm'].should == 'PartialScore'
131
+ end
132
+
133
+ it 'returns an ordering item' do
134
+ stub_get(@client, '/api/quiz/v1/courses/1/quizzes/1/items/7').to_return(json_response('new_quizzes/new_quiz_item_ordering.json'))
135
+ item = @client.new_quiz_item('1', '1', '7')
136
+ item['entry']['interaction_type_slug'].should == 'ordering'
137
+ item['entry']['interaction_data']['choices'].should be_a(Hash)
138
+ item['entry']['scoring_data']['value'].should == ['choice1', 'choice2', 'choice3', 'choice4']
139
+ item['entry']['scoring_algorithm'].should == 'DeepEquals'
140
+ end
141
+
142
+ it 'returns a short_answer item' do
143
+ stub_get(@client, '/api/quiz/v1/courses/1/quizzes/1/items/8').to_return(json_response('new_quizzes/new_quiz_item_short_answer.json'))
144
+ item = @client.new_quiz_item('1', '1', '8')
145
+ item['entry']['interaction_type_slug'].should == 'short_answer'
146
+ item['entry']['interaction_data']['answers'].first['item_body'].should == 'photosynthesis'
147
+ end
148
+
149
+ it 'returns an essay item' do
150
+ stub_get(@client, '/api/quiz/v1/courses/1/quizzes/1/items/9').to_return(json_response('new_quizzes/new_quiz_item_essay.json'))
151
+ item = @client.new_quiz_item('1', '1', '9')
152
+ item['entry']['interaction_type_slug'].should == 'essay'
153
+ item['entry']['scoring_algorithm'].should == 'None'
154
+ end
155
+
156
+ it 'returns a file-upload item' do
157
+ stub_get(@client, '/api/quiz/v1/courses/1/quizzes/1/items/10').to_return(json_response('new_quizzes/new_quiz_item_file_upload.json'))
158
+ item = @client.new_quiz_item('1', '1', '10')
159
+ item['entry']['interaction_type_slug'].should == 'file-upload'
160
+ item['entry']['interaction_data']['files_count'].should == '1'
161
+ item['entry']['scoring_algorithm'].should == 'None'
162
+ end
163
+
164
+ it 'returns a numeric item' do
165
+ stub_get(@client, '/api/quiz/v1/courses/1/quizzes/1/items/11').to_return(json_response('new_quizzes/new_quiz_item_numeric.json'))
166
+ item = @client.new_quiz_item('1', '1', '11')
167
+ item['entry']['interaction_type_slug'].should == 'numeric'
168
+ item['entry']['interaction_data'].should == {}
169
+ item['entry']['scoring_data']['value'].first['type'].should == 'exactResponse'
170
+ item['entry']['scoring_algorithm'].should == 'Numeric'
171
+ end
172
+
173
+ it 'returns a formula item' do
174
+ stub_get(@client, '/api/quiz/v1/courses/1/quizzes/1/items/12').to_return(json_response('new_quizzes/new_quiz_item_formula.json'))
175
+ item = @client.new_quiz_item('1', '1', '12')
176
+ item['entry']['interaction_type_slug'].should == 'formula'
177
+ item['entry']['interaction_data'].should == {}
178
+ item['entry']['scoring_data']['value']['variables'].count.should == 2
179
+ item['entry']['scoring_algorithm'].should == 'Numeric'
180
+ end
181
+
182
+ it 'returns a hot_spot item' do
183
+ stub_get(@client, '/api/quiz/v1/courses/1/quizzes/1/items/13').to_return(json_response('new_quizzes/new_quiz_item_hot_spot.json'))
184
+ item = @client.new_quiz_item('1', '1', '13')
185
+ item['entry']['interaction_type_slug'].should == 'hot_spot'
186
+ item['entry']['interaction_data']['regions'].first['shape'].should == 'rectangle'
187
+ end
188
+
189
+ it 'returns a stimulus item' do
190
+ stub_get(@client, '/api/quiz/v1/courses/1/quizzes/1/items/14').to_return(json_response('new_quizzes/new_quiz_item_stimulus.json'))
191
+ item = @client.new_quiz_item('1', '1', '14')
192
+ item['entry_type'].should == 'Stimulus'
193
+ item['entry']['interaction_type_slug'].should == 'stimulus'
194
+ item['points_possible'].should == 0.0
195
+ end
196
+
86
197
  # Submissions
87
198
  it 'returns a list of submissions for a new quiz' do
88
199
  stub_get(@client, '/api/quiz/v1/courses/1/quizzes/1/submissions').to_return(json_response('new_quizzes/new_quiz_submissions.json'))
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/spec/bearcat_spec.rb CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes