Module: CloudControl::Connection
- Included in:
- Client
- Defined in:
- lib/cloudcontrol/connection.rb
Instance Method Summary collapse
- #append_query(uri, query) ⇒ Object
- #build_request(type, endpoint, query = nil, body = nil, xml = true) ⇒ Object
- #log_response(request, response) ⇒ Object
- #perform_request(request) ⇒ Object
Instance Method Details
#append_query(uri, query) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/cloudcontrol/connection.rb', line 26 def append_query(uri, query) if uri.include?('?') uri << '&' else uri << '?' end uri << query end |
#build_request(type, endpoint, query = nil, body = nil, xml = true) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/cloudcontrol/connection.rb', line 3 def build_request(type, endpoint, query = nil, body = nil, xml=true) 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: { 'Accept' => 'application/json', 'User-Agent' => 'ACP Ruby SDK' } ) end end |
#log_response(request, response) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cloudcontrol/connection.rb', line 41 def log_response(request, response) if response.success? log "...........success!", :yellow elsif response.timed_out? log_error "ERROR\n-----", :red log_error "got a time out" elsif response.code == 0 # Could not get an http response, something's wrong. log_error "ERROR\n-----", :red log_error response. else # Received a non-successful http response. log_error "ERROR\n-----", :red log_error "HTTP request failed: " + response.code.to_s, :red log_error response.body, :yellow end end |
#perform_request(request) ⇒ Object
36 37 38 39 |
# File 'lib/cloudcontrol/connection.rb', line 36 def perform_request(request) log "\nrequesting #{request.url}...", :yellow request.run end |