bearcat 1.6.10 → 1.7.0
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.
- checksums.yaml +4 -4
- data/Rakefile +0 -0
- data/bearcat.gemspec +5 -3
- data/lib/badgrcat/api_array.rb +0 -0
- data/lib/badgrcat/client.rb +15 -2
- data/lib/badgrcat/version.rb +0 -0
- data/lib/bearcat/api_array.rb +1 -0
- data/lib/bearcat/client/account_reports.rb +0 -0
- data/lib/bearcat/client/analytics.rb +0 -0
- data/lib/bearcat/client/assignment_groups.rb +0 -0
- data/lib/bearcat/client/assignments.rb +0 -0
- data/lib/bearcat/client/blueprint_courses.rb +0 -0
- data/lib/bearcat/client/calendar_events.rb +0 -0
- data/lib/bearcat/client/canvas_files.rb +0 -0
- data/lib/bearcat/client/conferences.rb +0 -0
- data/lib/bearcat/client/content_exports.rb +0 -0
- data/lib/bearcat/client/content_migrations.rb +0 -0
- data/lib/bearcat/client/conversations.rb +0 -0
- data/lib/bearcat/client/custom_gradebook_columns.rb +0 -0
- data/lib/bearcat/client/discussions.rb +0 -0
- data/lib/bearcat/client/enrollments.rb +0 -0
- data/lib/bearcat/client/external_tools.rb +0 -0
- data/lib/bearcat/client/file_helper.rb +1 -1
- data/lib/bearcat/client/files.rb +0 -0
- data/lib/bearcat/client/folders.rb +0 -0
- data/lib/bearcat/client/group_categories.rb +0 -0
- data/lib/bearcat/client/group_memberships.rb +0 -0
- data/lib/bearcat/client/groups.rb +0 -0
- data/lib/bearcat/client/learning_outcomes.rb +0 -0
- data/lib/bearcat/client/logins.rb +0 -0
- data/lib/bearcat/client/module_items.rb +0 -0
- data/lib/bearcat/client/modules.rb +0 -0
- data/lib/bearcat/client/o_auth2.rb +0 -0
- data/lib/bearcat/client/outcome_groups.rb +0 -0
- data/lib/bearcat/client/outcome_imports.rb +1 -1
- data/lib/bearcat/client/outcomes.rb +0 -0
- data/lib/bearcat/client/progresses.rb +0 -0
- data/lib/bearcat/client/quizzes.rb +0 -0
- data/lib/bearcat/client/roles.rb +0 -0
- data/lib/bearcat/client/rubric.rb +0 -0
- data/lib/bearcat/client/rubric_assessment.rb +0 -0
- data/lib/bearcat/client/rubric_association.rb +0 -0
- data/lib/bearcat/client/search.rb +0 -0
- data/lib/bearcat/client/sections.rb +0 -0
- data/lib/bearcat/client/sis_imports.rb +1 -1
- data/lib/bearcat/client/tabs.rb +0 -0
- data/lib/bearcat/client.rb +14 -0
- data/lib/bearcat/client_module.rb +0 -0
- data/lib/bearcat/rate_limiting/functions.lua +11 -0
- data/lib/bearcat/rate_limiting/increment_bucket.lua +0 -0
- data/lib/bearcat/rate_limiting/redis_script.rb +0 -0
- data/lib/bearcat/rate_limiting.rb +0 -0
- data/lib/bearcat/version.rb +1 -1
- data/lib/catalogcat/api_array.rb +1 -1
- data/lib/catalogcat/client/catalogs.rb +0 -0
- data/lib/catalogcat/client/certificates.rb +0 -0
- data/lib/catalogcat/client/courses.rb +0 -0
- data/lib/catalogcat/client/email_domain_sets.rb +0 -0
- data/lib/catalogcat/client/enrollments.rb +0 -0
- data/lib/catalogcat/client/orders.rb +0 -0
- data/lib/catalogcat/client/user_registrations.rb +1 -1
- data/lib/catalogcat/client.rb +0 -0
- data/lib/catalogcat/version.rb +0 -0
- data/lib/catalogcat.rb +0 -0
- data/spec/badgrcat/client_spec.rb +151 -0
- data/spec/bearcat/api_array_spec.rb +8 -8
- data/spec/bearcat/client/analytics_spec.rb +0 -0
- data/spec/bearcat/client/assignment_groups_spec.rb +0 -0
- data/spec/bearcat/client/assignments_spec.rb +0 -0
- data/spec/bearcat/client/blueprint_courses_spec.rb +0 -0
- data/spec/bearcat/client/calendar_events_spec.rb +0 -0
- data/spec/bearcat/client/canvas_files_spec.rb +0 -0
- data/spec/bearcat/client/conferences_spec.rb +0 -0
- data/spec/bearcat/client/content_exports_spec.rb +0 -0
- data/spec/bearcat/client/content_migrations_spec.rb +0 -0
- data/spec/bearcat/client/conversations_spec.rb +0 -0
- data/spec/bearcat/client/courses_spec.rb +0 -0
- data/spec/bearcat/client/custom_gradebook_columns_spec.rb +0 -0
- data/spec/bearcat/client/discussions_spec.rb +0 -0
- data/spec/bearcat/client/enrollments_spec.rb +0 -0
- data/spec/bearcat/client/external_tools_spec.rb +0 -0
- data/spec/bearcat/client/files_spec.rb +0 -0
- data/spec/bearcat/client/folders_spec.rb +0 -0
- data/spec/bearcat/client/graph_ql_spec.rb +0 -0
- data/spec/bearcat/client/group_categories_spec.rb +0 -0
- data/spec/bearcat/client/group_membership_spec.rb +0 -0
- data/spec/bearcat/client/group_memberships_spec.rb +0 -0
- data/spec/bearcat/client/groups_spec.rb +0 -0
- data/spec/bearcat/client/learning_outcomes_spec.rb +0 -0
- data/spec/bearcat/client/module_items_spec.rb +0 -0
- data/spec/bearcat/client/modules_spec.rb +0 -0
- data/spec/bearcat/client/new_quizzes_spec.rb +111 -0
- data/spec/bearcat/client/o_auth2_spec.rb +0 -0
- data/spec/bearcat/client/outcome_groups_spec.rb +0 -0
- data/spec/bearcat/client/outcomes_spec.rb +0 -0
- data/spec/bearcat/client/quizzes_spec.rb +0 -0
- data/spec/bearcat/client/roles_spec.rb +0 -0
- data/spec/bearcat/client/rubric_assessment_spec.rb +0 -0
- data/spec/bearcat/client/rubric_association_spec.rb +0 -0
- data/spec/bearcat/client/rubric_spec.rb +0 -0
- data/spec/bearcat/client/search_spec.rb +0 -0
- data/spec/bearcat/client/sections_spec.rb +0 -0
- data/spec/bearcat/client/submissions_spec.rb +0 -0
- data/spec/bearcat/client/users_spec.rb +0 -0
- data/spec/bearcat/rate_limiting_spec.rb +0 -0
- data/spec/bearcat/stub_bearcat_spec.rb +0 -0
- data/spec/bearcat_spec.rb +0 -0
- data/spec/fixtures/access_token.json +0 -0
- data/spec/fixtures/account_admin_create.json +0 -0
- data/spec/fixtures/account_admin_delete.json +0 -0
- data/spec/fixtures/account_admins.json +0 -0
- data/spec/fixtures/account_courses.json +0 -0
- data/spec/fixtures/account_grading_standards.json +0 -0
- data/spec/fixtures/account_groups.json +0 -0
- data/spec/fixtures/account_reports.json +0 -0
- data/spec/fixtures/account_reports_index.json +0 -0
- data/spec/fixtures/account_reports_result_success.json +0 -0
- data/spec/fixtures/account_reports_start_result.json +0 -0
- data/spec/fixtures/account_role.json +0 -0
- data/spec/fixtures/account_roles.json +0 -0
- data/spec/fixtures/account_sis_imports.json +0 -0
- data/spec/fixtures/account_sub_accounts.json +0 -0
- data/spec/fixtures/account_user.json +0 -0
- data/spec/fixtures/account_users.json +0 -0
- data/spec/fixtures/accounts.json +0 -0
- data/spec/fixtures/add_custom_user_data.json +0 -0
- data/spec/fixtures/add_user.json +0 -0
- data/spec/fixtures/assignment.json +0 -0
- data/spec/fixtures/assignment_group.json +0 -0
- data/spec/fixtures/assignment_groups.json +0 -0
- data/spec/fixtures/assignment_section_override.json +0 -0
- data/spec/fixtures/assignments.json +0 -0
- data/spec/fixtures/bearcat.jpg +0 -0
- data/spec/fixtures/blueprint_migration.json +0 -0
- data/spec/fixtures/blueprint_subscriptions.json +0 -0
- data/spec/fixtures/blueprint_template.json +0 -0
- data/spec/fixtures/blueprint_update_assocations_success.json +0 -0
- data/spec/fixtures/calendar_event.json +0 -0
- data/spec/fixtures/calendar_events.json +0 -0
- data/spec/fixtures/canvas_files/declare_file.json +0 -0
- data/spec/fixtures/canvas_files/upload_success.json +0 -0
- data/spec/fixtures/cc.imscc +0 -0
- data/spec/fixtures/communication_channels.json +0 -0
- data/spec/fixtures/conclude_enrollment.json +0 -0
- data/spec/fixtures/content_export.json +0 -0
- data/spec/fixtures/content_migration_files/content_migration.json +0 -0
- data/spec/fixtures/content_migration_files/response.json +0 -0
- data/spec/fixtures/content_migration_files/upload_success.json +0 -0
- data/spec/fixtures/conversation.json +0 -0
- data/spec/fixtures/course.json +0 -0
- data/spec/fixtures/course_conferences.json +0 -0
- data/spec/fixtures/course_copy.json +0 -0
- data/spec/fixtures/course_enrollments.json +0 -0
- data/spec/fixtures/course_files.json +0 -0
- data/spec/fixtures/course_folder.json +0 -0
- data/spec/fixtures/course_folders.json +0 -0
- data/spec/fixtures/course_grading_standards.json +0 -0
- data/spec/fixtures/course_groups.json +0 -0
- data/spec/fixtures/course_sections.json +0 -0
- data/spec/fixtures/course_settings.json +0 -0
- data/spec/fixtures/course_students.json +0 -0
- data/spec/fixtures/create_course_discussion.json +0 -0
- data/spec/fixtures/create_group_discussion.json +0 -0
- data/spec/fixtures/create_outcome_in_group.json +0 -0
- data/spec/fixtures/create_section.json +0 -0
- data/spec/fixtures/created_assignment.json +0 -0
- data/spec/fixtures/created_course.json +0 -0
- data/spec/fixtures/created_group.json +0 -0
- data/spec/fixtures/created_group_category.json +0 -0
- data/spec/fixtures/created_group_membership.json +0 -0
- data/spec/fixtures/created_module.json +0 -0
- data/spec/fixtures/custom_data.json +0 -0
- data/spec/fixtures/custom_food_data.json +0 -0
- data/spec/fixtures/custom_gradebook_columns/column_data.json +0 -0
- data/spec/fixtures/custom_gradebook_columns/custom_gradebook_column.json +0 -0
- data/spec/fixtures/custom_gradebook_columns/custom_gradebook_columns.json +0 -0
- data/spec/fixtures/custom_gradebook_columns/gradebook_column_progress.json +0 -0
- data/spec/fixtures/dashboard.json +0 -0
- data/spec/fixtures/delete_course.json +0 -0
- data/spec/fixtures/delete_custom_data_scope.json +0 -0
- data/spec/fixtures/delete_group_category.json +0 -0
- data/spec/fixtures/delete_section.json +0 -0
- data/spec/fixtures/deleted_conversation.json +0 -0
- data/spec/fixtures/deleted_group.json +0 -0
- data/spec/fixtures/department_level_participation.json +0 -0
- data/spec/fixtures/department_level_statistics.json +0 -0
- data/spec/fixtures/discussion_entries.json +0 -0
- data/spec/fixtures/discussion_entry_replies.json +0 -0
- data/spec/fixtures/discussion_topic.json +0 -0
- data/spec/fixtures/discussion_topics.json +0 -0
- data/spec/fixtures/edited_group.json +0 -0
- data/spec/fixtures/edited_group_category.json +0 -0
- data/spec/fixtures/enroll_student.json +0 -0
- data/spec/fixtures/enrollment_terms.json +0 -0
- data/spec/fixtures/external_tool.json +0 -0
- data/spec/fixtures/external_tools.json +0 -0
- data/spec/fixtures/file.csv +0 -0
- data/spec/fixtures/gradebook_history.json +0 -0
- data/spec/fixtures/graph_ql_scores.json +0 -0
- data/spec/fixtures/group.json +0 -0
- data/spec/fixtures/group_categories.json +0 -0
- data/spec/fixtures/group_category.json +0 -0
- data/spec/fixtures/group_category_groups.json +0 -0
- data/spec/fixtures/group_conferences.json +0 -0
- data/spec/fixtures/group_membership.json +0 -0
- data/spec/fixtures/learning_outcome.json +0 -0
- data/spec/fixtures/link_unlink_outcome.json +0 -0
- data/spec/fixtures/merge_user.json +0 -0
- data/spec/fixtures/module.json +0 -0
- data/spec/fixtures/module_item.json +0 -0
- data/spec/fixtures/module_item_sequence.json +0 -0
- data/spec/fixtures/module_items.json +0 -0
- data/spec/fixtures/modules.json +0 -0
- data/spec/fixtures/new_quizzes/new_quiz_item_categorization.json +44 -0
- data/spec/fixtures/new_quizzes/new_quiz_item_essay.json +29 -0
- data/spec/fixtures/new_quizzes/new_quiz_item_file_upload.json +32 -0
- data/spec/fixtures/new_quizzes/new_quiz_item_fill_in_multiple_blanks.json +65 -0
- data/spec/fixtures/new_quizzes/new_quiz_item_formula.json +50 -0
- data/spec/fixtures/new_quizzes/new_quiz_item_hot_spot.json +42 -0
- data/spec/fixtures/new_quizzes/new_quiz_item_matching.json +52 -0
- data/spec/fixtures/new_quizzes/new_quiz_item_multiple_answer.json +38 -0
- data/spec/fixtures/new_quizzes/new_quiz_item_numeric.json +30 -0
- data/spec/fixtures/new_quizzes/new_quiz_item_ordering.json +40 -0
- data/spec/fixtures/new_quizzes/new_quiz_item_short_answer.json +31 -0
- data/spec/fixtures/new_quizzes/new_quiz_item_stimulus.json +26 -0
- data/spec/fixtures/new_quizzes/new_quiz_item_true_false.json +29 -0
- data/spec/fixtures/no_custom_data.json +0 -0
- data/spec/fixtures/ok.json +0 -0
- data/spec/fixtures/outcome_group_import.json +0 -0
- data/spec/fixtures/outcome_groups.json +0 -0
- data/spec/fixtures/outcome_result.json +0 -0
- data/spec/fixtures/outcome_subgroup.json +0 -0
- data/spec/fixtures/outcome_subgroups.json +0 -0
- data/spec/fixtures/outcomes.json +0 -0
- data/spec/fixtures/paged_body.json +0 -0
- data/spec/fixtures/pages.json +0 -0
- data/spec/fixtures/progress.json +0 -0
- data/spec/fixtures/quizzes/course_quiz.json +0 -0
- data/spec/fixtures/quizzes/course_quiz_questions.json +0 -0
- data/spec/fixtures/quizzes/course_quizzes.json +0 -0
- data/spec/fixtures/quizzes/quiz_assignment_override.json +0 -0
- data/spec/fixtures/quizzes/quiz_extension.json +0 -0
- data/spec/fixtures/reactivate_enrollment.json +0 -0
- data/spec/fixtures/report_history.json +0 -0
- data/spec/fixtures/report_list.json +0 -0
- data/spec/fixtures/report_status.json +0 -0
- data/spec/fixtures/rubric.json +0 -0
- data/spec/fixtures/rubric_assessment.json +0 -0
- data/spec/fixtures/rubric_association.json +0 -0
- data/spec/fixtures/search_find_recipients.json +0 -0
- data/spec/fixtures/section.json +0 -0
- data/spec/fixtures/section_enrollments.json +0 -0
- data/spec/fixtures/single_account.json +0 -0
- data/spec/fixtures/start_report.json +0 -0
- data/spec/fixtures/submissions/submission.json +0 -0
- data/spec/fixtures/update_outcome.json +0 -0
- data/spec/fixtures/update_outcome_group.json +0 -0
- data/spec/fixtures/update_section.json +0 -0
- data/spec/fixtures/updated_course.json +0 -0
- data/spec/fixtures/user_avatars.json +0 -0
- data/spec/fixtures/user_details.json +0 -0
- data/spec/fixtures/user_enrollments.json +0 -0
- data/spec/fixtures/user_logins.json +0 -0
- data/spec/fixtures/user_page_views.json +0 -0
- data/spec/fixtures/user_profile.json +0 -0
- data/spec/helper.rb +7 -0
- metadata +235 -182
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ff6d6d1426d021f6c2e7146de2884ecd9eb721b5529e56e49e25e82332dc3ddf
|
|
4
|
+
data.tar.gz: c59d392750a2b15b877c47efd96c317ce65299089aab856fa0944a0da5601cfe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 359e37b3e095419a8d74276b06dfeb2b41e5c68b5a19e4bd8c846abb5442e0dd0453738ceac3f121dd81099ee75b89c9ce8b3c01126f6e5327c5ef661d1743b2
|
|
7
|
+
data.tar.gz: 8f15f81e9d1ac4392104c4b8d3e65936ccfe4eeff9cf39ae77407086a8418eb82513ee984fc923e7a50b4169a8ee63c5795c4fa3768575119e8986a0d1264887
|
data/Rakefile
CHANGED
|
File without changes
|
data/bearcat.gemspec
CHANGED
|
@@ -26,14 +26,16 @@ Gem::Specification.new do |gem|
|
|
|
26
26
|
|
|
27
27
|
gem.add_development_dependency "rake"
|
|
28
28
|
gem.add_development_dependency "bundler", ">= 1.0.0"
|
|
29
|
-
gem.add_development_dependency "rspec", "~>
|
|
29
|
+
gem.add_development_dependency "rspec", "~> 3.13"
|
|
30
30
|
gem.add_development_dependency "webmock"
|
|
31
31
|
gem.add_development_dependency 'pry'
|
|
32
32
|
gem.add_development_dependency 'sidekiq', "< 7.0"
|
|
33
33
|
gem.add_development_dependency "ffi", "~> 1.16.3"
|
|
34
|
+
gem.add_development_dependency "appraisal", "~> 2.5"
|
|
34
35
|
|
|
35
36
|
gem.add_dependency "activesupport"
|
|
36
|
-
gem.add_dependency "faraday", "
|
|
37
|
-
gem.add_dependency "
|
|
37
|
+
gem.add_dependency "faraday", ">= 1.0", "< 3"
|
|
38
|
+
gem.add_dependency "faraday-multipart", "~> 1.0"
|
|
39
|
+
gem.add_dependency "footrest", ">= 0.6.1"
|
|
38
40
|
gem.add_dependency "rediconn", "~> 0.1.0"
|
|
39
41
|
end
|
data/lib/badgrcat/api_array.rb
CHANGED
|
File without changes
|
data/lib/badgrcat/client.rb
CHANGED
|
@@ -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
|
-
|
|
88
|
+
@expires_in = authdata["expires_in"]
|
|
76
89
|
|
|
77
|
-
|
|
90
|
+
connection.headers[:authorization] = "#{authdata['token_type']} #{@access_token}"
|
|
78
91
|
connection.headers['Content-Type'] = "application/json"
|
|
79
92
|
end
|
|
80
93
|
end
|
data/lib/badgrcat/version.rb
CHANGED
|
File without changes
|
data/lib/bearcat/api_array.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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -14,7 +14,7 @@ module Bearcat
|
|
|
14
14
|
|
|
15
15
|
def post_file(url, params, file_path)
|
|
16
16
|
params['Filename'] = File.basename(file_path)
|
|
17
|
-
params['file'] =
|
|
17
|
+
params['file'] = upload_io(file_path, params['content-type'])
|
|
18
18
|
response = upload_connection.post(url, params)
|
|
19
19
|
if [201, 302, 303].include? response.status #success if it is a redirect or 201
|
|
20
20
|
response.headers['Location']
|
data/lib/bearcat/client/files.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
|
|
File without changes
|
|
@@ -4,7 +4,7 @@ module Bearcat
|
|
|
4
4
|
|
|
5
5
|
def import_outcomes(file_path, params={})
|
|
6
6
|
params = params.with_indifferent_access
|
|
7
|
-
params['attachment'] =
|
|
7
|
+
params['attachment'] = upload_io(file_path, 'text/csv')
|
|
8
8
|
url = "api/v1/#{outcome_import_context_slug(params)}"
|
|
9
9
|
url += "group/#{params[:group]}/" if params[:group].present?
|
|
10
10
|
params.delete(:group)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
data/lib/bearcat/client/roles.rb
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -2,7 +2,7 @@ module Bearcat
|
|
|
2
2
|
class Client < Footrest::Client
|
|
3
3
|
module SisImports
|
|
4
4
|
def import_sis_data(account, file, options = {}, content_type: nil)
|
|
5
|
-
options['attachment'] =
|
|
5
|
+
options['attachment'] = upload_io(file, content_type || "application/zip")
|
|
6
6
|
post("/api/v1/accounts/#{account}/sis_imports", options)
|
|
7
7
|
end
|
|
8
8
|
|
data/lib/bearcat/client/tabs.rb
CHANGED
|
File without changes
|
data/lib/bearcat/client.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
require 'active_support/core_ext/hash'
|
|
2
|
+
require 'faraday'
|
|
3
|
+
require 'faraday/multipart'
|
|
2
4
|
require 'footrest/client'
|
|
3
5
|
require_relative 'rate_limiting'
|
|
4
6
|
require_relative 'client_module'
|
|
@@ -75,6 +77,18 @@ module Bearcat
|
|
|
75
77
|
connection.builder.delete(Faraday::Request::UrlEncoded)
|
|
76
78
|
end
|
|
77
79
|
|
|
80
|
+
# Builds a multipart file part for uploads, bridging Faraday 1.x and 2.x.
|
|
81
|
+
# Faraday 2.x dropped Faraday::UploadIO in favor of
|
|
82
|
+
# Faraday::Multipart::FilePart (from the faraday-multipart gem). Both accept
|
|
83
|
+
# the same (path_or_io, content_type) signature.
|
|
84
|
+
def upload_io(path_or_io, content_type)
|
|
85
|
+
if defined?(Faraday::Multipart::FilePart)
|
|
86
|
+
Faraday::Multipart::FilePart.new(path_or_io, content_type)
|
|
87
|
+
else
|
|
88
|
+
Faraday::UploadIO.new(path_or_io, content_type)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
78
92
|
def self.cache_on_self(key, &block)
|
|
79
93
|
@cache ||= {}
|
|
80
94
|
if Rails.env.development? || Rails.env.test?
|
|
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
|
data/lib/bearcat/version.rb
CHANGED
data/lib/catalogcat/api_array.rb
CHANGED
|
@@ -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 = '
|
|
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
|
data/lib/catalogcat/client.rb
CHANGED
|
File without changes
|
data/lib/catalogcat/version.rb
CHANGED
|
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
|
|
@@ -28,24 +28,24 @@ describe Bearcat::ApiArray do
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
it 'gets a page of results' do
|
|
31
|
-
expect(request).to receive(:url).with('https://fake.com', 'page' => '2')
|
|
31
|
+
expect(request).to receive(:url).with('https://fake.com', { 'page' => '2' })
|
|
32
32
|
api_array.send(:get_page, 'https://fake.com?page=2', {})
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it 'merges additonal params to the url query' do
|
|
36
|
-
expect(request).to receive(:url).with('https://fake.com', 'test' => 'param', 'page' => 2)
|
|
37
|
-
api_array.send(:get_page, 'https://fake.com?test=param', 'page' => 2)
|
|
36
|
+
expect(request).to receive(:url).with('https://fake.com', { 'test' => 'param', 'page' => 2 })
|
|
37
|
+
api_array.send(:get_page, 'https://fake.com?test=param', { 'page' => 2 })
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it 'handles array parameters' do
|
|
41
|
-
expect(request).to receive(:url).with('https://fake.com', 'test' => ['param'], 'second' => ['param'])
|
|
42
|
-
api_array.send(:get_page, 'https://fake.com?test%5B%5D=param', 'second' => ['param'])
|
|
41
|
+
expect(request).to receive(:url).with('https://fake.com', { 'test' => ['param'], 'second' => ['param'] })
|
|
42
|
+
api_array.send(:get_page, 'https://fake.com?test%5B%5D=param', { 'second' => ['param'] })
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
it 'sets the per_page parameter if not already set and @page_count has a value' do
|
|
46
46
|
api_array.instance_variable_set('@page_count', 50)
|
|
47
47
|
|
|
48
|
-
expect(request).to receive(:url).with('https://fake.com', 'per_page' => 50)
|
|
48
|
+
expect(request).to receive(:url).with('https://fake.com', { 'per_page' => 50 })
|
|
49
49
|
api_array.send(:get_page, 'https://fake.com?', {})
|
|
50
50
|
end
|
|
51
51
|
|
|
@@ -59,8 +59,8 @@ describe Bearcat::ApiArray do
|
|
|
59
59
|
it 'does not set the per_page parameter if it is already set' do
|
|
60
60
|
api_array.instance_variable_set('@page_count', 50)
|
|
61
61
|
|
|
62
|
-
expect(request).to receive(:url).with('https://fake.com', 'per_page' => 10)
|
|
63
|
-
api_array.send(:get_page, 'https://fake.com?', 'per_page' => 10)
|
|
62
|
+
expect(request).to receive(:url).with('https://fake.com', { 'per_page' => 10 })
|
|
63
|
+
api_array.send(:get_page, 'https://fake.com?', { 'per_page' => 10 })
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
|
|
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
|