module Appolo
This module is the main provider for the public API that this gem provides.
Constants
- Api_Codename
In order to build the hash of Link objects, each class must have a codename to append later during the construction. Since I dont believe in magical strings, I’ve putted all of those in here.
- Api_Links
This hash structure contains the main web links in order to perform and build future http requests. This set of links are based upon the Thoth WebApp REST API.
Check adeetc.thothapp.com/api/doc for more info.
- Builder_Element
This hash acts the same as
Builder_Elements
but instead of creating a set of elements, it creates only one since its purpose is to be used when the method Appolo#get_element_by_id is called.- Builder_Elements
This hash contains the procs that build and populate the hashes that contain all the objects from the last made request. So, when we request all the students, the proc related to the symbol “:student” will be used to create the instances and insert them into the hash.
- Elements
This hash contains each hash structure that contains the different elements after being requested by the method Appolo#get_set_of_elements.
- VERSION
Public Class Methods
Call this method in order to get a single element. To specify which element to search you must specify element_name
as:
-
:students -> Set of Students
-
:teachers -> Set of Teachers
-
:classes -> Set of
Classes
-
:programs -> Set of Programs
-
:courses -> Set of Courses
-
:lec_semesters -> Set of Lective Semesters
The id
specifies the id related to the element inside the Thoth API. _This gem is not responsible for the numbers used._
# File lib/Appolo.rb, line 191 def self.get_element_by_id(element_name, id) begin response = RestClient.get Api_Links[element_name] + id.to_s Builder_Element[element_name].call(response) rescue => e e end end
Call this method in order to get an array of elements. To specify which element to search you must specify element_name
as:
-
:students -> Set of Students
-
:teachers -> Set of Teachers
-
:classes -> Set of
Classes
-
:programs -> Set of Programs
-
:courses -> Set of Courses
-
:lec_semesters -> Set of Lective Semesters
# File lib/Appolo.rb, line 163 def self.get_set_of_elements(element_name) return Elements[element_name] unless Elements[element_name].length == 0 begin response = RestClient.get Api_Links[element_name] valid_resp = verify_response response element_api_codename = Api_Codename[element_name] set_of_elements = JSON.parse(valid_resp) set_of_elements = set_of_elements[element_api_codename] Builder_Elements[element_name].call(set_of_elements) Elements[element_name] rescue => e Elements[element_name] end end
Private Class Methods
# File lib/Appolo.rb, line 82 def self.build_result(result,error) Result.new(result, error) end
# File lib/Appolo.rb, line 74 def self.check_json_info(json_str) unless json_str.is_a? Hash JSON.parse json_str else json_str end end
# File lib/Appolo.rb, line 69 def self.verify_response(resp) #I dont like this nil.. (resp.code == 200) ? resp : nil end