epitech_api 0.1.2 → 0.1.3

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: f9aa47121fcb332a5c89bf53789c206c1da88724
4
- data.tar.gz: 9c78ab50c4abec739c4acfe6c3d996df60bda660
3
+ metadata.gz: 67b007c5fab2d1b27993ab9a3668ede6f8dd09d1
4
+ data.tar.gz: 46056b75fd7c547db05a7f07ab52c08c25345e23
5
5
  SHA512:
6
- metadata.gz: 2020def9566af1514fbe5693e63fec59472c419f2e3efb41c591f9f1e75594ca7b1f725ddeb33fcee6f669620a48d36fa8cee0b5ce140678a1be1d4f0cbdfe6b
7
- data.tar.gz: a9c2905c7dc69d69b5e047d0decece2c9902ebda88e47e2c19fa55cda3f54b0a2d89fee444b46658028ffde757776ffffb220a1e6334db81cfbe6e358fe2c39e
6
+ metadata.gz: 2bf3f7b893a87873a95ec424abf428d7a7d25fa6f4eeb491c5abbe1965610f6d50e106889769286c0ce03f3428a9bd916f033bbd794b5d7d7ee5c569f931148d
7
+ data.tar.gz: 032cb5fc1367bb5b589fa9882d61811cf2d09fa4a68d9cad40f3114a05c9b05ac15eddde99c72548885ea66e62432fe691c04d3717b528f783c9ad648a192cc3
@@ -5,14 +5,8 @@
5
5
  </component>
6
6
  <component name="NewModuleRootManager">
7
7
  <content url="file://$MODULE_DIR$" />
8
- <orderEntry type="jdk" jdkName="Remote: ruby-2.3.1-p112" jdkType="RUBY_SDK" />
8
+ <orderEntry type="jdk" jdkName="ruby-2.3.1-p112" jdkType="RUBY_SDK" />
9
9
  <orderEntry type="sourceFolder" forTests="false" />
10
- <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.3, Remote: ruby-2.3.1-p112) [gem]" level="application" />
11
- <orderEntry type="library" scope="PROVIDED" name="json (v2.1.0, Remote: ruby-2.3.1-p112) [gem]" level="application" />
12
- <orderEntry type="library" scope="PROVIDED" name="rspec (v3.7.0, Remote: ruby-2.3.1-p112) [gem]" level="application" />
13
- <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.7.0, Remote: ruby-2.3.1-p112) [gem]" level="application" />
14
- <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.7.0, Remote: ruby-2.3.1-p112) [gem]" level="application" />
15
- <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.7.0, Remote: ruby-2.3.1-p112) [gem]" level="application" />
16
- <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.7.0, Remote: ruby-2.3.1-p112) [gem]" level="application" />
10
+ <orderEntry type="library" scope="PROVIDED" name="json (v2.1.0, ruby-2.3.1-p112) [gem]" level="application" />
17
11
  </component>
18
12
  </module>
@@ -0,0 +1,15 @@
1
+ module EpitechApi
2
+ class BasicStudent
3
+
4
+ attr_accessor :login, :first_name, :last_name, :location, :picture
5
+
6
+ def initialize(login, first_name, last_name, picture, location)
7
+ @login = login
8
+ @first_name = first_name
9
+ @last_name = last_name
10
+ @picture = picture
11
+ @location = location
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module EpitechApi
2
+ class Promo
3
+
4
+ attr_accessor :name, :size, :year, :location
5
+
6
+ def initialize(name, size, year, location)
7
+ @name = name
8
+ @size = size
9
+ @year = year
10
+ @location = location
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ require 'epitech_api/DataTypes/basic_student'
2
+
3
+ module EpitechApi
4
+ class Student < BasicStudent
5
+
6
+ attr_accessor :closed, :time_active, :time_needed
7
+
8
+ def initialize(login, first_name, last_name, picture, location, time_active, time_needed, closed)
9
+ @login = login
10
+ @first_name = first_name
11
+ @last_name = last_name
12
+ @picture = picture
13
+ @location = location
14
+ @time_active = time_active
15
+ @time_needed = time_needed
16
+ @closed = closed
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module EpitechApi
2
+ class InvalidParameters < ArgumentError
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module EpitechApi
2
+ class ResourceNotFound < Exception
3
+
4
+ end
5
+ end
@@ -0,0 +1,78 @@
1
+ require 'epitech_api/DataTypes/basic_student'
2
+
3
+ module EpitechApi
4
+ class PromoManager
5
+
6
+ def initialize(token)
7
+ @token = token
8
+ end
9
+
10
+ # @param [string] location base location for the promotion
11
+ # @param [number] year of activity of this promotion
12
+ # @return List of all promotions matching criteria
13
+ def list(location, year)
14
+ uri = URI("https://intra.epitech.eu/user/filter/promo?format=json&location=#{location}&year=#{year}&active=true")
15
+
16
+ req = Net::HTTP::Get.new uri
17
+ req['Cookie'] = "#{@token}"
18
+
19
+ http = Net::HTTP.new(uri.hostname, uri.port)
20
+ http.use_ssl = true
21
+
22
+ response = http.request req
23
+ raise InvalidRights unless response.code.to_i == 200
24
+ response_body = JSON.parse response.body
25
+
26
+ promos = []
27
+ response_body.each do |p|
28
+ promos.push Promo.new(p['promo'], p['students'].to_i, year, location)
29
+ end
30
+ promos
31
+ end
32
+
33
+ # @param [string] name Promo name
34
+ # @param [string] location location (ex FR/LIL)
35
+ # @param [number] year year of selected promotion
36
+ def get(name, location, year)
37
+ promos = list(location, year)
38
+ promos.each do |promo|
39
+ return promo if promo.name == name && promo.location == location && promo.year == year
40
+ end
41
+ raise ResourceNotFound
42
+ end
43
+
44
+ # @param [Promo] promo Promotion to extract students information
45
+ # @return Array<BasicUser>
46
+ def extract_students(promo)
47
+ students = []
48
+ idx = 0
49
+ while idx < promo.size
50
+ uri = URI("https://intra.epitech.eu/user/filter/user?format=json&location=#{promo.location}&year=#{promo.year}&active=true&promo=#{promo.name}&offset=#{idx}")
51
+
52
+ req = Net::HTTP::Get.new uri
53
+ req['Cookie'] = "#{@token}"
54
+
55
+ http = Net::HTTP.new(uri.hostname, uri.port)
56
+ http.use_ssl = true
57
+
58
+ response = http.request req
59
+
60
+ raise InvalidRights unless response.code.to_i == 200
61
+ response_body = JSON.parse response.body
62
+ students.push *convert_users(response_body['items'])
63
+ idx += response_body['items'].size
64
+ end
65
+ students
66
+ end
67
+
68
+ private
69
+
70
+ def convert_users(users)
71
+ students = []
72
+ users.each do |u|
73
+ students.push BasicStudent.new(u['login'], u['prenom'], u['nom'], u['picture'], u['location'])
74
+ end
75
+ students
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,27 @@
1
+ require 'epitech_api/DataTypes/student'
2
+
3
+ module EpitechApi
4
+ class UserManager
5
+
6
+ def initialize(token)
7
+ @token = token
8
+ end
9
+
10
+ def get(login)
11
+ uri = URI("https://intra.epitech.eu/user/#{login}/?format=json")
12
+
13
+ req = Net::HTTP::Get.new uri
14
+ req['Cookie'] = "#{@token}"
15
+
16
+ http = Net::HTTP.new(uri.hostname, uri.port)
17
+ http.use_ssl = true
18
+
19
+ response = http.request req
20
+
21
+ raise InvalidRights unless response.code.to_i == 200
22
+ body = JSON.parse response.body
23
+ Student.new body['login'], body['firstname'], body['lastname'], body['picture'], body['location'], body['nsstat']['active'], body['nsstat']['nslog_norm'], body['close']
24
+ end
25
+
26
+ end
27
+ end
@@ -1,26 +1,19 @@
1
+ require 'epitech_api/DataTypes/promo'
2
+ require 'epitech_api/Managers/promo_manager'
3
+ require 'epitech_api/Managers/user_manager'
4
+
5
+
1
6
  module EpitechApi
2
7
 
3
8
  class Gatherer
4
9
 
10
+ attr_accessor :promo_manager, :user_manager
11
+
5
12
  def initialize(token)
6
13
  @token = token
14
+ @promo_manager = PromoManager.new @token
15
+ @user_manager = UserManager.new @token
7
16
  end
8
17
 
9
- def promos(location, year)
10
- uri = URI("https://intra.epitech.eu/user/filter/promo?format=json&location=#{location}&year=#{year}&active=true")
11
- puts uri
12
-
13
- req = Net::HTTP::Get.new uri
14
- req['Cookie'] = "#{@token}"
15
-
16
- http = Net::HTTP.new(uri.hostname, uri.port)
17
- http.use_ssl = true
18
-
19
- response = http.request req
20
-
21
- puts response
22
- raise InvalidRights unless response.code.to_i == 200
23
- JSON.parse response.body
24
- end
25
18
  end
26
19
  end
@@ -0,0 +1,2 @@
1
+ require 'epitech_api/Providers/intra_provider'
2
+ require 'epitech_api/Providers/office_provider'
@@ -1,3 +1,3 @@
1
1
  module EpitechApi
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitech_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antoine FORET
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-22 00:00:00.000000000 Z
11
+ date: 2017-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -92,11 +92,19 @@ files:
92
92
  - bin/setup
93
93
  - epitech_api.gemspec
94
94
  - lib/epitech_api.rb
95
+ - lib/epitech_api/DataTypes/basic_student.rb
96
+ - lib/epitech_api/DataTypes/promo.rb
97
+ - lib/epitech_api/DataTypes/student.rb
95
98
  - lib/epitech_api/Exceptions/invalid_credentials.rb
99
+ - lib/epitech_api/Exceptions/invalid_parameters.rb
96
100
  - lib/epitech_api/Exceptions/invalid_rights.rb
97
- - lib/epitech_api/Provider/intra_provider.rb
98
- - lib/epitech_api/Provider/office_provider.rb
101
+ - lib/epitech_api/Exceptions/resource_not_found.rb
102
+ - lib/epitech_api/Managers/promo_manager.rb
103
+ - lib/epitech_api/Managers/user_manager.rb
104
+ - lib/epitech_api/Providers/intra_provider.rb
105
+ - lib/epitech_api/Providers/office_provider.rb
99
106
  - lib/epitech_api/gatherer.rb
107
+ - lib/epitech_api/providers.rb
100
108
  - lib/epitech_api/user.rb
101
109
  - lib/epitech_api/version.rb
102
110
  homepage: https://github.com/eliastre100/epitech-api-gem