susies 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 231a7208b3e4000328f8260676aa1412a96372af
4
- data.tar.gz: 24a9607e3371480fc777fc85c7ce936ce3d502cd
3
+ metadata.gz: cf7da5127df09154bacf3cbb580d41f61ebfda47
4
+ data.tar.gz: 082c4d806dcceac2c188c0057c18569ce91bcf9c
5
5
  SHA512:
6
- metadata.gz: d6db7cadda7408b3aca1d33590ffacf2c3a3c4cc4f796bce18e4a636e8c205282094579abc4304f68709426feb5e4343347c20f9e714439d2ce600b694377c41
7
- data.tar.gz: a373a9962f28f5c76cd9f897981bbf80c118fe7c11d19cc99dd7761b10a3a487b7181b421f7f4d869ea9a7a1e9e9d41a484be39df003089eacd619adeac679a6
6
+ metadata.gz: 2ffc7e22c0a978a4b1c9c98c0d62e4be0dbd8f626a116a6b907f1bc9cf7cad8d43aa71806d2cdff06e019fdfa1c4de126cda436d2fe22b04635432a22d7ce3cb
7
+ data.tar.gz: 1bb0a3d5e2efe415593417ac9728d71a1af7cf26625419d04274ef6a285a63d8fb482986a8364c7a912909db43a398430393a034b87d17521b66dfb37d2e31e4
@@ -4,15 +4,11 @@ require 'net/http'
4
4
  require 'json'
5
5
 
6
6
  class IntraRequestsManager
7
-
8
- INTRA_BASE_URL = 'intra.epitech.eu'
9
- LIST_SUSIES_PATH = '/planning/1919/events'
10
- REGISTER_SUSIE_PATH = '/planning/1919'
11
-
12
7
 
13
8
  def initialize
14
- @http = Net::HTTP.new INTRA_BASE_URL, 443
9
+ @http = Net::HTTP.new 'intra.epitech.eu', 443
15
10
  @http.use_ssl = true
11
+ @planningID = 0
16
12
  end
17
13
 
18
14
 
@@ -21,19 +17,36 @@ class IntraRequestsManager
21
17
 
22
18
  response_cookies = response.get_fields 'set-cookie'
23
19
  cookies_array = response_cookies.collect { |cookie| cookie.split('; ').first }
24
-
25
20
  @cookies = cookies_array.join('; ')
21
+
22
+ fetchPlanningID!
23
+ end
24
+
25
+ def fetchPlanningID!
26
+ path = "/planning/all-schedules/?format=json"
27
+ response = @http.get path, { 'Cookie' => @cookies }
28
+
29
+ planningsJSON = JSON.parse response.body
30
+
31
+ unless planningsJSON.nil?
32
+ planningsJSON.each do |planning|
33
+ if planning['type'] == 'susie'
34
+ @planningID = planning['id']
35
+ break
36
+ end
37
+ end
38
+ end
26
39
  end
27
40
 
28
41
 
29
42
  def getSusies(startDate, endDate)
30
- path = "#{ LIST_SUSIES_PATH }?start=#{ formatDate startDate }&end=#{ formatDate endDate }&format=json"
43
+ path = "/planning/#{ @planningID }/events?start=#{ formatDate startDate }&end=#{ formatDate endDate }&format=json"
31
44
  response = @http.get path, { 'Cookie' => @cookies }
32
45
 
33
46
  susiesJSON = JSON.parse response.body
34
47
 
35
48
  unless susiesJSON.nil?
36
- susiesJSON.collect { |susieJSON| Susie.new susieJSON }
49
+ susiesJSON.collect { |susieJSON| Susie.new susieJSON, "https://intra.epitech.eu/planning/#{ @planningID }/#{ susieJSON['id'] }" }
37
50
  else
38
51
  []
39
52
  end
@@ -41,7 +54,7 @@ class IntraRequestsManager
41
54
 
42
55
 
43
56
  def registerSusie(susie)
44
- path = "#{ REGISTER_SUSIE_PATH }/#{ susie.id }/subscribe?format=json&registercalendar"
57
+ path = "/planning/#{ @planningID }/#{ susie.id }/subscribe?format=json&registercalendar"
45
58
  response = @http.post path, '', { 'Cookie' => @cookies }
46
59
 
47
60
  susie.nb_registered -= 1
data/lib/Susie.rb CHANGED
@@ -6,7 +6,7 @@ class Susie
6
6
  attr_accessor :is_registered, :nb_registered, :login, :id, :start, :end, :type, :title, :description, :url
7
7
 
8
8
 
9
- def initialize(susieJSON)
9
+ def initialize(susieJSON, susieURL = "")
10
10
  self.id = susieJSON['id']
11
11
  self.title = susieJSON['title']
12
12
  self.type = susieJSON['type']
@@ -16,7 +16,7 @@ class Susie
16
16
  self.end = Time.parse susieJSON['end']
17
17
  self.is_registered = susieJSON['event_registered']
18
18
  self.nb_registered = susieJSON['registered']
19
- self.url = "#{ IntraRequestsManager::INTRA_BASE_URL }#{ IntraRequestsManager::REGISTER_SUSIE_PATH }/#{ self.id }"
19
+ self.url = susieURL
20
20
  end
21
21
 
22
22
 
data/susies.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'susies'
3
- s.version = '0.1.0'
4
- s.date = '2014-09-28'
3
+ s.version = '0.1.1'
4
+ s.date = '2014-10-07'
5
5
  s.summary = 'Epitech Susie Classes Bot'
6
6
  s.description = 'Susies is a Gem to register easily for Epitech Susie Classes'
7
7
  s.authors = ['Simon Ninon']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: susies
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Ninon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-28 00:00:00.000000000 Z
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Susies is a Gem to register easily for Epitech Susie Classes
14
14
  email: simon.ninon@gmail.com