Sha256: 6e3854116ec5891e8f0e05a377c9a30c66567f37f740be2fa4b37e09ac3f85af

Contents?: true

Size: 1.31 KB

Versions: 25

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require 'eac_rest/api'
require 'eac_ruby_utils/core_ext'
require 'ehbrs_ruby_utils/web_utils/request_error'
require 'avm/instances/base'

module EhbrsRubyUtils
  module WebUtils
    class Instance < ::Avm::Instances::Base
      class HttpRequest
        enable_method_class
        enable_simple_cache
        common_constructor :instance, :resource_url_suffix, :source_options, default: [{}]

        # @return [EacRest::Response]
        def result
          r = request.response
          ::EhbrsRubyUtils::WebUtils::RequestError.raise_if_error(r)
          ::Struct.new(:status, :body).new(r.status, ::JSON.parse(r.body_str))
        end

        private

        # @return [::Struct.new(:verb, :body_data, :headers)]
        def options_uncached
          options = source_options.to_options_consumer
          verb = options.consume(:method, :get).to_sym
          body_data = options.consume(:body)
          headers = options.consume(:header)
          options.validate
          ::Struct.new(:verb, :body_data, :headers).new(verb, body_data, headers)
        end

        # @return [EacRest::Request]
        def request
          instance.api.request(resource_url_suffix).verb(options.verb).headers(options.headers)
            .body_data(options.body_data)
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
ehbrs_ruby_utils-0.44.0 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.41.1 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.41.0 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.40.0 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.39.0 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.38.0 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.37.0 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.36.1 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.36.0 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.35.0 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.33.0 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.32.0 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.31.0 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.30.0 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.29.0 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.28.0 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.27.1 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.27.0 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.26.0 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
ehbrs_ruby_utils-0.25.1 lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb