Sha256: 2f0bbf2eff23736f046f5bdcc2c8bfbef367ae377533b4312ee458e09ef828bc
Contents?: true
Size: 1.57 KB
Versions: 1
Compression:
Stored size: 1.57 KB
Contents
require 'rubygems' require 'httparty' require 'json' class Kindling::Request CAMPFIRE_HOST = 'campfirenow.com' include HTTParty format :json headers 'Content-Type' => 'application/json' def self.rooms(campfire) response = get rooms_url(campfire), :basic_auth => campfire.credentials case response.code when 404 raise Kindling::InvalidSubdomain.new(campfire.subdomain) when 401 raise Kindling::InvalidAPIToken.new(campfire.api_token) when 405 # retry with SSL campfire.ssl = true rooms(campfire) when 200 return response["rooms"] end end def self.speak(message, campfire, room_id, type="Textmessage") response = post(room_url(campfire, room_id), :body => {:message => {:body => message, :type => type}}.to_json, :basic_auth => campfire.credentials) case response.code when 404 raise Kindling::InvalidRoomID.new(room_id) when 401 raise Kindling::InvalidAPIToken.new(campfire.api_token) when 405 # retry with SSL campfire.ssl = true speak(message, campfire, room_id, type) when 200..201 response else raise Kindling::Error.new("Unexpected error occured #{response.code}/#{response.message}") end end private def self.room_url(campfire, room_id) "#{subdomain(campfire)}/room/#{room_id}/speak.json" end def self.rooms_url(campfire) "#{subdomain(campfire)}/rooms.json" end def self.subdomain(campfire) "#{campfire.ssl ? 'https' : 'http' }://#{campfire.subdomain}.#{CAMPFIRE_HOST}" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
kindling-1.0.1 | lib/kindling/request.rb |