summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2016-09-14 20:59:56 -0400
committerRobert Speicher <rspeicher@gmail.com>2016-09-20 08:19:32 +0300
commitd834ee2c709fcd4fe0082adc22c2a3a7197b1e25 (patch)
tree9a9b231adbe124016164e52dea74a9233f4b489a
parent5550bbec106835584f5eb5be3a00fbf1d78585f4 (diff)
downloadgitlab-ce-rs-dry-akismet-service.tar.gz
Reduce duplication in AkismetServicers-dry-akismet-service
-rw-r--r--app/services/akismet_service.rb43
1 files changed, 16 insertions, 27 deletions
diff --git a/app/services/akismet_service.rb b/app/services/akismet_service.rb
index 5c60addbe7c..76b9f1feda7 100644
--- a/app/services/akismet_service.rb
+++ b/app/services/akismet_service.rb
@@ -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 = {
@@ -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