class Xooa::Util::RequestUtil
Public Instance Methods
buildRequest(url, method, opts = {})
click to toggle source
Build request to be made @param url url for the request @param method request method @options opts options for the request @return TyphoeusRequest
# File lib/xooa/util/Request.rb, line 42 def buildRequest(url, method, opts = {}) method = method.to_sym.downcase headerParams = opts[:headerParams] || {} queryParams = opts[:queryParams] || {} body = opts[:body] || {} reqOpts = { :method => method, :headers => headerParams, :params => queryParams, :body => body } request = Typhoeus::Request.new(url, reqOpts) request end
getResponse(request)
click to toggle source
Get the response for the request @param request request to be submitted to the blockchain @return responseJson
# File lib/xooa/util/Request.rb, line 65 def getResponse(request) begin response = request.run =begin unless response.success? if response.timed_out? raise Xooa::Exception::XooaApiException.new('0', 'Connection Timed Out') elsif response.code == 0 raise Xooa::Exception::XooaApiException.new('0', :errorMessage => response.return_message) else raise Xooa::Exception::XooaApiException.new(response.code, response.status_message) end end =end responseBody = response.body return nil, response.code if responseBody.nil? || responseBody.empty? return responseBody, response.code if response.headers['Content-Type'] == 'string' begin data = JSON.parse(responseBody) rescue JSON::ParseError => e raise Xooa::Exception::XooaApiException.new('0', e.to_s) end return data, response.code rescue Xooa::Exception::XooaApiException => e raise e rescue StandardError => e raise Xooa::Exception::XooaApiException.new('0', e.to_s) end end
getUrl(url, path)
click to toggle source
Create a Url with the base url and the path for the request @param url base url for the app @param path path for the request @return url
# File lib/xooa/util/Request.rb, line 31 def getUrl(url, path) path = "/#{path}".gsub(/\/+/, '/') URI.encode(url + path) end