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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2cbd06f389e0118e1f7c3e9366af9638ee643bbf
4
- data.tar.gz: b4c7f3e7680653e4920a2c30876107c2dbf1ce2c
2
+ SHA256:
3
+ metadata.gz: ebf21f664665d4883acd83607d526dfedcbfb5032673879e736e69c39e87fa8e
4
+ data.tar.gz: 6acaecd93f80e40fc4c9345fc0306edd1bb643b9f8de1d6c048c21dd7985e21d
5
5
  SHA512:
6
- metadata.gz: dee4adbe8a2bdd0f8a975aaeb7797cdf61cc0230540b66666f8e30bf973b64d9ce919ab3d030981f45b8ce67fc5e590dd6252cdd24c74b44c7de36ba1f0c4d8b
7
- data.tar.gz: 8f327d32b45559da7156b0ca039fffbb73e64bb77e366f59574d9fe8cdcc8ce7a8e748f12e25f1004e83d62fb0c50438e81b5ff66fc098a94a5f3ea34fcd6c53
6
+ metadata.gz: 8d3160b80ba8ad6bbef7bfc1696fc2a25c561d058c8915489efd9ab81dc277556175caa79017436bcff8a2492bdac7e1cd7f93da29e061f75a80aff139efa707
7
+ data.tar.gz: 9e5df05b73018490a895132ef24f5d3c38bbd28401cb5b29a65ee87613f910abe968e64f47cfdbedb56b0823e7ce8fc78d5c4339f526168afe98381a7842268f
@@ -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', '~> 1.3'
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'
@@ -21,3 +21,4 @@ require 'kosapi_client/entity/teacher'
21
21
  require 'kosapi_client/entity/semester'
22
22
  require 'kosapi_client/entity/student'
23
23
  require 'kosapi_client/entity/exam'
24
+ require 'kosapi_client/entity/branch'
@@ -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
- path = mapping_options[:path]
111
- if path
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
@@ -10,6 +10,9 @@ module KOSapiClient
10
10
  map_data :first_hour, Integer
11
11
  map_data :parity, Enum
12
12
  map_data :title, String
13
+ map_data :start_time, Time
14
+ map_data :end_time, Time
15
+ map_data :weeks, String
13
16
 
14
17
  end
15
18
  end
@@ -10,6 +10,9 @@ module KOSapiClient
10
10
  map_data :first_hour, Integer
11
11
  map_data :parity, Enum
12
12
  map_data :room, Link
13
+ map_data :start_time, Time
14
+ map_data :end_time, Time
15
+ map_data :weeks, String
13
16
 
14
17
  end
15
18
  end
@@ -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 = {})
@@ -1,4 +1,5 @@
1
1
  require 'kosapi_client/request_builder'
2
+ require 'kosapi_client/resource/branches_builder'
2
3
  require 'kosapi_client/resource/courses_builder'
3
4
  require 'kosapi_client/resource/parallels_builder'
4
5
  require 'kosapi_client/resource/exams_builder'
@@ -0,0 +1,11 @@
1
+ module KOSapiClient
2
+ module Resource
3
+ class BranchesBuilder < RequestBuilder
4
+ def study_plans
5
+ raise 'Call #find before asking for branch\'s study plans' unless id_set?
6
+ url_builder.set_path(id, 'studyPlans')
7
+ self
8
+ end
9
+ end
10
+ end
11
+ end
@@ -3,17 +3,34 @@ module KOSapiClient
3
3
  class CoursesBuilder < RequestBuilder
4
4
 
5
5
  def detail(level = 1)
6
- @url_builder.set_query_param(:detail, level)
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
- @url_builder.set_query_param(:sem, semesters.join(','))
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
@@ -1,3 +1,3 @@
1
1
  module KOSapiClient
2
- VERSION = '0.8.0'
2
+ VERSION = '0.13.0'
3
3
  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.8.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: 2018-01-19 00:00:00.000000000 Z
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: '1.3'
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: '1.3'
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.11
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