Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: setting 'use_ssl' option on 'Net::HTTP' object inorder to work c… #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/ari/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def initialize(options = {})
%w{ get put post delete }.each do |http_method|
method_klass = Net::HTTP.const_get http_method.to_s.capitalize
define_method http_method do |path, params = {}|
request_body = params.delete(:body)
http_body = params.delete(:http_body)
params.merge!({ api_key: @options[:api_key], app: @options[:app] })
query_string = URI.encode_www_form params
request_path = "#{@uri.path}#{path}?#{query_string}"
request = method_klass.new request_path, HTTP_HEADERS
request.body = request_body.is_a?(Hash) ? MultiJson.dump(request_body) : request_body
request.body = http_body.is_a?(Hash) ? MultiJson.dump(http_body) : http_body
send_request request
end
end
Expand All @@ -63,11 +63,14 @@ def handle_websocket_open
end

def handle_websocket_message(event)
# puts event.inspect
handle_websocket_close(event) and return if event.type == :close
return unless event.type == :text

object = MultiJson.load event.data

#puts "XXXXXXXX ARI-client: #{object['type']} XXXXXXXX"

handler_klass = Ari.const_get object['type'] rescue nil
return unless handler_klass
event_name = object['type'].gsub(/([a-z\d])([A-Z])/,'\1_\2').downcase
Expand Down Expand Up @@ -99,8 +102,10 @@ def handle_websocket_close(event)

def send_request(request)
http = Net::HTTP.new(@uri.host, @uri.port)
http.use_ssl = @uri.scheme == 'https'
http.open_timeout = @options[:open_timeout]
http.read_timeout = @options[:read_timeout]

response = http.request(request)
if response.body and !response.body.empty?
object = MultiJson.load response.body
Expand Down