bearcat 0.1.1 → 0.3
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.
- data/bearcat.gemspec +1 -1
- data/lib/bearcat/api_array.rb +2 -2
- data/lib/bearcat/client.rb +11 -0
- data/lib/bearcat/client/enrollments.rb +8 -0
- data/lib/bearcat/client/o_auth2.rb +32 -0
- data/lib/bearcat/client/outcome_groups.rb +3 -3
- data/lib/bearcat/version.rb +2 -2
- data/spec/bearcat/client/assignments_spec.rb +10 -10
- data/spec/bearcat/client/courses_spec.rb +7 -7
- data/spec/bearcat/client/enrollments_spec.rb +35 -16
- data/spec/bearcat/client/o_auth2_spec.rb +20 -0
- data/spec/bearcat/client/outcome_groups_spec.rb +33 -27
- data/spec/bearcat/client/outcomes_spec.rb +7 -7
- data/spec/bearcat/client/sections_spec.rb +15 -17
- data/spec/bearcat/client_spec.rb +2 -2
- data/spec/bearcat_spec.rb +0 -2
- data/spec/fixtures/course_enrollments.json +145 -0
- data/spec/fixtures/section_enrollments.json +55 -0
- data/spec/helper.rb +0 -6
- metadata +11 -4
data/bearcat.gemspec
CHANGED
data/lib/bearcat/api_array.rb
CHANGED
|
@@ -40,7 +40,7 @@ module Bearcat
|
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def pages?
|
|
43
|
-
|
|
43
|
+
@link_hash[:next] || @link_hash[:prev]
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def next_page
|
|
@@ -78,8 +78,8 @@ module Bearcat
|
|
|
78
78
|
init_pages(@headers[:link])
|
|
79
79
|
end
|
|
80
80
|
@link_hash = {}
|
|
81
|
-
self
|
|
82
81
|
end
|
|
82
|
+
self
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
private
|
data/lib/bearcat/client.rb
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
require 'footrest/client'
|
|
2
|
+
require 'bearcat/api_array'
|
|
2
3
|
require 'bearcat/client/assignments'
|
|
3
4
|
require 'bearcat/client/courses'
|
|
4
5
|
require 'bearcat/client/enrollments'
|
|
5
6
|
require 'bearcat/client/outcome_groups'
|
|
6
7
|
require 'bearcat/client/outcomes'
|
|
7
8
|
require 'bearcat/client/sections'
|
|
9
|
+
require 'bearcat/client/o_auth2'
|
|
8
10
|
|
|
9
11
|
module Bearcat
|
|
10
12
|
class Client < Footrest::Client
|
|
@@ -15,6 +17,15 @@ module Bearcat
|
|
|
15
17
|
include OutcomeGroups
|
|
16
18
|
include Outcomes
|
|
17
19
|
include Sections
|
|
20
|
+
include OAuth2
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# Override Footrest request for ApiArray support
|
|
24
|
+
def request(method, &block)
|
|
25
|
+
ApiArray::process_response(connection.send(method, &block), self)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
|
|
18
29
|
end
|
|
19
30
|
|
|
20
31
|
end
|
|
@@ -6,6 +6,14 @@ module Bearcat
|
|
|
6
6
|
get("/api/v1/users/#{user.to_s}/enrollments", params)
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
+
def course_enrollments(course, params={})
|
|
10
|
+
get("/api/v1/courses/#{course.to_s}/enrollments", params)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def section_enrollments(section, params={})
|
|
14
|
+
get("/api/v1/sections/#{section.to_s}/enrollments", params)
|
|
15
|
+
end
|
|
16
|
+
|
|
9
17
|
def enroll_in_section(section, params={})
|
|
10
18
|
post("/api/v1/sections/#{section.to_s}/enrollments", params)
|
|
11
19
|
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Bearcat
|
|
2
|
+
class Client < Footrest::Client
|
|
3
|
+
module OAuth2
|
|
4
|
+
|
|
5
|
+
def auth_redirect_url(client_id, redirect_uri, scopes = nil, response_type='code')
|
|
6
|
+
fullpath('login/oauth2/auth')
|
|
7
|
+
uri = URI.parse(fullpath('login/oauth2/auth'))
|
|
8
|
+
query = [
|
|
9
|
+
['client_id', client_id],
|
|
10
|
+
['redirect_uri', redirect_uri],
|
|
11
|
+
['response_type', response_type]
|
|
12
|
+
]
|
|
13
|
+
query << ['scopes', scopes] if scopes
|
|
14
|
+
uri.query = URI.encode_www_form(query)
|
|
15
|
+
uri.to_s
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def retrieve_token(client_id, redirect_url, client_secret, code)
|
|
19
|
+
body = post('/login/oauth2/token', {
|
|
20
|
+
client_id: client_id,
|
|
21
|
+
redirect_url: redirect_url,
|
|
22
|
+
client_secret: client_secret,
|
|
23
|
+
code: code
|
|
24
|
+
})
|
|
25
|
+
config[:token] = body['access_token']
|
|
26
|
+
set_connection(config)
|
|
27
|
+
config[:token]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -48,14 +48,14 @@ module Bearcat
|
|
|
48
48
|
if context_hash.keys.count > 1
|
|
49
49
|
raise ArgumentError, "cannot have account and course in params"
|
|
50
50
|
elsif context_hash.empty?
|
|
51
|
-
return "#{
|
|
51
|
+
return "#{global_slug}"
|
|
52
52
|
else
|
|
53
53
|
context_hash_key = context_hash.keys.first
|
|
54
54
|
case context_hash_key
|
|
55
55
|
when 'account'
|
|
56
|
-
"#{
|
|
56
|
+
"#{account_slug(context_hash[context_hash_key])}"
|
|
57
57
|
when 'course'
|
|
58
|
-
"#{
|
|
58
|
+
"#{course_slug(context_hash[context_hash_key])}"
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
61
|
end
|
data/lib/bearcat/version.rb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
module Bearcat
|
|
2
|
-
VERSION = '0.
|
|
3
|
-
end
|
|
2
|
+
VERSION = '0.3' unless defined?(Bearcat::VERSION)
|
|
3
|
+
end
|
|
@@ -8,10 +8,10 @@ describe Bearcat::Client::Assignments do
|
|
|
8
8
|
it "returns all assignments for a course" do
|
|
9
9
|
stub_get(@client, "/api/v1/courses/3/assignments").to_return(json_response("assignments.json"))
|
|
10
10
|
assignments = @client.assignments(3)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
assignments.count.should == 2
|
|
12
|
+
assignments.first["assignment_group_id"].should == 53
|
|
13
|
+
assignments.first["id"].should == 123
|
|
14
|
+
assignments.first["due_at"].should == nil
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it "creates an assignment override for a section" do
|
|
@@ -22,18 +22,18 @@ describe Bearcat::Client::Assignments do
|
|
|
22
22
|
"assignment_override[course_section_id]" => 74,
|
|
23
23
|
"assignment_override[due_at]" => "2013-06-27T21:08:46Z"
|
|
24
24
|
})
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
override["all_day"].should == false
|
|
26
|
+
override["due_at"].should == "2013-06-27T15:08:46-06:00"
|
|
27
|
+
override["id"].should == 1
|
|
28
|
+
override["course_section_id"].should == 74
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
it "creates a new assignment" do
|
|
32
32
|
name = "new assignment"
|
|
33
33
|
stub_post(@client, "/api/v1/courses/1/assignments").with(body: {"assignment" => {"name" => name}}).to_return(json_response("created_assignment.json"))
|
|
34
34
|
assignment = @client.create_assignment(1, {"assignment" => {"name" => name}})
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
assignment["name"].should == name
|
|
36
|
+
assignment["id"].should == 1
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
end
|
|
@@ -8,24 +8,24 @@ describe Bearcat::Client::Sections do
|
|
|
8
8
|
it "returns a section" do
|
|
9
9
|
stub_get(@client, "/api/v1/courses/3").to_return(json_response("course.json"))
|
|
10
10
|
course = @client.course(3)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
course['name'].should == 'Course 3'
|
|
12
|
+
course['id'].should == 3
|
|
13
|
+
course['start_at'].should == '2012-06-01T00:00:00-06:00'
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it "creates a new course" do
|
|
17
17
|
name = "new course"
|
|
18
18
|
stub_post(@client, "/api/v1/accounts/1/courses").with(body: {"course" => {"name" => name}}).to_return(json_response("created_course.json"))
|
|
19
19
|
course = @client.create_course(1, {"course[name]" => name})
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
course['name'].should == name
|
|
21
|
+
course['id'].should == 1
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it "lists all of the students in a course" do
|
|
25
25
|
stub_get(@client, "/api/v1/courses/1/users?enrollment_type=student").to_return(json_response("course_students.json"))
|
|
26
26
|
students = @client.list_users(1, {"enrollment_type" => "student"})
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
students['name'].should == 'test@student.com'
|
|
28
|
+
students['id'].should == 2
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
end
|
|
@@ -8,11 +8,31 @@ describe Bearcat::Client::Enrollments do
|
|
|
8
8
|
it "returns all enrollments for a user" do
|
|
9
9
|
stub_get(@client, "/api/v1/users/1/enrollments").to_return(json_response("user_enrollments.json"))
|
|
10
10
|
enrollments = @client.user_enrollments(1)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
enrollments.first['course_id'].should == 3
|
|
12
|
+
enrollments.first['course_section_id'].should == 70
|
|
13
|
+
enrollments.first['id'].should == 2
|
|
14
|
+
enrollments.first['user']['id'].should == 1
|
|
15
|
+
enrollments.first['user']['name'].should == 'test@instructure.com'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "returns all enrollments for a course" do
|
|
19
|
+
stub_get(@client, "/api/v1/courses/1/enrollments").to_return(json_response("course_enrollments.json"))
|
|
20
|
+
enrollments = @client.course_enrollments(1)
|
|
21
|
+
enrollments.first['course_id'].should == 9
|
|
22
|
+
enrollments.first['course_section_id'].should == 11
|
|
23
|
+
enrollments.first['id'].should == 27
|
|
24
|
+
enrollments.first['user']['id'].should == 7
|
|
25
|
+
enrollments.first['user']['name'].should == 'User 1'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "returns all enrollments for a section" do
|
|
29
|
+
stub_get(@client, "/api/v1/sections/1/enrollments").to_return(json_response("section_enrollments.json"))
|
|
30
|
+
enrollments = @client.section_enrollments(1)
|
|
31
|
+
enrollments.first['course_id'].should == 2
|
|
32
|
+
enrollments.first['course_section_id'].should == 2
|
|
33
|
+
enrollments.first['id'].should == 6
|
|
34
|
+
enrollments.first['user']['id'].should == 8
|
|
35
|
+
enrollments.first['user']['name'].should == 'User 2'
|
|
16
36
|
end
|
|
17
37
|
|
|
18
38
|
it "enrolls a student in a section" do
|
|
@@ -21,22 +41,21 @@ describe Bearcat::Client::Enrollments do
|
|
|
21
41
|
.to_return(json_response("enroll_student.json"))
|
|
22
42
|
|
|
23
43
|
enrollment = @client.enroll_in_section(70, {"enrollment[user_id]" => 1, "enrollment[type]" => "StudentEnrollment"})
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
44
|
+
enrollment["course_id"].should == 3
|
|
45
|
+
enrollment["course_section_id"].should == 70
|
|
46
|
+
enrollment["id"].should == 1386
|
|
47
|
+
enrollment["role"].should == "StudentEnrollment"
|
|
48
|
+
enrollment["enrollment_state"].should == "invited"
|
|
29
49
|
end
|
|
30
50
|
|
|
31
51
|
it "concludes a students enrollment" do
|
|
32
52
|
stub_request(:delete, "http://canvas.instructure.com/api/v1/courses/3/enrollments/1386?task=conclude").to_return(json_response("conclude_enrollment.json"))
|
|
33
53
|
enrollment = @client.conclude_enrollment(3, 1386, {"task" => "conclude"})
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
54
|
+
enrollment["course_id"].should == 3
|
|
55
|
+
enrollment["course_section_id"].should == 70
|
|
56
|
+
enrollment["id"].should == 1386
|
|
57
|
+
enrollment["role"].should == "StudentEnrollment"
|
|
58
|
+
enrollment["enrollment_state"].should == "completed"
|
|
39
59
|
end
|
|
40
60
|
|
|
41
|
-
|
|
42
61
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'helper'
|
|
2
|
+
|
|
3
|
+
describe Bearcat::Client::Enrollments do
|
|
4
|
+
let(:client){Bearcat::Client.new(prefix: "http://canvas.instructure.com")}
|
|
5
|
+
|
|
6
|
+
it "generates a redirect url" do
|
|
7
|
+
redirect_url = client.auth_redirect_url(10000000000002, 'http://localhost:9393')
|
|
8
|
+
redirect_url.should == "http://canvas.instructure.com/login/oauth2/auth?client_id=10000000000002&redirect_uri=http%3A%2F%2Flocalhost%3A9393&response_type=code"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "sets the auth_token" do
|
|
12
|
+
stub_post(client, "/login/oauth2/token").
|
|
13
|
+
with(:body => {"client_id"=>"10000000000002", "client_secret"=>"secret", "code"=>"code", "redirect_url"=>"http://localhost:9393"}).
|
|
14
|
+
to_return(:body => {'access_token' => 'foo_bar_token'})
|
|
15
|
+
client.retrieve_token(10000000000002, 'http://localhost:9393', 'secret', 'code')
|
|
16
|
+
client.config.token.should == "foo_bar_token"
|
|
17
|
+
client.instance_variable_get(:@connection).headers[:authorization].should == 'Bearer foo_bar_token'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
@@ -9,49 +9,53 @@ describe Bearcat::Client::OutcomeGroups do
|
|
|
9
9
|
|
|
10
10
|
describe "outcomes api slugs" do
|
|
11
11
|
it "returns the account api slug" do
|
|
12
|
-
|
|
12
|
+
@client.outcomes_context_slug({'account' => 3}).should ==
|
|
13
|
+
'accounts/3/outcome_groups/'
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
it "returns the course api slug" do
|
|
16
|
-
|
|
17
|
+
@client.outcomes_context_slug(PARAMS).should ==
|
|
18
|
+
'courses/1/outcome_groups/'
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
it "returns the global api slug" do
|
|
20
|
-
|
|
22
|
+
@client.outcomes_context_slug({}).should ==
|
|
23
|
+
'global/outcome_groups/'
|
|
21
24
|
end
|
|
22
25
|
|
|
23
26
|
it "raises an error if both account and course are in params" do
|
|
24
|
-
expect { @client.outcomes_context_slug({'account' => 3, 'course' => 5}) }.
|
|
27
|
+
expect { @client.outcomes_context_slug({'account' => 3, 'course' => 5}) }.
|
|
28
|
+
to raise_error(ArgumentError)
|
|
25
29
|
end
|
|
26
30
|
end
|
|
27
31
|
|
|
28
32
|
it "returns an outcome group" do
|
|
29
33
|
stub_get(@client, "#{@client.outcomes_context_slug(PARAMS)}5").to_return(json_response("outcome_groups.json"))
|
|
30
34
|
outcome = @client.show_outcome_group(5, PARAMS)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
outcome['id'].should == 5
|
|
36
|
+
outcome['title'].should == 'Outcome group title'
|
|
37
|
+
outcome['description'].should == 'Outcome group description'
|
|
34
38
|
end
|
|
35
39
|
|
|
36
40
|
it "updates an outcome group" do
|
|
37
41
|
updated_outcome_title = 'updated outcome group title'
|
|
38
42
|
stub_put(@client, "#{@client.outcomes_context_slug(PARAMS)}2").with(:body => {"course" => "1", "title" => updated_outcome_title}).to_return(json_response("update_outcome_group.json"))
|
|
39
43
|
updated_outcome = @client.update_outcome_group(2, {"course" => "1", "title" => updated_outcome_title})
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
updated_outcome['id'].should == 2
|
|
45
|
+
updated_outcome['title'].should == updated_outcome_title
|
|
42
46
|
end
|
|
43
47
|
|
|
44
48
|
it "deletes an outcome group" do
|
|
45
49
|
stub_delete(@client, "#{@client.outcomes_context_slug(PARAMS)}2").to_return(json_response("outcome_groups.json"))
|
|
46
50
|
deleted_outcome = @client.delete_outcome_group(2, PARAMS)
|
|
47
|
-
|
|
51
|
+
deleted_outcome.should_not == "error"
|
|
48
52
|
end
|
|
49
53
|
|
|
50
54
|
it "returns linked outcomes" do
|
|
51
55
|
stub_get(@client, "#{@client.outcomes_context_slug(PARAMS)}2/outcomes").to_return(json_response("link_unlink_outcome.json"))
|
|
52
56
|
linked_outcomes = @client.list_linked_outcomes(2, PARAMS)
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
linked_outcomes['outcome_group']['title'].should == 'sup'
|
|
58
|
+
linked_outcomes['outcome']['context_type'].should == 'Course'
|
|
55
59
|
end
|
|
56
60
|
|
|
57
61
|
it "creates outcome in outcome group" do
|
|
@@ -59,30 +63,32 @@ describe Bearcat::Client::OutcomeGroups do
|
|
|
59
63
|
description = 'this is a new description 3'
|
|
60
64
|
stub_post(@client, "#{@client.outcomes_context_slug(PARAMS)}2/outcomes").with(:body => {"course" => "1", "title" => title, "description" => description}).to_return(json_response('create_outcome_in_group.json'))
|
|
61
65
|
created_outcome = @client.create_outcome_in_group(2, {"course" => "1", "title" => title, "description" => description})
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
created_outcome['outcome']['title'].should == title
|
|
67
|
+
created_outcome['outcome']['id'].should == 18
|
|
68
|
+
created_outcome['url'].should == '/api/v1/courses/1/outcome_groups/2/outcomes/18'
|
|
65
69
|
end
|
|
66
70
|
|
|
67
71
|
it "links outcome in outcome group" do
|
|
68
|
-
stub_put(@client, "#{@client.outcomes_context_slug(PARAMS)}2/outcomes/14").
|
|
72
|
+
stub_put(@client, "#{@client.outcomes_context_slug(PARAMS)}2/outcomes/14").
|
|
73
|
+
to_return(json_response('link_unlink_outcome.json'))
|
|
69
74
|
linked_outcome = @client.link_outcome(2, 14, PARAMS)
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
linked_outcome['outcome']['title'].should == 'New Outcome sup'
|
|
76
|
+
linked_outcome['url'].should == '/api/v1/courses/1/outcome_groups/2/outcomes/14'
|
|
72
77
|
end
|
|
73
78
|
|
|
74
79
|
it "unlinks an outcome" do
|
|
75
|
-
stub_delete(@client, "#{@client.outcomes_context_slug(PARAMS)}2/outcomes/14").
|
|
80
|
+
stub_delete(@client, "#{@client.outcomes_context_slug(PARAMS)}2/outcomes/14").
|
|
81
|
+
to_return(json_response('link_unlink_outcome.json'))
|
|
76
82
|
unlinked_outcome = @client.unlink_outcome(2, 14, PARAMS)
|
|
77
|
-
|
|
83
|
+
unlinked_outcome.should_not == "error"
|
|
78
84
|
end
|
|
79
85
|
|
|
80
86
|
it "returns subgroups" do
|
|
81
87
|
stub_get(@client, "#{@client.outcomes_context_slug(PARAMS)}2/subgroups").to_return(json_response("outcome_subgroups.json"))
|
|
82
88
|
outcome_subgroups = @client.list_subgroups(2, PARAMS)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
outcome_subgroups.count.should == 2
|
|
90
|
+
outcome_subgroups.first['title'].should == 'hello this is a new group'
|
|
91
|
+
outcome_subgroups.last['title'].should == 'this is the last group'
|
|
86
92
|
end
|
|
87
93
|
|
|
88
94
|
it "creates subgroups" do
|
|
@@ -90,15 +96,15 @@ describe Bearcat::Client::OutcomeGroups do
|
|
|
90
96
|
description = "api created subgroup desc"
|
|
91
97
|
stub_post(@client, "#{@client.outcomes_context_slug(PARAMS)}2/subgroups").with(:body => {"course" => "1", "description" => description, "title" => title}).to_return(json_response("outcome_subgroup.json"))
|
|
92
98
|
outcome_subgroup = @client.create_subgroup(2, {"course" => "1", "description" => description, "title" => title})
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
outcome_subgroup['title'].should == title
|
|
100
|
+
outcome_subgroup['description'].should == description
|
|
95
101
|
end
|
|
96
102
|
|
|
97
103
|
it "imports outcome groups" do
|
|
98
104
|
stub_post(@client, "#{@client.outcomes_context_slug(PARAMS)}2/import").with(:body => {"course" => "1", "source_outcome_group_id" => "14"}).to_return(json_response("outcome_group_import.json"))
|
|
99
105
|
imported_outcome = @client.import_outcome_group(2, {"course" => "1", "source_outcome_group_id" => "14"})
|
|
100
|
-
|
|
101
|
-
|
|
106
|
+
imported_outcome['title'].should == 'this is a new group'
|
|
107
|
+
imported_outcome['parent_outcome_group'].should_not be_empty
|
|
102
108
|
end
|
|
103
109
|
|
|
104
110
|
end
|
|
@@ -8,11 +8,11 @@ describe Bearcat::Client::Outcomes do
|
|
|
8
8
|
it "returns an outcome" do
|
|
9
9
|
stub_get(@client, "/api/v1/outcomes/1").to_return(json_response("outcomes.json"))
|
|
10
10
|
outcome = @client.show_outcome(1)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
outcome['title'].should == 'Test Outcome title'
|
|
12
|
+
outcome['id'].should == 1
|
|
13
|
+
outcome['description'].should == 'Test Outcome description'
|
|
14
|
+
outcome['points_possible'].should == 5
|
|
15
|
+
outcome['mastery_points'].should == 3
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
it "updates an outcome" do
|
|
@@ -20,8 +20,8 @@ describe Bearcat::Client::Outcomes do
|
|
|
20
20
|
description = 'updated outcome desc'
|
|
21
21
|
stub_put(@client, "/api/v1/outcomes/5").with(:body => {"title" => title, "description" => description}).to_return(json_response("update_outcome.json"))
|
|
22
22
|
outcome = @client.update_outcome(5, {"title" => title, "description" => description})
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
outcome['title'].should == title
|
|
24
|
+
outcome['description'].should == description
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
end
|
|
@@ -8,44 +8,42 @@ describe Bearcat::Client::Sections do
|
|
|
8
8
|
it "returns all sections for a course" do
|
|
9
9
|
stub_get(@client, "/api/v1/courses/3/sections").to_return(json_response("course_sections.json"))
|
|
10
10
|
sections = @client.course_sections(3)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
sections.first['name'].should == 'test'
|
|
12
|
+
sections.first['id'].should == 70
|
|
13
|
+
sections.first['course_id'].should == 3
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it "returns a section" do
|
|
17
17
|
stub_get(@client, "/api/v1/sections/72").to_return(json_response("section.json"))
|
|
18
18
|
section = @client.section(72)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
section['name'].should == 'Section003'
|
|
20
|
+
section['id'].should == 72
|
|
21
|
+
section['course_id'].should == 3
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it "creates a section" do
|
|
25
25
|
stub_post(@client, "/api/v1/courses/3/sections").
|
|
26
26
|
with(:body => {"course_section"=>{"name"=>"Section003"}}).to_return(json_response("create_section.json"))
|
|
27
27
|
section = @client.create_section(3, {"course_section[name]" => "Section003"})
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
section['course_id'].should == 3
|
|
29
|
+
section['id'].should == 72
|
|
30
|
+
section['name'].should == 'Section003'
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
it "updates a section" do
|
|
34
34
|
stub_put(@client, "/api/v1/sections/72").with(:body => {"course_section"=>{"name"=>"Section003"}}).to_return(json_response("update_section.json"))
|
|
35
35
|
section = @client.update_section(72, {"course_section[name]" => "Section003"})
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
section['course_id'].should == 3
|
|
37
|
+
section['id'].should == 72
|
|
38
|
+
section['name'].should == 'Section003'
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it "deletes a section" do
|
|
42
42
|
stub_delete(@client, "/api/v1/sections/72").to_return(json_response("update_section.json"))
|
|
43
43
|
section = @client.delete_section(72)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
section['course_id'].should == 3
|
|
45
|
+
section['id'].should == 72
|
|
46
|
+
section['name'].should == 'Section003'
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
49
|
end
|
data/spec/bearcat/client_spec.rb
CHANGED
|
@@ -4,13 +4,13 @@ describe Bearcat::Client do
|
|
|
4
4
|
|
|
5
5
|
it "sets the domain" do
|
|
6
6
|
client = Bearcat::Client.new(domain: "http://canvas.instructure.com")
|
|
7
|
-
|
|
7
|
+
client.config[:domain].should == "http://canvas.instructure.com"
|
|
8
8
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
it "sets the authtoken" do
|
|
12
12
|
client = Bearcat::Client.new(token: "test_token")
|
|
13
|
-
|
|
13
|
+
client.config[:token].should == "test_token"
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
end
|
data/spec/bearcat_spec.rb
CHANGED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"associated_user_id": null,
|
|
4
|
+
"course_id": 9,
|
|
5
|
+
"course_section_id": 11,
|
|
6
|
+
"id": 27,
|
|
7
|
+
"limit_privileges_to_course_section": false,
|
|
8
|
+
"root_account_id": 1,
|
|
9
|
+
"type": "StudentEnrollment",
|
|
10
|
+
"updated_at": "2013-09-24T18:22:21Z",
|
|
11
|
+
"user_id": 7,
|
|
12
|
+
"enrollment_state": "active",
|
|
13
|
+
"role": "StudentEnrollment",
|
|
14
|
+
"grades": {
|
|
15
|
+
"html_url": "http://localhost:3000/courses/9/grades/7",
|
|
16
|
+
"current_score": null,
|
|
17
|
+
"final_score": 0.0,
|
|
18
|
+
"current_grade": null,
|
|
19
|
+
"final_grade": "F"
|
|
20
|
+
},
|
|
21
|
+
"html_url": "http://localhost:3000/courses/9/users/7",
|
|
22
|
+
"user": {
|
|
23
|
+
"id": 7,
|
|
24
|
+
"name": "User 1",
|
|
25
|
+
"sortable_name": "1, User",
|
|
26
|
+
"short_name": "User 1",
|
|
27
|
+
"sis_user_id": "user1",
|
|
28
|
+
"sis_login_id": "user1",
|
|
29
|
+
"login_id": "user1"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"associated_user_id": null,
|
|
34
|
+
"course_id": 9,
|
|
35
|
+
"course_section_id": 11,
|
|
36
|
+
"id": 29,
|
|
37
|
+
"limit_privileges_to_course_section": false,
|
|
38
|
+
"root_account_id": 1,
|
|
39
|
+
"type": "StudentEnrollment",
|
|
40
|
+
"updated_at": "2013-11-04T21:51:23Z",
|
|
41
|
+
"user_id": 8,
|
|
42
|
+
"enrollment_state": "active",
|
|
43
|
+
"role": "StudentEnrollment",
|
|
44
|
+
"grades": {
|
|
45
|
+
"html_url": "http://localhost:3000/courses/9/grades/8",
|
|
46
|
+
"current_score": null,
|
|
47
|
+
"final_score": 0.0,
|
|
48
|
+
"current_grade": null,
|
|
49
|
+
"final_grade": "F"
|
|
50
|
+
},
|
|
51
|
+
"html_url": "http://localhost:3000/courses/9/users/8",
|
|
52
|
+
"user": {
|
|
53
|
+
"id": 8,
|
|
54
|
+
"name": "User 2",
|
|
55
|
+
"sortable_name": "2, User",
|
|
56
|
+
"short_name": "User 2",
|
|
57
|
+
"sis_user_id": "user2",
|
|
58
|
+
"sis_login_id": "user2",
|
|
59
|
+
"login_id": "user2"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"associated_user_id": null,
|
|
64
|
+
"course_id": 9,
|
|
65
|
+
"course_section_id": 11,
|
|
66
|
+
"id": 28,
|
|
67
|
+
"limit_privileges_to_course_section": false,
|
|
68
|
+
"root_account_id": 1,
|
|
69
|
+
"type": "StudentEnrollment",
|
|
70
|
+
"updated_at": "2013-09-24T18:22:21Z",
|
|
71
|
+
"user_id": 9,
|
|
72
|
+
"enrollment_state": "invited",
|
|
73
|
+
"role": "StudentEnrollment",
|
|
74
|
+
"grades": {
|
|
75
|
+
"html_url": "http://localhost:3000/courses/9/grades/9",
|
|
76
|
+
"current_score": null,
|
|
77
|
+
"final_score": 0.0,
|
|
78
|
+
"current_grade": null,
|
|
79
|
+
"final_grade": "F"
|
|
80
|
+
},
|
|
81
|
+
"html_url": "http://localhost:3000/courses/9/users/9",
|
|
82
|
+
"user": {
|
|
83
|
+
"id": 9,
|
|
84
|
+
"name": "User 3",
|
|
85
|
+
"sortable_name": "3, User",
|
|
86
|
+
"short_name": "User 3",
|
|
87
|
+
"sis_user_id": "user3",
|
|
88
|
+
"sis_login_id": "user3",
|
|
89
|
+
"login_id": "user3"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"associated_user_id": null,
|
|
94
|
+
"course_id": 9,
|
|
95
|
+
"course_section_id": 11,
|
|
96
|
+
"id": 26,
|
|
97
|
+
"limit_privileges_to_course_section": false,
|
|
98
|
+
"root_account_id": 1,
|
|
99
|
+
"type": "StudentEnrollment",
|
|
100
|
+
"updated_at": "2013-09-24T18:22:21Z",
|
|
101
|
+
"user_id": 10,
|
|
102
|
+
"enrollment_state": "invited",
|
|
103
|
+
"role": "StudentEnrollment",
|
|
104
|
+
"grades": {
|
|
105
|
+
"html_url": "http://localhost:3000/courses/9/grades/10",
|
|
106
|
+
"current_score": null,
|
|
107
|
+
"final_score": 0.0,
|
|
108
|
+
"current_grade": null,
|
|
109
|
+
"final_grade": "F"
|
|
110
|
+
},
|
|
111
|
+
"html_url": "http://localhost:3000/courses/9/users/10",
|
|
112
|
+
"user": {
|
|
113
|
+
"id": 10,
|
|
114
|
+
"name": "User 4",
|
|
115
|
+
"sortable_name": "4, User",
|
|
116
|
+
"short_name": "User 4",
|
|
117
|
+
"sis_user_id": "user4",
|
|
118
|
+
"sis_login_id": "user4",
|
|
119
|
+
"login_id": "user4"
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"associated_user_id": null,
|
|
124
|
+
"course_id": 9,
|
|
125
|
+
"course_section_id": 11,
|
|
126
|
+
"id": 30,
|
|
127
|
+
"limit_privileges_to_course_section": true,
|
|
128
|
+
"root_account_id": 1,
|
|
129
|
+
"type": "TeacherEnrollment",
|
|
130
|
+
"updated_at": "2013-09-10T22:45:03Z",
|
|
131
|
+
"user_id": 11,
|
|
132
|
+
"enrollment_state": "invited",
|
|
133
|
+
"role": "TeacherEnrollment",
|
|
134
|
+
"html_url": "http://localhost:3000/courses/9/users/11",
|
|
135
|
+
"user": {
|
|
136
|
+
"id": 11,
|
|
137
|
+
"name": "User 5",
|
|
138
|
+
"sortable_name": "5, User",
|
|
139
|
+
"short_name": "User 5",
|
|
140
|
+
"sis_user_id": "user5",
|
|
141
|
+
"sis_login_id": "user5",
|
|
142
|
+
"login_id": "user5"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"associated_user_id": null,
|
|
4
|
+
"course_id": 2,
|
|
5
|
+
"course_section_id": 2,
|
|
6
|
+
"id": 6,
|
|
7
|
+
"limit_privileges_to_course_section": false,
|
|
8
|
+
"root_account_id": 1,
|
|
9
|
+
"type": "StudentEnrollment",
|
|
10
|
+
"updated_at": "2013-11-05T20:05:12Z",
|
|
11
|
+
"user_id": 8,
|
|
12
|
+
"enrollment_state": "active",
|
|
13
|
+
"role": "StudentEnrollment",
|
|
14
|
+
"grades": {
|
|
15
|
+
"html_url": "http://localhost:3000/courses/2/grades/8",
|
|
16
|
+
"current_score": null,
|
|
17
|
+
"final_score": 0.0,
|
|
18
|
+
"current_grade": null,
|
|
19
|
+
"final_grade": null
|
|
20
|
+
},
|
|
21
|
+
"html_url": "http://localhost:3000/courses/2/users/8",
|
|
22
|
+
"user": {
|
|
23
|
+
"id": 8,
|
|
24
|
+
"name": "User 2",
|
|
25
|
+
"sortable_name": "2, User",
|
|
26
|
+
"short_name": "User 2",
|
|
27
|
+
"sis_user_id": "user2",
|
|
28
|
+
"sis_login_id": "user2",
|
|
29
|
+
"login_id": "user2"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"associated_user_id": null,
|
|
34
|
+
"course_id": 2,
|
|
35
|
+
"course_section_id": 2,
|
|
36
|
+
"id": 5,
|
|
37
|
+
"limit_privileges_to_course_section": false,
|
|
38
|
+
"root_account_id": 1,
|
|
39
|
+
"type": "TeacherEnrollment",
|
|
40
|
+
"updated_at": "2013-11-05T20:05:12Z",
|
|
41
|
+
"user_id": 7,
|
|
42
|
+
"enrollment_state": "active",
|
|
43
|
+
"role": "TeacherEnrollment",
|
|
44
|
+
"html_url": "http://localhost:3000/courses/2/users/7",
|
|
45
|
+
"user": {
|
|
46
|
+
"id": 7,
|
|
47
|
+
"name": "User 1",
|
|
48
|
+
"sortable_name": "1, User",
|
|
49
|
+
"short_name": "User 1",
|
|
50
|
+
"sis_user_id": "user1",
|
|
51
|
+
"sis_login_id": "user1",
|
|
52
|
+
"login_id": "user1"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
]
|
data/spec/helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bearcat
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: '0.3'
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-
|
|
12
|
+
date: 2013-11-13 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rake
|
|
@@ -98,7 +98,7 @@ dependencies:
|
|
|
98
98
|
requirements:
|
|
99
99
|
- - ! '>='
|
|
100
100
|
- !ruby/object:Gem::Version
|
|
101
|
-
version: 0.
|
|
101
|
+
version: 0.2.2
|
|
102
102
|
type: :runtime
|
|
103
103
|
prerelease: false
|
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -106,7 +106,7 @@ dependencies:
|
|
|
106
106
|
requirements:
|
|
107
107
|
- - ! '>='
|
|
108
108
|
- !ruby/object:Gem::Version
|
|
109
|
-
version: 0.
|
|
109
|
+
version: 0.2.2
|
|
110
110
|
description: Ruby interface for interacting with the canvas API
|
|
111
111
|
email:
|
|
112
112
|
- nathanm@instructure.com
|
|
@@ -120,6 +120,7 @@ files:
|
|
|
120
120
|
- lib/bearcat/client/assignments.rb
|
|
121
121
|
- lib/bearcat/client/courses.rb
|
|
122
122
|
- lib/bearcat/client/enrollments.rb
|
|
123
|
+
- lib/bearcat/client/o_auth2.rb
|
|
123
124
|
- lib/bearcat/client/outcome_groups.rb
|
|
124
125
|
- lib/bearcat/client/outcomes.rb
|
|
125
126
|
- lib/bearcat/client/sections.rb
|
|
@@ -129,6 +130,7 @@ files:
|
|
|
129
130
|
- spec/bearcat/client/assignments_spec.rb
|
|
130
131
|
- spec/bearcat/client/courses_spec.rb
|
|
131
132
|
- spec/bearcat/client/enrollments_spec.rb
|
|
133
|
+
- spec/bearcat/client/o_auth2_spec.rb
|
|
132
134
|
- spec/bearcat/client/outcome_groups_spec.rb
|
|
133
135
|
- spec/bearcat/client/outcomes_spec.rb
|
|
134
136
|
- spec/bearcat/client/sections_spec.rb
|
|
@@ -138,6 +140,7 @@ files:
|
|
|
138
140
|
- spec/fixtures/assignments.json
|
|
139
141
|
- spec/fixtures/conclude_enrollment.json
|
|
140
142
|
- spec/fixtures/course.json
|
|
143
|
+
- spec/fixtures/course_enrollments.json
|
|
141
144
|
- spec/fixtures/course_sections.json
|
|
142
145
|
- spec/fixtures/course_students.json
|
|
143
146
|
- spec/fixtures/create_outcome_in_group.json
|
|
@@ -154,6 +157,7 @@ files:
|
|
|
154
157
|
- spec/fixtures/outcomes.json
|
|
155
158
|
- spec/fixtures/paged_body.json
|
|
156
159
|
- spec/fixtures/section.json
|
|
160
|
+
- spec/fixtures/section_enrollments.json
|
|
157
161
|
- spec/fixtures/update_outcome.json
|
|
158
162
|
- spec/fixtures/update_outcome_group.json
|
|
159
163
|
- spec/fixtures/update_section.json
|
|
@@ -187,6 +191,7 @@ test_files:
|
|
|
187
191
|
- spec/bearcat/client/assignments_spec.rb
|
|
188
192
|
- spec/bearcat/client/courses_spec.rb
|
|
189
193
|
- spec/bearcat/client/enrollments_spec.rb
|
|
194
|
+
- spec/bearcat/client/o_auth2_spec.rb
|
|
190
195
|
- spec/bearcat/client/outcome_groups_spec.rb
|
|
191
196
|
- spec/bearcat/client/outcomes_spec.rb
|
|
192
197
|
- spec/bearcat/client/sections_spec.rb
|
|
@@ -196,6 +201,7 @@ test_files:
|
|
|
196
201
|
- spec/fixtures/assignments.json
|
|
197
202
|
- spec/fixtures/conclude_enrollment.json
|
|
198
203
|
- spec/fixtures/course.json
|
|
204
|
+
- spec/fixtures/course_enrollments.json
|
|
199
205
|
- spec/fixtures/course_sections.json
|
|
200
206
|
- spec/fixtures/course_students.json
|
|
201
207
|
- spec/fixtures/create_outcome_in_group.json
|
|
@@ -212,6 +218,7 @@ test_files:
|
|
|
212
218
|
- spec/fixtures/outcomes.json
|
|
213
219
|
- spec/fixtures/paged_body.json
|
|
214
220
|
- spec/fixtures/section.json
|
|
221
|
+
- spec/fixtures/section_enrollments.json
|
|
215
222
|
- spec/fixtures/update_outcome.json
|
|
216
223
|
- spec/fixtures/update_outcome_group.json
|
|
217
224
|
- spec/fixtures/update_section.json
|