appolo 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ecc284a43e5df985d8dc112580091bbf85f59bb7
4
- data.tar.gz: 78fbd70effa5701950d40863f8e732349012700a
3
+ metadata.gz: 5d6f5d7cf36b6b63bd48ef55d6f39ccf372fda45
4
+ data.tar.gz: db2e520a27f22384907daf918ee94c5318f7e35d
5
5
  SHA512:
6
- metadata.gz: f4ba4b2b85bf5fa7765bf71e8848cca7e15e468c07efbb718a3fc0110c6c2e0811ef6e14fefa98e68069473d547bfe65d85c1cbc9859994f0c0cafe734afd3c5
7
- data.tar.gz: c1965a86e1dd129fbc52b7e9dd5f6deca8b41fdd2bd028d8ddf5f0e4351f28d09f98d4f2081e03232ec679804c6fefa42a2aca37b9215dc644e7b0076a7878f2
6
+ metadata.gz: 3e82c51ff707d454a815571ff4f1107bdde56d1100aa10f90f5e93750a9065861b5caf8032c0e28aae55fb675a887eef67dfa1b93ceb76b390c2ea4258c6150a
7
+ data.tar.gz: 1ce9eb4e2aec62595ac51974158ba15c9b8810cacae09436ad54a00a4aec24cc4f7c9a457c3f468ed39a3b6e581abcaaf802690f89eaf0b15953dde9ac6e6d08
data/Appolo.gemspec CHANGED
@@ -26,6 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'rspec', '~> 3.0'
27
27
  spec.add_development_dependency 'rest-client', '~> 1.8', '>= 1.8.0'
28
28
  spec.add_development_dependency 'json', '~> 1.8', '>= 1.8.3'
29
-
29
+ spec.add_development_dependency 'parallel', '~> 1.6.1'
30
30
 
31
31
  end
@@ -12,7 +12,16 @@ class Element
12
12
  def initialize (id, s_name, links, type_for_links)
13
13
  @id = id
14
14
  @short_name = s_name
15
- @links = Links.new(links, type_for_links)
15
+ @links = Links.new(links, type_for_links) unless links.nil?
16
+ end
17
+
18
+ def check_json_info(json_info)
19
+ if json_info.is_a? Hash
20
+ json_data = json_info
21
+ else
22
+ json_data = JSON.parse json_info
23
+ end
24
+ json_data
16
25
  end
17
26
 
18
27
  end
@@ -1,5 +1,6 @@
1
1
  require 'json'
2
2
  require 'rest-client'
3
+ require 'parallel'
3
4
  require_relative '../model_utils'
4
5
  require_relative '../secondary/links'
5
6
  require_relative '../secondary/avatar_url'
@@ -19,7 +20,7 @@ class Classes < Element
19
20
  # Initiate an instance of Classes based upon +json_info*
20
21
  # that can be an hash or a JSON string.
21
22
  def initialize(json_info)
22
- json_data = ModelUtils::check_json_info json_info
23
+ json_data = check_json_info json_info
23
24
 
24
25
  super(json_data[ModelUtils::ID],
25
26
  json_data[ModelUtils::CLASS_NAME],
@@ -69,9 +70,9 @@ class Classes < Element
69
70
  response_all_lectures = RestClient.get @links.lectures
70
71
  all_lectures = JSON.parse response_all_lectures
71
72
  temp = []
72
- all_lectures['classLectures'].each do |lecture|
73
- temp.push Lecture.new lecture
74
- end
73
+ temp = Parallel.each(all_lectures['classLectures'], :in_processes => 1){
74
+ |lecture| temp.push Lecture.new lecture
75
+ }
75
76
  temp
76
77
  end
77
78
 
@@ -81,9 +82,9 @@ class Classes < Element
81
82
  response_all_resources = RestClient.get @links.resources
82
83
  all_resources = JSON.parse response_all_resources
83
84
  temp = []
84
- all_resources['classResources'].each do |resource|
85
- temp.push Resource.new resource
86
- end
85
+ temp = Parallel.each(all_resources['classResources'], :in_processes => 1){
86
+ |resource| temp.push Resource.new resource
87
+ }
87
88
  temp
88
89
  end
89
90
 
@@ -8,11 +8,14 @@ class CourseUnit < Element
8
8
  attr_reader :name, :programs
9
9
 
10
10
  def initialize(json_info)
11
- super(json_info[ModelUtils::ID],
12
- json_info[ModelUtils::SHORT_NAME],
13
- json_info[ModelUtils::LINKS],
11
+
12
+ json_data = check_json_info json_info
13
+
14
+ super(json_data[ModelUtils::ID],
15
+ json_data[ModelUtils::SHORT_NAME],
16
+ json_data[ModelUtils::LINKS],
14
17
  @@type_of_links)
15
- @name = json_info[ModelUtils::NAME]
18
+ @name = json_data[ModelUtils::NAME]
16
19
 
17
20
  #@programs = TODO
18
21
  end
@@ -9,7 +9,7 @@ class LectiveSemester < Element
9
9
  @@type_of_links = 'lectiveSemesters'
10
10
 
11
11
  def initialize(json_str)
12
- json_data = ModelUtils.check_json_info json_str
12
+ json_data = check_json_info json_str
13
13
 
14
14
  super(json_data[ModelUtils::LECTIVE_ID],
15
15
  json_data[ModelUtils::SHORT_NAME],
@@ -9,7 +9,8 @@ class Program < Element
9
9
  @@type_for_links = 'programs'
10
10
 
11
11
  def initialize(data)
12
- json_data = ModelUtils::check_json_info data
12
+ json_data = check_json_info data
13
+
13
14
 
14
15
  super(json_data[ModelUtils::ID],
15
16
  json_data[ModelUtils::SHORT_NAME],
@@ -17,7 +17,7 @@ class Student < Element
17
17
  return
18
18
  end
19
19
 
20
- json_data = Appolo.check_json_info json_str
20
+ json_data = check_json_info json_str
21
21
 
22
22
  super(json_data[ModelUtils::ID],
23
23
  json_data[ModelUtils::SHORT_NAME],
@@ -11,7 +11,7 @@ class Teacher < Element
11
11
 
12
12
 
13
13
  def initialize(json_info)
14
- json_data = Appolo.check_json_info json_info
14
+ json_data = check_json_info json_info
15
15
 
16
16
  super(json_data[ModelUtils::ID],
17
17
  json_data[ModelUtils::SHORT_NAME],
@@ -24,7 +24,6 @@ class Teacher < Element
24
24
  @avatar_url = AvatarUrl.new(json_data[ModelUtils::AVATAR_URL])
25
25
  end
26
26
 
27
-
28
27
  def to_s
29
28
  "#{@id} - #{@short_name} : #{@academic_email}"
30
29
  end
@@ -47,13 +47,6 @@ module ModelUtils
47
47
  TITLE = 'title'
48
48
  DESCRIPTION = 'description'
49
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
50
+
58
51
 
59
52
  end
@@ -1,20 +1,21 @@
1
1
  require_relative '../model_utils'
2
+ require_relative '../element'
2
3
  require 'json'
3
4
  require 'rest-client'
4
5
 
5
6
  ##
6
7
  # This class represents a lecture given at some point in some class.
7
- class Lecture
8
+ class Lecture < Element
8
9
 
9
- attr_reader :id, :content, :date_created, :title
10
+ attr_reader :content, :date_created, :title
10
11
 
11
12
  ##
12
13
  # Create an instance of Lecture based upon +json_str+
13
14
  # that can be an hash or a JSON string.
14
15
  def initialize (json_str)
15
- json_data = Appolo.check_json_info json_str
16
+ json_data = check_json_info json_str
16
17
 
17
- @id = json_data[ModelUtils::ID]
18
+ super(json_data[ModelUtils::ID],nil,nil,nil)
18
19
  @content = json_data[ModelUtils::CONTENT]
19
20
  @date_created = json_data[ModelUtils::CREATED_WHEN]
20
21
  @title = json_data[ModelUtils::TITLE]
@@ -1,19 +1,23 @@
1
1
  require_relative 'links'
2
2
  require_relative '../model_utils'
3
3
 
4
- class Resource
4
+ class Resource < Element
5
5
 
6
- attr_reader :id, :description, :class_id, :title
7
- attr_reader :links
6
+ @@type_of_links = 'resources'
7
+
8
+ attr_reader :description, :class_id, :title
8
9
 
9
10
  def initialize(json_str)
10
- json_data = ModelUtils::check_json_info json_str
11
-
12
- @id = json_data[ModelUtils::ID]
11
+ json_data = check_json_info json_str
12
+
13
+ super(json_data[ModelUtils::ID],
14
+ nil,
15
+ json_data[ModelUtils::LINKS],
16
+ @@type_of_links)
17
+
13
18
  @description = json_data[ModelUtils::DESCRIPTION]
14
19
  @class_id = json_data[ModelUtils::CLASS_ID]
15
20
  @title = json_data[ModelUtils::TITLE]
16
- @links = Links.new json_data[ModelUtils::LINKS], 'resources'
17
21
  end
18
22
 
19
23
  def to_s
@@ -1,3 +1,3 @@
1
1
  module Appolo
2
- VERSION = '2.0.0'
2
+ VERSION = '2.0.1'
3
3
  end
data/lib/Appolo.rb CHANGED
@@ -26,7 +26,7 @@ module Appolo
26
26
 
27
27
  ##
28
28
  # This hash contains each hash structure that contains the different
29
- # elements after being requested by the method Appolo#get_set_of_elements
29
+ # elements after being requested by the method Appolo#get_set_of_elements.
30
30
  Elements = {
31
31
  :students => $all_students,
32
32
  :teachers => $all_teachers,
@@ -49,9 +49,14 @@ module Appolo
49
49
  :programs => 'https://adeetc.thothapp.com/api/v1/programs/',
50
50
  :courses => 'https://adeetc.thothapp.com/api/v1/courseunits/',
51
51
  :lec_semesters => 'https://adeetc.thothapp.com/api/v1/lectivesemesters'
52
-
53
52
  }
54
53
 
54
+ ##
55
+ # In order to build the hash of Link objects,
56
+ # each class must have a codename to append later
57
+ # during the construction. Since I dont believe in
58
+ # magical strings, I've putted all of those in here.
59
+
55
60
  Api_Codename = {
56
61
  :students => 'students',
57
62
  :teachers => 'teachers',
@@ -78,15 +83,62 @@ module Appolo
78
83
  Result.new(result, error)
79
84
  end
80
85
 
86
+ ##
87
+ # This hash contains the procs that build and populate the hashes
88
+ # that contain all the objects from the last made request.
89
+ # So, when we request all the students, the proc related to the symbol
90
+ # ":student" will be used to create the instances and insert them into the hash.
91
+
81
92
  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}}
93
+ students: lambda{
94
+ |students| students.each_with_index {
95
+ |student, idx|
96
+ stub = Student.new(student)
97
+ $all_students[idx] = stub
98
+ }
99
+ },
100
+ teachers: lambda{
101
+ |teachers| teachers.each_with_index {
102
+ |teacher, idx|
103
+ stub = Teacher.new(teacher)
104
+ $all_teachers[idx] =stub
105
+ }
106
+ },
107
+ classes: lambda{
108
+ |classes| classes.each_with_index{
109
+ |classe, idx|
110
+ stub = Classes.new(classe)
111
+ $all_classes[idx] = stub
112
+ }
113
+ },
114
+ programs: lambda{
115
+ |programs| programs.each_with_index{
116
+ |program, idx|
117
+ stub = Program.new(program)
118
+ $all_programs[idx] = stub
119
+ }
120
+ },
121
+ courses: lambda{
122
+ |courses| courses.each_with_index{
123
+ |course, idx|
124
+ stub = CourseUnit.new(course)
125
+ $all_courses[idx] = stub
126
+ }
127
+ },
128
+ lec_semesters: lambda{
129
+ |semesters| semesters.each_with_index{
130
+ |lec_sem, idx|
131
+ stub = LectiveSemester.new(lec_sem)
132
+ $all_lective_sem[idx] = stub
133
+ }
134
+ }
88
135
  }
89
136
 
137
+ ##
138
+ # This hash acts the same as Builder_Elements but instead of creating
139
+ # a set of elements, it creates only one since its purpose is to be used
140
+ # when the method Appolo#get_element_by_id is called.
141
+
90
142
  Builder_Element = {
91
143
  students: lambda{|data| Student.new(verify_response data)},
92
144
  teachers: lambda{|data| Teacher.new(verify_response data)},
@@ -99,7 +151,14 @@ module Appolo
99
151
  public
100
152
 
101
153
  ##
102
- #
154
+ # Call this method in order to get an array of elements.
155
+ # To specify which element to search you must specify +element_name+ as:
156
+ # * :students -> Set of Students
157
+ # * :teachers -> Set of Teachers
158
+ # * :classes -> Set of Classes
159
+ # * :programs -> Set of Programs
160
+ # * :courses -> Set of Courses
161
+ # * :lec_semesters -> Set of Lective Semesters
103
162
 
104
163
  def self.get_set_of_elements(element_name)
105
164
  return Elements[element_name] unless Elements[element_name].length == 0
@@ -116,6 +175,19 @@ module Appolo
116
175
  end
117
176
  end
118
177
 
178
+ ##
179
+ # Call this method in order to get a single element.
180
+ # To specify which element to search you must specify +element_name+ as:
181
+ # * :students -> Set of Students
182
+ # * :teachers -> Set of Teachers
183
+ # * :classes -> Set of Classes
184
+ # * :programs -> Set of Programs
185
+ # * :courses -> Set of Courses
186
+ # * :lec_semesters -> Set of Lective Semesters
187
+ #
188
+ # The +id+ specifies the *id* related to the element inside the Thoth API.
189
+ # _This gem is not responsible for the numbers used._
190
+
119
191
  def self.get_element_by_id(element_name, id)
120
192
  begin
121
193
  response = RestClient.get Api_Links[element_name] + id.to_s
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: 2.0.0
4
+ version: 2.0.1
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-06 00:00:00.000000000 Z
11
+ date: 2015-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,6 +92,20 @@ dependencies:
92
92
  - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: 1.8.3
95
+ - !ruby/object:Gem::Dependency
96
+ name: parallel
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: 1.6.1
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: 1.6.1
95
109
  description: |-
96
110
  Ruby gem that provides quick and easy access to the web api of Thoth WebApp -
97
111
  https://adeetc.thothapp.com/
@@ -107,9 +121,6 @@ files:
107
121
  - LICENSE.txt
108
122
  - README.md
109
123
  - Rakefile
110
- - bin/console
111
- - bin/example.rb
112
- - bin/setup
113
124
  - lib/Appolo.rb
114
125
  - lib/Appolo/Models/element.rb
115
126
  - lib/Appolo/Models/main_model/classes.rb
@@ -146,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
157
  version: '0'
147
158
  requirements: []
148
159
  rubyforge_project:
149
- rubygems_version: 2.4.5
160
+ rubygems_version: 2.4.8
150
161
  signing_key:
151
162
  specification_version: 4
152
163
  summary: Provides easy access to Thoth web API
data/bin/console DELETED
@@ -1,14 +0,0 @@
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 DELETED
@@ -1,30 +0,0 @@
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 DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here