Module: Alidayu::Helper

Included in:
Sms, Tts, Voice
Defined in:
lib/alidayu/helper.rb

Instance Method Summary collapse

Instance Method Details

#get_response(params) ⇒ Object

获得响应结果



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/alidayu/helper.rb', line 7

def get_response(params)
  uri = URI(Alidayu.config.server)
  http = Net::HTTP.new(uri.host, uri.port)
  if uri.scheme == "https"
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
  request = Net::HTTP::Post.new(uri.path)
  request_params = build_params(params)
  request.add_field('Content-Type', 'application/json')
  request.set_form_data(request_params)
  response = http.request(request)
  Alidayu.logger.info response.body
  return JSON.parse(response.body)
end