webuntis 0.0.1
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/.gitignore +22 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +7 -0
- data/lib/webuntis.rb +86 -0
- data/lib/webuntis/version.rb +7 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/webuntis_spec.rb +7 -0
- data/webuntis.gemspec +25 -0
- metadata +124 -0
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 nilsding
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Webuntis
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'webuntis'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install webuntis
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/nilsding/webuntis/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/webuntis.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require "webuntis/version"
|
2
|
+
require "httparty"
|
3
|
+
require "securerandom"
|
4
|
+
require "pp"
|
5
|
+
|
6
|
+
class WebUntis
|
7
|
+
include HTTParty # http://www.youtube.com/watch?v=6Zbi0XmGtMw
|
8
|
+
format :json
|
9
|
+
base_uri "demo.webuntis.com"
|
10
|
+
|
11
|
+
attr_accessor :school
|
12
|
+
attr_accessor :user
|
13
|
+
attr_accessor :password
|
14
|
+
|
15
|
+
attr_reader :session_id
|
16
|
+
attr_reader :person_type
|
17
|
+
attr_reader :person_id
|
18
|
+
attr_reader :class_id
|
19
|
+
|
20
|
+
# @param school [String] The school name (e.g. htl-stp)
|
21
|
+
# @param user [String] The user name
|
22
|
+
# @param password [String] The user's password
|
23
|
+
# @param server [String] The server to use, without +/WebUntis+ (e.g.
|
24
|
+
# demo.webuntis.com).
|
25
|
+
def initialize(school, user, password, server="demo.webuntis.com")
|
26
|
+
@school = school
|
27
|
+
@user = user
|
28
|
+
@password = password
|
29
|
+
self.class.base_uri server
|
30
|
+
end
|
31
|
+
|
32
|
+
# Authenticates the given user and starts a session.
|
33
|
+
def authenticate()
|
34
|
+
options = make_options("authenticate", {user: @user, password: @password, client: CLIENT_NAME})
|
35
|
+
response = self.class.post("/WebUntis/jsonrpc.do?school=#{@school}", options)
|
36
|
+
raise response["error"]["message"] unless response["error"].nil?
|
37
|
+
@session_id = response["result"]["sessionId"]
|
38
|
+
@class_id = response["result"]["klasseId"]
|
39
|
+
@person_type = response["result"]["personType"]
|
40
|
+
@person_id = response["result"]["personId"]
|
41
|
+
end
|
42
|
+
alias authorize authenticate
|
43
|
+
alias login authenticate
|
44
|
+
|
45
|
+
# Ends the session. Requires Authentication.
|
46
|
+
def logout()
|
47
|
+
require_authentication!
|
48
|
+
options = make_options("logout")
|
49
|
+
response = self.class.post("/WebUntis/jsonrpc.do;jsessionid=#{@session_id}?school=#{@school}", options)
|
50
|
+
raise response["error"]["message"] unless response["error"].nil?
|
51
|
+
@session_id = nil
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def require_authentication!
|
56
|
+
raise "Please authenticate first!" if @session_id.nil?
|
57
|
+
end
|
58
|
+
|
59
|
+
# contains options given to HTTParty, including params for webuntis calls
|
60
|
+
# @param method [String] the method that gets called
|
61
|
+
# @param params [Hash] additional params for the method
|
62
|
+
# @return [Hash]
|
63
|
+
def make_options(method, params={})
|
64
|
+
options = base_options
|
65
|
+
options[:body][:params].merge! params
|
66
|
+
options[:body].merge!({ method: method })
|
67
|
+
options[:body] = options[:body].to_json
|
68
|
+
options
|
69
|
+
end
|
70
|
+
|
71
|
+
# @return [Hash] the base options used for all HTTP POST requests
|
72
|
+
def base_options
|
73
|
+
{
|
74
|
+
body: {
|
75
|
+
id: SecureRandom.hex,
|
76
|
+
params: {},
|
77
|
+
jsonrpc: "2.0"
|
78
|
+
},
|
79
|
+
options: {
|
80
|
+
headers: {
|
81
|
+
"Content-Type" => "application/json",
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
end
|
86
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/webuntis.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'webuntis/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "webuntis"
|
8
|
+
spec.version = WebUntis::VERSION
|
9
|
+
spec.authors = ["nilsding"]
|
10
|
+
spec.email = ["nilsding@nilsding.org"]
|
11
|
+
spec.summary = %q{Makes calls to the WebUntis API.}
|
12
|
+
spec.description = %q{This gem makes calls to the WebUntis JSON-RPC API.}
|
13
|
+
spec.homepage = "https://github.com/nilsding/webuntis"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_runtime_dependency "httparty", "~> 0.13"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webuntis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- nilsding
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-10-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.6'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.6'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: httparty
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.13'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.13'
|
78
|
+
description: This gem makes calls to the WebUntis JSON-RPC API.
|
79
|
+
email:
|
80
|
+
- nilsding@nilsding.org
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- .rspec
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- lib/webuntis.rb
|
92
|
+
- lib/webuntis/version.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
- spec/webuntis_spec.rb
|
95
|
+
- webuntis.gemspec
|
96
|
+
homepage: https://github.com/nilsding/webuntis
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 1.8.23
|
118
|
+
signing_key:
|
119
|
+
specification_version: 3
|
120
|
+
summary: Makes calls to the WebUntis API.
|
121
|
+
test_files:
|
122
|
+
- spec/spec_helper.rb
|
123
|
+
- spec/webuntis_spec.rb
|
124
|
+
has_rdoc:
|