kosapi_client 0.8.0 → 0.13.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 +5 -5
- data/kosapi_client.gemspec +1 -1
- data/lib/kosapi_client/api_client.rb +2 -1
- data/lib/kosapi_client/configuration.rb +1 -1
- data/lib/kosapi_client/entity.rb +1 -0
- data/lib/kosapi_client/entity/branch.rb +15 -0
- data/lib/kosapi_client/entity/coursin.rb +22 -1
- data/lib/kosapi_client/entity/data_mappings.rb +5 -2
- data/lib/kosapi_client/entity/teacher_timetable_slot.rb +3 -0
- data/lib/kosapi_client/entity/timetable_slot.rb +3 -0
- data/lib/kosapi_client/oauth2_http_adapter.rb +3 -1
- data/lib/kosapi_client/resource.rb +1 -0
- data/lib/kosapi_client/resource/branches_builder.rb +11 -0
- data/lib/kosapi_client/resource/courses_builder.rb +19 -2
- data/lib/kosapi_client/version.rb +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ebf21f664665d4883acd83607d526dfedcbfb5032673879e736e69c39e87fa8e
|
4
|
+
data.tar.gz: 6acaecd93f80e40fc4c9345fc0306edd1bb643b9f8de1d6c048c21dd7985e21d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d3160b80ba8ad6bbef7bfc1696fc2a25c561d058c8915489efd9ab81dc277556175caa79017436bcff8a2492bdac7e1cd7f93da29e061f75a80aff139efa707
|
7
|
+
data.tar.gz: 9e5df05b73018490a895132ef24f5d3c38bbd28401cb5b29a65ee87613f910abe968e64f47cfdbedb56b0823e7ce8fc78d5c4339f526168afe98381a7842268f
|
data/kosapi_client.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
|
17
17
|
spec.required_ruby_version = '>= 2.0.0'
|
18
18
|
|
19
|
-
spec.add_development_dependency 'bundler', '~>
|
19
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
20
20
|
spec.add_development_dependency 'rake'
|
21
21
|
spec.add_development_dependency 'rspec'
|
22
22
|
spec.add_development_dependency 'rspec-given'
|
@@ -6,6 +6,7 @@ module KOSapiClient
|
|
6
6
|
include ResourceMapper
|
7
7
|
|
8
8
|
# accessible resources definition
|
9
|
+
resource :branches
|
9
10
|
resource :courses
|
10
11
|
resource :course_events
|
11
12
|
resource :divisions
|
@@ -21,7 +22,7 @@ module KOSapiClient
|
|
21
22
|
# Creates a new KOSapi client.
|
22
23
|
#
|
23
24
|
def initialize(config = Configuration.new)
|
24
|
-
http_adapter = OAuth2HttpAdapter.new(config.credentials, config.base_url)
|
25
|
+
http_adapter = OAuth2HttpAdapter.new(config.credentials, config.base_url, config.to_h)
|
25
26
|
@http_client = HTTPClient.new(http_adapter)
|
26
27
|
end
|
27
28
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module KOSapiClient
|
2
|
-
class Configuration < Struct.new(:client_id, :client_secret, :base_url)
|
2
|
+
class Configuration < Struct.new(:client_id, :client_secret, :base_url, :token_url, :auth_url, :connection_opts)
|
3
3
|
|
4
4
|
DEFAULT_OPTIONS = {
|
5
5
|
base_url: 'https://kosapi.fit.cvut.cz/api/3'
|
data/lib/kosapi_client/entity.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
module KOSapiClient
|
2
|
+
module Entity
|
3
|
+
class Branch < BaseEntity
|
4
|
+
map_data :abbrev
|
5
|
+
map_data :capacity, Integer
|
6
|
+
map_data :code
|
7
|
+
map_data :description, MLString
|
8
|
+
map_data :diploma_name, MLString
|
9
|
+
map_data :division, Link
|
10
|
+
map_data :guarantor, Link
|
11
|
+
map_data :name, MLString
|
12
|
+
map_data :open_for_admission, Boolean
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,18 +1,39 @@
|
|
1
1
|
module KOSapiClient
|
2
2
|
module Entity
|
3
3
|
class Coursin < BaseEntity
|
4
|
-
# TODO: Add capacity
|
5
4
|
|
6
5
|
# XXX: This is really ugly hack! The problem is that "semester" is both
|
7
6
|
# element and attribute, and they are mapped into single Ruby attribute.
|
8
7
|
map_data :semester, Link, element: 1, path: :semester
|
9
8
|
map_data :capacity_overfill, Enum
|
10
9
|
map_data :occupied, Integer
|
10
|
+
map_data :editors, [Link], element: :teacher, path: :editors
|
11
11
|
map_data :examiners, [Link], element: :teacher, path: :examiners
|
12
12
|
map_data :guarantors, [Link], element: :teacher, path: :guarantors
|
13
13
|
map_data :instructors, [Link], element: :teacher, path: :instructors
|
14
14
|
map_data :lecturers, [Link], element: :teacher, path: :lecturers
|
15
15
|
|
16
|
+
map_data :instance_capacity, Integer, reader: ->(source_hash, _key) do
|
17
|
+
retrieve_capacity('instance', source_hash)
|
18
|
+
end
|
19
|
+
map_data :tutorial_capacity, Integer, reader: ->(source_hash, _key) do
|
20
|
+
retrieve_capacity('tutorial', source_hash)
|
21
|
+
end
|
22
|
+
|
23
|
+
alias_method :capacity, :instance_capacity
|
24
|
+
|
25
|
+
class << self
|
26
|
+
private
|
27
|
+
|
28
|
+
def retrieve_capacity(type, source_hash)
|
29
|
+
capacity = source_hash[:capacity]
|
30
|
+
return unless capacity
|
31
|
+
|
32
|
+
capacity = [capacity] unless capacity.is_a? Array
|
33
|
+
element = capacity.find { |el| el[:of] == type }
|
34
|
+
element[:__content__] if element
|
35
|
+
end
|
36
|
+
end
|
16
37
|
end
|
17
38
|
end
|
18
39
|
end
|
@@ -107,8 +107,11 @@ module KOSapiClient
|
|
107
107
|
end
|
108
108
|
|
109
109
|
def retrieve_value(source_hash, key, mapping_options)
|
110
|
-
|
111
|
-
|
110
|
+
if (reader = mapping_options[:reader])
|
111
|
+
return reader.call(source_hash, key)
|
112
|
+
end
|
113
|
+
|
114
|
+
if (path = mapping_options[:path])
|
112
115
|
parent_element = source_hash[path]
|
113
116
|
else
|
114
117
|
parent_element = source_hash
|
@@ -13,6 +13,7 @@ module KOSapiClient
|
|
13
13
|
@credentials = credentials
|
14
14
|
auth_url = opts[:auth_url] || DEFAULT_AUTH_URL
|
15
15
|
token_url = opts[:token_url] || DEFAULT_TOKEN_URL
|
16
|
+
connection_opts = opts[:connection_opts] || {}
|
16
17
|
MultiXml.parser = :ox # make sure to use Ox because of different namespace handling in other MultiXML parsers
|
17
18
|
@client = OAuth2::Client.new(
|
18
19
|
credentials[:client_id],
|
@@ -20,7 +21,8 @@ module KOSapiClient
|
|
20
21
|
auth_scheme: :basic_auth,
|
21
22
|
site: base_url,
|
22
23
|
authorize_url: auth_url,
|
23
|
-
token_url: token_url
|
24
|
+
token_url: token_url,
|
25
|
+
connection_opts: connection_opts)
|
24
26
|
end
|
25
27
|
|
26
28
|
def send_request(verb, url, options = {})
|
@@ -3,17 +3,34 @@ module KOSapiClient
|
|
3
3
|
class CoursesBuilder < RequestBuilder
|
4
4
|
|
5
5
|
def detail(level = 1)
|
6
|
-
|
6
|
+
url_builder.set_query_param(:detail, level)
|
7
7
|
self
|
8
8
|
end
|
9
9
|
|
10
10
|
# Selects courses scheduled in the specified semester(s).
|
11
11
|
def sem(*semesters)
|
12
|
-
|
12
|
+
url_builder.set_query_param(:sem, semesters.join(','))
|
13
13
|
self
|
14
14
|
end
|
15
15
|
|
16
16
|
alias semester sem
|
17
|
+
|
18
|
+
# XXX: This is quite insane, we need some support to DRY subresources.
|
19
|
+
%w[events exams parallels students instances branches].each do |resource|
|
20
|
+
define_method(resource) do |semester: 'current'|
|
21
|
+
raise "Call #find({course_code}) before asking for #{resource}" unless id_set?
|
22
|
+
url_builder.set_path(id, resource)
|
23
|
+
url_builder.set_query_param(:sem, semester)
|
24
|
+
self
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def parallel(code, semester: 'current')
|
29
|
+
raise 'Call #find({course_code}) before asking for parallel' unless id_set?
|
30
|
+
url_builder.set_path(id, 'parallels', code)
|
31
|
+
url_builder.set_query_param(:sem, semester)
|
32
|
+
self
|
33
|
+
end
|
17
34
|
end
|
18
35
|
end
|
19
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kosapi_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tibor Szolár
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -265,6 +265,7 @@ files:
|
|
265
265
|
- lib/kosapi_client/entity/base_entity.rb
|
266
266
|
- lib/kosapi_client/entity/base_person.rb
|
267
267
|
- lib/kosapi_client/entity/boolean.rb
|
268
|
+
- lib/kosapi_client/entity/branch.rb
|
268
269
|
- lib/kosapi_client/entity/course.rb
|
269
270
|
- lib/kosapi_client/entity/course_event.rb
|
270
271
|
- lib/kosapi_client/entity/coursin.rb
|
@@ -292,6 +293,7 @@ files:
|
|
292
293
|
- lib/kosapi_client/request_builder.rb
|
293
294
|
- lib/kosapi_client/request_builder_delegator.rb
|
294
295
|
- lib/kosapi_client/resource.rb
|
296
|
+
- lib/kosapi_client/resource/branches_builder.rb
|
295
297
|
- lib/kosapi_client/resource/course_events_builder.rb
|
296
298
|
- lib/kosapi_client/resource/courses_builder.rb
|
297
299
|
- lib/kosapi_client/resource/exams_builder.rb
|
@@ -323,7 +325,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
323
325
|
version: '0'
|
324
326
|
requirements: []
|
325
327
|
rubyforge_project:
|
326
|
-
rubygems_version: 2.6.
|
328
|
+
rubygems_version: 2.7.6.2
|
327
329
|
signing_key:
|
328
330
|
specification_version: 4
|
329
331
|
summary: Simple Ruby client library for accessing KOSapi service resources
|