Class: CardanoWallet::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/cardano_wallet/base.rb

Overview

Base class for all APIs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opt = {}) ⇒ Base

Initialize CardanoWallet.

Examples:

Initialize CardanoWallet with default settings

@cw = CardanoWallet.new

Initialize CardanoWallet with custom settings

@cw = CardanoWallet.new({ port: 4445,
                          protocol: 'https',
                          cacert: '/path/to/cacert',
                          pem: '/path/to/client.pem',
                          timeout: 600 })

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cardano_wallet/base.rb', line 21

def initialize(opt = {})
  raise ArgumentError, 'argument should be Hash' unless opt.is_a?(Hash)

  opt[:protocol] ||= 'http'
  opt[:host] ||= 'localhost'
  opt[:port] ||= 8090
  opt[:url] ||= "#{opt[:protocol]}://#{opt[:host]}:#{opt[:port]}/v2"
  opt[:cacert] ||= ''
  opt[:pem] ||= ''
  opt[:timeout] ||= -1
  self.class.base_uri opt[:url]
  self.class.default_timeout(opt[:timeout].to_i) unless opt[:timeout] == -1

  unless opt[:cacert].empty?
    ENV['SSL_CERT_FILE'] = opt[:cacert]
    self.class.ssl_ca_file(File.read(ENV.fetch('SSL_CERT_FILE', nil)))
  end
  self.class.pem(File.read(opt[:pem])) unless opt[:pem].empty?

  @opt = opt
end

Instance Attribute Details

#optObject

Returns the value of attribute opt.



9
10
11
# File 'lib/cardano_wallet/base.rb', line 9

def opt
  @opt
end

Instance Method Details

#byronObject

Init API for Byron



54
55
56
# File 'lib/cardano_wallet/base.rb', line 54

def byron
  Byron.new @opt
end

#miscObject

Init API for Misc



59
60
61
# File 'lib/cardano_wallet/base.rb', line 59

def misc
  Misc.new @opt
end

#sharedObject

Init API for Shared wallets



49
50
51
# File 'lib/cardano_wallet/base.rb', line 49

def shared
  Shared.new @opt
end

#shelleyObject

Init API for Shelley



44
45
46
# File 'lib/cardano_wallet/base.rb', line 44

def shelley
  Shelley.new @opt
end

#utilsObject

Init API for Utils



64
65
66
# File 'lib/cardano_wallet/base.rb', line 64

def utils
  Utils.new @opt
end