Commit 78cee84a authored by charlieablett's avatar charlieablett

Refactor Akismet service

- Takes serialisable string arguments instead of an object
parent 67e3add6
# frozen_string_literal: true # frozen_string_literal: true
class AkismetService class AkismetService
attr_accessor :owner, :text, :options attr_accessor :text, :options
def initialize(owner, text, options = {}) def initialize(owner_name, owner_email, text, options = {})
@owner = owner @owner_name = owner_name
@owner_email = owner_email
@text = text @text = text
@options = options @options = options
end end
...@@ -16,8 +17,8 @@ class AkismetService ...@@ -16,8 +17,8 @@ class AkismetService
type: 'comment', type: 'comment',
text: text, text: text,
created_at: DateTime.now, created_at: DateTime.now,
author: owner.name, author: owner_name,
author_email: owner.email, author_email: owner_email,
referrer: options[:referrer] referrer: options[:referrer]
} }
...@@ -40,6 +41,8 @@ class AkismetService ...@@ -40,6 +41,8 @@ class AkismetService
private private
attr_accessor :owner_name, :owner_email
def akismet_client def akismet_client
@akismet_client ||= ::Akismet::Client.new(Gitlab::CurrentSettings.akismet_api_key, @akismet_client ||= ::Akismet::Client.new(Gitlab::CurrentSettings.akismet_api_key,
Gitlab.config.gitlab.url) Gitlab.config.gitlab.url)
...@@ -55,8 +58,8 @@ class AkismetService ...@@ -55,8 +58,8 @@ class AkismetService
params = { params = {
type: 'comment', type: 'comment',
text: text, text: text,
author: owner.name, author: owner_name,
author_email: owner.email author_email: owner_email
} }
begin begin
......
...@@ -18,8 +18,10 @@ class HamService ...@@ -18,8 +18,10 @@ class HamService
private private
def akismet def akismet
user = spam_log.user
@akismet ||= AkismetService.new( @akismet ||= AkismetService.new(
spam_log.user, user.name,
user.email,
spam_log.text, spam_log.text,
ip_address: spam_log.source_ip, ip_address: spam_log.source_ip,
user_agent: spam_log.user_agent user_agent: spam_log.user_agent
......
...@@ -56,7 +56,8 @@ class SpamService ...@@ -56,7 +56,8 @@ class SpamService
def akismet def akismet
@akismet ||= AkismetService.new( @akismet ||= AkismetService.new(
spammable_owner, spammable_owner.name,
spammable_owner.email,
spammable.spammable_text, spammable.spammable_text,
options options
) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment