Class: LedgerSync::NetSuite::Record::Metadata
- Inherits:
-
Object
- Object
- LedgerSync::NetSuite::Record::Metadata
- 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
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
- #find ⇒ Object
- #http_methods ⇒ Object
- #index ⇒ Object
-
#initialize(client:, record:) ⇒ Metadata
constructor
A new instance of Metadata.
- #metadata_response ⇒ Object
- #patch ⇒ Object
- #properties ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
- #upsert ⇒ Object
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
#client ⇒ Object (readonly)
Returns the value of attribute client.
14 15 16 |
# File 'lib/ledger_sync/netsuite/record/metadata.rb', line 14 def client @client end |
#record ⇒ Object (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
.config ⇒ Object
99 100 101 |
# File 'lib/ledger_sync/netsuite/record/metadata.rb', line 99 def self.config Client.config end |
Instance Method Details
#create ⇒ Object
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 |
#delete ⇒ Object
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 |
#find ⇒ Object
30 31 32 |
# File 'lib/ledger_sync/netsuite/record/metadata.rb', line 30 def find @find ||= show end |
#http_methods ⇒ Object
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 |
#index ⇒ Object
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_response ⇒ Object
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 |
#patch ⇒ Object
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 |
#properties ⇒ Object
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 |
#show ⇒ Object
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 |
#update ⇒ Object
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 |
#upsert ⇒ Object
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 |