lib/statsmix.rb in statsmix-0.1.3 vs lib/statsmix.rb in statsmix-0.1.4
- old
+ new
@@ -1,6 +1,7 @@
require 'net/http'
+require 'net/https'
require 'rubygems'
require 'json'
class StatsMix
@@ -261,16 +262,16 @@
def self.connect(resource)
self.setup
if @api_key.nil?
- raise "API key not set. You must set it frist with StatsMix.api_key = [your api key]"
+ raise "API key not set. You must set it first with StatsMix.api_key = [your api key]"
end
# Resources available: stats, metrics, TODO: profiles
@url = URI.parse(BASE_URI + resource)
@connection = Net::HTTP.new(@url.host, @url.port)
-
+ @connection.use_ssl = (@url.scheme == 'https')
@request = Hash.new
@request["User-Agent"] = @user_agent
@params = Hash.new
@params[:api_key] = @api_key
end
@@ -290,9 +291,19 @@
else
@error = JSON.parse(@response.body)['errors']['error']
end
end
@response.body
+ end
+end
+
+#added to suppress ssl warnings per advice at http://www.5dollarwhitebox.org/drupal/node/64
+class Net::HTTP
+ alias_method :old_initialize, :initialize
+ def initialize(*args)
+ old_initialize(*args)
+ @ssl_context = OpenSSL::SSL::SSLContext.new
+ @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
end
StatsMix.api_from_env
\ No newline at end of file