Sha256: c60439799c02c939b053f013479979efc43a8b7f666e468419dc43c25d63ad7f
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 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) "http://#{campfire.subdomain}.#{CAMPFIRE_HOST}" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
kindling-0.0.2 | lib/kindling/request.rb |