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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ft_42.rb +37 -9
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee8455922c793c66e2c06cfc25d93e660c129fbb
4
- data.tar.gz: fa2ec6a5bd91395d33b8aa5c92f5bdd8c9a307ba
3
+ metadata.gz: 1de92e1b2395f0aca367f9a9824ff379b22d5168
4
+ data.tar.gz: adbaba8cf515a66415e99fc90766991922a3e4ba
5
5
  SHA512:
6
- metadata.gz: 6c6c10242e7ca2d0ed67ed12f2da59701495f8021eeaf2499ed993ce2d802f8b5db0b652d215a6027d5aa31a42237048f617ff610a82bf8b566c36375fccc080
7
- data.tar.gz: a53115729bd3f1ede65206454617e4f568a526a0e36a107b81ad63a83d8639f1786fb7bc4d4186446ac6e6779c10993c8b47673dbd35df0b6f7a38f898715299
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
- ft_42 = Client.new(args.first)
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 = username
37
- @token = Token.new.token
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
- Time.current.beginning_of_week.to_s.split(" ")[0...-1].join("T")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ft_42
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matias Fernandez