Module: Appolo

Defined in:
lib/Appolo.rb,
lib/Appolo/version.rb

Overview

This module is the main provider for the public API that this gem contains.

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.get_class_by_id(id) ⇒ Object

Return a single instance of Classes based upon the id given.


192
193
194
195
196
197
198
199
# File 'lib/Appolo.rb', line 192

def self.get_class_by_id(id)
  begin
    response = RestClient.get CLASSES_API_LINK + id.to_s
    Classes.new (verify_response response)
  rescue => e
    nil
  end
end

.get_classesObject

Returns an array of Classes instances based upon the main API link.


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/Appolo.rb', line 160

def self.get_classes
  return $all_classes unless $all_classes.length == 0
  begin
    response = RestClient.get CLASSES_API_LINK
    valid_resp = verify_response response
    classes_temp = JSON.parse(valid_resp)[CLASSES_API_CODENAME]
    classes_temp.each do |classe|
      stub = Classes.new classe
      $all_classes[stub.id] = stub
    end
    $all_classes
  rescue => e
    nil
  end
end

.get_coursesObject

Returns an array of CourseUnit instances based upon the main API link.


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/Appolo.rb', line 120

def self.get_courses
  return $all_courses unless $all_courses.length == 0
  begin
    response = RestClient.get COURSES_API_LINK
    valid_resp = verify_response response #debug
    courses_temp = JSON.parse(valid_resp)[COURSES_API_CODENAME]
    courses_temp.each do |course|
      stub = CourseUnit.new course
      $all_courses[stub.id] = stub
    end
    $all_courses
  rescue => e
    nil
  end
end

.get_lective_semestersObject

Returns an array of LectiveSemester instances based upon the main API link.


140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/Appolo.rb', line 140

def self.get_lective_semesters
  return $all_lective_sem unless $all_lective_sem.length == 0
  begin
    response = RestClient.get LECTIVE_SEMESTERS_API_LINK
    valid_resp = verify_response response
    lective_temp = JSON.parse(valid_resp)[LECTIVESEM_API_CODENAME]
    lective_temp.each do |lec_sem|
      stub = LectiveSemester.new lec_sem
      $all_lective_sem[stub.lective_semester_id] = stub
    end
    $all_lective_sem
  rescue => e
    nil
  end
end

.get_programsObject

Returns an array of Program instances based upon the main API link.


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/Appolo.rb', line 100

def self.get_programs
  return $all_programs unless $all_programs.length == 0
  begin
    response = RestClient.get PROGRAMS_API_LINK
    valid_resp = verify_response response
    programs_temp = JSON.parse(valid_resp)[PROGRAMS_API_CODENAME]
    programs_temp.each do |program|
      stub = Program.new program
      $all_programs[stub.id] = stub
    end
    $all_programs
  rescue => e
    nil
  end
end

.get_student_by_id(id) ⇒ Object

Return a single instance of Student based upon the id given.


204
205
206
207
208
209
210
211
212
# File 'lib/Appolo.rb', line 204

def self.get_student_by_id(id)
  return $all_students[id] unless $all_students.count == 0
  begin
    response = RestClient.get STUDENTS_API_LINK + id.to_s
    Student.new (verify_response response)
  rescue => e
    nil
  end
end

.get_studentsObject

Returns an array of Student instances based upon the main API link.


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/Appolo.rb', line 60

def self.get_students
  return $all_students unless $all_students.length == 0
  begin
    response = RestClient.get STUDENTS_API_LINK
    valid_resp = verify_response response
    students_temp = JSON.parse(valid_resp)[STUDENTS_API_CODENAME]
    students_temp.each do |student|
      stub = Student.new(student)
      $all_students[stub.id] = stub
    end
    $all_students
  rescue => e
    nil #TODO - exceptions
  end
end

.get_teacher_by_id(id) ⇒ Object

Return a single instance of Teacher based upon the id given.


179
180
181
182
183
184
185
186
# File 'lib/Appolo.rb', line 179

def self.get_teacher_by_id(id)
  begin
    response = RestClient.get TEACHERS_API_LINK + id.to_s
    Teacher.new (verify_response response)
  rescue => e
    nil
  end
end

.get_teachersObject

Returns an array of Teacher instances based upon the main API link.


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/Appolo.rb', line 80

def self.get_teachers
  return $all_teachers unless $all_teachers.length == 0
  begin
    response = RestClient.get TEACHERS_API_LINK
    valid_response = verify_response response
    teachers_temp = JSON.parse(valid_response)[TEACHERS_API_CODENAME]
    teachers_temp.each do |teacher|
      stub = Teacher.new(teacher)
      $all_teachers[stub.id] = stub
    end
    $all_teachers
  rescue => e
    nil
  end
end