Class: Misty::HTTP::Client

Inherits:
Object
  • Object
show all
Includes:
Direct, MethodBuilder, NetHTTP, Request
Defined in:
lib/misty/http/client.rb

Defined Under Namespace

Classes: InvalidDataError, Options

Constant Summary collapse

INTERFACES =
%w{admin public internal}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Direct

#base_set, #delete, #get, #post, #put

Methods included from Request

#decode?, #http, #http_copy, #http_delete, #http_get, #http_head, #http_options, #http_patch, #http_post, #http_put, #http_to_s

Methods included from MethodBuilder

#method_missing

Methods included from NetHTTP

net_http

Constructor Details

#initialize(auth, config, options) ⇒ Client

Options - Values shown are the default

Base path can be forced (Not recommended, mainly used for test purposes)
 :base_path => nil
URL can be forced (Helps when setup is broken)
 :base_url => nil
Endpoint type (admin, public or internal)
  :interface => "public"
Region ID
 :region_id => "regionOne"
Service name
 The Service names are pre defined but more can be added using this option.
 :service_name
SSL Verify Mode
  :ssl_verify_mode => true
(micro)version: Can be numbered (3.1) or by state (CURRENT, LATEST or SUPPORTED)
  :version => "CURRENT"


50
51
52
53
54
55
56
57
58
59
60
# File 'lib/misty/http/client.rb', line 50

def initialize(auth, config, options)
  @auth = auth
  @config = config
  @options = setup(options)
  @uri = URI.parse(@auth.get_endpoint(@options.service_names, @options.region_id, @options.interface))
  @base_path = @options.base_path ? @options.base_path : @uri.path
  @base_path = @base_path.chomp("/")
  @http = Misty::HTTP::NetHTTP.net_http(@uri, @options.ssl_verify_mode, @config.log)
  @version = nil
  @microversion = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Misty::HTTP::MethodBuilder

Instance Attribute Details

#microversionObject (readonly)

Returns the value of attribute microversion.



22
23
24
# File 'lib/misty/http/client.rb', line 22

def microversion
  @microversion
end

Class Method Details

.prefix_path_to_ignoreObject

Sub classes to override When a catalog provides a base path and the Service API definition containts the generic equivalent as prefix then the preifx is redundant and must be removed from the path. For example: Catalog provides “192.0.2.21:8004/v1/48985e6b8da145699d411f12a3459fca” and Service API has “/v1/tenant_id/stacks” then the path prefix is ignored and path is only “/stacks”



69
70
71
# File 'lib/misty/http/client.rb', line 69

def self.prefix_path_to_ignore
  ""
end

Instance Method Details

#headersObject



77
78
79
80
81
# File 'lib/misty/http/client.rb', line 77

def headers
  h = headers_default.merge("X-Auth-Token" => "#{@auth.get_token}")
  h.merge!(microversion_header) if microversion
  h
end

#headers_defaultObject



73
74
75
# File 'lib/misty/http/client.rb', line 73

def headers_default
  Misty::HEADER_JSON
end

#requestsObject



24
25
26
27
28
29
30
31
32
# File 'lib/misty/http/client.rb', line 24

def requests
  list = []
  self.class.api.each do |_path, verbs|
    verbs.each do |_verb, requests|
      list << requests
    end
  end
  list.flatten.sort
end