class RHC::Rest::Api

Attributes

client_api_versions[R]
server_api_versions[R]

Public Class Methods

new(client, preferred_api_versions=[]) click to toggle source
# File lib/rhc/rest/api.rb, line 6
def initialize(client, preferred_api_versions=[])
  super(nil, client)

  # API version negotiation
  @server_api_versions = []
  debug "Client supports API versions #{preferred_api_versions.join(', ')}"
  @client_api_versions = preferred_api_versions
  @server_api_versions, links = api_info({
    :url => client.url,
    :method => :get,
    :lazy_auth => true,
  })
  debug "Server supports API versions #{@server_api_versions.join(', ')}"

  if api_version_negotiated
    unless server_api_version_current?
      debug "Client API version #{api_version_negotiated} is not current. Refetching API"
      # need to re-fetch API
      @server_api_versions, links = api_info({
        :url => client.url,
        :method => :get,
        :accept => :json,
        :api_version => api_version_negotiated,
        :lazy_auth => true,
      })
    end
  else
    warn_about_api_versions
  end

  attributes['links'] = links

rescue RHC::Rest::ResourceNotFoundException => e
  raise ApiEndpointNotFound.new(
    "The OpenShift server is not responding correctly.  Check "           "that '#{client.url}' is the correct URL for your server. "           "The server may be offline or misconfigured.")
end

Public Instance Methods

api_version_match?() click to toggle source

API version related methods

# File lib/rhc/rest/api.rb, line 46
def api_version_match?
  ! api_version_negotiated.nil?
end
api_version_negotiated() click to toggle source

return the API version that the server and this client can agree on

# File lib/rhc/rest/api.rb, line 51
def api_version_negotiated
  client_api_versions.reverse. # choose the last API version listed
    detect { |v| @server_api_versions.include? v }
end
client_api_version_current?() click to toggle source
# File lib/rhc/rest/api.rb, line 56
def client_api_version_current?
  current_client_api_version == api_version_negotiated
end
current_client_api_version() click to toggle source
# File lib/rhc/rest/api.rb, line 60
def current_client_api_version
  client_api_versions.last
end
server_api_version_current?() click to toggle source
# File lib/rhc/rest/api.rb, line 64
def server_api_version_current?
  @server_api_versions && @server_api_versions.max == api_version_negotiated
end
warn_about_api_versions() click to toggle source
# File lib/rhc/rest/api.rb, line 68
      def warn_about_api_versions
        if !api_version_match?
          warn "WARNING: API version mismatch. This client supports #{client_api_versions.join(', ')} but
server at #{URI.parse(client.url).host} supports #{@server_api_versions.join(', ')}."
          warn "The client version may be outdated; please consider updating 'rhc'. We will continue, but you may encounter problems."
        end
      end