Class: Messenger::Campfire

Inherits:
Object
  • Object
show all
Defined in:
lib/messenger/campfire.rb

Class Method Summary collapse

Class Method Details

.deliver(url, body, options = {}) ⇒ Object

URL format:

campfire://api-key:[email protected]


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/messenger/campfire.rb', line 14

def self.deliver(url, body, options={})
  raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url)
  ssl, api_key, room, subdomain = matcher(url)
  options[:headers] ||= {}
  response = HTTParty.post(
    "http#{ssl ? "s" : ""}://#{subdomain}.campfirenow.com/room/#{room}/speak.json",
    :headers => { "Content-Type" => "application/json"}.merge(options[:headers]),
    :body => { "message" => { "body" => body } }.to_json,
    :basic_auth => {:username => api_key, :password => 'x'}
  )
  Messenger::Result.new(success?(response), response)
end

.obfuscate(url) ⇒ Object



27
28
29
30
31
# File 'lib/messenger/campfire.rb', line 27

def self.obfuscate(url)
  raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url)
  ssl, api_key, room, subdomain = matcher(url)
  "campfire#{ssl ? "-ssl" : ""}://xxxx:#{room}@#{subdomain}.campfirenow.com"
end

.valid_url?(url) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
# File 'lib/messenger/campfire.rb', line 6

def self.valid_url?(url)
  !!matcher(url)
rescue NoMethodError
  false
end