Sha256: e1bf68b1a02843e2c776397120e7ede4de90d82c3b8e40c2e641ae4afb99aede

Contents?: true

Size: 1.85 KB

Versions: 3

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

module LedgerSync
  module Adaptors
    module NetSuite
      module Record
        #
        # Helper class for retrieving record metadata:
        # - available http_methods
        # - record properties/attributes
        #
        class Metadata
          BASE_PATH = 'metadata-catalog/record'

          attr_reader :adaptor,
                      :record

          def initialize(adaptor:, record:)
            @adaptor = adaptor
            @record = record
          end

          def http_methods
            @http_methods ||= begin
              ret = []

              http_methods_response.body['paths'].each do |path, path_data|
                path_data.each do |method, method_data|
                  ret << HTTPMethod.new_from_hash(
                    data: method_data,
                    method: method,
                    path: path
                  )
                end
              end

              ret
            end
          end

          def http_methods_response
            @http_methods_response = begin
              adaptor.get(
                headers: {
                  'Accept' => 'application/swagger+json'
                },
                path: "#{BASE_PATH}?select=#{record}"
              )
            end
          end

          def properties
            @properties = properties_response.body['properties'].map do |key, data|
              Property.new_from_hash(
                data: data,
                key: key
              )
            end
          end

          def properties_response
            @properties_response = begin
              adaptor.get(
                headers: {
                  'Accept' => 'application/swagger+json'
                },
                path: "#{BASE_PATH}/#{record}"
              )
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ledger_sync-1.3.3 lib/ledger_sync/adaptors/netsuite/record/metadata.rb
ledger_sync-1.3.2 lib/ledger_sync/adaptors/netsuite/record/metadata.rb
ledger_sync-1.3.1 lib/ledger_sync/adaptors/netsuite/record/metadata.rb