Module: Worldline::Acquiring::SDK::Authentication::OAuth2Scopes

Defined in:
lib/worldline/acquiring/sdk/authentication/oauth2_scopes.rb

Class Method Summary collapse

Class Method Details

.all ⇒ Object

Returns all available scopes.



43
44
45
# File 'lib/worldline/acquiring/sdk/authentication/oauth2_scopes.rb', line 43

def self.all
  ALL_SCOPES
end

.for_api_version(api_version) ⇒ Object

Returns all scopes needed for all operations of the given API version.



48
49
50
51
# File 'lib/worldline/acquiring/sdk/authentication/oauth2_scopes.rb', line 48

def self.for_api_version(api_version)
  operations = SCOPES_BY_OPERATION[api_version] || {}
  operations.values.flatten.uniq.freeze
end

.for_filtered_operations(filter) ⇒ Object

Returns all scopes needed for the operations that pass the given filter. The first argument to the filter is the API version, the second is the operation id.



68
69
70
71
72
73
74
75
# File 'lib/worldline/acquiring/sdk/authentication/oauth2_scopes.rb', line 68

def self.for_filtered_operations(filter)
  SCOPES_BY_OPERATION.keys.map { |api_version|
    operations = SCOPES_BY_OPERATION[api_version]
    operations.keys
              .filter { |operation_id| filter.call(api_version, operation_id) }
              .map { |operation_id| operations[operation_id] }
  }.flatten.uniq.freeze
end

.for_operation(api_version, operation_id) ⇒ Object

Returns all scopes needed for the given operation of the given API version.



54
55
56
57
58
# File 'lib/worldline/acquiring/sdk/authentication/oauth2_scopes.rb', line 54

def self.for_operation(api_version, operation_id)
  operations = SCOPES_BY_OPERATION[api_version] || {}
  scopes = operations[operation_id] || []
  scopes.uniq.freeze
end

.for_operations(api_version, *operation_ids) ⇒ Object

Returns all scopes needed for the given operations of the given API version.



61
62
63
64
# File 'lib/worldline/acquiring/sdk/authentication/oauth2_scopes.rb', line 61

def self.for_operations(api_version, *operation_ids)
  operations = SCOPES_BY_OPERATION[api_version] || {}
  operation_ids.map { |operation_id| operations[operation_id] || [] }.flatten.uniq.freeze
end