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

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

Overview

Helper class for retrieving record metadata:

  • available http_methods

  • record properties/attributes

Constant Summary collapse

BASE_PATH =
'metadata-catalog'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, record:) ⇒ Metadata

Returns a new instance of Metadata.



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

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#recordObject (readonly)

Returns the value of attribute record.



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

def record
  @record
end

Class Method Details

.configObject



99
100
101
# File 'lib/ledger_sync/netsuite/record/metadata.rb', line 99

def self.config
  Client.config
end

Instance Method Details

#createObject



22
23
24
# File 'lib/ledger_sync/netsuite/record/metadata.rb', line 22

def create
  @create ||= http_methods.find { |e| e.key == "post /#{record}" }
end

#deleteObject



26
27
28
# File 'lib/ledger_sync/netsuite/record/metadata.rb', line 26

def delete
  @delete ||= http_methods.find { |e| e.key == "delete /#{record}/{id}" }
end

#findObject



30
31
32
# File 'lib/ledger_sync/netsuite/record/metadata.rb', line 30

def find
  @find ||= show
end

#http_methodsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ledger_sync/netsuite/record/metadata.rb', line 34

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

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

    ret
  end
end

#indexObject



53
54
55
# File 'lib/ledger_sync/netsuite/record/metadata.rb', line 53

def index
  @index ||= http_methods.find { |e| e.key == "get /#{record}" }
end

#metadata_responseObject



57
58
59
60
61
62
63
64
# File 'lib/ledger_sync/netsuite/record/metadata.rb', line 57

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

#patchObject



83
84
85
# File 'lib/ledger_sync/netsuite/record/metadata.rb', line 83

def patch
  @patch ||= http_methods.find { |e| e.key == "patch /#{record}/{id}" }
end

#propertiesObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ledger_sync/netsuite/record/metadata.rb', line 66

def properties
  @properties ||= begin
    ret = []
    props = .body['components']['schemas'][record.to_s]['properties']
    props.map do |key, prop|
      next unless prop.key?('title')

      ret << Property.new_from_hash(
        prop.merge(
          key: key
        )
      )
    end
    ret
  end
end

#showObject



87
88
89
# File 'lib/ledger_sync/netsuite/record/metadata.rb', line 87

def show
  @show ||= http_methods.find { |e| e.key == "get /#{record}/{id}" }
end

#updateObject



91
92
93
# File 'lib/ledger_sync/netsuite/record/metadata.rb', line 91

def update
  @update ||= http_methods.find { |e| e.key == "patch /#{record}/{id}" }
end

#upsertObject



95
96
97
# File 'lib/ledger_sync/netsuite/record/metadata.rb', line 95

def upsert
  @upsert ||= http_methods.find { |e| e.key == "put /#{record}/{id}" }
end