Last active
October 11, 2015 23:47
-
-
Save vhata/3938390 to your computer and use it in GitHub Desktop.
Campfire notifications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def campfire(token, subdomain, room_id, message, msgtype): | |
requests.post( | |
'https://%s.campfirenow.com/room/%s/speak.json' % ( | |
subdomain, room_id | |
), | |
auth=(token, 'x'), | |
headers={ | |
'Content-type': 'application/json' | |
}, | |
data=json.dumps({ | |
'message': { | |
'body': message, | |
'type': msgtype | |
} | |
}) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
require 'net/https' | |
require 'json' | |
def campfire_message(token, subdomain, room_id, msg, msgtype) | |
begin | |
timeout(10) do | |
cf_uri = "https://#{subdomain}.campfirenow.com/room/#{room_id}/speak.json" | |
uri = URI.parse(cf_uri) | |
req = Net::HTTP::Post.new(uri.request_uri) | |
req.basic_auth(token, 'x') | |
req.content_type = 'application/json' | |
req.body = JSON.dump({ :message => { :body => msg, :type => msgtype } }) | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
http.request(req) | |
end | |
rescue Timeout::Error | |
# log.error() | |
rescue StandardError => e | |
# log.error() | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
campfire() { | |
token=$1 ; shift | |
subdomain=$1 ; shift | |
room_id=$1 ; shift # room number, not name | |
type=$1 ; shift # PasteMessage or TextMessage or SoundMessage or TweetMessage | |
message="$*" | |
curl --connect-timeout 3 -u $token:X -H 'Content-Type: application/xml' -d "<message><body>$message</body><type</message>" https://$subdomain.campfirenow.com/room/$room_id/speak.xml | |
} | |
get_campfire_room_ids() { | |
token=$1 ; shift | |
subdomain=$1 ; shift | |
curl -v -u $token:x https://$subdomain.campfirenow.com/rooms.json | python2.7 -mjson.tool | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment