Module: XeroKiwi::Accounting::Resource::ClassMethods
- Defined in:
- lib/xero_kiwi/accounting/resource.rb
Instance Method Summary collapse
- #attribute(name, xero:, type: :string, of: nil, reference: false, hydrate: nil, query: false) ⇒ Object
- #attributes ⇒ Object
- #from_response(payload) ⇒ Object
- #identity(*attrs) ⇒ Object
- #identity_attributes ⇒ Object
- #payload_key(key = nil) ⇒ Object
-
#query_fields ⇒ Object
The queryable schema for this resource: the subset of attributes that can appear in Xero’s ‘where` / `order` query params.
Instance Method Details
#attribute(name, xero:, type: :string, of: nil, reference: false, hydrate: nil, query: false) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/xero_kiwi/accounting/resource.rb', line 41 def attribute(name, xero:, type: :string, of: nil, reference: false, hydrate: nil, query: false) attributes[name] = { xero: xero, type: type, of: of, reference: reference, hydrate: hydrate, query: query } attr_reader name end |
#attributes ⇒ Object
54 55 56 |
# File 'lib/xero_kiwi/accounting/resource.rb', line 54 def attributes @_attributes ||= {} end |
#from_response(payload) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/xero_kiwi/accounting/resource.rb', line 102 def from_response(payload) return [] if payload.nil? items = payload[payload_key] return [] if items.nil? items.map { |attrs| new(attrs) } end |
#identity(*attrs) ⇒ Object
58 59 60 |
# File 'lib/xero_kiwi/accounting/resource.rb', line 58 def identity(*attrs) @identity_attributes = attrs.freeze end |
#identity_attributes ⇒ Object
62 63 64 |
# File 'lib/xero_kiwi/accounting/resource.rb', line 62 def identity_attributes @identity_attributes end |
#payload_key(key = nil) ⇒ Object
35 36 37 38 39 |
# File 'lib/xero_kiwi/accounting/resource.rb', line 35 def payload_key(key = nil) return @payload_key if key.nil? @payload_key = key end |
#query_fields ⇒ Object
The queryable schema for this resource: the subset of attributes that can appear in Xero’s ‘where` / `order` query params. Any attribute declared with `query: true` is included, and every `identity` attribute is implicitly queryable (resources always filter by their primary key).
For ‘:object` attributes, the child’s own ‘query_fields` is included as a nested schema so callers can filter on e.g. `contact: { contact_id: “…” }`, which the compiler renders as `Contact.ContactID==guid(“…”)`.
76 77 78 79 80 81 82 |
# File 'lib/xero_kiwi/accounting/resource.rb', line 76 def query_fields @_query_fields ||= attributes.each_with_object({}) do |(name, spec), acc| next unless queryable?(name, spec) acc[name] = build_query_field(spec) end end |