Class: Spam::AkismetService
- Inherits:
-
Object
- Object
- Spam::AkismetService
- Defined in:
- app/services/spam/akismet_service.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(owner_name, owner_email, text, options = {}) ⇒ AkismetService
constructor
A new instance of AkismetService.
- #spam? ⇒ Boolean
- #submit_ham ⇒ Object
- #submit_spam ⇒ Object
Constructor Details
#initialize(owner_name, owner_email, text, options = {}) ⇒ AkismetService
Returns a new instance of AkismetService.
7 8 9 10 11 12 |
# File 'app/services/spam/akismet_service.rb', line 7 def initialize(owner_name, owner_email, text, = {}) @owner_name = owner_name @owner_email = owner_email @text = text @options = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'app/services/spam/akismet_service.rb', line 5 def @options end |
#text ⇒ Object
Returns the value of attribute text.
5 6 7 |
# File 'app/services/spam/akismet_service.rb', line 5 def text @text end |
Instance Method Details
#spam? ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/spam/akismet_service.rb', line 14 def spam? return false unless params = { type: 'comment', text: text, created_at: DateTime.current, author: owner_name, author_email: owner_email, # NOTE: The akismet_client needs the option to be named `:referrer`, not `:referer` referrer: [:referer] } begin is_spam, is_blatant = .check([:ip_address], [:user_agent], params) is_spam || is_blatant rescue ArgumentError => e Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e) false rescue StandardError => e Gitlab::ErrorTracking.track_exception(e) Gitlab::AppLogger.error("Error during Akismet spam check, flagging as not spam: #{e}") false end end |
#submit_ham ⇒ Object
40 41 42 |
# File 'app/services/spam/akismet_service.rb', line 40 def submit_ham submit(:ham) end |
#submit_spam ⇒ Object
44 45 46 |
# File 'app/services/spam/akismet_service.rb', line 44 def submit_spam submit(:spam) end |