Sha256: de08023c21a52a710c28ce2ae0e49f35af7d39bbd6d43f1ad8d736c5cc2e4862

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require 'net/http'
require 'json'
require 'capistrano/blaze/version'
require 'capistrano/blaze/message'
require 'capistrano/blaze/configuration'
require 'capistrano/blaze/recipes' if defined?(Capistrano::Configuration)

module Capistrano
  module Blaze
    extend self

    def configure
      yield configuration
    end

    def configuration
      @configuration ||= Configuration.new
    end

    def speak(message)
      configuration.validate!
      port = configuration.ssl ? 443 : 80

      req = Net::HTTP::Post.new("/room/#{configuration.room_id}/speak.json")
      req.basic_auth configuration.token, 'X'
      req.body = { :message => { :body => message } }.to_json
      req.content_type = "application/json"
      req["User-Agent"] = "Capistrano::Blaze"

      res = Net::HTTP.start("#{configuration.account}.campfirenow.com", port, :use_ssl => configuration.ssl) do |http|
        http.request(req)
      end

      if res.is_a?(Net::HTTPSuccess)
        warn "Campfire message sent!"
      else
        warn "Campfire communication failed!"
        warn res.inspect
        warn res.body.inspect
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capistrano-blaze-0.2.0 lib/capistrano/blaze.rb