Module: LedgerSync::Xero::Operation::Mixin::InstanceMethods
- Defined in:
- lib/ledger_sync/xero/operation.rb
Instance Method Summary collapse
- #deserialized_resource(response:) ⇒ Object
- #ledger_resource_path ⇒ Object
- #ledger_resource_type_for_path ⇒ Object
- #perform ⇒ Object
- #response_to_operation_result(response:) ⇒ Object
- #xero_resource_type ⇒ Object
Instance Method Details
#deserialized_resource(response:) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/ledger_sync/xero/operation.rb', line 13 def deserialized_resource(response:) deserializer.deserialize( hash: response, resource: resource ) end |
#ledger_resource_path ⇒ Object
20 21 22 |
# File 'lib/ledger_sync/xero/operation.rb', line 20 def ledger_resource_path @ledger_resource_path ||= "#{ledger_resource_type_for_path}/#{resource.ledger_id}" end |
#ledger_resource_type_for_path ⇒ Object
24 25 26 |
# File 'lib/ledger_sync/xero/operation.rb', line 24 def ledger_resource_type_for_path Util::StringHelpers.camelcase(xero_resource_type.pluralize) end |
#perform ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/ledger_sync/xero/operation.rb', line 42 def perform super rescue LedgerSync::Error::OperationError, OAuth2::Error => e failure(e) ensure client.update_secrets_in_dotenv end |
#response_to_operation_result(response:) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ledger_sync/xero/operation.rb', line 28 def response_to_operation_result(response:) if response.success? success( resource: deserialized_resource( response: response.body[ledger_resource_type_for_path.to_s.capitalize]&.first ), response: response ) else failure # TODO: implement failure handler end end |
#xero_resource_type ⇒ Object
50 51 52 |
# File 'lib/ledger_sync/xero/operation.rb', line 50 def xero_resource_type @xero_resource_type ||= client.class.ledger_resource_type_for(resource_class: resource.class) end |