bearcat 1.3.52 → 1.4.2

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: 57aeab92bce2490d628818355f14eda3f2a78015e865daea4f41c3f4ab5b0753
4
- data.tar.gz: fbec8269e921270245d25fd59c9f63647cd2e34ce794b16b1c0b62d50cf92cb9
2
+ SHA1:
3
+ metadata.gz: 8d7986f7cb9c9c46c9bf669ec4bad9e8eb4d7f33
4
+ data.tar.gz: cc54f03e7e146f71f24d0d80c2342ffa6e662ca2
5
5
  SHA512:
6
- metadata.gz: ce9efc0afffbc1e3e7aba6cd027a1f6c282a953bb62585328d28911c46f8b794e34bd896e16926f927533784263608854dabcaaecfbb7b7f10cc351478dea28b
7
- data.tar.gz: d8912116b917f0b98e7bab56fcbf8c6c20dd7723d667cb8b0f449d48dd06514c19bb6424733bb99d4f79bf781962f6382a6af7061cebbc4ac2954741001629c7
6
+ metadata.gz: 44cacec26e61027f954ddeb3700a85a4241cf32738a12e628878a94bc9cf952f93a3f71b5f530cbc9ec38a62de9f8bcc8e13a12b667396ebe27e986709994f20
7
+ data.tar.gz: a93d140338dbca79e0e9af138c306d580044f3f62a9639ec8bfe2eb7a0605446e8a3c5b21be62a268066dedcb7a6f71e98a289202a34f077b13fb4c6a80aeed0
@@ -2,7 +2,7 @@ module Bearcat
2
2
  class ApiArray
3
3
  include Enumerable
4
4
 
5
- attr_reader :status, :headers, :members
5
+ attr_reader :raw_response, :members
6
6
 
7
7
  def self.process_response(response, api_client)
8
8
  if response.body.is_a?(Array)
@@ -10,24 +10,39 @@ module Bearcat
10
10
  elsif key = array_key(response)
11
11
  ApiArray.new(response, api_client, key)
12
12
  else
13
- response.body
13
+ make_indifferent(response.body)
14
+ end
15
+ end
16
+
17
+ def self.make_indifferent(thing)
18
+ if thing.is_a?(Array)
19
+ thing.map { |v| make_indifferent(v) }
20
+ elsif thing.is_a?(Hash)
21
+ thing.with_indifferent_access
22
+ else
23
+ thing
14
24
  end
15
25
  end
16
26
 
17
27
  def initialize(response, api_client, array_key = nil)
18
28
  @api_client = api_client
29
+ @raw_response = response
19
30
  @array_key = array_key
20
- @page_count = 100
31
+ @page_count = nil
32
+
21
33
  case response.status
22
34
  when 200..206
23
35
  @members = process_body(response)
24
- @status = response.status
25
- @headers = response.headers
26
- @method = response.env[:method]
27
- init_pages(@headers['Link'])
36
+ init_pages(headers[:link])
28
37
  end
29
38
  end
30
39
 
40
+ delegate :status, :headers, to: :raw_response
41
+
42
+ def method
43
+ raw_response.env[:method]
44
+ end
45
+
31
46
  def [](i)
32
47
  @members[i]
33
48
  end
@@ -44,71 +59,37 @@ module Bearcat
44
59
  @link_hash['next'] || @link_hash['prev']
45
60
  end
46
61
 
47
- def next_page
48
- load_page('next')
49
- end
50
-
51
- def prev_page
52
- load_page('prev')
53
- end
54
-
55
- def first_page
56
- load_page('first')
57
- end
58
-
59
- def last_page
60
- load_page('last')
62
+ %w[next prev first last].each do |rel|
63
+ define_method :"#{rel}_page" do
64
+ load_page(rel)
65
+ end
61
66
  end
62
67
 
63
- def each_page(page_count = 50, &block)
64
- @page_count = page_count
68
+ def each_page(page_count = nil, &block)
65
69
  if pages?
66
- response = get_page(@link_hash['first'])
67
- @headers = response.headers
68
- @status = response.status
69
- @method = response.env[:method]
70
- init_pages(@headers[:link])
71
- @members = process_body(response)
72
- block.call(@members)
73
- while @link_hash['next'] && @members.present?
74
- response = get_page(@link_hash['next'])
75
- @headers = response.headers
76
- @status = response.status
77
- @method = response.env[:method]
78
- @members = process_body(response)
79
- init_pages(@headers[:link])
70
+ iterate_pages(page_count) do |page_response|
71
+ @members = process_body(page_response)
72
+ break unless @members.present?
80
73
  block.call(@members)
81
74
  end
82
- @link_hash = {}
83
75
  else
84
76
  block.call(@members)
85
77
  end
86
78
  end
87
79
 
88
- def all_pages_each(page_count = 50, &block)
80
+ def all_pages_each(page_count = nil, &block)
89
81
  each_page(page_count) do |page|
90
82
  page.each &block
91
83
  end
92
84
  end
93
85
 
94
- def all_pages!(page_count = 50)
86
+ def all_pages!(page_count = nil)
95
87
  if pages?
96
- @page_count = page_count
97
- response = get_page(@link_hash['first'])
98
- @headers = response.headers
99
- @status = response.status
100
- @method = response.env[:method]
101
- init_pages(@headers[:link])
102
- @members = process_body(response)
103
- while @link_hash['next']
104
- response = get_page(@link_hash['next'])
105
- @headers = response.headers
106
- @status = response.status
107
- @method = response.env[:method]
108
- page_members = process_body(response)
88
+ @members = []
89
+ iterate_pages(page_count) do |page_response|
90
+ page_members = process_body(page_response)
109
91
  break unless page_members.present?
110
92
  @members.concat(page_members)
111
- init_pages(@headers[:link])
112
93
  end
113
94
  @link_hash = {}
114
95
  end
@@ -117,9 +98,10 @@ module Bearcat
117
98
 
118
99
  private
119
100
 
120
- def init_pages(link_header)
101
+ def init_pages(link_header = headers[:link])
121
102
  @link_hash = {}
122
- if @headers.has_key? 'Link'
103
+ if headers.has_key? 'Link'
104
+
123
105
  links = link_header.split(/,\s?/)
124
106
 
125
107
  links.each do |link|
@@ -133,14 +115,11 @@ module Bearcat
133
115
 
134
116
  def get_page(url, params = {})
135
117
  params['per_page'] = @page_count unless params.key?('per_page') || !@page_count
136
- query = URI.parse(url).query
137
- p = CGI.parse(query)
138
- u = url.gsub("?#{query}", '')
139
118
 
140
- # strip value out of array if value is an array and key doesn't have [] (parameter is not an array parameter)
141
- p.each { |k, v| p[k] = v.first if v.is_a?(Array) && k !~ /\[\]$/ }
142
- # remove [] from key names, this is copied from rails' {}.transform_keys!
143
- p.keys.each { |k| p[k.delete('[]')] = p.delete(k) }
119
+ parsed_url = URI.parse(url)
120
+ p = parse_url_params(parsed_url)
121
+ u = url.gsub("?#{parsed_url.query}", '')
122
+
144
123
  # merge params
145
124
  p.merge!(params)
146
125
 
@@ -156,6 +135,44 @@ module Bearcat
156
135
  end
157
136
  end
158
137
 
138
+ def iterate_pages(per_page = @page_count)
139
+ return to_enum(:iterate_pages, per_page) unless block_given?
140
+
141
+ if per_page.present? && per_page != per_page_count && @link_hash['first']
142
+ @page_count = per_page
143
+ @raw_response = response = get_page(@link_hash['first'])
144
+ yield response
145
+ init_pages(headers[:link])
146
+ else
147
+ yield @raw_response
148
+ end
149
+
150
+ while @link_hash['next']
151
+ @raw_response = response = get_page(@link_hash['next'])
152
+ yield response
153
+ init_pages(headers[:link])
154
+ end
155
+ end
156
+
157
+ def per_page_count
158
+ url = raw_response.env[:url]
159
+ query_params = parse_url_params(url)
160
+ query_params[:per_page]&.to_i
161
+ end
162
+
163
+ def parse_url_params(url)
164
+ url = URI.parse(url) if url.is_a?(String)
165
+ p = CGI.parse(url.query || '')
166
+ p.default = nil
167
+
168
+ # strip value out of array if value is an array and key doesn't have [] (parameter is not an array parameter)
169
+ p.each { |k, v| p[k] = v.first if v.is_a?(Array) && k !~ /\[\]$/ }
170
+ # remove [] from key names, this is copied from rails' {}.transform_keys!
171
+ p.keys.each { |k| p[k.delete('[]')] = p.delete(k) }
172
+
173
+ p.with_indifferent_access
174
+ end
175
+
159
176
  #TODO: This is a quick fix for JSONAPI responses if we need to do this for anything else we need to do this a better way
160
177
  def self.array_key(response)
161
178
  key = nil
@@ -172,11 +189,10 @@ module Bearcat
172
189
 
173
190
  def process_body(response)
174
191
  if response.body.is_a?(Array)
175
- response.body
192
+ ApiArray.make_indifferent(response.body)
176
193
  elsif response.body.is_a?(Hash) && @array_key
177
- response.body[@array_key]
194
+ ApiArray.make_indifferent(response.body[@array_key])
178
195
  end
179
196
  end
180
-
181
197
  end
182
198
  end
@@ -7,6 +7,7 @@ module Bearcat
7
7
  require 'bearcat/api_array'
8
8
  require 'bearcat/client/file_helper'
9
9
  require 'bearcat/client/assignments'
10
+ require 'bearcat/client/blueprint_courses'
10
11
  require 'bearcat/client/courses'
11
12
  require 'bearcat/client/enrollments'
12
13
  require 'bearcat/client/outcome_groups'
@@ -39,6 +40,7 @@ module Bearcat
39
40
  require 'bearcat/client/content_exports'
40
41
  require 'bearcat/client/custom_gradebook_columns'
41
42
  require 'bearcat/client/external_tools'
43
+ require 'bearcat/client/roles'
42
44
  require 'bearcat/client/rubric'
43
45
  require 'bearcat/client/rubric_assessment'
44
46
  require 'bearcat/client/rubric_association'
@@ -46,6 +48,7 @@ module Bearcat
46
48
  include Assignments
47
49
  include Accounts
48
50
  include Analytics
51
+ include BlueprintCourses
49
52
  include Courses
50
53
  include Enrollments
51
54
  include OutcomeGroups
@@ -77,6 +80,7 @@ module Bearcat
77
80
  include ContentExports
78
81
  include CustomGradebookColumns
79
82
  include ExternalTools
83
+ include Roles
80
84
  include Rubric
81
85
  include RubricAssessment
82
86
  include RubricAssociation
@@ -0,0 +1,31 @@
1
+ module Bearcat
2
+ class Client < Footrest::Client
3
+ module BlueprintCourses
4
+
5
+ # Get blueprint information
6
+ # https://canvas.instructure.com/doc/api/blueprint_courses.html#method.master_courses/master_templates.show
7
+ def blueprint_template(course, template_id='default')
8
+ get("/api/v1/courses/#{course}/blueprint_templates/#{template_id}")
9
+ end
10
+
11
+ # List blueprint subscriptions
12
+ # https://canvas.instructure.com/doc/api/blueprint_courses.html#method.master_courses/master_templates.subscriptions_index
13
+ def blueprint_subscriptions(course)
14
+ get("/api/v1/courses/#{course}/blueprint_subscriptions")
15
+ end
16
+
17
+ # Update associated courses
18
+ # https://canvas.instructure.com/doc/api/blueprint_courses.html#method.master_courses/master_templates.update_associations
19
+ def blueprint_update_associations(course, template_id='default', params={})
20
+ put("/api/v1/courses/#{course}/blueprint_templates/#{template_id}/update_associations", params)
21
+ end
22
+
23
+ # Begin a migration to push to associated courses
24
+ # https://canvas.instructure.com/doc/api/blueprint_courses.html#method.master_courses/master_templates.queue_migration
25
+ def start_blueprint_migration(course, template_id='default', params={})
26
+ post("/api/v1/courses/#{course}/blueprint_templates/#{template_id}/migrations", params)
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -63,9 +63,6 @@ module Bearcat
63
63
  get("api/v1/courses/#{course}/gradebook_history/feed", params)
64
64
  end
65
65
 
66
- def blueprint_subscriptions(course)
67
- get("/api/v1/courses/#{course}/blueprint_subscriptions")
68
- end
69
66
  end
70
67
  end
71
68
  end
@@ -0,0 +1,15 @@
1
+ module Bearcat
2
+ class Client < Footrest::Client
3
+ module Roles
4
+
5
+ def roles(account_id='self', params={})
6
+ get("/api/v1/accounts/#{account_id}/roles", params)
7
+ end
8
+
9
+ def role(role_id, account_id='self', params={})
10
+ get("/api/v1/accounts/#{account_id}/roles/#{role_id}", params)
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -5,6 +5,7 @@ require 'bearcat'
5
5
  # - `require 'bearcat/spec_helpers'`
6
6
  # And
7
7
  # - `config.include Bearcat::SpecHelpers`
8
+ # This helper requires `gem 'method_source'` in your test group
8
9
  module Bearcat::SpecHelpers
9
10
  SOURCE_REGEX = /(?<method>get|post|delete|put)\((?<quote>\\?('|"))(?<url>.*)\k<quote>/
10
11
 
@@ -31,12 +32,9 @@ module Bearcat::SpecHelpers
31
32
  bits << between if between.present?
32
33
 
33
34
  bits.map do |bit|
34
- case bit
35
- when Regexp
36
- bit.source
37
- when String
38
- Regexp.escape(bit)
39
- end
35
+ next bit.source if bit.is_a?(Regexp)
36
+ bit = bit.canvas_id if bit.respond_to?(:canvas_id)
37
+ Regexp.escape(bit.to_s)
40
38
  end.join
41
39
  when String
42
40
  Regexp.escape(endpoint)
@@ -1,3 +1,3 @@
1
1
  module Bearcat
2
- VERSION = '1.3.52' unless defined?(Bearcat::VERSION)
2
+ VERSION = '1.4.2' unless defined?(Bearcat::VERSION)
3
3
  end
@@ -1,9 +1,20 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Bearcat::ApiArray do
4
+ let(:api_client) { double }
5
+ let(:response_headers) { { } }
6
+ let(:response_env) { { url: "https://fake.com" } }
7
+ let(:response_body) { @response_body || [] }
8
+ let(:original_response) do
9
+ double(
10
+ body: response_body,
11
+ status: 200,
12
+ headers: Faraday::Utils::Headers.new(response_headers),
13
+ env: Faraday::Env.from(response_env)
14
+ )
15
+ end
16
+
4
17
  describe 'get_page' do
5
- let(:api_client) { double }
6
- let(:original_response) { double(body: [], status: 200, headers: {}, env: {}) }
7
18
  let(:api_array) { described_class.process_response(original_response, api_client) }
8
19
  let(:connection) { double }
9
20
  let(:request) { double }
@@ -52,4 +63,50 @@ describe Bearcat::ApiArray do
52
63
  api_array.send(:get_page, 'https://fake.com?', 'per_page' => 10)
53
64
  end
54
65
  end
66
+
67
+ describe '#iterate_pages' do
68
+ let(:api_array) { described_class.process_response(original_response, api_client) }
69
+
70
+ let(:original_response) do
71
+ super().tap do |s|
72
+ s.headers['Link'] = [
73
+ '<https://fake.com?page=1>; rel="first"'
74
+ ].join(', ')
75
+ end
76
+ end
77
+
78
+ it 're-requests the first-page if per_page has changed' do
79
+ expect(api_array).to receive(:get_page).and_return(original_response)
80
+ api_array.send(:iterate_pages, 10).to_a
81
+ end
82
+
83
+ it 'yields existing first-page if per_page is unchanged' do
84
+ expect(api_array).not_to receive(:get_page)
85
+ api_array.send(:iterate_pages, nil).to_a
86
+ end
87
+ end
88
+
89
+ context 'makes returned values indifferent' do
90
+ it 'makes a Hash response indifferent' do
91
+ @response_body = { something: 1 }
92
+ result = described_class.process_response(original_response, api_client)
93
+ expect(result[:something]).to eq 1
94
+ expect(result['something']).to eq 1
95
+ end
96
+
97
+ it 'makes an Array response indifferent' do
98
+ @response_body = [{ something: 1 }]
99
+ result = described_class.process_response(original_response, api_client)
100
+ expect(result[0][:something]).to eq 1
101
+ expect(result[0]['something']).to eq 1
102
+ end
103
+
104
+ it 'makes a single-key Hash response indifferent' do
105
+ @response_body = { 'something' => [ { foo: 1 } ] }
106
+ allow(described_class).to receive(:array_key).and_return('something')
107
+ result = described_class.process_response(original_response, api_client)
108
+ expect(result[0][:foo]).to eq 1
109
+ expect(result[0]['foo']).to eq 1
110
+ end
111
+ end
55
112
  end
@@ -0,0 +1,43 @@
1
+ require 'helper'
2
+
3
+ describe Bearcat::Client::BlueprintCourses do
4
+ before do
5
+ @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token")
6
+ end
7
+
8
+ it 'returns a list of blueprint subscriptions for the given course' do
9
+ stub_get(@client, "/api/v1/courses/1/blueprint_subscriptions").to_return(json_response("blueprint_subscriptions.json"))
10
+ subs = @client.blueprint_subscriptions(1)
11
+ expect(subs['id']).to eq 101
12
+ expect(subs['template_id']).to eq 1
13
+ expect(subs['blueprint_course']).to be_present
14
+ end
15
+
16
+ it 'returns a blueprint template for the given course' do
17
+ stub_get(@client, "/api/v1/courses/2/blueprint_templates/default").to_return(json_response("blueprint_template.json"))
18
+ template = @client.blueprint_template(2)
19
+ expect(template['id']).to eq 1
20
+ expect(template['course_id']).to eq 2
21
+ end
22
+
23
+ it 'updates assocations for a blueprint course' do
24
+ stub_put(@client, "/api/v1/courses/2/blueprint_templates/default/update_associations").to_return(json_response("blueprint_update_assocations_success.json"))
25
+ result = @client.blueprint_update_associations(2, 'default', course_ids_to_add: [123])
26
+ expect(result['success']).to eq true
27
+ end
28
+
29
+ it 'starts a migration for a blueprint course' do
30
+ stub_post(@client, "/api/v1/courses/2/blueprint_templates/default/migrations").to_return(json_response("blueprint_migration.json"))
31
+ migration = @client.start_blueprint_migration(2, 'default', {
32
+ comment: 'An optional comment to be included in the sync history.',
33
+ send_notification: false,
34
+ copy_settings: true
35
+ })
36
+ expect(migration['id']).to eq 1
37
+ expect(migration['template_id']).to eq 2
38
+ expect(migration['subscription_id']).to eq 101
39
+ expect(migration['user_id']).to eq 3
40
+ expect(migration['workflow_state']).to eq 'running'
41
+ end
42
+
43
+ end
@@ -91,8 +91,9 @@ describe Bearcat::Client::Sections do
91
91
  it 'sets extensions on a quiz' do
92
92
  stub_post(@client, "/api/v1/courses/1/quiz_extensions").to_return(json_response("quizzes/quiz_extension.json"))
93
93
  quiz_extension = @client.course_quiz_extensions('1', {quiz_extensions: [{user_id: 1}, {extra_time: 30}]})
94
- quiz_extension.class.should eq(Hash)
94
+ quiz_extension.should be_a Hash
95
95
  quiz_extension['quiz_extensions'].first['extra_time'].should eq(30)
96
+ quiz_extension[:quiz_extensions].first[:extra_time].should eq(30)
96
97
  end
97
98
 
98
99
  it 'gets learning outcome results' do
@@ -25,8 +25,9 @@ describe Bearcat::Client::Discussions do
25
25
  discussions = @client.course_discussions('1')
26
26
  discussions.class.should eq(Bearcat::ApiArray)
27
27
  discussions.count.should == 1
28
- discussions[0].class.should eq(Hash)
28
+ discussions[0].should be_a Hash
29
29
  discussions[0]['id'].should == 1
30
+ discussions[0][:id].should == 1
30
31
  end
31
32
 
32
33
  it 'returns group discussion topics' do
@@ -34,8 +35,9 @@ describe Bearcat::Client::Discussions do
34
35
  discussions = @client.group_discussions('1')
35
36
  discussions.class.should eq(Bearcat::ApiArray)
36
37
  discussions.count.should == 1
37
- discussions[0].class.should eq(Hash)
38
+ discussions[0].should be_a Hash
38
39
  discussions[0]['id'].should == 1
40
+ discussions[0][:id].should == 1
39
41
  end
40
42
 
41
43
  it 'returns course discussion entries' do
@@ -43,8 +45,9 @@ describe Bearcat::Client::Discussions do
43
45
  discussions = @client.course_discussion_entries('1', '1')
44
46
  discussions.class.should eq(Bearcat::ApiArray)
45
47
  discussions.count.should == 1
46
- discussions[0].class.should eq(Hash)
48
+ discussions[0].should be_a Hash
47
49
  discussions[0]['id'].should == 1
50
+ discussions[0][:id].should == 1
48
51
  end
49
52
 
50
53
  it 'returns group discussion entries' do
@@ -52,8 +55,9 @@ describe Bearcat::Client::Discussions do
52
55
  discussions = @client.group_discussion_entries('1', '1')
53
56
  discussions.class.should eq(Bearcat::ApiArray)
54
57
  discussions.count.should == 1
55
- discussions[0].class.should eq(Hash)
58
+ discussions[0].should be_a Hash
56
59
  discussions[0]['id'].should == 1
60
+ discussions[0][:id].should == 1
57
61
  end
58
62
 
59
63
  it 'returns course discussion entry replies' do
@@ -61,8 +65,9 @@ describe Bearcat::Client::Discussions do
61
65
  discussions = @client.course_discussion_entry_replies('1', '1', '1')
62
66
  discussions.class.should eq(Bearcat::ApiArray)
63
67
  discussions.count.should == 1
64
- discussions[0].class.should eq(Hash)
68
+ discussions[0].should be_a Hash
65
69
  discussions[0]['id'].should == 3
70
+ discussions[0][:id].should == 3
66
71
  end
67
72
 
68
73
  it 'returns group discussion entry replies' do
@@ -70,8 +75,9 @@ describe Bearcat::Client::Discussions do
70
75
  discussions = @client.group_discussion_entry_replies('1', '1', '1')
71
76
  discussions.class.should eq(Bearcat::ApiArray)
72
77
  discussions.count.should == 1
73
- discussions[0].class.should eq(Hash)
78
+ discussions[0].should be_a Hash
74
79
  discussions[0]['id'].should == 3
80
+ discussions[0][:id].should == 3
75
81
  end
76
82
 
77
83
  it 'returns a single group discussion' do
@@ -8,8 +8,9 @@ describe Bearcat::Client::Quizzes do
8
8
  it "updates a single quiz" do
9
9
  stub_put(@client, "/api/v1/courses/1/quizzes/38").to_return(json_response("quizzes/course_quiz.json"))
10
10
  course_quiz = @client.edit_quiz('1', '38')
11
- course_quiz.class.should eq(Hash)
11
+ course_quiz.should be_a Hash
12
12
  course_quiz['id'].should == 38
13
+ course_quiz[:id].should == 38
13
14
  end
14
15
 
15
16
  it "returns a courses quizzes" do
@@ -24,22 +25,25 @@ describe Bearcat::Client::Quizzes do
24
25
  it "returns a single quiz" do
25
26
  stub_get(@client, "/api/v1/courses/1/quizzes/38").to_return(json_response("quizzes/course_quiz.json"))
26
27
  course_quiz = @client.quiz('1', '38')
27
- course_quiz.class.should eq(Hash)
28
+ course_quiz.should be_a Hash
28
29
  course_quiz['id'].should == 38
30
+ course_quiz[:id].should == 38
29
31
  end
30
32
 
31
33
  it 'sets extensions on a quiz' do
32
34
  stub_post(@client, "/api/v1/courses/1/quizzes/1/extensions").to_return(json_response("quizzes/quiz_extension.json"))
33
35
  quiz_extension = @client.quiz_extensions('1', '1', {quiz_extensions: [{user_id: 1}, {extra_time: 30}]})
34
- quiz_extension.class.should eq(Hash)
36
+ quiz_extension.should be_a Hash
35
37
  quiz_extension['quiz_extensions'].first['extra_time'].should eq(30)
38
+ quiz_extension[:quiz_extensions].first[:extra_time].should eq(30)
36
39
  end
37
40
 
38
41
  it 'returns a quiz assignment override' do
39
42
  stub_get(@client, "/api/v1/courses/1/quizzes/assignment_overrides?quiz_assignment_overrides%5B%5D%5Bquiz_ids%5D=13").to_return(json_response("quizzes/quiz_assignment_override.json"))
40
43
  quiz_overrides = @client.quiz_assignment_overrides('1',{:quiz_assignment_overrides => [{ :quiz_ids => 13 }] })
41
- quiz_overrides.class.should eq(Hash)
44
+ quiz_overrides.should be_a Hash
42
45
  quiz_overrides['quiz_assignment_overrides'].first['quiz_id'].should eq(1014)
46
+ quiz_overrides[:quiz_assignment_overrides].first[:quiz_id].should eq(1014)
43
47
  end
44
48
 
45
49
 
@@ -56,8 +60,9 @@ describe Bearcat::Client::Quizzes do
56
60
  course_quiz_questions = @client.quiz_questions('1', '1')
57
61
  course_quiz_questions.class.should eq(Bearcat::ApiArray)
58
62
  course_quiz_questions.count.should == 1
59
- course_quiz_questions[0].class.should eq(Hash)
63
+ course_quiz_questions[0].should be_a Hash
60
64
  course_quiz_questions[0]['id'].should == 1
65
+ course_quiz_questions[0][:id].should == 1
61
66
  end
62
67
 
63
68
  end
@@ -0,0 +1,24 @@
1
+ require 'helper'
2
+
3
+ describe Bearcat::Client::Roles do
4
+ before do
5
+ @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token")
6
+ end
7
+
8
+ it "returns all roles" do
9
+ stub_get(@client, "/api/v1/accounts/self/roles").to_return(json_response("account_roles.json"))
10
+ roles = @client.roles
11
+ roles.count.should == 1
12
+ roles.first["label"].should == 'Account Admin'
13
+ roles.first["id"].should == 1
14
+ roles.first["base_role_type"].should == 'AccountMembership'
15
+ end
16
+
17
+ it "returns an individual role" do
18
+ stub_get(@client, "/api/v1/accounts/self/roles/1").to_return(json_response("account_role.json"))
19
+ role = @client.role(1)
20
+ role["label"].should == 'Account Admin'
21
+ role["id"].should == 1
22
+ role["base_role_type"].should == 'AccountMembership'
23
+ end
24
+ end
@@ -0,0 +1,34 @@
1
+ {
2
+ "id": 1,
3
+ "role": "AccountAdmin",
4
+ "label": "Account Admin",
5
+ "base_role_type": "AccountMembership",
6
+ "workflow_state": "built_in",
7
+ "permissions": {
8
+ "read_forum": {
9
+ "enabled": true,
10
+ "locked": false,
11
+ "readonly": false,
12
+ "explicit": false
13
+ },
14
+ "post_to_forum": {
15
+ "enabled": true,
16
+ "locked": false,
17
+ "readonly": false,
18
+ "explicit": false
19
+ },
20
+ "moderate_forum": {
21
+ "enabled": true,
22
+ "locked": false,
23
+ "readonly": false,
24
+ "explicit": false
25
+ },
26
+ "manage_catalog": {
27
+ "enabled": true,
28
+ "locked": false,
29
+ "readonly": false,
30
+ "explicit": false
31
+ }
32
+ }
33
+ }
34
+
@@ -0,0 +1,12 @@
1
+ {
2
+ "id": 1,
3
+ "template_id": 2,
4
+ "subscription_id": 101,
5
+ "user_id": 3,
6
+ "workflow_state": "running",
7
+ "created_at": "2013-08-28T23:59:00-06:00",
8
+ "exports_started_at": "2013-08-28T23:59:00-06:00",
9
+ "imports_queued_at": "2013-08-28T23:59:00-06:00",
10
+ "imports_completed_at": "2013-08-28T23:59:00-06:00",
11
+ "comment": "Fixed spelling in question 3 of midterm exam"
12
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "id": 101,
3
+ "template_id": 1,
4
+ "blueprint_course": {"id":2,"name":"Biology 100 Blueprint","course_code":"BIOL 100 BP","term_name":"Default term"}
5
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "id": 1,
3
+ "course_id": 2,
4
+ "last_export_completed_at": "2013-08-28T23:59:00-06:00",
5
+ "associated_course_count": 3,
6
+ "latest_migration": null
7
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "success": true
3
+ }
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.3.52
4
+ version: 1.4.2
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: 2020-01-14 00:00:00.000000000 Z
11
+ date: 2020-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -139,6 +139,7 @@ files:
139
139
  - lib/bearcat/client/analytics.rb
140
140
  - lib/bearcat/client/assignment_groups.rb
141
141
  - lib/bearcat/client/assignments.rb
142
+ - lib/bearcat/client/blueprint_courses.rb
142
143
  - lib/bearcat/client/calendar_events.rb
143
144
  - lib/bearcat/client/canvas_files.rb
144
145
  - lib/bearcat/client/conferences.rb
@@ -165,6 +166,7 @@ files:
165
166
  - lib/bearcat/client/pages.rb
166
167
  - lib/bearcat/client/quizzes.rb
167
168
  - lib/bearcat/client/reports.rb
169
+ - lib/bearcat/client/roles.rb
168
170
  - lib/bearcat/client/rubric.rb
169
171
  - lib/bearcat/client/rubric_assessment.rb
170
172
  - lib/bearcat/client/rubric_association.rb
@@ -179,6 +181,7 @@ files:
179
181
  - spec/bearcat/client/analytics_spec.rb
180
182
  - spec/bearcat/client/assignment_groups_spec.rb
181
183
  - spec/bearcat/client/assignments_spec.rb
184
+ - spec/bearcat/client/blueprint_courses_spec.rb
182
185
  - spec/bearcat/client/calendar_events_spec.rb
183
186
  - spec/bearcat/client/canvas_files_spec.rb
184
187
  - spec/bearcat/client/conferences_spec.rb
@@ -204,6 +207,7 @@ files:
204
207
  - spec/bearcat/client/pages_spec.rb
205
208
  - spec/bearcat/client/quizzes_spec.rb
206
209
  - spec/bearcat/client/reports_spec.rb
210
+ - spec/bearcat/client/roles_spec.rb
207
211
  - spec/bearcat/client/rubric_assessment_spec.rb
208
212
  - spec/bearcat/client/rubric_association_spec.rb
209
213
  - spec/bearcat/client/rubric_spec.rb
@@ -225,6 +229,7 @@ files:
225
229
  - spec/fixtures/account_reports_index.json
226
230
  - spec/fixtures/account_reports_result_success.json
227
231
  - spec/fixtures/account_reports_start_result.json
232
+ - spec/fixtures/account_role.json
228
233
  - spec/fixtures/account_roles.json
229
234
  - spec/fixtures/account_sis_imports.json
230
235
  - spec/fixtures/account_sub_accounts.json
@@ -239,6 +244,10 @@ files:
239
244
  - spec/fixtures/assignment_section_override.json
240
245
  - spec/fixtures/assignments.json
241
246
  - spec/fixtures/bearcat.jpg
247
+ - spec/fixtures/blueprint_migration.json
248
+ - spec/fixtures/blueprint_subscriptions.json
249
+ - spec/fixtures/blueprint_template.json
250
+ - spec/fixtures/blueprint_update_assocations_success.json
242
251
  - spec/fixtures/calendar_event.json
243
252
  - spec/fixtures/calendar_events.json
244
253
  - spec/fixtures/canvas_files/declare_file.json
@@ -371,7 +380,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
371
380
  - !ruby/object:Gem::Version
372
381
  version: '0'
373
382
  requirements: []
374
- rubygems_version: 3.0.3
383
+ rubyforge_project:
384
+ rubygems_version: 2.6.14.1
375
385
  signing_key:
376
386
  specification_version: 4
377
387
  summary: Canvas API
@@ -395,9 +405,11 @@ test_files:
395
405
  - spec/bearcat/client/modules_spec.rb
396
406
  - spec/bearcat/client/discussions_spec.rb
397
407
  - spec/bearcat/client/files_spec.rb
408
+ - spec/bearcat/client/roles_spec.rb
398
409
  - spec/bearcat/client/graph_ql_spec.rb
399
410
  - spec/bearcat/client/group_categories_spec.rb
400
411
  - spec/bearcat/client/rubric_assessment_spec.rb
412
+ - spec/bearcat/client/blueprint_courses_spec.rb
401
413
  - spec/bearcat/client/submissions_spec.rb
402
414
  - spec/bearcat/client/module_items_spec.rb
403
415
  - spec/bearcat/client/content_migrations_spec.rb
@@ -463,6 +475,8 @@ test_files:
463
475
  - spec/fixtures/account_admin_create.json
464
476
  - spec/fixtures/assignment.json
465
477
  - spec/fixtures/calendar_event.json
478
+ - spec/fixtures/blueprint_subscriptions.json
479
+ - spec/fixtures/blueprint_update_assocations_success.json
466
480
  - spec/fixtures/course.json
467
481
  - spec/fixtures/rubric_association.json
468
482
  - spec/fixtures/external_tools.json
@@ -483,6 +497,7 @@ test_files:
483
497
  - spec/fixtures/start_report.json
484
498
  - spec/fixtures/custom_data.json
485
499
  - spec/fixtures/rubric.json
500
+ - spec/fixtures/account_role.json
486
501
  - spec/fixtures/update_outcome_group.json
487
502
  - spec/fixtures/module_item.json
488
503
  - spec/fixtures/report_status.json
@@ -498,6 +513,7 @@ test_files:
498
513
  - spec/fixtures/user_logins.json
499
514
  - spec/fixtures/module_item_sequence.json
500
515
  - spec/fixtures/enrollment_terms.json
516
+ - spec/fixtures/blueprint_migration.json
501
517
  - spec/fixtures/cc.imscc
502
518
  - spec/fixtures/user_profile.json
503
519
  - spec/fixtures/create_course_discussion.json
@@ -505,6 +521,7 @@ test_files:
505
521
  - spec/fixtures/created_module.json
506
522
  - spec/fixtures/course_groups.json
507
523
  - spec/fixtures/reactivate_enrollment.json
524
+ - spec/fixtures/blueprint_template.json
508
525
  - spec/fixtures/account_courses.json
509
526
  - spec/fixtures/calendar_events.json
510
527
  - spec/fixtures/submissions/submission.json