Module: QuizBrokerClient::AuthorizedContexts

Extended by:
DynamoDB
Defined in:
lib/quiz_broker_client/authorized_contexts.rb

Constant Summary collapse

AUTHORIZED_CONTEXTS_ATTRIBUTE =
'contexts'

Class Method Summary collapse

Methods included from DynamoDB

client

Class Method Details

.for(subject:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/quiz_broker_client/authorized_contexts.rb', line 9

def for(subject:)
  response = get_item(
    common_params.merge(
      key: {
        subject: subject
      }
    )
  )

  return Set.new if response.item.nil?

  response.item[AUTHORIZED_CONTEXTS_ATTRIBUTE]
end

.set(subject:, contexts:) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/quiz_broker_client/authorized_contexts.rb', line 23

def set(subject:, contexts:)
  put_item(
    common_params.merge(
      item: {
        subject: subject,
        created_at: Time.now.to_i,
        delete_at: Time.now.to_i + QuizBrokerClient.configuration.ttl.to_i,
        AUTHORIZED_CONTEXTS_ATTRIBUTE => Set.new(contexts)
      }
    )
  )

  true
end