fuck_facebook 0.5.0 → 0.5.4

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
  SHA256:
3
- metadata.gz: 4444d134e1ae1d10b948ae6432691f99c1c22498aea2f0530359b0c93a1df967
4
- data.tar.gz: b276c6b4a680c546b2b34366b5e28cd1af620ef7800ae7f2964bbded6235eff8
3
+ metadata.gz: f39f95c1ab04f9becec05ea79cb6f07c90d93628ef94c121394a6cdffe195098
4
+ data.tar.gz: 80c4db15e83c546edac23505e9d277c3b92219aae9ba731cf4bcc2132681e8d6
5
5
  SHA512:
6
- metadata.gz: 2e9a2254136c1886d20e7f164bbf1cf9d06d1a6191ed7522df717db580b6eea1b48f9ab5c9caebb9b84c75bc24f8467e0c92b30d5bae5f1131a99b7a6bb93b94
7
- data.tar.gz: 5b930019d90be80fb751a487c2b71b0021278dc1952fd2a61baac57b7e88a4bcfc33be612699193bd6caeeb1c43a5fb0b7a231fce555d41c32e6d69a6cb93185
6
+ metadata.gz: a9a9e910c17f7d70698e77a9c690168d52fc42898034a778673d823ec1e36a8d15e2d9c7106f59c6f525495ac850877af34810b9d1024a3f77f7cd6e95e4d3c3
7
+ data.tar.gz: 3100461e7973a50441f53145df781f6d8555cbe57f078cdd1991a48d25c2ca5af29d6bd3892581ccb2748000bc9b382fbfa164978bfa6e41b434945b75cba40f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fuck_facebook (0.4.1)
4
+ fuck_facebook (0.5.3)
5
5
  activesupport (~> 6.1)
6
6
  highline (~> 2.0)
7
7
  mail (~> 2.7)
@@ -1,3 +1,3 @@
1
1
  module FuckFacebook
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.5.4'.freeze
3
3
  end
data/src/config.rb CHANGED
@@ -3,16 +3,15 @@ require 'yaml'
3
3
  class Config
4
4
  CONFIG_FILE_PATH = "#{ENV['HOME']}/.local/share/fuck-facebook/config.yaml".freeze
5
5
 
6
- def self.option(*path, default: nil)
6
+ def self.option(*path, default: nil, type: nil)
7
7
  env_var = "FF_#{path.join('_').upcase}"
8
- return ENV[env_var] if ENV[env_var]
9
-
10
8
  path_strings = path.map(&:to_s)
11
- value = config.dig(*path_strings)
12
9
 
13
- return value if value
10
+ value = config.dig(*path_strings)
11
+ value = ENV[env_var] if ENV[env_var]
12
+ value = default if value.nil?
14
13
 
15
- default
14
+ cast_value_to_type(value, type)
16
15
  end
17
16
 
18
17
  def self.config
@@ -26,4 +25,23 @@ class Config
26
25
  FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
27
26
  File.write(CONFIG_FILE_PATH, '{}') unless File.exist?(CONFIG_FILE_PATH)
28
27
  end
28
+
29
+ private_class_method def self.cast_value_to_type(value, type)
30
+ case type
31
+ when nil
32
+ value
33
+ when :boolean
34
+ cast_value_to_boolean(value)
35
+ when :float
36
+ value.to_f
37
+ end
38
+ end
39
+
40
+ private_class_method def self.cast_value_to_boolean(value)
41
+ if [true, false].include?(value)
42
+ value
43
+ elsif value.is_a?(String)
44
+ value == 'true'
45
+ end
46
+ end
29
47
  end
@@ -2,16 +2,23 @@ class ErrorReporter
2
2
  def self.report_error(sender_name, error, facebook_connection: nil)
3
3
  raise error unless report_error?
4
4
 
5
- Storage.set(:last_error_reported_time, Time.now)
6
-
7
5
  screenshot = include_screenshot?(facebook_connection) ? create_screenshot(facebook_connection) : nil
8
6
 
9
7
  Senders.by_name(sender_name).send_error(error, screenshot: screenshot)
8
+
9
+ Storage.set(:last_error_reported_time, Time.now)
10
10
  raise error
11
11
  end
12
12
 
13
13
  private_class_method def self.include_screenshot?(facebook_connection)
14
- Config.option(:errors, :include_screenshot) && facebook_connection.present?
14
+ include_screenshot_config = Config.option(
15
+ :errors,
16
+ :include_screenshot,
17
+ default: false,
18
+ type: :boolean
19
+ )
20
+
21
+ include_screenshot_config && facebook_connection.present?
15
22
  end
16
23
 
17
24
  private_class_method def self.create_screenshot(facebook_connection)
@@ -21,7 +28,12 @@ class ErrorReporter
21
28
  end
22
29
 
23
30
  private_class_method def self.report_error?
24
- min_minutes_between_reports = Config.option(:errors, :min_minutes_between_reports, default: 0)
31
+ min_minutes_between_reports = Config.option(
32
+ :errors,
33
+ :min_minutes_between_reports,
34
+ default: 0,
35
+ type: :float
36
+ )
25
37
 
26
38
  last_error_reported_time = Storage.get(:last_error_reported_time, default: Time.new(2000))
27
39
 
data/src/fb_duration.rb CHANGED
@@ -3,29 +3,40 @@ require 'active_support/core_ext/numeric/time'
3
3
  class FbDuration
4
4
  DURATION_LETTER_TO_METHOD = {
5
5
  'm' => :minutes,
6
- 'd' => :days,
7
6
  'h' => :hours,
7
+ 'd' => :days,
8
8
  'w' => :weeks,
9
9
  'y' => :years
10
10
  }.freeze
11
11
 
12
12
  DURATION_LETTER_TO_BEGINNING_OF_METHOD = {
13
13
  'm' => :beginning_of_minute,
14
- 'd' => :beginning_of_day,
15
14
  'h' => :beginning_of_hour,
15
+ 'd' => :beginning_of_day,
16
16
  'w' => :beginning_of_week,
17
17
  'y' => :beginning_of_year
18
18
  }.freeze
19
19
 
20
+ # TODO: Fill in d w y extra time to add
21
+ ROUNDING_CORRECTION_TIMES = {
22
+ 'm' => 0,
23
+ 'h' => -5.minutes,
24
+ 'd' => 0,
25
+ 'w' => 0,
26
+ 'y' => 0
27
+ }
28
+
20
29
  def self.parse_to_time(facebook_format_duration)
21
30
  duration = parse(facebook_format_duration)
22
31
  time_to_beginning_of_duration_letter(Time.now - duration, facebook_format_duration)
23
32
  end
24
33
 
25
34
  def self.parse(facebook_format_duration)
26
- segments = facebook_format_duration.split
35
+ number, duration_letter = facebook_format_duration.split
36
+
37
+ rounding_correction_times = ROUNDING_CORRECTION_TIMES[duration_letter]
27
38
 
28
- segments[0].to_i.send(DURATION_LETTER_TO_METHOD[segments[1]])
39
+ number.to_i.send(DURATION_LETTER_TO_METHOD[duration_letter]) + rounding_correction_times
29
40
  end
30
41
 
31
42
  def self.time_to_beginning_of_duration_letter(time, facebook_format_duration)
@@ -53,12 +53,13 @@ class MessageHandler
53
53
  end
54
54
 
55
55
  def messages_after_last_message_time(messages)
56
- last_message_check_time = Storage.get(:last_message_check_time, default: Time.new(2004, 2, 4))
57
- last_check_time_with_buffer = last_message_check_time - 5.minutes
56
+ last_message_time = Storage.get(:last_message_time, default: Time.new(2004, 2, 4))
58
57
 
59
- messages_to_return = messages.select { _1.timestamp > last_check_time_with_buffer }
58
+ messages_to_return = messages.select { _1.timestamp > last_message_time }
60
59
 
61
- Storage.set(:last_message_check_time, Time.now)
60
+ last_message_time = messages.map(&:timestamp).max
61
+
62
+ Storage.set(:last_message_time, last_message_time)
62
63
 
63
64
  messages_to_return
64
65
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fuck_facebook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keeyan Nejad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-25 00:00:00.000000000 Z
11
+ date: 2021-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport