Sha256: dba72fee2110bb50e07dcbc64886f6b0385635084da2c4c8428194f45286c3f5

Contents?: true

Size: 1.6 KB

Versions: 13

Compression:

Stored size: 1.6 KB

Contents

require "json"

module Backup
  module Notifier
    class Campfire < Base
      ##
      # Campfire api authentication token
      attr_accessor :api_token

      ##
      # Campfire account's subdomain
      attr_accessor :subdomain

      ##
      # Campfire account's room id
      attr_accessor :room_id

      def initialize(model, &block)
        super
        instance_eval(&block) if block_given?
      end

      private

      ##
      # Notify the user of the backup operation results.
      #
      # `status` indicates one of the following:
      #
      # `:success`
      # : The backup completed successfully.
      # : Notification will be sent if `on_success` is `true`.
      #
      # `:warning`
      # : The backup completed successfully, but warnings were logged.
      # : Notification will be sent if `on_warning` or `on_success` is `true`.
      #
      # `:failure`
      # : The backup operation failed.
      # : Notification will be sent if `on_warning` or `on_success` is `true`.
      #
      def notify!(status)
        send_message(message.call(model, status: status_data_for(status)))
      end

      def send_message(message)
        uri = "https://#{subdomain}.campfirenow.com/room/#{room_id}/speak.json"
        options = {
          headers: { "Content-Type" => "application/json" },
          body: JSON.dump(
            message: { body: message, type: "Textmessage" }
          )
        }
        options[:user] = api_token
        options[:password] = "x" # Basic Auth
        options[:expects] = 201 # raise error if unsuccessful
        Excon.post(uri, options)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
backup-5.0.0.beta.3 lib/backup/notifier/campfire.rb
backedup-5.0.0.beta.5 lib/backup/notifier/campfire.rb
backedup-5.0.0.beta.4 lib/backup/notifier/campfire.rb
backedup-5.0.0.beta.3 lib/backup/notifier/campfire.rb
ext_backup-5.0.0.beta.2.1 lib/backup/notifier/campfire.rb
ext_backup-5.0.0.beta.2.ext.0.1.2 lib/backup/notifier/campfire.rb
ext_backup-5.0.0.beta.2.ext.0.1.1 lib/backup/notifier/campfire.rb
ext_backup-5.0.0.beta.2.ext.0.1.0 lib/backup/notifier/campfire.rb
backup-5.0.0.beta.2 lib/backup/notifier/campfire.rb
backup-5.0.0.beta.1 lib/backup/notifier/campfire.rb
backup-bouchard-4.4.4 lib/backup/notifier/campfire.rb
backup-bouchard-4.4.2 lib/backup/notifier/campfire.rb
backup-bouchard-4.4.1 lib/backup/notifier/campfire.rb