Sha256: d04a00fc30e4d0617a9766fb213d01267d2b7f03249d3c4f54329b4b681c0fff

Contents?: true

Size: 1.28 KB

Versions: 9

Compression:

Stored size: 1.28 KB

Contents

class CC::Service::Campfire < CC::Service
  class Config < CC::Service::Config
    attribute :subdomain, String,
      description: "The Campfire subdomain for the account"
    attribute :token, String,
      description: "Your Campfire API auth token"
    attribute :room_id, String,
      description: "Check your campfire URL for a room ID. Usually 6 digits."

    validates :subdomain, presence: true
    validates :room_id, presence: true
    validates :token, presence: true
  end

  self.description = "Send messages to a Campfire chat room"

  def receive_test
    speak(formatter.format_test).merge(
      message: "Test message sent"
    )
  end

  def receive_coverage
    speak(formatter.format_coverage)
  end

  def receive_quality
    speak(formatter.format_quality)
  end

  def receive_vulnerability
    speak(formatter.format_vulnerability)
  end

  private

  def formatter
    CC::Formatters::PlainFormatter.new(self)
  end

  def speak(line)
    http.headers['Content-Type']  = 'application/json'
    params = { message: { body: line } }

    http.basic_auth(config.token, "X")
    service_post(speak_uri, params.to_json)
  end

  def speak_uri
    subdomain = config.subdomain
    room_id = config.room_id
    "https://#{subdomain}.campfirenow.com/room/#{room_id}/speak.json"
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
codeclimate-services-0.6.1 lib/cc/services/campfire.rb
codeclimate-services-0.6.0 lib/cc/services/campfire.rb
codeclimate-services-0.5.3 lib/cc/services/campfire.rb
codeclimate-services-0.5.2 lib/cc/services/campfire.rb
codeclimate-services-0.5.1 lib/cc/services/campfire.rb
codeclimate-services-0.5.0 lib/cc/services/campfire.rb
codeclimate-services-0.4.1 lib/cc/services/campfire.rb
codeclimate-services-0.4.0 lib/cc/services/campfire.rb
codeclimate-services-0.3.0 lib/cc/services/campfire.rb