Top Level Namespace

Defined Under Namespace

Classes: Bikepoint

Instance Method Summary collapse

Instance Method Details

#attachment(bikepoint) ⇒ Object


12
13
14
15
16
17
18
19
# File 'lib/slack_notification.rb', line 12

def attachment(bikepoint)
  field_text = "#{bikepoint.bikes} bikes\n#{bikepoint.spaces} spaces"
  {
    'fallback' => "#{bikepoint.name}: #{bikepoint.bikes} bikes, #{bikepoint.spaces} spaces",
    'color' => 'good',
    'fields' => [{ 'title' => bikepoint.name, 'value' => field_text }]
  }
end

#generate_bikepoints_markdownObject


8
9
10
11
12
13
14
15
# File 'lib/bikepoints_markdown_generator.rb', line 8

def generate_bikepoints_markdown
  File.open('BIKEPOINTS.md', 'w+') do |f|
    f.puts('# All Santander Cycles bikepoint names')
    f.puts('Copy all the names you wish to receive notifications for into a semi-colon separated
            list in the `BIKEPOINT_COMMON_NAMES` environment variable.')
    f.puts(to_markdown_list(Bikepoint.all_names).sort)
  end
end

#notify_on_slackObject


21
22
23
24
25
# File 'lib/slack_notification.rb', line 21

def notify_on_slack
  ENV['BIKEPOINT_COMMON_NAMES'].split(';').each do |bikepoint_name|
    post_to_slack_webhook(ENV['SLACK_WEBHOOK_URL'], Bikepoint.all[bikepoint_name])
  end
end

#post_to_slack_webhook(url, bikepoint) ⇒ Object


7
8
9
10
# File 'lib/slack_notification.rb', line 7

def post_to_slack_webhook(url, bikepoint)
  attachments = [attachment(bikepoint)]
  RestClient.post url, { 'attachments' => attachments }.to_json, content_type: :json, accept: :json
end

#to_markdown_list(array) ⇒ Object


4
5
6
# File 'lib/bikepoints_markdown_generator.rb', line 4

def to_markdown_list(array)
  array.map { |e| ('- ' + e) }
end