Sha256: 9d8847de8a879acec87232e359aadad71cde96c39228c672ddc1153518d89dc5

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module CardanoWallet
  ##
  # Base class for all APIs
  class Base
    include HTTParty

    attr_accessor :opt

    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

    # Init API for Shelley
    def shelley
      Shelley.new @opt
    end

    # Init API for Shared wallets
    def shared
      Shared.new @opt
    end

    # Init API for Byron
    def byron
      Byron.new @opt
    end

    # Init API for Misc
    def misc
      Misc.new @opt
    end

    # Init API for Proxy
    def proxy
      Proxy.new @opt
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cardano_wallet-0.3.26 lib/cardano_wallet/base.rb
cardano_wallet-0.3.25 lib/cardano_wallet/base.rb
cardano_wallet-0.3.24 lib/cardano_wallet/base.rb
cardano_wallet-0.3.23 lib/cardano_wallet/base.rb
cardano_wallet-0.3.22 lib/cardano_wallet/base.rb