Sha256: 61b739e4879c7581f455aa05bdca718b1e61c4b232bc18723d78eda751e3709e
Contents?: true
Size: 871 Bytes
Versions: 2
Compression:
Stored size: 871 Bytes
Contents
require 'httparty' require 'json' module Messenger class Campfire # URL format: # campfire://api-key:room-id@subdomain.campfirenow.com def self.send(url, body, options={}) begin api_key, room, subdomain = url.match(/^campfire:\/\/([^:]+):([^@]+)@([^\.]+)/)[1,3] rescue raise URLError, "The URL provided is invalid" end response = HTTParty.post( "http://#{subdomain}.campfirenow.com/room/#{room}/speak.json", :basic_auth => { :username => api_key, :password => "x" }, :headers => { "Content-Type" => "application/json" }, :body => { "message" => { "body" => body } }.to_json ) [success?(response), response] end private def self.success?(response) case response.code when 200, 201: true else false end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
messenger-0.0.3 | lib/messenger/campfire.rb |
messenger-0.0.2 | lib/messenger/campfire.rb |