bearcat 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/Rakefile +8 -0
  2. data/bearcat.gemspec +27 -0
  3. data/lib/bearcat.rb +2 -0
  4. data/lib/bearcat/api_array.rb +118 -0
  5. data/lib/bearcat/client.rb +20 -0
  6. data/lib/bearcat/client/assignments.rb +18 -0
  7. data/lib/bearcat/client/courses.rb +19 -0
  8. data/lib/bearcat/client/enrollments.rb +19 -0
  9. data/lib/bearcat/client/outcome_groups.rb +81 -0
  10. data/lib/bearcat/client/outcomes.rb +15 -0
  11. data/lib/bearcat/client/sections.rb +27 -0
  12. data/lib/bearcat/version.rb +3 -0
  13. data/spec/bearcat/client/assignments_spec.rb +39 -0
  14. data/spec/bearcat/client/courses_spec.rb +31 -0
  15. data/spec/bearcat/client/enrollments_spec.rb +42 -0
  16. data/spec/bearcat/client/outcome_groups_spec.rb +104 -0
  17. data/spec/bearcat/client/outcomes_spec.rb +27 -0
  18. data/spec/bearcat/client/sections_spec.rb +51 -0
  19. data/spec/bearcat/client_spec.rb +16 -0
  20. data/spec/bearcat_spec.rb +8 -0
  21. data/spec/fixtures/assignment_section_override.json +9 -0
  22. data/spec/fixtures/assignments.json +86 -0
  23. data/spec/fixtures/conclude_enrollment.json +20 -0
  24. data/spec/fixtures/course.json +46 -0
  25. data/spec/fixtures/course_sections.json +20 -0
  26. data/spec/fixtures/course_students.json +6 -0
  27. data/spec/fixtures/create_outcome_in_group.json +23 -0
  28. data/spec/fixtures/create_section.json +1 -0
  29. data/spec/fixtures/created_assignment.json +25 -0
  30. data/spec/fixtures/created_course.json +27 -0
  31. data/spec/fixtures/delete_section.json +1 -0
  32. data/spec/fixtures/enroll_student.json +20 -0
  33. data/spec/fixtures/link_unlink_outcome.json +23 -0
  34. data/spec/fixtures/outcome_group_import.json +22 -0
  35. data/spec/fixtures/outcome_groups.json +29 -0
  36. data/spec/fixtures/outcome_subgroup.json +22 -0
  37. data/spec/fixtures/outcome_subgroups.json +20 -0
  38. data/spec/fixtures/outcomes.json +33 -0
  39. data/spec/fixtures/paged_body.json +92 -0
  40. data/spec/fixtures/section.json +1 -0
  41. data/spec/fixtures/update_outcome.json +1 -0
  42. data/spec/fixtures/update_outcome_group.json +22 -0
  43. data/spec/fixtures/update_section.json +1 -0
  44. data/spec/fixtures/user_enrollments.json +23 -0
  45. data/spec/helper.rb +43 -0
  46. metadata +220 -0
@@ -0,0 +1,42 @@
1
+ require 'helper'
2
+
3
+ describe Bearcat::Client::Enrollments do
4
+ before do
5
+ @client = Bearcat::Client.new(prefix:"http://canvas.instructure.com", token: "test_token")
6
+ end
7
+
8
+ it "returns all enrollments for a user" do
9
+ stub_get(@client, "/api/v1/users/1/enrollments").to_return(json_response("user_enrollments.json"))
10
+ enrollments = @client.user_enrollments(1)
11
+ expect(enrollments.first['course_id']).to eq(3)
12
+ expect(enrollments.first['course_section_id']).to eq(70)
13
+ expect(enrollments.first['id']).to eq(2)
14
+ expect(enrollments.first['user']['id']).to eq(1)
15
+ expect(enrollments.first['user']['name']).to eq('test@instructure.com')
16
+ end
17
+
18
+ it "enrolls a student in a section" do
19
+ stub_post(@client, "/api/v1/sections/70/enrollments")
20
+ .with(:body => {"enrollment"=>{"user_id"=>"1", "type"=>"StudentEnrollment"}})
21
+ .to_return(json_response("enroll_student.json"))
22
+
23
+ enrollment = @client.enroll_in_section(70, {"enrollment[user_id]" => 1, "enrollment[type]" => "StudentEnrollment"})
24
+ expect(enrollment["course_id"]).to eq(3)
25
+ expect(enrollment["course_section_id"]).to eq(70)
26
+ expect(enrollment["id"]).to eq(1386)
27
+ expect(enrollment["role"]).to eq("StudentEnrollment")
28
+ expect(enrollment["enrollment_state"]).to eq("invited")
29
+ end
30
+
31
+ it "concludes a students enrollment" do
32
+ stub_request(:delete, "http://canvas.instructure.com/api/v1/courses/3/enrollments/1386?task=conclude").to_return(json_response("conclude_enrollment.json"))
33
+ enrollment = @client.conclude_enrollment(3, 1386, {"task" => "conclude"})
34
+ expect(enrollment["course_id"]).to eq(3)
35
+ expect(enrollment["course_section_id"]).to eq(70)
36
+ expect(enrollment["id"]).to eq(1386)
37
+ expect(enrollment["role"]).to eq("StudentEnrollment")
38
+ expect(enrollment["enrollment_state"]).to eq("completed")
39
+ end
40
+
41
+
42
+ end
@@ -0,0 +1,104 @@
1
+ require 'helper'
2
+
3
+ describe Bearcat::Client::OutcomeGroups do
4
+ PARAMS = {'course' => 1}
5
+
6
+ before do
7
+ @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com/api/v1/", token: "test_token")
8
+ end
9
+
10
+ describe "outcomes api slugs" do
11
+ it "returns the account api slug" do
12
+ expect(@client.outcomes_context_slug({'account' => 3})).to eq("#{@client.config.prefix}accounts/3/outcome_groups/")
13
+ end
14
+
15
+ it "returns the course api slug" do
16
+ expect(@client.outcomes_context_slug(PARAMS)).to eq("#{@client.config.prefix}courses/1/outcome_groups/")
17
+ end
18
+
19
+ it "returns the global api slug" do
20
+ expect(@client.outcomes_context_slug({})).to eq("#{@client.config.prefix}global/outcome_groups/")
21
+ end
22
+
23
+ it "raises an error if both account and course are in params" do
24
+ expect { @client.outcomes_context_slug({'account' => 3, 'course' => 5}) }.to raise_error(ArgumentError)
25
+ end
26
+ end
27
+
28
+ it "returns an outcome group" do
29
+ stub_get(@client, "#{@client.outcomes_context_slug(PARAMS)}5").to_return(json_response("outcome_groups.json"))
30
+ outcome = @client.show_outcome_group(5, PARAMS)
31
+ expect(outcome['id']).to eq(5)
32
+ expect(outcome['title']).to eq('Outcome group title')
33
+ expect(outcome['description']).to eq('Outcome group description')
34
+ end
35
+
36
+ it "updates an outcome group" do
37
+ updated_outcome_title = 'updated outcome group title'
38
+ 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
+ updated_outcome = @client.update_outcome_group(2, {"course" => "1", "title" => updated_outcome_title})
40
+ expect(updated_outcome['id']).to eq(2)
41
+ expect(updated_outcome['title']).to eq(updated_outcome_title)
42
+ end
43
+
44
+ it "deletes an outcome group" do
45
+ stub_delete(@client, "#{@client.outcomes_context_slug(PARAMS)}2").to_return(json_response("outcome_groups.json"))
46
+ deleted_outcome = @client.delete_outcome_group(2, PARAMS)
47
+ expect(deleted_outcome).to_not eq("error")
48
+ end
49
+
50
+ it "returns linked outcomes" do
51
+ stub_get(@client, "#{@client.outcomes_context_slug(PARAMS)}2/outcomes").to_return(json_response("link_unlink_outcome.json"))
52
+ linked_outcomes = @client.list_linked_outcomes(2, PARAMS)
53
+ expect(linked_outcomes['outcome_group']['title']).to eq('sup')
54
+ expect(linked_outcomes['outcome']['context_type']).to eq('Course')
55
+ end
56
+
57
+ it "creates outcome in outcome group" do
58
+ title = 'this is a new title 3'
59
+ description = 'this is a new description 3'
60
+ 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
+ created_outcome = @client.create_outcome_in_group(2, {"course" => "1", "title" => title, "description" => description})
62
+ expect(created_outcome['outcome']['title']).to eq(title)
63
+ expect(created_outcome['outcome']['id']).to eq(18)
64
+ expect(created_outcome['url']).to eq('/api/v1/courses/1/outcome_groups/2/outcomes/18')
65
+ end
66
+
67
+ it "links outcome in outcome group" do
68
+ stub_put(@client, "#{@client.outcomes_context_slug(PARAMS)}2/outcomes/14").to_return(json_response('link_unlink_outcome.json'))
69
+ linked_outcome = @client.link_outcome(2, 14, PARAMS)
70
+ expect(linked_outcome['outcome']['title']).to eq('New Outcome sup')
71
+ expect(linked_outcome['url']).to eq('/api/v1/courses/1/outcome_groups/2/outcomes/14')
72
+ end
73
+
74
+ it "unlinks an outcome" do
75
+ stub_delete(@client, "#{@client.outcomes_context_slug(PARAMS)}2/outcomes/14").to_return(json_response('link_unlink_outcome.json'))
76
+ unlinked_outcome = @client.unlink_outcome(2, 14, PARAMS)
77
+ expect(unlinked_outcome).to_not eq("error")
78
+ end
79
+
80
+ it "returns subgroups" do
81
+ stub_get(@client, "#{@client.outcomes_context_slug(PARAMS)}2/subgroups").to_return(json_response("outcome_subgroups.json"))
82
+ outcome_subgroups = @client.list_subgroups(2, PARAMS)
83
+ expect(outcome_subgroups.count).to eq(2)
84
+ expect(outcome_subgroups.first['title']).to eq('hello this is a new group')
85
+ expect(outcome_subgroups.last['title']).to eq('this is the last group')
86
+ end
87
+
88
+ it "creates subgroups" do
89
+ title = "api created subgroup title"
90
+ description = "api created subgroup desc"
91
+ 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
+ outcome_subgroup = @client.create_subgroup(2, {"course" => "1", "description" => description, "title" => title})
93
+ expect(outcome_subgroup['title']).to eq(title)
94
+ expect(outcome_subgroup['description']).to eq(description)
95
+ end
96
+
97
+ it "imports outcome groups" do
98
+ 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
+ imported_outcome = @client.import_outcome_group(2, {"course" => "1", "source_outcome_group_id" => "14"})
100
+ expect(imported_outcome['title']).to eq('this is a new group')
101
+ expect(imported_outcome['parent_outcome_group']).to_not be_empty
102
+ end
103
+
104
+ end
@@ -0,0 +1,27 @@
1
+ require 'helper'
2
+
3
+ describe Bearcat::Client::Outcomes do
4
+ before do
5
+ @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token")
6
+ end
7
+
8
+ it "returns an outcome" do
9
+ stub_get(@client, "/api/v1/outcomes/1").to_return(json_response("outcomes.json"))
10
+ outcome = @client.show_outcome(1)
11
+ expect(outcome['title']).to eq('Test Outcome title')
12
+ expect(outcome['id']).to eq(1)
13
+ expect(outcome['description']).to eq('Test Outcome description')
14
+ expect(outcome['points_possible']).to eq(5)
15
+ expect(outcome['mastery_points']).to eq(3)
16
+ end
17
+
18
+ it "updates an outcome" do
19
+ title = 'updated outcome title'
20
+ description = 'updated outcome desc'
21
+ stub_put(@client, "/api/v1/outcomes/5").with(:body => {"title" => title, "description" => description}).to_return(json_response("update_outcome.json"))
22
+ outcome = @client.update_outcome(5, {"title" => title, "description" => description})
23
+ expect(outcome['title']).to eq(title)
24
+ expect(outcome['description']).to eq(description)
25
+ end
26
+
27
+ end
@@ -0,0 +1,51 @@
1
+ require 'helper'
2
+
3
+ describe Bearcat::Client::Sections do
4
+ before do
5
+ @client = Bearcat::Client.new(prefix:"http://canvas.instructure.com", token: "test_token")
6
+ end
7
+
8
+ it "returns all sections for a course" do
9
+ stub_get(@client, "/api/v1/courses/3/sections").to_return(json_response("course_sections.json"))
10
+ sections = @client.course_sections(3)
11
+ expect(sections.first['name']).to eq('test')
12
+ expect(sections.first['id']).to eq(70)
13
+ expect(sections.first['course_id']).to eq(3)
14
+ end
15
+
16
+ it "returns a section" do
17
+ stub_get(@client, "/api/v1/sections/72").to_return(json_response("section.json"))
18
+ section = @client.section(72)
19
+ expect(section['name']).to eq('Section003')
20
+ expect(section['id']).to eq(72)
21
+ expect(section['course_id']).to eq(3)
22
+ end
23
+
24
+ it "creates a section" do
25
+ stub_post(@client, "/api/v1/courses/3/sections").
26
+ with(:body => {"course_section"=>{"name"=>"Section003"}}).to_return(json_response("create_section.json"))
27
+ section = @client.create_section(3, {"course_section[name]" => "Section003"})
28
+ expect(section['course_id']).to eq(3)
29
+ expect(section['id']).to eq(72)
30
+ expect(section['name']).to eq('Section003')
31
+ end
32
+
33
+ it "updates a section" do
34
+ stub_put(@client, "/api/v1/sections/72").with(:body => {"course_section"=>{"name"=>"Section003"}}).to_return(json_response("update_section.json"))
35
+ section = @client.update_section(72, {"course_section[name]" => "Section003"})
36
+ expect(section['course_id']).to eq(3)
37
+ expect(section['id']).to eq(72)
38
+ expect(section['name']).to eq('Section003')
39
+ end
40
+
41
+ it "deletes a section" do
42
+ stub_delete(@client, "/api/v1/sections/72").to_return(json_response("update_section.json"))
43
+ section = @client.delete_section(72)
44
+ expect(section['course_id']).to eq(3)
45
+ expect(section['id']).to eq(72)
46
+ expect(section['name']).to eq('Section003')
47
+ end
48
+
49
+
50
+
51
+ end
@@ -0,0 +1,16 @@
1
+ require 'helper'
2
+
3
+ describe Bearcat::Client do
4
+
5
+ it "sets the domain" do
6
+ client = Bearcat::Client.new(domain: "http://canvas.instructure.com")
7
+ expect(client.config[:domain]).to eq("http://canvas.instructure.com")
8
+
9
+ end
10
+
11
+ it "sets the authtoken" do
12
+ client = Bearcat::Client.new(token: "test_token")
13
+ expect(client.config[:token]).to eq("test_token")
14
+ end
15
+
16
+ end
@@ -0,0 +1,8 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ describe Bearcat do
5
+
6
+
7
+
8
+ end
@@ -0,0 +1,9 @@
1
+ {
2
+ "all_day": false,
3
+ "all_day_date": "2013-06-27",
4
+ "assignment_id": 123,
5
+ "due_at": "2013-06-27T15:08:46-06:00",
6
+ "id": 1,
7
+ "title": "Section003",
8
+ "course_section_id": 74
9
+ }
@@ -0,0 +1,86 @@
1
+ [
2
+ {
3
+ "assignment_group_id": 53,
4
+ "automatic_peer_reviews": false,
5
+ "description": "",
6
+ "due_at": null,
7
+ "grade_group_students_individually": false,
8
+ "grading_standard_id": null,
9
+ "grading_type": "points",
10
+ "group_category_id": null,
11
+ "id": 123,
12
+ "lock_at": null,
13
+ "peer_reviews": false,
14
+ "points_possible": 0,
15
+ "position": 14,
16
+ "unlock_at": null,
17
+ "course_id": 3,
18
+ "name": "Start",
19
+ "submission_types": [
20
+ "external_tool"
21
+ ],
22
+ "turnitin_enabled": false,
23
+ "turnitin_settings": {
24
+ "originality_report_visibility": "immediate",
25
+ "s_paper_check": true,
26
+ "internet_check": true,
27
+ "journal_check": true,
28
+ "exclude_biblio": true,
29
+ "exclude_quoted": true,
30
+ "exclude_small_matches_type": null,
31
+ "exclude_small_matches_value": null
32
+ },
33
+ "muted": false,
34
+ "html_url": "http://localhost:3000/courses/310/assignments/123",
35
+ "external_tool_tag_attributes": {
36
+ "url": "http://localhost:3001/lti/start",
37
+ "new_tab": false,
38
+ "resource_link_id": "4a4c01e00e46d0068c68be240c532df2ff3a8f1a"
39
+ },
40
+ "url": "http://localhost:3000/api/v1/courses/310/external_tools/sessionless_launch?assignment_id=123&launch_type=assessment",
41
+ "needs_grading_count": 0,
42
+ "locked_for_user": false
43
+ },
44
+ {
45
+ "assignment_group_id": 53,
46
+ "automatic_peer_reviews": false,
47
+ "description": "",
48
+ "due_at": null,
49
+ "grade_group_students_individually": false,
50
+ "grading_standard_id": null,
51
+ "grading_type": "points",
52
+ "group_category_id": null,
53
+ "id": 124,
54
+ "lock_at": null,
55
+ "peer_reviews": false,
56
+ "points_possible": 0,
57
+ "position": 15,
58
+ "unlock_at": null,
59
+ "course_id": 3,
60
+ "name": "End",
61
+ "submission_types": [
62
+ "external_tool"
63
+ ],
64
+ "turnitin_enabled": false,
65
+ "turnitin_settings": {
66
+ "originality_report_visibility": "immediate",
67
+ "s_paper_check": true,
68
+ "internet_check": true,
69
+ "journal_check": true,
70
+ "exclude_biblio": true,
71
+ "exclude_quoted": true,
72
+ "exclude_small_matches_type": null,
73
+ "exclude_small_matches_value": null
74
+ },
75
+ "muted": false,
76
+ "html_url": "http://localhost:3000/courses/310/assignments/124",
77
+ "external_tool_tag_attributes": {
78
+ "url": "http://localhost:3001/lti/end",
79
+ "new_tab": false,
80
+ "resource_link_id": "e754637c2b191a4a19af29aa9f61141856b79c11"
81
+ },
82
+ "url": "http://localhost:3000/api/v1/courses/310/external_tools/sessionless_launch?assignment_id=124&launch_type=assessment",
83
+ "needs_grading_count": 0,
84
+ "locked_for_user": false
85
+ }
86
+ ]
@@ -0,0 +1,20 @@
1
+ {"associated_user_id": null,
2
+ "course_id": 3,
3
+ "course_section_id": 70,
4
+ "id": 1386,
5
+ "limit_privileges_to_course_section": false,
6
+ "root_account_id": 1,
7
+ "type": "StudentEnrollment",
8
+ "updated_at": "2013-06-27T10:05:15-06:00",
9
+ "user_id": 1,
10
+ "enrollment_state": "completed",
11
+ "role": "StudentEnrollment",
12
+ "grades": {
13
+ "html_url": "http://localhost:3000/courses/310/grades/1",
14
+ "current_score": null,
15
+ "final_score": null,
16
+ "current_grade": null,
17
+ "final_grade": null
18
+ },
19
+ "html_url": "http://localhost:3000/courses/310/users/1"
20
+ }
@@ -0,0 +1,46 @@
1
+ {
2
+ "id": 3,
3
+
4
+ "sis_course_id": null,
5
+
6
+ "name": "Course 3",
7
+
8
+ "course_code": "Course3",
9
+
10
+ "workflow_state": "available",
11
+
12
+ "account_id": 81259,
13
+
14
+ "start_at": "2012-06-01T00:00:00-06:00",
15
+
16
+ "end_at": null,
17
+
18
+ "enrollments": [
19
+ {
20
+ "type": "student",
21
+ "role": "StudentEnrollment",
22
+ "computed_final_score": 41.5,
23
+ "computed_current_score": 90,
24
+ "computed_final_grade": "F",
25
+ "computed_current_grade": "A-"
26
+ }
27
+ ],
28
+
29
+ "calendar": {
30
+ "ics": "https:\/\/canvas.instructure.com\/feeds\/calendars\/course_abcdef.ics"
31
+ },
32
+
33
+ "default_view": "feed",
34
+
35
+ "syllabus_body": "<p>syllabus html goes here<\/p>",
36
+
37
+ "needs_grading_count": "17",
38
+
39
+ "term": {
40
+ "id": 1,
41
+ "name": "Default Term",
42
+ "start_at": "2012-06-01T00:00:00-06:00",
43
+ "end_at": null
44
+ }
45
+
46
+ }
@@ -0,0 +1,20 @@
1
+ [
2
+ {
3
+ "course_id": 3,
4
+ "end_at": null,
5
+ "id": 70,
6
+ "name": "test",
7
+ "nonxlist_course_id": null,
8
+ "start_at": null,
9
+ "sis_section_id": null
10
+ },
11
+ {
12
+ "course_id": 3,
13
+ "end_at": null,
14
+ "id": 71,
15
+ "name": "section 001",
16
+ "nonxlist_course_id": null,
17
+ "start_at": null,
18
+ "sis_section_id": null
19
+ }
20
+ ]