From cf398131626381263a9db0810ed80ffbca299adb Mon Sep 17 00:00:00 2001 From: mallowlabs Date: Mon, 24 Nov 2014 13:17:03 +0900 Subject: [PATCH] Refactored: misc/bot refs #205 --- misc/bot/simple-ssl.rb | 32 -------------------------------- misc/bot/simple.rb | 23 +++++++++++++++-------- 2 files changed, 15 insertions(+), 40 deletions(-) delete mode 100644 misc/bot/simple-ssl.rb diff --git a/misc/bot/simple-ssl.rb b/misc/bot/simple-ssl.rb deleted file mode 100644 index 8d34128f8..000000000 --- a/misc/bot/simple-ssl.rb +++ /dev/null @@ -1,32 +0,0 @@ -#! /user/bin/env ruby -# -*- mode:ruby; coding:utf-8 -*- - -# ------------------------------ -# example for bot -# ------------------------------ - -# Get from http://$AS_ROOT/account/index -ApiKey = "YOUR_API_KEY" - -# EntryPoint -EntryPoint = "https://localhost:3000/api/v1" - -# ------------------------------ -require 'net/https' - -if ARGV.size != 2 then - puts "#{$0} " - exit 0 -end - -room_id, message = *ARGV -uri = URI(EntryPoint) - -https = Net::HTTP.new(uri.host, uri.port) -https.use_ssl = true -https.verify_mode = OpenSSL::SSL::VERIFY_NONE -https.start do| conn | - # post message - p conn.post(uri.path + "/message", - "room_id=#{room_id}&message=#{message}&api_key=#{ApiKey}") -end diff --git a/misc/bot/simple.rb b/misc/bot/simple.rb index d60b48604..7c87b8254 100644 --- a/misc/bot/simple.rb +++ b/misc/bot/simple.rb @@ -1,4 +1,4 @@ -#! /user/bin/env ruby +#!/user/bin/env ruby # -*- mode:ruby; coding:utf-8 -*- # ------------------------------ @@ -6,13 +6,13 @@ # ------------------------------ # Get from http://$AS_ROOT/account/index -ApiKey = "YOUR_API_KEY" +API_KEY = "YOUR_API_KEY" # EntryPoint -EntryPoint = "http://localhost:3000/api/v1" +ENTRY_POINT = "http://localhost:3000/api/v1" # ------------------------------ -require 'net/http' +require 'net/https' if ARGV.size != 2 then puts "#{$0} " @@ -20,10 +20,17 @@ end room_id, message = *ARGV -uri = URI(EntryPoint) +uri = URI(ENTRY_POINT) -Net::HTTP.start(uri.host, uri.port) do| http | +http = Net::HTTP.new(uri.host, uri.port) +http.use_ssl = uri.scheme == 'https' +http.verify_mode = OpenSSL::SSL::VERIFY_NONE +http.start do |h| # post message - p http.post(uri.path + "/message", - "room_id=#{room_id}&message=#{message}&api_key=#{ApiKey}") + p h.post(uri.path + "/message", URI.encode_www_form({ + room_id: room_id, + api_key: API_KEY, + message: message + })) end +