fuck_facebook 0.3.0 → 0.4.0

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: 9f15615d0c24e530547c2a40e4509d434bc25578dde17737a5b8d8ef5fe2e68f
4
- data.tar.gz: e3c8a9d379b9df92d0d986bfb1dba35846779d32d4cf1bbf16ae39d1f778fae4
3
+ metadata.gz: 24caa7bf76958d703667ca687fb2bc9cf4aa7b6ea2bc56db68e08a13ab74bc08
4
+ data.tar.gz: 540bdba30c7e8b0761fde58f30d87decfbd6593f137e2d293e5a8b292c1c180d
5
5
  SHA512:
6
- metadata.gz: cffa79b7c7b58717a8507ba129668db846b40e6682621527b7799665d4fa74a5032a27ef471da20659ee01cd57662e82d85f76aff5b01e43a547d638e0c70374
7
- data.tar.gz: 4acc110f1bb5e7115b28a429594a5fc8459f402fcffe88391a7189687791d677e857117049227d656d977c00b5daac88b4bded2780b1044b81fdce8cc603f0e6
6
+ metadata.gz: fd41131b5187fe85b56adcb45d3d1f857d109bb925c0cf65012baf4aaf195d67317484593764a869eaf2b2ed18f336b98f47346031cfe000c1ced8cb1823afc7
7
+ data.tar.gz: 0c1873d36d15249e85311aabf4de4ed4517b0f378881a032e871b96a35d0c02db6113fe65f70980896633680df85efe70155d230d18e4c2824cf9d67e88dae7d
data/README.md CHANGED
@@ -36,6 +36,8 @@ smtp:
36
36
  authentication: plain
37
37
  ```
38
38
 
39
+ Place this file in `~/.local/share/fuck-facebook/config.yaml`
40
+
39
41
  These options can be passed as environment variables, by:
40
42
  * Joining the keys with `_`
41
43
  * Capitalizing the entire string
data/bin/fuck-facebook CHANGED
@@ -7,59 +7,22 @@ require_relative '../src/facebook_connection'
7
7
  require_relative '../src/config'
8
8
  require_relative '../src/initializers/mail_initializer'
9
9
  require_relative '../src/senders'
10
-
11
- options = {
12
- headless: true,
13
- clear_cookies: false,
14
- unread_messages: false,
15
- messages: false,
16
- sender: 'stdout'
17
- }
18
-
19
- OptionParser.new do |opts|
20
- opts.banner = 'Usage: fuck-facebook.rb [options]'
21
-
22
- opts.on('-h', '--[no-]headless', 'Run in a headless browser') do |v|
23
- options[:headless] = v
24
- end
25
-
26
- opts.on('--clear-cookies') do |v|
27
- options[:clear_cookies] = v
28
- end
29
-
30
- opts.on('--unread-messages') do |v|
31
- options[:unread_messages] = v
32
- end
33
-
34
- opts.on('--messages') do |v|
35
- options[:messages] = v
36
- end
37
-
38
- opts.on('--login') do |v|
39
- options[:login] = v
40
- end
41
-
42
- opts.on('--sender=SENDER') do |sender|
43
- options[:sender] = sender
44
- end
45
- end.parse!
46
-
47
- facebook_connection = FacebookConnection.new(headless: options[:headless])
48
-
49
- facebook_connection.cookie_handler.clear! if options[:clear_cookies]
50
-
51
- facebook_connection.login if options[:login]
52
-
53
- messages =
54
- if options[:unread_messages]
55
- facebook_connection.message_handler.unread
56
- elsif options[:messages]
57
- facebook_connection.message_handler.messages
58
- else
59
- []
60
- end
61
-
62
- sender = Senders.by_name(options[:sender])
63
- sender.send_messages(messages)
64
-
65
- facebook_connection.close
10
+ require_relative '../src/args_parser'
11
+ require_relative '../src/message_sender'
12
+ require_relative '../src/error_reporter'
13
+
14
+ options = ArgsParser.parse_args
15
+
16
+ begin
17
+ raise 'Error triggered by --simulate-error flag' if options[:simulate_error]
18
+
19
+ facebook_connection = FacebookConnection.new(headless: options[:headless])
20
+ facebook_connection.cookie_handler.clear! if options[:clear_cookies]
21
+ facebook_connection.login if options[:login]
22
+ message_sender = MessageSender.new(options[:sender], facebook_connection)
23
+ message_sender.send_unread_messages if options[:unread_messages]
24
+ message_sender.send_messages if options[:messages]
25
+ facebook_connection.close
26
+ rescue StandardError => e
27
+ ErrorReporter.report_error(options[:sender], e)
28
+ end
@@ -1,3 +1,3 @@
1
1
  module FuckFacebook
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -0,0 +1,82 @@
1
+ class ArgsParser
2
+ DEFAULT_OPTIONS = {
3
+ headless: true,
4
+ clear_cookies: false,
5
+ unread_messages: false,
6
+ messages: false,
7
+ sender: 'stdout',
8
+ simulate_error: false
9
+ }.freeze
10
+
11
+ AVAILABLE_OPTIONS = [
12
+ {
13
+ short: '-h',
14
+ long: '--[no-]headless',
15
+ message: 'Run in a headless browser',
16
+ option: :headless
17
+ },
18
+ {
19
+ short: nil,
20
+ long: '--clear-cookies',
21
+ message: 'Clears all cookies',
22
+ option: :clear_cookies
23
+ },
24
+ {
25
+ short: nil,
26
+ long: '--unread-messages',
27
+ message: 'Outputs all unread messages sent since the last check',
28
+ option: :unread_messages
29
+ },
30
+ {
31
+ short: nil,
32
+ long: '--messages',
33
+ message: 'Outputs all messages sent since the last check',
34
+ option: :messages
35
+ },
36
+ {
37
+ short: nil,
38
+ long: '--login',
39
+ message: 'Prompts for details to login to Facebook account',
40
+ option: :login
41
+ },
42
+ {
43
+ short: nil,
44
+ long: '--sender=SENDER',
45
+ message: 'Send results to either stdout or email',
46
+ option: :sender
47
+ },
48
+ {
49
+ short: nil,
50
+ long: '--simulate-error',
51
+ message: 'Simulates an error so you can see how it will be outputted',
52
+ option: :simulate_error
53
+ }
54
+ ].freeze
55
+
56
+ def self.parse_args
57
+ passed_options = DEFAULT_OPTIONS.dup
58
+
59
+ OptionParser.new do |opts|
60
+ generate_banner(opts)
61
+
62
+ AVAILABLE_OPTIONS.each do |available_option|
63
+ parser_for_available_option(opts, available_option, passed_options)
64
+ end
65
+ end.parse!
66
+
67
+ passed_options
68
+ end
69
+
70
+ private_class_method def self.generate_banner(opts)
71
+ opts.banner = 'Usage: fuck-facebook.rb [options]'
72
+ end
73
+
74
+ private_class_method def self.parser_for_available_option(opts, available_option, passed_options)
75
+ args = [available_option[:long], available_option[:message]]
76
+ args = [available_option[:short]] + args if available_option[:short]
77
+
78
+ opts.on(*args) do |v|
79
+ passed_options[available_option[:option]] = v
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,6 @@
1
+ class ErrorReporter
2
+ def self.report_error(sender_name, error)
3
+ Senders.by_name(sender_name).send_error(error)
4
+ raise error
5
+ end
6
+ end
@@ -0,0 +1,25 @@
1
+ class MessageSender
2
+ attr_accessor :sender_name, :facebook_connection
3
+
4
+ def initialize(sender_name, facebook_connection)
5
+ @sender_name = sender_name
6
+ @facebook_connection = facebook_connection
7
+ end
8
+
9
+ def send_unread_messages
10
+ messages = facebook_connection.message_handler.unread
11
+ send_array_of_messages(messages)
12
+ end
13
+
14
+ def send_messages
15
+ messages = facebook_connection.message_handler.messages
16
+ send_array_of_messages(messages)
17
+ end
18
+
19
+ private
20
+
21
+ def send_array_of_messages(messages)
22
+ sender = Senders.by_name(sender_name)
23
+ sender.send_messages(messages)
24
+ end
25
+ end
data/src/senders/email.rb CHANGED
@@ -10,5 +10,14 @@ module Senders
10
10
  end
11
11
  end
12
12
  end
13
+
14
+ def self.send_error(error)
15
+ Mail.deliver do
16
+ from Config.option(:smtp, :from_email)
17
+ to Config.option(:smtp, :to_email)
18
+ subject 'Error occurred during Fuck Facebook command'
19
+ body error.full_message(highlight: false)
20
+ end
21
+ end
13
22
  end
14
23
  end
@@ -5,5 +5,9 @@ module Senders
5
5
  puts message
6
6
  end
7
7
  end
8
+
9
+ def self.send_error(error)
10
+ puts error
11
+ end
8
12
  end
9
13
  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.3.0
4
+ version: 0.4.0
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-23 00:00:00.000000000 Z
11
+ date: 2021-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -94,13 +94,16 @@ files:
94
94
  - fuck_facebook.gemspec
95
95
  - lib/fuck_facebook.rb
96
96
  - lib/fuck_facebook/version.rb
97
+ - src/args_parser.rb
97
98
  - src/authenticator.rb
98
99
  - src/config.rb
99
100
  - src/cookie_handler.rb
101
+ - src/error_reporter.rb
100
102
  - src/facebook_connection.rb
101
103
  - src/fb_duration.rb
102
104
  - src/initializers/mail_initializer.rb
103
105
  - src/message_handler.rb
106
+ - src/message_sender.rb
104
107
  - src/models/message.rb
105
108
  - src/models/message_thread.rb
106
109
  - src/models/user.rb