kurki 0.1.0 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ead63983b995b93ce4704249d06579fe9fe03df3
4
- data.tar.gz: 63c6cae4d423d7fe15a1887b1f1ee1c28f031739
3
+ metadata.gz: abd040581cb690dfd3754b687b345ac81834ff6d
4
+ data.tar.gz: bd94ac99b08ef5afa54d238e00d2db1fe81256dd
5
5
  SHA512:
6
- metadata.gz: 0670108ce07b761db746ecd550bc383b58acc90e4c6985925fc68e00823250bcf61c674be9e754cf624bc4cfefcc66983104721eca89824ef9b61a769f3d49b0
7
- data.tar.gz: f3598f0e3b4c3a8d944c865e28163cc7fdaa0df1a80e37c6c8d09dfdbf444a3a73e66c58820ec720e482ee60d2410ec732119c105194cc8f3742568dbfb1993a
6
+ metadata.gz: b9925794efd6aedb7849cb04424c549ff50580069c8375a279b3c4e0ec2a5a9cd50ed450f83408415df3b9bc08a6426a7587688374db7f6975658fc64f422f07
7
+ data.tar.gz: 2f803a2196a3f3d0d2ee7c75af84123872e2dfc400a2e91105793246e4212171dc0c2230fdbcc5458ffe6f9c7185eef21b8cc377c495c3851e3cb766eb13adfa
data/.gitignore CHANGED
@@ -13,3 +13,4 @@
13
13
  *.a
14
14
  mkmf.log
15
15
  *.gem
16
+ .idea/
data/.travis.yml CHANGED
@@ -2,4 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - "2.2.0"
4
4
  # uncomment this line if your project needs to run something other than `rake`:
5
- script: bundle exec rspec spec
5
+ script:
6
+ - bundle exec rspec spec
7
+ - bundle exec codeclimate-test-reporter
8
+
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
@@ -1,3 +1,3 @@
1
1
  module Kurki
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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
- @@url
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(@@url + "courses/#{course_id}/students", parse_students(student_ids))
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(@@url + "courses/#{course_id}/students", parse_grades(grades))
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
@@ -0,0 +1,5 @@
1
+ Student,grade
2
+ 123123123,3
3
+ 014475359,5
4
+ 014291915,1
5
+ 123456789,0
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
- with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}).
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
- with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}).
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
- with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}).
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
- with(:body => "{\"students\":[{\"id\":\"012345678\"},{\"id\":\"01293492\"}]}",
24
- :headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'51', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}).
25
- to_return(:status => 200, :body => "{\"success\":[{\"id\":\"012345678\"},{\"id\":\"01293492\"}],\"error\":[]}", :headers => {})
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
- with(:body => "{\"students\":[{\"id\":\"012345678\",\"arvosana\":\"4\"}]}",
29
- :headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'48', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}).
30
- to_return(:status => 200, :body => "{\"success\":[{\"id\":\"012345678\",\"arvosana\":\"4\"}],\"error\":[]}", :headers => {})
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
- Kurki.url = "test"
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
- JSON.parse("{\"success\":[{\"id\":\"012345678\"},{\"id\":\"01293492\"}],\"error\":[]}"))
89
+ JSON.parse("{\"success\":[{\"id\":\"012345678\"},{\"id\":\"01293492\"}],\"error\":[]}"))
90
90
  end
91
91
 
92
- it "can POST grades to a course" do
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
- JSON.parse("{\"success\":[{\"id\":\"012345678\",\"arvosana\":\"4\"}],\"error\":[]}"))
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
- CodeClimate::TestReporter.start
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.1.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-08 00:00:00.000000000 Z
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.4.5
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