Class: Messenger::Campfire
- Inherits:
-
Object
- Object
- Messenger::Campfire
- Defined in:
- lib/messenger/campfire.rb
Class Method Summary collapse
-
.deliver(url, body, options = {}) ⇒ Object
URL format: campfire://api-key:[email protected].
- .obfuscate(url) ⇒ Object
- .valid_url?(url) ⇒ Boolean
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, ={}) raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url) ssl, api_key, room, subdomain = matcher(url) [:headers] ||= {} response = HTTParty.post( "http#{ssl ? "s" : ""}://#{subdomain}.campfirenow.com/room/#{room}/speak.json", :headers => { "Content-Type" => "application/json"}.merge([: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
6 7 8 9 10 |
# File 'lib/messenger/campfire.rb', line 6 def self.valid_url?(url) !!matcher(url) rescue NoMethodError false end |