appolo 1.2.2 → 2.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 +4 -4
- data/README.md +31 -5
- data/lib/Appolo/version.rb +1 -1
- data/lib/Appolo.rb +68 -174
- metadata +2 -3
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecc284a43e5df985d8dc112580091bbf85f59bb7
|
4
|
+
data.tar.gz: 78fbd70effa5701950d40863f8e732349012700a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4ba4b2b85bf5fa7765bf71e8848cca7e15e468c07efbb718a3fc0110c6c2e0811ef6e14fefa98e68069473d547bfe65d85c1cbc9859994f0c0cafe734afd3c5
|
7
|
+
data.tar.gz: c1965a86e1dd129fbc52b7e9dd5f6deca8b41fdd2bd028d8ddf5f0e4351f28d09f98d4f2081e03232ec679804c6fefa42a2aca37b9215dc644e7b0076a7878f2
|
data/README.md
CHANGED
@@ -11,7 +11,9 @@ This project does not intends to show any super efficient or professional progra
|
|
11
11
|
Add this line to your application's Gemfile:
|
12
12
|
|
13
13
|
```ruby
|
14
|
+
|
14
15
|
gem 'Appolo'
|
16
|
+
|
15
17
|
```
|
16
18
|
|
17
19
|
And then execute:
|
@@ -24,23 +26,41 @@ Or install it yourself as:
|
|
24
26
|
|
25
27
|
## Usage
|
26
28
|
|
29
|
+
In order to specify which element to get, you can use one of the following
|
30
|
+
symbols:
|
31
|
+
|
32
|
+
* :classes
|
33
|
+
* :students
|
34
|
+
* :programs
|
35
|
+
* :courses
|
36
|
+
* :lec_semesters
|
37
|
+
* :teachers
|
38
|
+
|
39
|
+
Take a look at the tests for more info.
|
40
|
+
|
41
|
+
|
27
42
|
The following line of code
|
28
43
|
|
29
44
|
```ruby
|
30
|
-
|
45
|
+
|
46
|
+
puts Appolo::get_element_by_id(:students,38209)
|
47
|
+
|
31
48
|
```
|
32
49
|
|
33
50
|
will print the following info about a student with the id 38209:
|
34
51
|
|
35
52
|
```
|
53
|
+
|
36
54
|
Pedro Almeida - 38209
|
55
|
+
|
37
56
|
```
|
38
57
|
|
39
58
|
You can also get an instance related to the class with id 409 and
|
40
59
|
afterwards all the lectures that were given there like this:
|
41
60
|
|
42
61
|
```ruby
|
43
|
-
|
62
|
+
|
63
|
+
some_class = Appolo.get_element_by_id(:classes, 409)
|
44
64
|
all_lectures_now = some_class.lectures
|
45
65
|
|
46
66
|
puts all_lectures[0].title
|
@@ -49,24 +69,30 @@ puts all_lectures[1].title
|
|
49
69
|
# Aula 02 Distribuição e ligação de componetes em ambiente Unmanaged
|
50
70
|
puts all_lectures[2].title
|
51
71
|
# Aula 03 Características da distribuição e ligação de componentes Managed
|
72
|
+
|
52
73
|
```
|
53
74
|
|
54
75
|
To get all the students participating in a certain class:
|
55
76
|
|
56
77
|
```ruby
|
57
|
-
|
78
|
+
|
79
|
+
some_class = .get_element_by_id(:classes, 409)
|
58
80
|
participants = some_class.participants
|
59
81
|
|
60
82
|
puts participants[0].name
|
61
|
-
#
|
83
|
+
#Humberto Pedro Pinto da Silva
|
84
|
+
|
62
85
|
```
|
63
86
|
|
64
87
|
For more information, just grab the id and get the specific student
|
88
|
+
|
65
89
|
```ruby
|
90
|
+
|
66
91
|
id = participants[0].id
|
67
|
-
student =
|
92
|
+
student = .get_element_by_id(:students, id)
|
68
93
|
puts student.short_name
|
69
94
|
# Humberto Silva
|
95
|
+
|
70
96
|
```
|
71
97
|
|
72
98
|
## Development
|
data/lib/Appolo/version.rb
CHANGED
data/lib/Appolo.rb
CHANGED
@@ -11,19 +11,12 @@ require 'json'
|
|
11
11
|
|
12
12
|
##
|
13
13
|
# This module is the main provider for the public API that
|
14
|
-
# this gem
|
14
|
+
# this gem provides.
|
15
15
|
|
16
16
|
module Appolo
|
17
17
|
|
18
18
|
private
|
19
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
20
|
$all_students = Hash.new
|
28
21
|
$all_teachers = Hash.new
|
29
22
|
$all_classes = Hash.new
|
@@ -31,16 +24,45 @@ module Appolo
|
|
31
24
|
$all_courses = Hash.new
|
32
25
|
$all_lective_sem = Hash.new
|
33
26
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
27
|
+
##
|
28
|
+
# This hash contains each hash structure that contains the different
|
29
|
+
# elements after being requested by the method Appolo#get_set_of_elements
|
30
|
+
Elements = {
|
31
|
+
:students => $all_students,
|
32
|
+
:teachers => $all_teachers,
|
33
|
+
:classes => $all_classes,
|
34
|
+
:programs => $all_programs,
|
35
|
+
:courses => $all_courses,
|
36
|
+
:lec_semesters => $all_lective_sem
|
37
|
+
}
|
38
|
+
|
39
|
+
##
|
40
|
+
# This hash structure contains the main web links in order to perform
|
41
|
+
# and build future http requests. This set of links are based upon the
|
42
|
+
# Thoth WebApp REST API.
|
43
|
+
# ---
|
44
|
+
# Check https://adeetc.thothapp.com/api/doc for more info.
|
45
|
+
Api_Links = {
|
46
|
+
:students => 'https://adeetc.thothapp.com/api/v1/students/',
|
47
|
+
:teachers => 'https://adeetc.thothapp.com/api/v1/teachers/',
|
48
|
+
:classes => 'https://adeetc.thothapp.com/api/v1/classes/',
|
49
|
+
:programs => 'https://adeetc.thothapp.com/api/v1/programs/',
|
50
|
+
:courses => 'https://adeetc.thothapp.com/api/v1/courseunits/',
|
51
|
+
:lec_semesters => 'https://adeetc.thothapp.com/api/v1/lectivesemesters'
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
Api_Codename = {
|
56
|
+
:students => 'students',
|
57
|
+
:teachers => 'teachers',
|
58
|
+
:classes => 'classes',
|
59
|
+
:programs => 'programs',
|
60
|
+
:courses => 'courseUnits',
|
61
|
+
:lec_semesters => 'lectiveSemesters'
|
62
|
+
}
|
41
63
|
|
42
|
-
#TODO should raise exception when not 200
|
43
64
|
def self.verify_response(resp)
|
65
|
+
#I dont like this nil..
|
44
66
|
(resp.code == 200) ? resp : nil
|
45
67
|
end
|
46
68
|
|
@@ -56,176 +78,48 @@ module Appolo
|
|
56
78
|
Result.new(result, error)
|
57
79
|
end
|
58
80
|
|
81
|
+
Builder_Elements = {
|
82
|
+
students: lambda{|students| students.each{|student| stub , $all_students[stub.id] = Student.new(student), stub}},
|
83
|
+
teachers: lambda{|teachers| teachers.each{|teacher| stub, $all_teachers[stub.id] = Teacher.new(teacher), stub }},
|
84
|
+
classes: lambda{|classes| classes.each{|classe| stub, $all_classes[stub.id] = Classes.new(classe), stub}},
|
85
|
+
programs: lambda{|programs| programs.each{|program| stub, $all_programs[stub.id] = Program.new(program), stub}},
|
86
|
+
courses: lambda{|courses| courses.each{|course| stub, $all_courses[stub.id] = CourseUnit.new(course), stub}},
|
87
|
+
lec_semesters: lambda{|semesters| semesters.each{|lec_sem| stub, $all_lective_sem[stub.id] = LectiveSemester.new(lec_sem), stub}}
|
88
|
+
}
|
89
|
+
|
90
|
+
Builder_Element = {
|
91
|
+
students: lambda{|data| Student.new(verify_response data)},
|
92
|
+
teachers: lambda{|data| Teacher.new(verify_response data)},
|
93
|
+
classes: lambda{|data| Classes.new(verify_response data)},
|
94
|
+
programs: lambda{|data| Program.new(verify_response data)},
|
95
|
+
courses: lambda{|data| CourseUnit.new(verify_response data)},
|
96
|
+
lec_semesters: lambda{|data| LectiveSemester.new(verify_response data)}
|
97
|
+
}
|
59
98
|
|
60
99
|
public
|
61
100
|
|
62
101
|
##
|
63
|
-
#
|
64
|
-
|
65
|
-
def self.get_students
|
66
|
-
return $all_students unless $all_students.length == 0
|
67
|
-
begin
|
68
|
-
response = RestClient.get STUDENTS_API_LINK
|
69
|
-
valid_resp = verify_response response
|
70
|
-
students_temp = JSON.parse(valid_resp)[STUDENTS_API_CODENAME]
|
71
|
-
students_temp.each do |student|
|
72
|
-
stub = Student.new(student)
|
73
|
-
$all_students[stub.id] = stub
|
74
|
-
end
|
75
|
-
$all_students
|
76
|
-
rescue => e
|
77
|
-
$all_students
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
##
|
83
|
-
#Returns an array of Teacher instances based upon the main API link.
|
84
|
-
|
85
|
-
def self.get_teachers
|
86
|
-
return $all_teachers unless $all_teachers.length == 0
|
87
|
-
begin
|
88
|
-
response = RestClient.get TEACHERS_API_LINK
|
89
|
-
valid_response = verify_response response
|
90
|
-
teachers_temp = JSON.parse(valid_response)[TEACHERS_API_CODENAME]
|
91
|
-
teachers_temp.each do |teacher|
|
92
|
-
stub = Teacher.new(teacher)
|
93
|
-
$all_teachers[stub.id] = stub
|
94
|
-
end
|
95
|
-
$all_teachers
|
96
|
-
rescue => e
|
97
|
-
$all_teachers
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
|
102
|
-
##
|
103
|
-
# Returns an array of Program instances based upon the main API link.
|
104
|
-
|
105
|
-
def self.get_programs
|
106
|
-
return $all_programs unless $all_programs.length == 0
|
107
|
-
begin
|
108
|
-
response = RestClient.get PROGRAMS_API_LINK
|
109
|
-
valid_resp = verify_response response
|
110
|
-
programs_temp = JSON.parse(valid_resp)[PROGRAMS_API_CODENAME]
|
111
|
-
programs_temp.each do |program|
|
112
|
-
stub = Program.new program
|
113
|
-
$all_programs[stub.id] = stub
|
114
|
-
end
|
115
|
-
$all_programs
|
116
|
-
rescue => e
|
117
|
-
$all_programs
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
|
122
|
-
##
|
123
|
-
# Returns an array of CourseUnit instances based upon the main API link.
|
124
|
-
|
125
|
-
def self.get_courses
|
126
|
-
return $all_courses unless $all_courses.length == 0
|
127
|
-
begin
|
128
|
-
response = RestClient.get COURSES_API_LINK
|
129
|
-
valid_resp = verify_response response #debug
|
130
|
-
courses_temp = JSON.parse(valid_resp)[COURSES_API_CODENAME]
|
131
|
-
courses_temp.each do |course|
|
132
|
-
stub = CourseUnit.new course
|
133
|
-
$all_courses[stub.id] = stub
|
134
|
-
end
|
135
|
-
$all_courses
|
136
|
-
rescue => e
|
137
|
-
$all_courses
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
|
142
|
-
##
|
143
|
-
# Returns an array of LectiveSemester instances based upon the main API link.
|
102
|
+
#
|
144
103
|
|
145
|
-
def self.
|
146
|
-
return
|
104
|
+
def self.get_set_of_elements(element_name)
|
105
|
+
return Elements[element_name] unless Elements[element_name].length == 0
|
147
106
|
begin
|
148
|
-
response = RestClient.get
|
107
|
+
response = RestClient.get Api_Links[element_name]
|
149
108
|
valid_resp = verify_response response
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
$all_lective_sem
|
109
|
+
element_api_codename = Api_Codename[element_name]
|
110
|
+
set_of_elements = JSON.parse(valid_resp)
|
111
|
+
set_of_elements = set_of_elements[element_api_codename]
|
112
|
+
Builder_Elements[element_name].call(set_of_elements)
|
113
|
+
Elements[element_name]
|
156
114
|
rescue => e
|
157
|
-
|
115
|
+
Elements[element_name]
|
158
116
|
end
|
159
117
|
end
|
160
118
|
|
161
|
-
|
162
|
-
##
|
163
|
-
# Returns an array of Classes instances based upon the main API link.
|
164
|
-
|
165
|
-
def self.get_classes
|
166
|
-
return $all_classes unless $all_classes.length == 0
|
167
|
-
begin
|
168
|
-
response = RestClient.get CLASSES_API_LINK
|
169
|
-
valid_resp = verify_response response
|
170
|
-
classes_temp = JSON.parse(valid_resp)[CLASSES_API_CODENAME]
|
171
|
-
classes_temp.each do |classe|
|
172
|
-
stub = Classes.new classe
|
173
|
-
$all_classes[stub.id] = stub
|
174
|
-
end
|
175
|
-
$all_classes
|
176
|
-
rescue => e
|
177
|
-
$all_classes
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
##
|
182
|
-
# Return a single instance of Teacher based upon the +id+ given.
|
183
|
-
|
184
|
-
def self.get_teacher_by_id(id)
|
185
|
-
#return $all_teachers[id] unless $all_teachers.count == 0
|
186
|
-
begin
|
187
|
-
response = RestClient.get TEACHERS_API_LINK + id.to_s
|
188
|
-
Teacher.new(verify_response response)
|
189
|
-
rescue => e
|
190
|
-
e
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
|
195
|
-
##
|
196
|
-
# Return a single instance of Classes based upon the +id+ given.
|
197
|
-
|
198
|
-
def self.get_class_by_id(id)
|
199
|
-
#return $all_classes[id] unless $all_classes.count == 0
|
200
|
-
begin
|
201
|
-
response = RestClient.get CLASSES_API_LINK + id.to_s
|
202
|
-
Classes.new(verify_response response)
|
203
|
-
rescue => e
|
204
|
-
e
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
##
|
209
|
-
# Return a single instance of Student based upon the +id+ given.
|
210
|
-
|
211
|
-
def self.get_student_by_id(id)
|
212
|
-
#return $all_students[id] unless $all_students.count == 0
|
213
|
-
begin
|
214
|
-
response = RestClient.get STUDENTS_API_LINK + id.to_s
|
215
|
-
Student.new(verify_response response)
|
216
|
-
rescue => e
|
217
|
-
e
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
##
|
222
|
-
# Return a single instance of program based upon the +id+ given.
|
223
|
-
|
224
|
-
def self.get_program_by_id(id)
|
225
|
-
#return $all_programs[id] unless $all_programs.count == 0
|
119
|
+
def self.get_element_by_id(element_name, id)
|
226
120
|
begin
|
227
|
-
response = RestClient.get
|
228
|
-
|
121
|
+
response = RestClient.get Api_Links[element_name] + id.to_s
|
122
|
+
Builder_Element[element_name].call(response)
|
229
123
|
rescue => e
|
230
124
|
e
|
231
125
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appolo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Gabriel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,7 +102,6 @@ extensions: []
|
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
104
|
- ".gitignore"
|
105
|
-
- ".travis.yml"
|
106
105
|
- Appolo.gemspec
|
107
106
|
- Gemfile
|
108
107
|
- LICENSE.txt
|