appolo 1.0.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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Appolo.gemspec +30 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +83 -0
- data/Rakefile +14 -0
- data/bin/console +14 -0
- data/bin/example.rb +30 -0
- data/bin/setup +7 -0
- data/lib/Appolo/Models/avatar_url.rb +13 -0
- data/lib/Appolo/Models/lecture.rb +30 -0
- data/lib/Appolo/Models/links.rb +28 -0
- data/lib/Appolo/Models/main_model/classes.rb +87 -0
- data/lib/Appolo/Models/main_model/courses.rb +20 -0
- data/lib/Appolo/Models/main_model/lective_semester.rb +29 -0
- data/lib/Appolo/Models/main_model/program.rb +20 -0
- data/lib/Appolo/Models/main_model/student.rb +34 -0
- data/lib/Appolo/Models/main_model/teacher.rb +33 -0
- data/lib/Appolo/Models/model_utils.rb +59 -0
- data/lib/Appolo/Models/resource.rb +23 -0
- data/lib/Appolo/version.rb +3 -0
- data/lib/Appolo.rb +216 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9e8888ad31328cfd3892c4907b7cd9b61f88cec6
|
4
|
+
data.tar.gz: 97acaf885d74b45987699232f792668bd74a2aed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1368bdd16eeeccdb9e933c25862fff49d7149be2e1f7ed2ceaae414c8be13310640eb72f2d1ade6bf15f47dc757018bcc352856e5d6691c22a1de1868595e7c9
|
7
|
+
data.tar.gz: 708ee79a4f4618cc39fa41b710efebc56f2f1561861bb084468e53d4da690b95721afb3cc7f7e7188b5deed0688fc9583a3387afaffb447b5c6821560fe147bb
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Appolo.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'Appolo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "appolo"
|
8
|
+
spec.version = Appolo::VERSION
|
9
|
+
spec.authors = ["Pedro Gabriel"]
|
10
|
+
spec.email = ["pedrogabriel@protonmail.ch"]
|
11
|
+
|
12
|
+
spec.summary = %q{Provides easy access to Thoth web API}
|
13
|
+
spec.description = %q{Ruby gem that provides quick and easy access to the web api of Thoth WebApp}
|
14
|
+
spec.homepage = "https://github.com/CaptainGabriel/AppoloGem"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "rest-client"
|
27
|
+
spec.add_development_dependency "json"
|
28
|
+
|
29
|
+
|
30
|
+
end
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# Appolo
|
2
|
+
[](https://codeclimate.com/github/CaptainGabriel/AppoloGem)
|
3
|
+
|
4
|
+
Ruby gem that provides quick and easy access to the web api of [Thoth WebApp](https://adeetc.thothapp.com)
|
5
|
+
|
6
|
+
This project does not intends to show any super efficient or professional programming features since it´s only purpose was for me to learn the language and at the same time to build a ruby gem.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'Appolo'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install Appolo
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
The following line of code
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
puts Appolo::get_student_by_id 38209
|
30
|
+
```
|
31
|
+
|
32
|
+
will print the following info about a student with the id 38209:
|
33
|
+
|
34
|
+
```
|
35
|
+
Pedro Almeida - 38209
|
36
|
+
```
|
37
|
+
|
38
|
+
You can also get an instance related to the class with id 409 and
|
39
|
+
afterwards all the lectures that were given there like this:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
some_class = Appolo.get_class_by_id 409
|
43
|
+
all_lectures_now = some_class.lectures
|
44
|
+
|
45
|
+
puts all_lectures[0].title
|
46
|
+
# Aula 01 Introdução às VMs processo e comparação .Net vs JVM
|
47
|
+
puts all_lectures[1].title
|
48
|
+
# Aula 02 Distribuição e ligação de componetes em ambiente Unmanaged
|
49
|
+
puts all_lectures[2].title
|
50
|
+
# Aula 03 Características da distribuição e ligação de componentes Managed
|
51
|
+
```
|
52
|
+
|
53
|
+
To get all the students participating in a certain class:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
some_class = Appolo.get_class_by_id 409
|
57
|
+
participants = some_class.participants
|
58
|
+
|
59
|
+
puts participants[0].name
|
60
|
+
# Humberto Pedro Pinto da Silva
|
61
|
+
```
|
62
|
+
|
63
|
+
For more information, just grab the id and get the specific student
|
64
|
+
```ruby
|
65
|
+
id = participants[0].id
|
66
|
+
student = Appolo.get_student_by_id id
|
67
|
+
puts student.short_name
|
68
|
+
# Humberto Silva
|
69
|
+
```
|
70
|
+
|
71
|
+
## Development
|
72
|
+
|
73
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
74
|
+
|
75
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
1. Fork it ( https://github.com/CaptainGabriel/Appolo/fork )
|
80
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
81
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
82
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
83
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
# Default directory to look in is `/specs`
|
6
|
+
# Run with `rake spec`
|
7
|
+
#will enable us (manually) or Guard to execute the task and run the RSpec test suite
|
8
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
9
|
+
task.rspec_opts = ['--color', '--format', 'nested']
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => :spec
|
13
|
+
|
14
|
+
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "Appolo"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/example.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'Appolo'
|
4
|
+
|
5
|
+
def any_key
|
6
|
+
puts '<<any key to continue>>'
|
7
|
+
gets
|
8
|
+
end
|
9
|
+
|
10
|
+
puts 'This program shows how this gem can be used by you.'
|
11
|
+
|
12
|
+
any_key
|
13
|
+
|
14
|
+
puts 'To start, let\'s get one student.'
|
15
|
+
puts 'We can get students by their ID so let\'s use the ID \'38209\':'
|
16
|
+
any_key
|
17
|
+
puts 'You can type \'puts Appolo::get_student_by_id 38209\' and we get:'
|
18
|
+
puts '<<' + Appolo.get_student_by_id(38209).to_s + '>>'
|
19
|
+
any_key
|
20
|
+
|
21
|
+
puts 'Now, let\'s get some teachers at once.'
|
22
|
+
puts 'You can do it by typing \'Appolo::get_teachers.each {|teacher| puts teacher}\''
|
23
|
+
puts 'and you will see something like:'
|
24
|
+
puts '1 - Carlos Guedes : cguedes@cc.isel.ipl.pt'
|
25
|
+
puts '2 - Ezequiel Conde : ezeq@cc.isel.ipl.pt'
|
26
|
+
puts '3 - Miguel Gamboa Carvalho : mcarvalho@cc.isel.ipl.pt'
|
27
|
+
puts '...'
|
28
|
+
any_key
|
29
|
+
|
30
|
+
puts 'Simple, right ? :)'
|
data/bin/setup
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
class AvatarUrl
|
3
|
+
|
4
|
+
attr_reader :size_24, :size_32, :size_64, :size_128
|
5
|
+
|
6
|
+
|
7
|
+
def initialize(avatar_json_object)
|
8
|
+
@size_24 = avatar_json_object['size24']
|
9
|
+
@size_32 = avatar_json_object['size32']
|
10
|
+
@size_64 = avatar_json_object['size64']
|
11
|
+
@size_128 = avatar_json_object['size128']
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative '../../../lib/Appolo/Models/model_utils'
|
2
|
+
require 'json'
|
3
|
+
require 'rest-client'
|
4
|
+
|
5
|
+
##
|
6
|
+
# This class represents a lecture given at some point in some class.
|
7
|
+
class Lecture
|
8
|
+
|
9
|
+
attr_reader :id, :content, :date_created, :title
|
10
|
+
|
11
|
+
##
|
12
|
+
# Create an instance of Lecture based upon +json_str+
|
13
|
+
# that can be an hash or a JSON string.
|
14
|
+
def initialize (json_str)
|
15
|
+
json_data = Appolo.check_json_info json_str
|
16
|
+
|
17
|
+
@id = json_data[ModelUtils::ID]
|
18
|
+
@content = json_data[ModelUtils::CONTENT]
|
19
|
+
@date_created = json_data[ModelUtils::CREATED_WHEN]
|
20
|
+
@title = json_data[ModelUtils::TITLE]
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# String representation of a Lecture object.
|
26
|
+
def to_s
|
27
|
+
"#{@id} - #{@title} : #{@date_created}"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'model_utils'
|
2
|
+
|
3
|
+
class Links
|
4
|
+
|
5
|
+
attr_reader :self, :root, :type, :main_teacher, :course_unit,
|
6
|
+
:lective_semester, :classes, :pages, :participants,
|
7
|
+
:groups, :lectures, :news_items, :work_items, :resources
|
8
|
+
|
9
|
+
|
10
|
+
def initialize(links, tpe)
|
11
|
+
@self = links[ModelUtils::SELF]
|
12
|
+
@root = links[ModelUtils::ROOT]
|
13
|
+
@type = links[tpe]
|
14
|
+
|
15
|
+
@main_teacher = links[ModelUtils::MAIN_TEACHER]
|
16
|
+
@course_unit = links[ModelUtils::COURSE_UNIT]
|
17
|
+
@lective_semester = links[ModelUtils::LECTIVE_SEMESTER]
|
18
|
+
@classes = links[ModelUtils::CLASSES]
|
19
|
+
@pages = links[ModelUtils::PAGES]
|
20
|
+
@participants = links[ModelUtils::PARTICIPANTS]
|
21
|
+
@groups = links[ModelUtils::GROUPS]
|
22
|
+
@lectures = links[ModelUtils::LECTURES]
|
23
|
+
@news_items = links[ModelUtils::NEWS_ITEMS]
|
24
|
+
@work_items = links[ModelUtils::WORK_ITEMS]
|
25
|
+
@resources = links[ModelUtils::RESOURCES]
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest-client'
|
3
|
+
require_relative '../../Models/model_utils'
|
4
|
+
require_relative '../../Models/links'
|
5
|
+
require_relative '../../Models/avatar_url'
|
6
|
+
require_relative '../../Models/lecture'
|
7
|
+
require_relative '../../Models/resource'
|
8
|
+
require_relative 'program'
|
9
|
+
|
10
|
+
class Classes
|
11
|
+
|
12
|
+
TYPE = 'classes'
|
13
|
+
|
14
|
+
attr_reader :id, :full_name, :course_unit_short_name, :class_name, :main_teacher_short_name
|
15
|
+
attr_reader :course_unit_id, :lective_semester_id, :main_teacher_id, :max_group_size
|
16
|
+
attr_reader :main_teacher, :links
|
17
|
+
|
18
|
+
##
|
19
|
+
# Initiate an instance of Classes based upon +json_info*
|
20
|
+
# that can be an hash or a JSON string.
|
21
|
+
def initialize(json_info)
|
22
|
+
json_data = ModelUtils::check_json_info json_info
|
23
|
+
|
24
|
+
@id = json_data[ModelUtils::ID]
|
25
|
+
@full_name = json_data[ModelUtils::FULL_NAME]
|
26
|
+
@course_unit_short_name = json_data[ModelUtils::COURSE_UNIT_SHORT_NAME]
|
27
|
+
@class_name = json_data[ModelUtils::CLASS_NAME]
|
28
|
+
@main_teacher_short_name = json_data[ModelUtils::MAIN_TEACHER_SHORT_NAME]
|
29
|
+
@course_unit_id = json_data[ModelUtils::COURSE_UNIT_ID]
|
30
|
+
@lective_semester_id = json_data[ModelUtils::LECTIVE_SEMESTER_ID]
|
31
|
+
@main_teacher_id = json_data[ModelUtils::MAIN_TEACHER_ID]
|
32
|
+
@max_group_size = json_data[ModelUtils::MAX_GROUP_SIZE]
|
33
|
+
|
34
|
+
teacher_self_link = json_data[ModelUtils::LINKS]
|
35
|
+
teacher_self_link = teacher_self_link[ModelUtils::MAIN_TEACHER]
|
36
|
+
unless teacher_self_link.nil?
|
37
|
+
#TODO get the id and check if a request has been made in the past
|
38
|
+
teacher_self_response = RestClient.get teacher_self_link
|
39
|
+
@main_teacher = Teacher.new teacher_self_response
|
40
|
+
end
|
41
|
+
|
42
|
+
@links = Links.new(json_data[ModelUtils::LINKS], TYPE)
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Small representation of the Classes object
|
47
|
+
def to_s
|
48
|
+
"#{@id} - #{@full_name} - #{@main_teacher_short_name}"
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Returns all the students related to this class.
|
53
|
+
def participants
|
54
|
+
response_all_participants = RestClient.get @links.participants
|
55
|
+
all_participants = JSON.parse response_all_participants
|
56
|
+
temp = []
|
57
|
+
all_participants['students'].each do |participant|
|
58
|
+
temp.push Student.new participant
|
59
|
+
end
|
60
|
+
temp
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
# Returns all the lectures related to this class.
|
65
|
+
def lectures
|
66
|
+
response_all_lectures = RestClient.get @links.lectures
|
67
|
+
all_lectures = JSON.parse response_all_lectures
|
68
|
+
temp = []
|
69
|
+
all_lectures['classLectures'].each do |lecture|
|
70
|
+
temp.push Lecture.new lecture
|
71
|
+
end
|
72
|
+
temp
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Returns all the resources related to a certain class.
|
77
|
+
def resources
|
78
|
+
response_all_resources = RestClient.get @links.resources
|
79
|
+
all_resources = JSON.parse response_all_resources
|
80
|
+
temp = []
|
81
|
+
all_resources['classResources'].each do |resource|
|
82
|
+
temp.push Resource.new resource
|
83
|
+
end
|
84
|
+
temp
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class CourseUnit
|
2
|
+
private
|
3
|
+
TYPE = 'courseunits'
|
4
|
+
|
5
|
+
public
|
6
|
+
attr_reader :id, :short_name, :name
|
7
|
+
attr_reader :programs, :links
|
8
|
+
|
9
|
+
def initialize(json_info)
|
10
|
+
@id = json_info[ModelUtils::ID]
|
11
|
+
@short_name = json_info[ModelUtils::SHORT_NAME]
|
12
|
+
@name = json_info[ModelUtils::NAME]
|
13
|
+
@links = Links.new json_info[ModelUtils::LINKS], TYPE
|
14
|
+
#@programs = TODO
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
"#{@id} - #{@short_name}"
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative '../../Models/model_utils'
|
2
|
+
require_relative '../../Models/links'
|
3
|
+
|
4
|
+
class LectiveSemester
|
5
|
+
|
6
|
+
attr_reader :lective_semester_id, :short_name, :start_year, :term, :term_name
|
7
|
+
attr_reader :links
|
8
|
+
|
9
|
+
TYPE = 'lectiveSemesters'
|
10
|
+
|
11
|
+
def initialize(json_str)
|
12
|
+
if json_str.is_a? Hash
|
13
|
+
json_data = json_str
|
14
|
+
else
|
15
|
+
json_data = JSON.parse json_str
|
16
|
+
end
|
17
|
+
|
18
|
+
@lective_semester_id = json_data[ModelUtils::LECTIVE_ID]
|
19
|
+
@short_name = json_data[ModelUtils::SHORT_NAME]
|
20
|
+
@start_year = json_data[ModelUtils::START_YEAR]
|
21
|
+
@term = json_data[ModelUtils::TERM]
|
22
|
+
@term_name = json_data[ModelUtils::TERM_NAME]
|
23
|
+
@links = Links.new json_data[ModelUtils::LINKS], TYPE
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
"#{@lective_semester_id} - #{@short_name} : #{@term_name} #{@start_year}"
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative '../../Models/model_utils'
|
2
|
+
require_relative '../../Models/links'
|
3
|
+
class Program
|
4
|
+
|
5
|
+
|
6
|
+
attr_reader :id, :short_name, :links, :full_name
|
7
|
+
|
8
|
+
TYPE = 'programs'
|
9
|
+
|
10
|
+
def initialize(program_json_struct, links_tpe=TYPE)
|
11
|
+
@id = program_json_struct[ModelUtils::ID]
|
12
|
+
@short_name = program_json_struct[ModelUtils::SHORT_NAME]
|
13
|
+
@links = Links.new(program_json_struct[ModelUtils::LINKS], links_tpe)
|
14
|
+
@full_name = program_json_struct[ModelUtils::FULL_NAME]
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
"#{@id} - #{@full_name}"
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'json'
|
2
|
+
require_relative '../../Models/model_utils'
|
3
|
+
require_relative '../../Models/links'
|
4
|
+
require_relative '../../Models/avatar_url'
|
5
|
+
require_relative 'program'
|
6
|
+
|
7
|
+
class Student
|
8
|
+
|
9
|
+
TYPE = 'students'
|
10
|
+
|
11
|
+
attr_reader :id, :number, :short_name, :name, :academic_email, :github_username
|
12
|
+
attr_reader :avatar_url, :program, :links , :students
|
13
|
+
|
14
|
+
def initialize(json_str)
|
15
|
+
json_data = Appolo.check_json_info json_str
|
16
|
+
|
17
|
+
@id = json_data[ModelUtils::ID]
|
18
|
+
@number = json_data[ModelUtils::NUMBER]
|
19
|
+
@short_name = json_data[ModelUtils::SHORT_NAME]
|
20
|
+
@name = json_data[ModelUtils::NAME] || json_data[ModelUtils::FULL_NAME]
|
21
|
+
@academic_email = json_data[ModelUtils::ACADEMIC_EMAIL]
|
22
|
+
@github_username = json_data[ModelUtils::GITHUB_USERNAME]
|
23
|
+
|
24
|
+
program_info = json_data[ModelUtils::PROGRAM]
|
25
|
+
@program = Program.new(program_info, TYPE) unless program_info.nil?
|
26
|
+
@avatar_url = AvatarUrl.new(json_data[ModelUtils::AVATAR_URL])
|
27
|
+
@links = Links.new(json_data[ModelUtils::LINKS], TYPE)
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
"#{@short_name} - Number #{@number.to_s}"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'json'
|
2
|
+
require_relative '../../Models/links'
|
3
|
+
|
4
|
+
class Teacher
|
5
|
+
|
6
|
+
TYPE = 'teachers'
|
7
|
+
|
8
|
+
attr_reader :id, :number, :short_name, :name, :academic_email
|
9
|
+
attr_reader :avatar_url, :links
|
10
|
+
|
11
|
+
|
12
|
+
def initialize(json_info)
|
13
|
+
if json_info.is_a? Hash
|
14
|
+
json_data = json_info
|
15
|
+
else
|
16
|
+
json_data = JSON.parse json_info
|
17
|
+
end
|
18
|
+
|
19
|
+
@id = json_data[ModelUtils::ID]
|
20
|
+
@number = json_data[ModelUtils::NUMBER]
|
21
|
+
@short_name = json_data[ModelUtils::SHORT_NAME]
|
22
|
+
@name = json_data[ModelUtils::NAME]
|
23
|
+
@academic_email = json_data[ModelUtils::ACADEMIC_EMAIL]
|
24
|
+
@links = Links.new(json_data[ModelUtils::LINKS], TYPE)
|
25
|
+
@avatar_url = AvatarUrl.new(json_data[ModelUtils::AVATAR_URL])
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
"#{@id} - #{@short_name} : #{@academic_email}"
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module ModelUtils
|
2
|
+
|
3
|
+
NAME = 'name'
|
4
|
+
SHORT_NAME = 'shortName'
|
5
|
+
ID = 'id'
|
6
|
+
NUMBER = 'number'
|
7
|
+
GITHUB_USERNAME = 'gitHubUsername'
|
8
|
+
ACADEMIC_EMAIL = 'academicEmail'
|
9
|
+
AVATAR_URL = 'avatarUrl'
|
10
|
+
LINKS = '_links'
|
11
|
+
|
12
|
+
SELF = 'self'
|
13
|
+
ROOT = 'root'
|
14
|
+
PROGRAM = 'program'
|
15
|
+
|
16
|
+
FULL_NAME = 'fullName'
|
17
|
+
COURSE_UNIT_SHORT_NAME = 'courseUnitShortName'
|
18
|
+
LECTIVE_SEMESTER_SHORT_NAME = 'lectiveSemesterShortName'
|
19
|
+
LECTIVE_SEMESTER = 'lectiveSemester'
|
20
|
+
CLASS_NAME = 'className'
|
21
|
+
CLASSES = 'classes'
|
22
|
+
CLASS_ID = 'classId'
|
23
|
+
MAIN_TEACHER_SHORT_NAME = 'mainTeacherShortName'
|
24
|
+
COURSE_UNIT_ID = 'courseUnitId'
|
25
|
+
COURSE_UNIT = 'courseUnit'
|
26
|
+
LECTIVE_SEMESTER_ID = 'lectiveSemesterId'
|
27
|
+
MAIN_TEACHER_ID = 'mainTeacherId'
|
28
|
+
MAX_GROUP_SIZE = 'maxGroupSize'
|
29
|
+
MAIN_TEACHER = 'mainTeacher'
|
30
|
+
|
31
|
+
LECTIVE_ID = 'lectiveSemesterId'
|
32
|
+
START_YEAR = 'startYear'
|
33
|
+
TERM = 'term'
|
34
|
+
TERM_NAME = 'termName'
|
35
|
+
OTHER_TEACHERS = 'otherTeachers'
|
36
|
+
PAGES = 'pages'
|
37
|
+
PARTICIPANTS = 'participants'
|
38
|
+
GROUPS = 'groups'
|
39
|
+
LECTURES = 'lectures'
|
40
|
+
NEWS_ITEMS = 'newsItems'
|
41
|
+
WORK_ITEMS = 'workItems'
|
42
|
+
RESOURCES = 'resources'
|
43
|
+
|
44
|
+
CONTENT = 'content'
|
45
|
+
DATE_CREATED = 'dateCreated'
|
46
|
+
CREATED_WHEN = 'when'
|
47
|
+
TITLE = 'title'
|
48
|
+
DESCRIPTION = 'description'
|
49
|
+
|
50
|
+
def self.check_json_info(json_info)
|
51
|
+
if json_info.is_a? Hash
|
52
|
+
json_data = json_info
|
53
|
+
else
|
54
|
+
json_data = JSON.parse json_info
|
55
|
+
end
|
56
|
+
json_data
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'links'
|
2
|
+
require_relative 'model_utils'
|
3
|
+
|
4
|
+
class Resource
|
5
|
+
|
6
|
+
attr_reader :id, :description, :class_id, :title
|
7
|
+
attr_reader :links
|
8
|
+
|
9
|
+
def initialize(json_str)
|
10
|
+
json_data = ModelUtils::check_json_info json_str
|
11
|
+
|
12
|
+
@id = json_data[ModelUtils::ID]
|
13
|
+
@description = json_data[ModelUtils::DESCRIPTION]
|
14
|
+
@class_id = json_data[ModelUtils::CLASS_ID]
|
15
|
+
@title = json_data[ModelUtils::TITLE]
|
16
|
+
@links = Links.new json_data[ModelUtils::LINKS], 'resources'
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
"Resource : #{@class_id} - #{@title}"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/Appolo.rb
ADDED
@@ -0,0 +1,216 @@
|
|
1
|
+
require 'Appolo/version'
|
2
|
+
require 'rest-client'
|
3
|
+
require_relative '../lib/Appolo/Models/main_model/student'
|
4
|
+
require_relative '../lib/Appolo/Models/main_model/teacher'
|
5
|
+
require_relative '../lib/Appolo/Models/main_model/classes'
|
6
|
+
require_relative '../lib/Appolo/Models/main_model/program'
|
7
|
+
require_relative '../lib/Appolo/Models/main_model/courses'
|
8
|
+
require_relative '../lib/Appolo/Models/main_model/lective_semester'
|
9
|
+
require_relative '../lib/Appolo/Models/lecture'
|
10
|
+
require 'json'
|
11
|
+
|
12
|
+
##
|
13
|
+
# This module is the main provider for the public API that
|
14
|
+
# this gem contains.
|
15
|
+
|
16
|
+
module Appolo
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
COURSES_API_CODENAME = 'courseUnits'
|
21
|
+
TEACHERS_API_CODENAME = 'teachers'
|
22
|
+
STUDENTS_API_CODENAME = 'students'
|
23
|
+
CLASSES_API_CODENAME = 'classes'
|
24
|
+
PROGRAMS_API_CODENAME = 'programs'
|
25
|
+
LECTIVESEM_API_CODENAME = 'lectiveSemesters'
|
26
|
+
|
27
|
+
$all_students = Hash.new
|
28
|
+
$all_teachers = Hash.new
|
29
|
+
$all_classes = Hash.new
|
30
|
+
$all_programs = Hash.new
|
31
|
+
$all_courses = Hash.new
|
32
|
+
$all_lective_sem = Hash.new
|
33
|
+
|
34
|
+
#main API links
|
35
|
+
TEACHERS_API_LINK = 'https://adeetc.thothapp.com/api/v1/teachers/'
|
36
|
+
STUDENTS_API_LINK = 'https://adeetc.thothapp.com/api/v1/students/'
|
37
|
+
CLASSES_API_LINK = 'https://adeetc.thothapp.com/api/v1/classes/'
|
38
|
+
PROGRAMS_API_LINK = 'https://adeetc.thothapp.com/api/v1/programs/'
|
39
|
+
COURSES_API_LINK = 'https://adeetc.thothapp.com/api/v1/courseunits/'
|
40
|
+
LECTIVE_SEMESTERS_API_LINK = 'https://adeetc.thothapp.com/api/v1/lectivesemesters'
|
41
|
+
|
42
|
+
|
43
|
+
def self.verify_response(resp)
|
44
|
+
(resp.code == 200) ? resp : nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.check_json_info(json_str)
|
48
|
+
unless json_str.is_a? Hash
|
49
|
+
JSON.parse json_str
|
50
|
+
else
|
51
|
+
json_str
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
public
|
56
|
+
|
57
|
+
##
|
58
|
+
#Returns an array of Student instances based upon the main API link.
|
59
|
+
|
60
|
+
def self.get_students
|
61
|
+
return $all_students unless $all_students.length == 0
|
62
|
+
begin
|
63
|
+
response = RestClient.get STUDENTS_API_LINK
|
64
|
+
valid_resp = verify_response response
|
65
|
+
students_temp = JSON.parse(valid_resp)[STUDENTS_API_CODENAME]
|
66
|
+
students_temp.each do |student|
|
67
|
+
stub = Student.new(student)
|
68
|
+
$all_students[stub.id] = stub
|
69
|
+
end
|
70
|
+
$all_students
|
71
|
+
rescue => e
|
72
|
+
nil #TODO - exceptions
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
##
|
78
|
+
#Returns an array of Teacher instances based upon the main API link.
|
79
|
+
|
80
|
+
def self.get_teachers
|
81
|
+
return $all_teachers unless $all_teachers.length == 0
|
82
|
+
begin
|
83
|
+
response = RestClient.get TEACHERS_API_LINK
|
84
|
+
valid_response = verify_response response
|
85
|
+
teachers_temp = JSON.parse(valid_response)[TEACHERS_API_CODENAME]
|
86
|
+
teachers_temp.each do |teacher|
|
87
|
+
stub = Teacher.new(teacher)
|
88
|
+
$all_teachers[stub.id] = stub
|
89
|
+
end
|
90
|
+
$all_teachers
|
91
|
+
rescue => e
|
92
|
+
nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
##
|
98
|
+
# Returns an array of Program instances based upon the main API link.
|
99
|
+
|
100
|
+
def self.get_programs
|
101
|
+
return $all_programs unless $all_programs.length == 0
|
102
|
+
begin
|
103
|
+
response = RestClient.get PROGRAMS_API_LINK
|
104
|
+
valid_resp = verify_response response
|
105
|
+
programs_temp = JSON.parse(valid_resp)[PROGRAMS_API_CODENAME]
|
106
|
+
programs_temp.each do |program|
|
107
|
+
stub = Program.new program
|
108
|
+
$all_programs[stub.id] = stub
|
109
|
+
end
|
110
|
+
$all_programs
|
111
|
+
rescue => e
|
112
|
+
nil
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
##
|
118
|
+
# Returns an array of CourseUnit instances based upon the main API link.
|
119
|
+
|
120
|
+
def self.get_courses
|
121
|
+
return $all_courses unless $all_courses.length == 0
|
122
|
+
begin
|
123
|
+
response = RestClient.get COURSES_API_LINK
|
124
|
+
valid_resp = verify_response response #debug
|
125
|
+
courses_temp = JSON.parse(valid_resp)[COURSES_API_CODENAME]
|
126
|
+
courses_temp.each do |course|
|
127
|
+
stub = CourseUnit.new course
|
128
|
+
$all_courses[stub.id] = stub
|
129
|
+
end
|
130
|
+
$all_courses
|
131
|
+
rescue => e
|
132
|
+
nil
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
##
|
138
|
+
# Returns an array of LectiveSemester instances based upon the main API link.
|
139
|
+
|
140
|
+
def self.get_lective_semesters
|
141
|
+
return $all_lective_sem unless $all_lective_sem.length == 0
|
142
|
+
begin
|
143
|
+
response = RestClient.get LECTIVE_SEMESTERS_API_LINK
|
144
|
+
valid_resp = verify_response response
|
145
|
+
lective_temp = JSON.parse(valid_resp)[LECTIVESEM_API_CODENAME]
|
146
|
+
lective_temp.each do |lec_sem|
|
147
|
+
stub = LectiveSemester.new lec_sem
|
148
|
+
$all_lective_sem[stub.lective_semester_id] = stub
|
149
|
+
end
|
150
|
+
$all_lective_sem
|
151
|
+
rescue => e
|
152
|
+
nil
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
##
|
158
|
+
# Returns an array of Classes instances based upon the main API link.
|
159
|
+
|
160
|
+
def self.get_classes
|
161
|
+
return $all_classes unless $all_classes.length == 0
|
162
|
+
begin
|
163
|
+
response = RestClient.get CLASSES_API_LINK
|
164
|
+
valid_resp = verify_response response
|
165
|
+
classes_temp = JSON.parse(valid_resp)[CLASSES_API_CODENAME]
|
166
|
+
classes_temp.each do |classe|
|
167
|
+
stub = Classes.new classe
|
168
|
+
$all_classes[stub.id] = stub
|
169
|
+
end
|
170
|
+
$all_classes
|
171
|
+
rescue => e
|
172
|
+
nil
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
##
|
177
|
+
# Return a single instance of Teacher based upon the +id+ given.
|
178
|
+
|
179
|
+
def self.get_teacher_by_id(id)
|
180
|
+
begin
|
181
|
+
response = RestClient.get TEACHERS_API_LINK + id.to_s
|
182
|
+
Teacher.new (verify_response response)
|
183
|
+
rescue => e
|
184
|
+
nil
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
##
|
190
|
+
# Return a single instance of Classes based upon the +id+ given.
|
191
|
+
|
192
|
+
def self.get_class_by_id(id)
|
193
|
+
begin
|
194
|
+
response = RestClient.get CLASSES_API_LINK + id.to_s
|
195
|
+
Classes.new (verify_response response)
|
196
|
+
rescue => e
|
197
|
+
nil
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
##
|
202
|
+
# Return a single instance of Student based upon the +id+ given.
|
203
|
+
|
204
|
+
def self.get_student_by_id(id)
|
205
|
+
return $all_students[id] unless $all_students.count == 0
|
206
|
+
begin
|
207
|
+
response = RestClient.get STUDENTS_API_LINK + id.to_s
|
208
|
+
Student.new (verify_response response)
|
209
|
+
rescue => e
|
210
|
+
nil
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: appolo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pedro Gabriel
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Ruby gem that provides quick and easy access to the web api of Thoth
|
84
|
+
WebApp
|
85
|
+
email:
|
86
|
+
- pedrogabriel@protonmail.ch
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Appolo.gemspec
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/example.rb
|
100
|
+
- bin/setup
|
101
|
+
- lib/Appolo.rb
|
102
|
+
- lib/Appolo/Models/avatar_url.rb
|
103
|
+
- lib/Appolo/Models/lecture.rb
|
104
|
+
- lib/Appolo/Models/links.rb
|
105
|
+
- lib/Appolo/Models/main_model/classes.rb
|
106
|
+
- lib/Appolo/Models/main_model/courses.rb
|
107
|
+
- lib/Appolo/Models/main_model/lective_semester.rb
|
108
|
+
- lib/Appolo/Models/main_model/program.rb
|
109
|
+
- lib/Appolo/Models/main_model/student.rb
|
110
|
+
- lib/Appolo/Models/main_model/teacher.rb
|
111
|
+
- lib/Appolo/Models/model_utils.rb
|
112
|
+
- lib/Appolo/Models/resource.rb
|
113
|
+
- lib/Appolo/version.rb
|
114
|
+
homepage: https://github.com/CaptainGabriel/AppoloGem
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.4.5
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Provides easy access to Thoth web API
|
138
|
+
test_files: []
|