ft_42 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ft_42.rb +37 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1de92e1b2395f0aca367f9a9824ff379b22d5168
|
4
|
+
data.tar.gz: adbaba8cf515a66415e99fc90766991922a3e4ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 315726ad581ebbfd9fc6fbc16ad097910b332c6221d9d7eabb61fb41b2d47734b1a6df643c19222a25872f2706e4346707b9d786c3be4d059465a7215cd88650
|
7
|
+
data.tar.gz: 6cbdac9a0515aea813b3509707703dac8737693adcb19419679524697ed72a1c3933a16a7b54a95ab63d91a2246027c52c50edc0629f6a8686f313ef386aed57
|
data/lib/ft_42.rb
CHANGED
@@ -13,10 +13,14 @@ module Constants
|
|
13
13
|
HOURS_CHALLENGE = 100
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
16
|
class FT_42
|
18
17
|
def initialize(*args)
|
19
|
-
|
18
|
+
if (args.size > 2)
|
19
|
+
puts "This could take a while..."
|
20
|
+
ft_42 = Client.new(args.first, args.third)
|
21
|
+
else
|
22
|
+
ft_42 = Client.new(args.first)
|
23
|
+
end
|
20
24
|
user = User.new(ft_42.user)
|
21
25
|
user_sessions = UserSessions.new(ft_42.user_sessions)
|
22
26
|
user_print = UserPrinter.new(user)
|
@@ -24,33 +28,41 @@ class FT_42
|
|
24
28
|
if args.size == 1
|
25
29
|
user_print.all
|
26
30
|
user_sessions_print.all
|
31
|
+
elsif args.second == "sessions"
|
32
|
+
user_sessions_print.sessions
|
33
|
+
else
|
34
|
+
puts"Wrong arguments. Usage ft_42 [USER_LOGIN] [OPTIONAL CMD]"
|
27
35
|
end
|
28
36
|
end
|
29
37
|
end
|
30
38
|
|
31
39
|
|
32
40
|
class Client
|
33
|
-
attr_reader :username, :token
|
41
|
+
attr_reader :username, :token, :weeks_ago
|
34
42
|
|
35
|
-
def initialize(username)
|
36
|
-
@username
|
37
|
-
@
|
43
|
+
def initialize(username, weeks_ago = nil)
|
44
|
+
@username = username
|
45
|
+
@weeks_ago = weeks_ago
|
46
|
+
@token = Token.new.token
|
38
47
|
end
|
39
48
|
|
40
49
|
def user
|
41
|
-
puts "Getting #{username}'s info..."
|
42
50
|
token.get("/v2/users/#{username}", params: { per_page: 100 }).parsed
|
43
51
|
end
|
44
52
|
|
45
53
|
def user_sessions
|
46
|
-
puts "Getting #{username}'s session this week..."
|
47
54
|
token.get("/v2/users/#{username}/locations?range[end_at]=#{time_ago},#{right_now}", params: { per_page: 100 }).parsed
|
48
55
|
end
|
49
56
|
|
50
57
|
private
|
51
58
|
|
52
59
|
def time_ago
|
53
|
-
|
60
|
+
if weeks_ago
|
61
|
+
time = Time.current - (weeks_ago.to_i * 7).days
|
62
|
+
return time.to_s.split(" ")[0...-1].join("T")
|
63
|
+
else
|
64
|
+
return Time.current.beginning_of_week.to_s.split(" ")[0...-1].join("T")
|
65
|
+
end
|
54
66
|
end
|
55
67
|
|
56
68
|
def right_now
|
@@ -255,6 +267,22 @@ class UserSessionsPrinter
|
|
255
267
|
hours_this_week
|
256
268
|
end
|
257
269
|
|
270
|
+
def sessions
|
271
|
+
unless user_sessions.sessions.empty?
|
272
|
+
user_sessions.sessions.each do |session|
|
273
|
+
session_start = "Session start: " + session.begin_at.to_time.strftime("%A, %B %d at %I:%M:%S %p")
|
274
|
+
session_end = "Session end: " + session.end_at.to_time.strftime("%A, %B %d at %I:%M:%S %p")
|
275
|
+
duration_in_hours = ActiveSupport::NumberHelper.number_to_rounded((session.end_at.to_time - session.begin_at.to_time) / 60 / 60, :precision => 2)
|
276
|
+
puts
|
277
|
+
puts "Session duration: " + highlight("#{duration_in_hours} hours")
|
278
|
+
puts session_start
|
279
|
+
puts session_end
|
280
|
+
puts "Session host: " + session.host + " at " + cluster(session.host)
|
281
|
+
end
|
282
|
+
puts
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
258
286
|
def active_or_last_active
|
259
287
|
unless user_sessions.sessions.empty?
|
260
288
|
active = false
|