Sha256: bf01830b910c25f66bf58799d2c3fd2ddb8b8cadbd31df691df7ca8ed9212af4
Contents?: true
Size: 1.36 KB
Versions: 1
Compression:
Stored size: 1.36 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 200 return response["rooms"] end end def self.speak(message, campfire) response = post room_url(campfire), :body => {:message => {:body => message, :type => "Textmessage"}}.to_json, :basic_auth => campfire.credentials case response.code when 404 raise Kindling::InvalidRoomID.new(campfire.room_id) when 401 raise Kindling::InvalidAPIToken.new(campfire.api_token) when 200..201 response else raise Kindling::Error.new("Unexpected error occured #{response.code}/#{response.message}") end end private def self.room_url(campfire) "#{subdomain(campfire)}/room/#{campfire.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-0.0.3 | lib/kindling/request.rb |