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

http_request

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
Optional headers
 :headers => {}
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"


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

def initialize(auth, config, options)
  @auth = auth
  @config = config
  @options = setup(options)
  @uri = URI.parse(@auth.get_url(@options.service_names, @options.region_id, @options.interface))
  @base_path = @options.base_path ? @options.base_path : @uri.path
  @base_path = @base_path.chomp('/')
  @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.



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

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’



71
72
73
# File 'lib/misty/http/client.rb', line 71

def self.prefix_path_to_ignore
  ''
end

Instance Method Details

#headersObject



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

def headers
  header = {}
  header.merge!({'Content-Type' => 'application/json', 'Accept' => 'application/json'})
  header.merge!('X-Auth-Token' => @auth.get_token.to_s)
  header.merge!(@config.headers) if @config.headers
  header.merge!(@options.headers) if @options.headers
  header.merge!(microversion_header) if microversion
  header
end

#requestsObject



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

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