1require 'slack-notifier'
 
2
 
3class NotifyTrendingIpJob < ApplicationJob
 
4  include Rails.application.routes.url_helpers
 
5
 
6  queue_as :low_priority
 
7
 
8  delegate :trending_items_notification_url, to: :rate_limit
 
 9
  • Complexity 1 » saikuro
10  def perform(ip)
 
11    slack.ping(message(ip))
 
12  end
 
 
14  private
 
  • FeatureEnvy - refers to 'params' more than self (maybe move it to another class?) » reek
  • TooManyStatements - has approx 7 statements » reek
  • Complexity 1 » saikuro
16  def message(ip)
 
17    params = []
 
18    params << ip.count
 
19    params << start_time(ip)
 
20    params << end_time(ip)
 
21    params << petition_link(ip)
 
22    params << ip_address_link(ip)
 
 
24    "%d signatures between %s and %s on %s from %s" % params
 
25  end
 
  • Complexity 1 » saikuro
27  def rate_limit
 
28    @rate_limit ||= RateLimit.first_or_create!
 
29  end
 
  • Complexity 1 » saikuro
31  def slack
 
32    @slack ||= Slack::Notifier.new(trending_items_notification_url)
 
33  end
 
  • Complexity 1 » saikuro
35  def time_format
 
36    "%-I:%M%P"
 
37  end
 
  • Complexity 1 » saikuro
39  def start_time(ip)
 
40    ip.starts_at.strftime(time_format)
 
41  end
 
  • Complexity 1 » saikuro
43  def end_time(ip)
 
44    ip.ends_at.strftime(time_format)
 
45  end
 
  • DuplicateMethodCall - calls 'ip.petition' 2 times » reek
  • FeatureEnvy - refers to 'ip' more than self (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
47  def petition_link(ip)
 
48    "<#{admin_petition_url(ip.petition)}|#{ip.petition.action}>"
 
49  end
 
  • DuplicateMethodCall - calls 'ip.ip_address' 2 times » reek
  • FeatureEnvy - refers to 'ip' more than self (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
51  def ip_address_link(ip)
 
52    "<#{admin_petition_signatures_url(ip.petition, q: ip.ip_address, window: ip.window)}|#{ip.ip_address}>"
 
53  end
 
54end