Module: Yao::Client

Defined in:
lib/yao/client.rb

Defined Under Namespace

Classes: ClientSet

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.default_clientObject

Returns the value of attribute default_client.



46
47
48
# File 'lib/yao/client.rb', line 46

def default_client
  @default_client
end

Class Method Details

.client_generatorObject



48
49
50
# File 'lib/yao/client.rb', line 48

def client_generator
  Plugins::Registry.instance[:client_generator][Yao.config.client_generator].new
end

.client_optionsObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/yao/client.rb', line 64

def client_options
  opt = {}
  opt.merge!({ request: { timeout: Yao.config.timeout }}) if Yao.config.timeout
  if Yao.config.client_cert && Yao.config.client_key
    require 'openssl'
    cert = OpenSSL::X509::Certificate.new(File.read(Yao.config.client_cert))
    key  = OpenSSL::PKey.read(File.read(Yao.config.client_key))
    opt.merge!(ssl: {
      client_cert: cert,
      client_key:  key,
    })
  end
  opt
end

.gen_client(endpoint, token: nil) ⇒ Object



52
53
54
55
56
# File 'lib/yao/client.rb', line 52

def gen_client(endpoint, token: nil)
  Faraday.new( endpoint, client_options ) do |f|
    client_generator.call(f, token)
  end
end

.reset_client(new_endpoint = nil) ⇒ Object



58
59
60
61
62
# File 'lib/yao/client.rb', line 58

def reset_client(new_endpoint=nil)
  set = ClientSet.new
  set.register_endpoints("default" => {public_url: new_endpoint || Yao.config.endpoint})
  self.default_client = set
end