kurki 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +4 -1
- data/README.md +9 -1
- data/kurki.gemspec +2 -1
- data/lib/kurki/version.rb +1 -1
- data/lib/kurki.rb +19 -9
- data/spec/fixtures/grades.csv +5 -0
- data/spec/kurki_spec.rb +32 -21
- data/spec/spec_helper.rb +3 -1
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abd040581cb690dfd3754b687b345ac81834ff6d
|
4
|
+
data.tar.gz: bd94ac99b08ef5afa54d238e00d2db1fe81256dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9925794efd6aedb7849cb04424c549ff50580069c8375a279b3c4e0ec2a5a9cd50ed450f83408415df3b9bc08a6426a7587688374db7f6975658fc64f422f07
|
7
|
+
data.tar.gz: 2f803a2196a3f3d0d2ee7c75af84123872e2dfc400a2e91105793246e4212171dc0c2230fdbcc5458ffe6f9c7185eef21b8cc377c495c3851e3cb766eb13adfa
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Kurki [![Build Status](https://travis-ci.org/Coolnesss/kurki.svg?branch=master)](https://travis-ci.org/Coolnesss/kurki) [![Code Climate](https://codeclimate.com/github/Coolnesss/kurki/badges/gpa.svg)](https://codeclimate.com/github/Coolnesss/kurki)
|
1
|
+
# Kurki [![Build Status](https://travis-ci.org/Coolnesss/kurki.svg?branch=master)](https://travis-ci.org/Coolnesss/kurki) [![Code Climate](https://codeclimate.com/github/Coolnesss/kurki/badges/gpa.svg)](https://codeclimate.com/github/Coolnesss/kurki) [![Test Coverage](https://codeclimate.com/github/Coolnesss/kurki/badges/coverage.svg)](https://codeclimate.com/github/Coolnesss/kurki/coverage)
|
2
2
|
|
3
3
|
Helsinki University Kurki system API Rubygem.
|
4
4
|
|
@@ -69,6 +69,14 @@ irb(main):006:0> Kurki.set_grades("58131.2011.K.K.1", {"013595141" => "5"})
|
|
69
69
|
=> {"success"=>[{"id"=>"013595141", "arvosana"=>"5"}], "error"=>[]}
|
70
70
|
```
|
71
71
|
|
72
|
+
```ruby
|
73
|
+
pry(main)> Kurki.set_grade_from_csv("582368.2016.K.K.1", "./spec/fixtures/grades.csv")
|
74
|
+
=> {"success"=>
|
75
|
+
[{"id"=>"014475359", "arvosana"=>"5"}, {"id"=>"014291915", "arvosana"=>"5"}],
|
76
|
+
"error"=>
|
77
|
+
[{"id"=>"123123123", "arvosana"=>"3"}, {"id"=>"123456789", "arvosana"=>"0"}]}
|
78
|
+
```
|
79
|
+
|
72
80
|
## Contributing
|
73
81
|
|
74
82
|
1. Fork it ( https://github.com/coolnesss/kurki/fork )
|
data/kurki.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'kurki/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "kurki"
|
8
8
|
spec.version = Kurki::VERSION
|
9
|
-
spec.authors = ["Chang Rajani"]
|
9
|
+
spec.authors = ["Chang Rajani", "Ville Tanskanen"]
|
10
10
|
spec.email = ["chra@cs.helsinki.fi"]
|
11
11
|
spec.summary = %q{Helsinki University Kurki system API}
|
12
12
|
spec.description = %q{Support for students and teachers}
|
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rspec"
|
24
24
|
spec.add_development_dependency "webmock"
|
25
25
|
spec.add_development_dependency "codeclimate-test-reporter"
|
26
|
+
spec.add_development_dependency "simplecov"
|
26
27
|
|
27
28
|
spec.add_runtime_dependency 'rest-client'
|
28
29
|
|
data/lib/kurki/version.rb
CHANGED
data/lib/kurki.rb
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
require "kurki/version"
|
2
2
|
require 'rest-client'
|
3
|
+
require 'json'
|
4
|
+
require 'csv'
|
3
5
|
|
4
6
|
module Kurki
|
5
|
-
@@url = "http://svm-23.cs.helsinki.fi:4567/"
|
6
|
-
|
7
|
-
def self.url=(url)
|
8
|
-
@@url = url
|
9
|
-
@@url += "/" if (url[-1, 1] != '/')
|
10
|
-
end
|
11
7
|
|
12
8
|
def self.url
|
13
|
-
|
9
|
+
return ENV["KURKI_URL"] if ENV["KURKI_URL"][-1] == "/"
|
10
|
+
ENV["KURKI_URL"]+"/"
|
14
11
|
end
|
15
12
|
|
16
13
|
def self.get_courses
|
@@ -28,16 +25,29 @@ module Kurki
|
|
28
25
|
|
29
26
|
# Student_ids in form ["12345678", "12345678"]
|
30
27
|
def self.set_students(course_id, student_ids)
|
31
|
-
post(
|
28
|
+
post(url + "courses/#{course_id}/students", parse_students(student_ids))
|
32
29
|
end
|
33
30
|
|
34
31
|
# Grades in form {"01234567": "3", "01243483": "4"}
|
35
32
|
def self.set_grades(course_id, grades)
|
36
|
-
post(
|
33
|
+
post(url + "courses/#{course_id}/students", parse_grades(grades))
|
34
|
+
end
|
35
|
+
|
36
|
+
# .csv in two columns, with one header row
|
37
|
+
def self.set_grade_from_csv(course_id, file_path, delimiter=",")
|
38
|
+
grades = {}
|
39
|
+
read_csv(file_path, delimiter).each do |result|
|
40
|
+
grades[result[0]] = result[1]
|
41
|
+
end
|
42
|
+
set_grades course_id, grades
|
37
43
|
end
|
38
44
|
|
39
45
|
private
|
40
46
|
|
47
|
+
def self.read_csv(file_path, delimiter)
|
48
|
+
CSV.read(file_path, col_sep: delimiter).drop(1)
|
49
|
+
end
|
50
|
+
|
41
51
|
def self.parse_students(student_ids)
|
42
52
|
parse(student_ids, lambda { |x| {"id": x} })
|
43
53
|
end
|
data/spec/kurki_spec.rb
CHANGED
@@ -4,42 +4,42 @@ describe Kurki do
|
|
4
4
|
|
5
5
|
before :each do
|
6
6
|
|
7
|
-
Kurki.url = "http://example.com"
|
8
|
-
ENV["KURKI_TOKEN"] = "fake"
|
9
|
-
|
10
7
|
stub_request(:get, /.*courses.*/).
|
11
|
-
|
8
|
+
with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'Content-Type'=>'application/json'}).
|
12
9
|
to_return(:status => 200, :body => IO.read("spec/fixtures/courses.json"), :headers => {})
|
13
10
|
|
14
11
|
stub_request(:get, /.*courses\/581259.2012.K.K.1/).
|
15
|
-
|
12
|
+
with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'Content-Type'=>'application/json'}).
|
16
13
|
to_return(:status => 200, :body => IO.read("spec/fixtures/course.json"), :headers => {})
|
17
14
|
|
18
15
|
stub_request(:get, /.*courses\/581259.2012.K.K.1\/students.*/).
|
19
|
-
|
16
|
+
with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'Content-Type'=>'application/json'}).
|
20
17
|
to_return(:status => 200, :body => IO.read("spec/fixtures/students.json"), :headers => {})
|
21
18
|
|
22
19
|
stub_request(:post, /.*581259.2012.K.K.1\/students.*/).
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
with(:body => "{\"students\":[{\"id\":\"012345678\"},{\"id\":\"01293492\"}]}",
|
21
|
+
:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'51', 'Content-Type'=>'application/json'}).
|
22
|
+
to_return(:status => 200, :body => "{\"success\":[{\"id\":\"012345678\"},{\"id\":\"01293492\"}],\"error\":[]}", :headers => {})
|
23
|
+
|
24
|
+
stub_request(:post, /.*581259.2012.K.K.1\/students.*/).
|
25
|
+
with(:body => "{\"students\":[{\"id\":\"012345678\",\"arvosana\":\"4\"}]}",
|
26
|
+
:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'48', 'Content-Type'=>'application/json'}).
|
27
|
+
to_return(:status => 200, :body => "{\"success\":[{\"id\":\"012345678\",\"arvosana\":\"4\"}],\"error\":[]}", :headers => {})
|
26
28
|
|
27
29
|
stub_request(:post, /.*581259.2012.K.K.1\/students.*/).
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
with(:body => "{\"students\":[{\"id\":\"123123123\",\"arvosana\":\"3\"},{\"id\":\"014475359\",\"arvosana\":\"5\"},{\"id\":\"014291915\",\"arvosana\":\"1\"},{\"id\":\"123456789\",\"arvosana\":\"0\"}]}",
|
31
|
+
:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'150', 'Content-Type'=>'application/json'}).
|
32
|
+
to_return(:status => 200, :body => "{\"success\":[{\"id\":\"123123123\",\"arvosana\":\"3\"},
|
33
|
+
{\"id\":\"014475359\",\"arvosana\":\"5\"},
|
34
|
+
{\"id\":\"014291915\",\"arvosana\":\"1\"},
|
35
|
+
{\"id\":\"123456789\",\"arvosana\":\"0\"}],\"error\":[]}", :headers => {})
|
31
36
|
|
32
37
|
end
|
33
38
|
|
34
39
|
describe "GET" do
|
35
40
|
|
36
|
-
it "allows setting of url" do
|
37
|
-
Kurki.url = "test/"
|
38
|
-
expect(Kurki.url).to eq("test/")
|
39
|
-
end
|
40
|
-
|
41
41
|
it "setting an url without a backslash adds it" do
|
42
|
-
|
42
|
+
ENV["KURKI_URL"] = "test"
|
43
43
|
expect(Kurki.url).to eq("test/")
|
44
44
|
end
|
45
45
|
|
@@ -86,14 +86,25 @@ describe Kurki do
|
|
86
86
|
students = ["012345678", "01293492"]
|
87
87
|
ans = Kurki.set_students("581259.2012.K.K.1", students)
|
88
88
|
expect(ans).to eq(
|
89
|
-
|
89
|
+
JSON.parse("{\"success\":[{\"id\":\"012345678\"},{\"id\":\"01293492\"}],\"error\":[]}"))
|
90
90
|
end
|
91
91
|
|
92
|
-
it "can POST grades
|
92
|
+
it "can POST grades from an array" do
|
93
93
|
grades = {"012345678" => "4"}
|
94
94
|
ans = Kurki.set_grades("581259.2012.K.K.1", grades)
|
95
95
|
expect(ans).to eq(
|
96
|
-
|
96
|
+
JSON.parse("{\"success\":[{\"id\":\"012345678\",\"arvosana\":\"4\"}],\"error\":[]}"))
|
97
|
+
end
|
98
|
+
|
99
|
+
it "can POST grades from a CSV file" do
|
100
|
+
ans = Kurki.set_grade_from_csv("581259.2012.K.K.1", "spec/fixtures/grades.csv")
|
101
|
+
expect(ans).to eq(
|
102
|
+
JSON.parse("{\"success\":[{\"id\":\"123123123\",\"arvosana\":\"3\"},
|
103
|
+
{\"id\":\"014475359\",\"arvosana\":\"5\"},
|
104
|
+
{\"id\":\"014291915\",\"arvosana\":\"1\"},
|
105
|
+
{\"id\":\"123456789\",\"arvosana\":\"0\"}],\"error\":[]}"
|
106
|
+
)
|
107
|
+
)
|
97
108
|
end
|
98
109
|
end
|
99
110
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
1
3
|
require 'bundler/setup'
|
2
4
|
require 'webmock/rspec'
|
3
5
|
require "codeclimate-test-reporter"
|
4
|
-
|
6
|
+
WebMock.disable_net_connect!(:allow => "codeclimate.com")
|
5
7
|
Bundler.setup
|
6
8
|
|
7
9
|
require 'kurki' # and any other gems you need
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kurki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chang Rajani
|
8
|
+
- Ville Tanskanen
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2016-04
|
12
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -80,6 +81,20 @@ dependencies:
|
|
80
81
|
- - ">="
|
81
82
|
- !ruby/object:Gem::Version
|
82
83
|
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: simplecov
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
83
98
|
- !ruby/object:Gem::Dependency
|
84
99
|
name: rest-client
|
85
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,6 +128,7 @@ files:
|
|
113
128
|
- lib/kurki/version.rb
|
114
129
|
- spec/fixtures/course.json
|
115
130
|
- spec/fixtures/courses.json
|
131
|
+
- spec/fixtures/grades.csv
|
116
132
|
- spec/fixtures/students.json
|
117
133
|
- spec/kurki_spec.rb
|
118
134
|
- spec/spec_helper.rb
|
@@ -136,13 +152,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
152
|
version: '0'
|
137
153
|
requirements: []
|
138
154
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.5.1
|
140
156
|
signing_key:
|
141
157
|
specification_version: 4
|
142
158
|
summary: Helsinki University Kurki system API
|
143
159
|
test_files:
|
144
160
|
- spec/fixtures/course.json
|
145
161
|
- spec/fixtures/courses.json
|
162
|
+
- spec/fixtures/grades.csv
|
146
163
|
- spec/fixtures/students.json
|
147
164
|
- spec/kurki_spec.rb
|
148
165
|
- spec/spec_helper.rb
|