Sha256: 5350df8d665ff3f1d647b7df45e72109ef6ffa5835766c9f144dc4cb8ea55ce7

Contents?: true

Size: 1003 Bytes

Versions: 9

Compression:

Stored size: 1003 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'
require 'avm/instances/base'
require 'httpclient'

module EhbrsRubyUtils
  module WebUtils
    class Instance < ::Avm::Instances::Base
      require_sub __FILE__

      def finances
        @finances ||= ::EhbrsRubyUtils::WebUtils::Instance::Finances.new(self)
      end

      def root_url
        read_entry(::Avm::Instances::EntryKeys::WEB_URL)
      end

      def resource_url(resource_url_suffix)
        root_url + '/' + resource_url_suffix.gsub(%r{\A/+}, '')
      end

      def http_request(resource_url_suffix, options = {})
        method = options.delete(:method) || 'get'
        url = resource_url(resource_url_suffix)
        http_client.request(method, url, options)
      end

      def http_client_uncached
        client = HTTPClient.new
        client.force_basic_auth = true
        client.set_basic_auth(root_url, read_entry(:admin_username), read_entry(:admin_password))
        client
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ehbrs_ruby_utils-0.19.0 lib/ehbrs_ruby_utils/web_utils/instance.rb
ehbrs_ruby_utils-0.18.0 lib/ehbrs_ruby_utils/web_utils/instance.rb
ehbrs_ruby_utils-0.17.3 lib/ehbrs_ruby_utils/web_utils/instance.rb
ehbrs_ruby_utils-0.17.2 lib/ehbrs_ruby_utils/web_utils/instance.rb
ehbrs_ruby_utils-0.17.1 lib/ehbrs_ruby_utils/web_utils/instance.rb
ehbrs_ruby_utils-0.17.0 lib/ehbrs_ruby_utils/web_utils/instance.rb
ehbrs_ruby_utils-0.16.1 lib/ehbrs_ruby_utils/web_utils/instance.rb
ehbrs_ruby_utils-0.16.0 lib/ehbrs_ruby_utils/web_utils/instance.rb
ehbrs_ruby_utils-0.15.0 lib/ehbrs_ruby_utils/web_utils/instance.rb