Class: LedgerSync::Ledgers::Client

Inherits:
Object
  • Object
show all
Includes:
Fingerprintable::Mixin, Util::Mixins::ResourceRegisterableMixin, Validatable, SimplySerializable::Mixin
Defined in:
lib/ledger_sync/ledgers/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::Mixins::ResourceRegisterableMixin

included

Methods included from Validatable

#valid?, #validate, #validate_or_fail

Constructor Details

#initializeClient

Returns a new instance of Client.

Raises:

  • (NotImplementedError)


15
16
17
# File 'lib/ledger_sync/ledgers/client.rb', line 15

def initialize(*)
  raise NotImplementedError
end

Class Method Details

.base_moduleObject



64
65
66
# File 'lib/ledger_sync/ledgers/client.rb', line 64

def self.base_module
  config.base_module
end

.base_operation_module_for(resource_class:) ⇒ Object



68
69
70
# File 'lib/ledger_sync/ledgers/client.rb', line 68

def self.base_operation_module_for(resource_class:)
  base_module.const_get("#{resource_class.resource_module_str}::Operations")
end

.configObject



72
73
74
# File 'lib/ledger_sync/ledgers/client.rb', line 72

def self.config
  @config ||= LedgerSync.ledgers.config_from_class(client_class: self)
end

.ledger_attributes_to_saveObject

These are attributes that must always be saved after the client is called. For example, the library will handle refreshing tokens that will need to be saved back to the application layer for future use.

Raises:

  • (NotImplementedError)


79
80
81
# File 'lib/ledger_sync/ledgers/client.rb', line 79

def self.ledger_attributes_to_save
  raise NotImplementedError
end

.ledger_resource_type_for(resource_class:) ⇒ Object



83
84
85
# File 'lib/ledger_sync/ledgers/client.rb', line 83

def self.ledger_resource_type_for(resource_class:)
  ledger_resource_type_overrides[resource_class] || resource_class.resource_type.to_s
end

.ledger_resource_type_overridesObject



87
88
89
# File 'lib/ledger_sync/ledgers/client.rb', line 87

def self.ledger_resource_type_overrides
  {}
end

.operation_class_for(method:, resource_class:) ⇒ Object



91
92
93
94
# File 'lib/ledger_sync/ledgers/client.rb', line 91

def self.operation_class_for(method:, resource_class:)
  base_operation_module_for(resource_class: resource_class)
    .const_get(LedgerSync::Util::StringHelpers.camelcase(method.to_s))
end

.resource_from_ledger_type(type:, converter: nil) ⇒ Object



96
97
98
99
# File 'lib/ledger_sync/ledgers/client.rb', line 96

def self.resource_from_ledger_type(type:, converter: nil)
  converter ||= proc { |n| n.underscore }
  ledger_resource_type_overrides.invert[converter.call(type).to_sym] || resources[converter.call(type).to_sym]
end

.resourcesObject



101
102
103
# File 'lib/ledger_sync/ledgers/client.rb', line 101

def self.resources
  @resources ||= {}
end

.root_keyObject



105
106
107
# File 'lib/ledger_sync/ledgers/client.rb', line 105

def self.root_key
  @root_key ||= config.root_key
end

.url_for(resource: nil) ⇒ Object



109
# File 'lib/ledger_sync/ledgers/client.rb', line 109

def self.url_for(resource: nil); end

Instance Method Details

#base_moduleObject



23
24
25
# File 'lib/ledger_sync/ledgers/client.rb', line 23

def base_module
  self.class.base_module
end

#ledger_attributes_to_saveObject



27
28
29
30
31
32
33
# File 'lib/ledger_sync/ledgers/client.rb', line 27

def ledger_attributes_to_save
  return {} if self.class.ledger_attributes_to_save.nil?

  Hash[self.class.ledger_attributes_to_save.map do |attribute|
    [attribute, send(attribute)]
  end]
end

#ledger_configurationObject



19
20
21
# File 'lib/ledger_sync/ledgers/client.rb', line 19

def ledger_configuration
  self.class.config
end

#operation_for(args = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ledger_sync/ledgers/client.rb', line 35

def operation_for(args = {})
  method = args.fetch(:method)
  resource = args.fetch(:resource)

  self.class.operation_class_for(
    method: method,
    resource_class: resource.class
  ).new(
    client: self,
    resource: resource
  )
end

#parse_operation_errorObject



60
61
62
# File 'lib/ledger_sync/ledgers/client.rb', line 60

def parse_operation_error(*)
  nil
end

#searcher_class_for(resource_type:) ⇒ Object



52
53
54
# File 'lib/ledger_sync/ledgers/client.rb', line 52

def searcher_class_for(resource_type:)
  base_module.const_get(LedgerSync::Util::StringHelpers.camelcase(resource_type.to_s))::Searcher
end

#searcher_for(resource_type:, query: '') ⇒ Object



48
49
50
# File 'lib/ledger_sync/ledgers/client.rb', line 48

def searcher_for(resource_type:, query: '')
  searcher_class_for(resource_type: resource_type).new(client: self, query: query)
end

#url_for(*_args) ⇒ Object

Raises:

  • (NotImplementedError)


56
57
58
# File 'lib/ledger_sync/ledgers/client.rb', line 56

def url_for(*_args)
  raise NotImplementedError
end