Skip to content
Snippets Groups Projects
Commit d834ee2c authored by Robert Speicher's avatar Robert Speicher
Browse files

Reduce duplication in AkismetService

parent 5550bbec
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -29,25 +29,25 @@ class AkismetService
end
 
def submit_ham
return false unless akismet_enabled?
submit(:ham)
end
 
params = {
type: 'comment',
text: text,
author: owner.name,
author_email: owner.email
}
def submit_spam
submit(:spam)
end
 
begin
akismet_client.submit_ham(options[:ip_address], options[:user_agent], params)
true
rescue => e
Rails.logger.error("Unable to connect to Akismet: #{e}, skipping!")
false
end
private
def akismet_client
@akismet_client ||= ::Akismet::Client.new(current_application_settings.akismet_api_key,
Gitlab.config.gitlab.url)
end
 
def submit_spam
def akismet_enabled?
current_application_settings.akismet_enabled
end
def submit(type)
return false unless akismet_enabled?
 
params = {
Loading
Loading
@@ -58,22 +58,11 @@ class AkismetService
}
 
begin
akismet_client.submit_spam(options[:ip_address], options[:user_agent], params)
akismet_client.public_send(type, options[:ip_address], options[:user_agent], params)
true
rescue => e
Rails.logger.error("Unable to connect to Akismet: #{e}, skipping!")
false
end
end
private
def akismet_client
@akismet_client ||= ::Akismet::Client.new(current_application_settings.akismet_api_key,
Gitlab.config.gitlab.url)
end
def akismet_enabled?
current_application_settings.akismet_enabled
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment