bearcat 1.4.8 → 1.4.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 9b90ec8e90ea31d17bebe5b08edbb4af296b201af79c052250c2655dedf734e6
4
- data.tar.gz: db220f338bdcd6ad166fed415080eb7f65367c6db99e13781ad3b1cc1335be2e
2
+ SHA1:
3
+ metadata.gz: 65992dcbb43af93a7a7f34bdf322bd82dd7ee45c
4
+ data.tar.gz: 3bf3d5f3e0849977b01b64df3c544519c2da928c
5
5
  SHA512:
6
- metadata.gz: 6c3ada3e912c59d97757232c5451cc5ffc5fc1f289d3009d8a1e71cc24e556d0529b43742778b94ded2a73294a7bae7043dd302720e82f755cdbd2e5e930c10f
7
- data.tar.gz: 6cbe47361dbfcb48cefc96353cf2cd34fc5e6974cbbaa673dc04b4363ed0d14669b3ed6c02b567a5266e08fdb1ede99402a498c7630b0a0ba38f2976cb96a40c
6
+ metadata.gz: 2936b59a7848832d98927f55e16abcce88f975a48319acaa2d8888ac5fe0ddb3e824f2eb1b638c44e0adeb0e5269eb6dd1304b0866feefca1714ce4c2c58565e
7
+ data.tar.gz: 1f176cce865ed38077e99e8a4960a09953d9c62bc0dbf7e0353caf8d1fc281152764ffbe05321ad13c01986b148c7f5154c20dee1096ab44ec444692cbb360c8
@@ -1,40 +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
+ }
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 [201, 302, 303].include? response.status #success if it is a redirect or 201
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
- query = uri.query
28
- query.blank? ? get(uri.path) : get(uri.path, CGI::parse(query))
29
- end
26
+ def confirm_file_upload(url)
27
+ uri = URI(url)
28
+ query = uri.query
29
+ query.blank? ? get(uri.path) : get(uri.path, CGI::parse(query))
30
+ end
30
31
 
31
- def upload_connection
32
- Faraday.new do |f|
33
- f.options[:open_timeout] = ENV.fetch('FARADAY_OPEN_TIMEOUT', 60).to_i
34
- f.options[:timeout] = ENV.fetch('FARADAY_TIMEOUT', 60).to_i
35
- f.request :multipart
36
- f.request :url_encoded
37
- 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
38
41
  end
39
42
  end
40
43
  end
@@ -0,0 +1,48 @@
1
+ module Bearcat
2
+ class Client < Footrest::Client
3
+ module OutcomeImports
4
+
5
+ def import_outcomes(file_path, params={})
6
+ params = params.with_indifferent_access
7
+ params['attachment'] = Faraday::UploadIO.new(file_path, 'text/csv')
8
+ url = "api/v1/#{outcome_import_context_slug(params)}"
9
+ url += "group/#{params[:group]}/" if params[:group].present?
10
+ params.delete(:group)
11
+ post(url, params)
12
+ end
13
+
14
+ def outcome_import_status(id, params={})
15
+ params = params.with_indifferent_access
16
+ get("api/v1/#{outcome_import_context_slug(params)}#{id}", params)
17
+ end
18
+
19
+ def outcome_import_created_group_ids(id, params={})
20
+ params = params.with_indifferent_access
21
+ get("api/v1/#{outcome_import_context_slug(params)}#{id}/created_group_ids", params)
22
+ end
23
+
24
+ protected
25
+
26
+ def outcome_import_context_slug(params)
27
+ context_hash = params.select { |k, _| k == "account" || k == "course" }
28
+
29
+ if context_hash.keys.count > 1
30
+ raise ArgumentError, "cannot have account and course in params"
31
+ elsif context_hash.empty?
32
+ "accounts/self/outcome_imports/"
33
+ else
34
+ context_hash_key = context_hash.keys.first
35
+ case context_hash_key
36
+ when 'account'
37
+ params.delete(:account)
38
+ "accounts/#{context_hash[context_hash_key]}/outcome_imports/"
39
+ when 'course'
40
+ params.delete(:course)
41
+ "courses/#{context_hash[context_hash_key]}/outcome_imports/"
42
+ end
43
+ end
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -17,7 +17,14 @@ module Bearcat
17
17
  def show_group_page(group, url, params={})
18
18
  get("/api/v1/groups/#{group}/pages/#{url}", params)
19
19
  end
20
-
20
+
21
+ def add_course_page(course, params={})
22
+ post("api/v1/courses/#{course}/pages", params)
23
+ end
24
+
25
+ def add_group_page(group, params={})
26
+ post("/api/v1/groups/#{group}/pages", params)
27
+ end
21
28
  end
22
29
  end
23
30
  end
@@ -5,89 +5,13 @@ require 'paul_walker'
5
5
  module Bearcat
6
6
  class Client < Footrest::Client
7
7
  require 'bearcat/api_array'
8
- require 'bearcat/client/file_helper'
9
- require 'bearcat/client/assignments'
10
- require 'bearcat/client/blueprint_courses'
11
- require 'bearcat/client/courses'
12
- require 'bearcat/client/enrollments'
13
- require 'bearcat/client/outcome_groups'
14
- require 'bearcat/client/outcomes'
15
- require 'bearcat/client/sections'
16
- require 'bearcat/client/o_auth2'
17
- require 'bearcat/client/groups'
18
- require 'bearcat/client/group_categories'
19
- require 'bearcat/client/group_memberships'
20
- require 'bearcat/client/conferences'
21
- require 'bearcat/client/users'
22
- require 'bearcat/client/reports'
23
- require 'bearcat/client/accounts'
24
- require 'bearcat/client/submissions'
25
- require 'bearcat/client/conversations'
26
- require 'bearcat/client/modules'
27
- require 'bearcat/client/canvas_files'
28
- require 'bearcat/client/calendar_events'
29
- require 'bearcat/client/discussions'
30
- require 'bearcat/client/search'
31
- require 'bearcat/client/quizzes'
32
- require 'bearcat/client/assignment_groups'
33
- require 'bearcat/client/pages'
34
- require 'bearcat/client/files'
35
- require 'bearcat/client/folders'
36
- require 'bearcat/client/graph_ql'
37
- require 'bearcat/client/analytics'
38
- require 'bearcat/client/module_items'
39
- require 'bearcat/client/content_migrations'
40
- require 'bearcat/client/content_exports'
41
- require 'bearcat/client/custom_gradebook_columns'
42
- require 'bearcat/client/external_tools'
43
- require 'bearcat/client/roles'
44
- require 'bearcat/client/rubric'
45
- require 'bearcat/client/rubric_assessment'
46
- require 'bearcat/client/rubric_association'
47
- require 'bearcat/client/progresses'
48
- require 'bearcat/client/tabs'
49
8
 
50
- include Assignments
51
- include Accounts
52
- include Analytics
53
- include BlueprintCourses
54
- include Courses
55
- include Enrollments
56
- include OutcomeGroups
57
- include Outcomes
58
- include Sections
59
- include OAuth2
60
- include Groups
61
- include GroupCategories
62
- include GroupMemberships
63
- include Conferences
64
- include Users
65
- include Reports
66
- include Submissions
67
- include Conversations
68
- include Modules
69
- include CanvasFiles
70
- include CalendarEvents
71
- include Discussions
72
- include FileHelper
73
- include Search
74
- include Quizzes
75
- include AssignmentGroups
76
- include Pages
77
- include Files
78
- include Folders
79
- include GraphQL
80
- include ModuleItems
81
- include ContentMigrations
82
- include ContentExports
83
- include CustomGradebookColumns
84
- include ExternalTools
85
- include Roles
86
- include Rubric
87
- include RubricAssessment
88
- include RubricAssociation
89
- include Progresses
90
- include Tabs
9
+ Dir[File.join(__dir__, 'client', '*.rb')].each do |mod|
10
+ mname = File.basename(mod, '.*').camelize
11
+ mname = 'GraphQL' if mname == 'GraphQl'
12
+ require mod
13
+ include "Bearcat::Client::#{mname}".constantize
14
+ end
91
15
 
92
16
  # Override Footrest request for ApiArray support
93
17
  def request(method, &block)
@@ -7,13 +7,15 @@ require 'bearcat'
7
7
  # - `config.include Bearcat::SpecHelpers`
8
8
  # This helper requires `gem 'method_source'` in your test group
9
9
  module Bearcat::SpecHelpers
10
+ extend ActiveSupport::Concern
11
+
10
12
  SOURCE_REGEX = /(?<method>get|post|delete|put)\((?<quote>\\?('|"))(?<url>.*)\k<quote>/
11
13
 
12
14
  # Helper method to Stub Bearcat requests.
13
15
  # Automagically parses the Bearcat method source to determine the correct URL to stub.
14
16
  # Accepts optional keyword parameters to interpolate specific values into the URL.
15
17
  # Returns a mostly-normal Webmock stub (:to_return has been overridden to allow :body to be set to a Hash)
16
- def stub_bearcat(endpoint, prefix: nil, **kwargs)
18
+ def stub_bearcat(endpoint, prefix: nil, method: :auto, **kwargs)
17
19
  url = case endpoint
18
20
  when Symbol
19
21
  ruby_method = Bearcat::Client.instance_method(endpoint)
@@ -43,16 +45,26 @@ module Bearcat::SpecHelpers
43
45
  end
44
46
 
45
47
  url = Regexp.escape(resolve_prefix(prefix)) + url
46
- stub = stub_request(match[:method].to_sym, Regexp.new(url))
48
+ stub = stub_request(method == :auto ? (match ? match[:method].to_sym : :get) : method, Regexp.new(url))
47
49
 
48
50
  # Override the to_return method to accept a Hash as body:
49
- stub.define_singleton_method(:to_return, ->(*resps) {
50
- resps.map do |resp|
51
- resp[:headers] ||= {}
52
- resp[:headers]["Content-Type"] ||= "application/json"
53
- resp[:body] = resp[:body].to_json
51
+ stub.define_singleton_method(:to_return, ->(*resps, &blk) {
52
+ if blk
53
+ super do |*args|
54
+ resp = blk.call(*args)
55
+ resp[:headers] ||= {}
56
+ resp[:headers]["Content-Type"] ||= "application/json"
57
+ resp[:body] = resp[:body].to_json
58
+ resp
59
+ end
60
+ else
61
+ resps.map do |resp|
62
+ resp[:headers] ||= {}
63
+ resp[:headers]["Content-Type"] ||= "application/json"
64
+ resp[:body] = resp[:body].to_json
65
+ end
66
+ super(*resps)
54
67
  end
55
- super(*resps)
56
68
  })
57
69
 
58
70
  stub
@@ -1,3 +1,3 @@
1
1
  module Bearcat
2
- VERSION = '1.4.8' unless defined?(Bearcat::VERSION)
2
+ VERSION = '1.4.11' unless defined?(Bearcat::VERSION)
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bearcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.8
4
+ version: 1.4.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Mills, Jake Sorce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-21 00:00:00.000000000 Z
11
+ date: 2022-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -162,6 +162,7 @@ files:
162
162
  - lib/bearcat/client/modules.rb
163
163
  - lib/bearcat/client/o_auth2.rb
164
164
  - lib/bearcat/client/outcome_groups.rb
165
+ - lib/bearcat/client/outcome_imports.rb
165
166
  - lib/bearcat/client/outcomes.rb
166
167
  - lib/bearcat/client/pages.rb
167
168
  - lib/bearcat/client/progresses.rb
@@ -382,7 +383,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
382
383
  - !ruby/object:Gem::Version
383
384
  version: '0'
384
385
  requirements: []
385
- rubygems_version: 3.1.2
386
+ rubyforge_project:
387
+ rubygems_version: 2.4.5.1
386
388
  signing_key:
387
389
  specification_version: 4
388
390
  summary: Canvas API