Sha256: 8b3d9121ab7dc82476fb170d32b7ab28965c111f20f612a7c1f839385e1ecff2

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Arclight
  module Requests
    ##
    # This class should be used to turn configuration into a URL and
    # POST form specifically aimed at Aeon's external request
    # endpoint (https://support.atlas-sys.com/hc/en-us/articles/360011820054-External-Request-Endpoint)
    class AeonExternalRequest
      def initialize(document, presenter)
        @document = document
        @presenter = presenter
      end

      def config
        @config ||= @document.repository_config.request_config_for_type('aeon_external_request_endpoint')
      end

      def url
        "#{config['request_url']}?#{url_params}"
      end

      def form_mapping
        static_mappings.merge(dynamic_mappings)
      end

      def static_mappings
        config['request_mappings']['static']
      end

      def dynamic_mappings
        config['request_mappings']['accessor'].transform_values do |v|
          @document.send(v.to_sym)
        end
      end

      def url_params
        config['request_mappings']['url_params'].to_query
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
arclight-0.5.0 app/models/arclight/requests/aeon_external_request.rb
arclight-0.4.0 app/models/arclight/requests/aeon_external_request.rb
arclight-0.3.3 app/models/arclight/requests/aeon_external_request.rb
arclight-0.3.2 app/models/arclight/requests/aeon_external_request.rb
arclight-0.3.1 app/models/arclight/requests/aeon_external_request.rb
arclight-0.3.0 app/models/arclight/requests/aeon_external_request.rb