Class: LedgerSync::Adaptors::NetSuite::Record::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/ledger_sync/adaptors/netsuite/record/metadata.rb

Overview

Helper class for retrieving record metadata:

  • available http_methods

  • record properties/attributes

Constant Summary collapse

BASE_PATH =
'metadata-catalog/record'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adaptor:, record:) ⇒ Metadata

Returns a new instance of Metadata.



18
19
20
21
# File 'lib/ledger_sync/adaptors/netsuite/record/metadata.rb', line 18

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

Instance Attribute Details

#adaptorObject (readonly)

Returns the value of attribute adaptor.



15
16
17
# File 'lib/ledger_sync/adaptors/netsuite/record/metadata.rb', line 15

def adaptor
  @adaptor
end

#recordObject (readonly)

Returns the value of attribute record.



15
16
17
# File 'lib/ledger_sync/adaptors/netsuite/record/metadata.rb', line 15

def record
  @record
end

Instance Method Details

#http_methodsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ledger_sync/adaptors/netsuite/record/metadata.rb', line 23

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

#http_methods_responseObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/ledger_sync/adaptors/netsuite/record/metadata.rb', line 41

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

#propertiesObject



52
53
54
55
56
57
58
59
# File 'lib/ledger_sync/adaptors/netsuite/record/metadata.rb', line 52

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

#properties_responseObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/ledger_sync/adaptors/netsuite/record/metadata.rb', line 61

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