Class: Workato::Connector::Sdk::Connection

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
MonitorMixin
Defined in:
lib/workato/connector/sdk/connection.rb

Defined Under Namespace

Classes: Authorization

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection: {}, methods: {}, settings: {}) ⇒ void

Parameters:



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/workato/connector/sdk/connection.rb', line 64

def initialize(connection: {}, methods: {}, settings: {})
  super()
  @methods_source = T.let(
    Utilities::HashWithIndifferentAccess.wrap(methods),
    ActiveSupport::HashWithIndifferentAccess
  )
  @source = T.let(
    Utilities::HashWithIndifferentAccess.wrap(connection),
    ActiveSupport::HashWithIndifferentAccess
  )
  @settings = T.let(settings, SorbetTypes::SettingsHash)
end

Instance Attribute Details

#sourceActiveSupport::HashWithIndifferentAccess (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (ActiveSupport::HashWithIndifferentAccess)


52
53
54
# File 'lib/workato/connector/sdk/connection.rb', line 52

def source
  @source
end

Instance Method Details

#authorizationAuthorization

Returns:

Raises:

  • (::NotImplementedError)


106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/workato/connector/sdk/connection.rb', line 106

def authorization
  raise ::NotImplementedError, 'define authorization: before use' if source[:authorization].blank?

  @authorization ||= T.let(
    Authorization.new(
      connection: self,
      authorization: source[:authorization],
      methods: methods_source
    ),
    T.nilable(Authorization)
  )
end

#authorization?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


101
102
103
# File 'lib/workato/connector/sdk/connection.rb', line 101

def authorization?
  source[:authorization].present?
end

#base_uri(settings = nil) ⇒ String?

Parameters:

Returns:

  • (String, nil)


120
121
122
123
124
125
# File 'lib/workato/connector/sdk/connection.rb', line 120

def base_uri(settings = nil)
  return unless source[:base_uri]

  merge_settings!(settings) if settings
  global_dsl_context.execute(self.settings, &source['base_uri'])
end

#merge_settings!(settings) ⇒ SorbetTypes::SettingsHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Returns:



95
96
97
# File 'lib/workato/connector/sdk/connection.rb', line 95

def merge_settings!(settings)
  @settings.merge!(settings)
end

#settingsActiveSupport::HashWithIndifferentAccess

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (ActiveSupport::HashWithIndifferentAccess)


85
86
87
88
89
90
91
# File 'lib/workato/connector/sdk/connection.rb', line 85

def settings
  # we can't freeze or memoise because some developers modify it for storing something temporary in it.
  # always return a new copy
  synchronize do
    @settings.with_indifferent_access
  end
end

#settings!SorbetTypes::SettingsHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



79
80
81
# File 'lib/workato/connector/sdk/connection.rb', line 79

def settings!
  @settings
end

#update_settings!(message, settings_before, &refresher) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Returns:

  • (Boolean)


135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/workato/connector/sdk/connection.rb', line 135

def update_settings!(message, settings_before, &refresher)
  updater = lambda do
    new_settings = refresher.call
    next unless new_settings

    settings.merge(new_settings)
  end

  synchronize do
    new_settings = if on_settings_update
                     T.must(on_settings_update).call(message, settings_before, updater)
                   else
                     updater.call
                   end
    return false unless new_settings

    merge_settings!(new_settings)

    true
  end
end