Sha256: f023da4c81e1d5dcd42d7e9ecff6ccc05b573164964fcc2da20f1564857727c0
Contents?: true
Size: 1.56 KB
Versions: 1
Compression:
Stored size: 1.56 KB
Contents
module Opsource module Connection def build_request(type, endpoint, query = nil, body = nil, xml=true) # url = "https://cloudapi.nttamerica.com/oec/0.9" + "/server" uri = api_base + endpoint append_query(uri, query) if query if xml request = Typhoeus::Request.new( uri, method: type, body: body, userpwd: "#{@username}:#{@password}", headers: { 'Content-Type' =>'text/xml', 'User-Agent' => 'ACP Ruby SDK' } ) else request = Typhoeus::Request.new( uri, method: type, body: body, userpwd: "#{@username}:#{@password}", headers: { 'User-Agent' => 'ACP Ruby SDK' } ) end end def append_query(uri, query) if uri.include?('?') uri << '&' else uri << '?' end uri << query end def perform_request(request) log "\nrequesting #{request.url}...", :yellow request.run end def log_response(request, response) if response.success? log "...........success!", :yellow elsif response.timed_out? log "ERROR\n-----", :red log "got a time out" elsif response.code == 0 # Could not get an http response, something's wrong. log "ERROR\n-----", :red log response.return_message else # Received a non-successful http response. log "ERROR\n-----", :red log "HTTP request failed: " + response.code.to_s, :red log response.body, :yellow end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
didata_cloud_sdk-0.3.1 | lib/opsource/connection.rb |