Class: CardDB::Resources::Decks

Inherits:
Base
  • Object
show all
Defined in:
lib/carddb/resources/decks.rb

Overview

Decks resource for hosted decks and external deck hydration. rubocop:disable Metrics/ClassLength

Constant Summary collapse

JSON_OBJECT_INPUT_KEYS =
%w[metadata annotations].freeze

Instance Attribute Summary

Attributes inherited from Base

#client, #config, #connection

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from CardDB::Resources::Base

Instance Method Details

#add_entry(input:) ⇒ Object



353
354
355
356
# File 'lib/carddb/resources/decks.rb', line 353

def add_entry(input:)
  data = connection.execute(QueryBuilder.add_deck_entry, { input: normalize_deck_json_input(input) })
  DeckEntryMutationPayload.new(data['deckEntryAdd'], client: client)
end

#api_application_accesses(deck_id:, include_revoked: nil, cache: nil) ⇒ Object



292
293
294
295
296
297
298
299
300
301
# File 'lib/carddb/resources/decks.rb', line 292

def api_application_accesses(deck_id:, include_revoked: nil, cache: nil)
  variables = build_variables(deckId: deck_id, includeRevoked: include_revoked)
  key = cache_key('decks', 'api_application_accesses', **variables)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(QueryBuilder.deck_api_application_accesses, variables)
    (data['deckApiApplicationAccesses'] || []).map do |access|
      DeckAPIApplicationAccess.new(access, client: client)
    end
  end
end

#archive(id:) ⇒ Object



461
462
463
464
# File 'lib/carddb/resources/decks.rb', line 461

def archive(id:)
  data = connection.execute(QueryBuilder.archive_deck, { id: id })
  Deck.new(data['deckArchive'], client: client)
end

#archive_import_format(id:) ⇒ Object



440
441
442
443
# File 'lib/carddb/resources/decks.rb', line 440

def archive_import_format(id:)
  data = connection.execute(QueryBuilder.archive_deck_import_format, { id: id })
  DeckImportFormatDefinition.new(data['deckImportFormatArchive'], client: client)
end

#claim(id:, input:) ⇒ Object



338
339
340
341
# File 'lib/carddb/resources/decks.rb', line 338

def claim(id:, input:)
  data = connection.execute(QueryBuilder.claim_deck, { id: id, input: input })
  DeckOwnershipTransferPayload.new(data['deckClaim'], client: client)
end

#collaborators(deck_id:, cache: nil) ⇒ Object

List collaborators for a deck.



284
285
286
287
288
289
290
# File 'lib/carddb/resources/decks.rb', line 284

def collaborators(deck_id:, cache: nil)
  key = cache_key('decks', 'collaborators', deck_id: deck_id)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(QueryBuilder.deck_collaborators, { deckId: deck_id })
    (data['deckCollaborators'] || []).map { |collaborator| DeckCollaborator.new(collaborator, client: client) }
  end
end

#copy(id:, input:) ⇒ Object



348
349
350
351
# File 'lib/carddb/resources/decks.rb', line 348

def copy(id:, input:)
  data = connection.execute(QueryBuilder.copy_deck, { id: id, input: input })
  DeckCopyPayload.new(data['deckCopy'], client: client)
end

#create(input:) ⇒ Object

Create a hosted deck.



315
316
317
318
# File 'lib/carddb/resources/decks.rb', line 315

def create(input:)
  data = connection.execute(QueryBuilder.create_deck, { input: normalize_deck_json_input(input) })
  Deck.new(data['deckCreate'], client: client)
end

#create_import_format(input:) ⇒ Object



430
431
432
433
# File 'lib/carddb/resources/decks.rb', line 430

def create_import_format(input:)
  data = connection.execute(QueryBuilder.create_deck_import_format, { input: input })
  DeckImportFormatDefinition.new(data['deckImportFormatCreate'], client: client)
end

#create_token_issuer(input:) ⇒ Object

rubocop:enable Naming/PredicateMethod



496
497
498
499
500
501
# File 'lib/carddb/resources/decks.rb', line 496

def create_token_issuer(input:)
  config.require_secret_credential!('decks.create_token_issuer')

  data = connection.execute(QueryBuilder.create_deck_token_issuer, { input: input })
  DeckTokenIssuer.new(data['deckTokenIssuerCreate'], client: client)
end

#delete(id:) ⇒ Object

Delete a hosted deck. rubocop:disable Naming/PredicateMethod



552
553
554
555
# File 'lib/carddb/resources/decks.rb', line 552

def delete(id:)
  data = connection.execute(QueryBuilder.delete_deck, { id: id })
  !!data['deckDelete']
end

#draft_diff(id:, cache: nil) ⇒ Object



210
211
212
213
214
215
216
# File 'lib/carddb/resources/decks.rb', line 210

def draft_diff(id:, cache: nil)
  key = cache_key('decks', 'draft_diff', id: id)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(QueryBuilder.deck_draft_diff, { id: id })
    DeckDiff.new(data['deckDraftDiff'], client: client)
  end
end

#exchange_token(input:) ⇒ Object

rubocop:enable Naming/PredicateMethod



534
535
536
537
538
539
# File 'lib/carddb/resources/decks.rb', line 534

def exchange_token(input:)
  config.require_secret_credential!('decks.exchange_token')

  data = connection.execute(QueryBuilder.exchange_deck_token, { input: input })
  DeckTokenExchangePayload.new(data['deckTokenExchange'], client: client)
end

#export_deck(id:, format: 'SIMPLE_TEXT', cache: nil) ⇒ Object



245
246
247
248
249
250
251
252
# File 'lib/carddb/resources/decks.rb', line 245

def export_deck(id:, format: 'SIMPLE_TEXT', cache: nil)
  variables = { id: id, format: format }
  key = cache_key('decks', 'export_deck', **variables)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(QueryBuilder.deck_export, variables)
    DeckExportPayload.new(data['deckExport'], client: client)
  end
end

#fetch(id, cache: nil) ⇒ Object

Fetch a hosted deck by CardDB UUID.



89
90
91
92
93
94
95
# File 'lib/carddb/resources/decks.rb', line 89

def fetch(id, cache: nil)
  key = cache_key('decks', 'fetch', id: id)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(QueryBuilder.fetch_deck, { id: id })
    data['fetchDeck'] ? Deck.new(data['fetchDeck'], client: client) : nil
  end
end

#fetch_by_external_ref(external_ref:, cache: nil) ⇒ Object

Fetch a hosted deck by external reference for the current API application.



157
158
159
160
161
162
163
# File 'lib/carddb/resources/decks.rb', line 157

def fetch_by_external_ref(external_ref:, cache: nil)
  key = cache_key('decks', 'fetch_by_external_ref', external_ref: external_ref)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(QueryBuilder.fetch_deck_by_external_ref, { externalRef: external_ref })
    data['fetchDeckByExternalRef'] ? Deck.new(data['fetchDeckByExternalRef'], client: client) : nil
  end
end

#fetch_by_slug(slug:, publisher_slug: nil, game_key: nil, cache: nil) ⇒ Object

Fetch a hosted deck by canonical or historical slug.



125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/carddb/resources/decks.rb', line 125

def fetch_by_slug(slug:, publisher_slug: nil, game_key: nil, cache: nil)
  resolved_publisher = resolve_publisher(publisher_slug)
  resolved_game = resolve_game(game_key)
  validate_access!(resolved_publisher, resolved_game)

  key = cache_key('decks', 'fetch_by_slug', publisher_slug: resolved_publisher, game_key: resolved_game, slug: slug)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(
      QueryBuilder.fetch_deck_by_slug,
      { publisherSlug: resolved_publisher, gameKey: resolved_game, slug: slug }
    )
    data['fetchDeckBySlug'] ? Deck.new(data['fetchDeckBySlug'], client: client) : nil
  end
end

#fetch_import_format(id, cache: nil) ⇒ Object



417
418
419
420
421
422
423
# File 'lib/carddb/resources/decks.rb', line 417

def fetch_import_format(id, cache: nil)
  key = cache_key('decks', 'fetch_import_format', id: id)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(QueryBuilder.deck_import_format, { id: id })
    data['deckImportFormat'] ? DeckImportFormatDefinition.new(data['deckImportFormat'], client: client) : nil
  end
end

#fetch_mine(id, cache: nil) ⇒ Object

Fetch one deck owned by the current account or API application.



116
117
118
119
120
121
122
# File 'lib/carddb/resources/decks.rb', line 116

def fetch_mine(id, cache: nil)
  key = cache_key('decks', 'fetch_mine', id: id)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(QueryBuilder.my_deck, { id: id })
    data['myDeck'] ? Deck.new(data['myDeck'], client: client) : nil
  end
end

#fetch_version(id, cache: nil) ⇒ Object

Fetch one immutable published deck version.



184
185
186
187
188
189
190
# File 'lib/carddb/resources/decks.rb', line 184

def fetch_version(id, cache: nil)
  key = cache_key('decks', 'fetch_version', id: id)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(QueryBuilder.deck_version, { id: id })
    data['deckVersion'] ? DeckVersion.new(data['deckVersion'], client: client) : nil
  end
end

#get(id, read_state:, version: nil, cache: nil) ⇒ Object

Fetch by UUID using the ownership-aware deck API.



98
99
100
101
102
103
104
105
# File 'lib/carddb/resources/decks.rb', line 98

def get(id, read_state:, version: nil, cache: nil)
  variables = build_variables(id: id, readState: read_state, version: version)
  key = cache_key('decks', 'get', **variables)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(QueryBuilder.deck, variables)
    data['deck'] ? Deck.new(data['deck'], client: client) : nil
  end
end

#get_by_external_ref(external_ref:, read_state:, version: nil, cache: nil) ⇒ Object

Fetch by external reference using the ownership-aware deckByExternalRef API.



166
167
168
169
170
171
172
173
# File 'lib/carddb/resources/decks.rb', line 166

def get_by_external_ref(external_ref:, read_state:, version: nil, cache: nil)
  variables = build_variables(externalRef: external_ref, readState: read_state, version: version)
  key = cache_key('decks', 'get_by_external_ref', **variables)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(QueryBuilder.deck_by_external_ref, variables)
    data['deckByExternalRef'] ? Deck.new(data['deckByExternalRef'], client: client) : nil
  end
end

#get_by_slug(slug:, publisher_slug: nil, game_key: nil, cache: nil) ⇒ Object

Fetch by slug using the ownership-aware deckBySlug API.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/carddb/resources/decks.rb', line 141

def get_by_slug(slug:, publisher_slug: nil, game_key: nil, cache: nil)
  resolved_publisher = resolve_publisher(publisher_slug)
  resolved_game = resolve_game(game_key)
  validate_access!(resolved_publisher, resolved_game)

  key = cache_key('decks', 'get_by_slug', publisher_slug: resolved_publisher, game_key: resolved_game, slug: slug)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(
      QueryBuilder.deck_by_slug,
      { publisherSlug: resolved_publisher, gameKey: resolved_game, slug: slug }
    )
    data['deckBySlug'] ? Deck.new(data['deckBySlug'], client: client) : nil
  end
end

#get_draft(id, cache: nil) ⇒ Object



107
108
109
# File 'lib/carddb/resources/decks.rb', line 107

def get_draft(id, cache: nil)
  get(id, read_state: 'DRAFT', cache: cache)
end

#get_draft_by_external_ref(external_ref:, cache: nil) ⇒ Object



175
176
177
# File 'lib/carddb/resources/decks.rb', line 175

def get_draft_by_external_ref(external_ref:, cache: nil)
  get_by_external_ref(external_ref: external_ref, read_state: 'DRAFT', cache: cache)
end

#get_published(id, version: nil, cache: nil) ⇒ Object



111
112
113
# File 'lib/carddb/resources/decks.rb', line 111

def get_published(id, version: nil, cache: nil)
  get(id, read_state: 'PUBLISHED', version: version, cache: cache)
end

#get_published_by_external_ref(external_ref:, version: nil, cache: nil) ⇒ Object



179
180
181
# File 'lib/carddb/resources/decks.rb', line 179

def get_published_by_external_ref(external_ref:, version: nil, cache: nil)
  get_by_external_ref(external_ref: external_ref, read_state: 'PUBLISHED', version: version, cache: cache)
end

#grant_api_application_access(input:) ⇒ Object



519
520
521
522
# File 'lib/carddb/resources/decks.rb', line 519

def grant_api_application_access(input:)
  data = connection.execute(QueryBuilder.grant_deck_api_application_access, { input: input })
  DeckAPIApplicationAccess.new(data['deckApiApplicationAccessGrant'], client: client)
end

#hydrate_deck_entries(input:, cache: nil) ⇒ Object



236
237
238
239
240
241
242
243
# File 'lib/carddb/resources/decks.rb', line 236

def hydrate_deck_entries(input:, cache: nil)
  normalized_input = normalize_deck_json_input(input)
  key = cache_key('decks', 'hydrate_deck_entries', input: normalized_input)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(QueryBuilder.deck_hydrate_entries, { input: normalized_input })
    DeckHydrateEntriesPayload.new(data['deckHydrateEntries'], client: client)
  end
end

#hydrate_entries(dataset_key:, entries:, publisher_slug: nil, game_key: nil, identifier_field: nil, cache: nil) ⇒ Object

Hydrate third-party-owned deck entries without storing them in CardDB.



559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
# File 'lib/carddb/resources/decks.rb', line 559

def hydrate_entries(dataset_key:, entries:, publisher_slug: nil, game_key: nil, identifier_field: nil, cache: nil)
  return [] if entries.empty?

  resolved_publisher = resolve_publisher(publisher_slug)
  resolved_game = resolve_game(game_key)
  validate_access!(resolved_publisher, resolved_game)

  identifiers = entries.map { |entry| entry_identifier(entry) }
  key = cache_key(
    'decks',
    'hydrate_entries',
    publisher_slug: resolved_publisher,
    game_key: resolved_game,
    dataset_key: dataset_key,
    identifiers: identifiers
  )
  records = with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(
      QueryBuilder.fetch_records_by_identifier,
      {
        publisherSlug: resolved_publisher,
        gameKey: resolved_game,
        datasetKey: dataset_key,
        identifiers: identifiers
      }
    )
    (data['fetchRecordsByIdentifier'] || []).map { |record| Record.new(record, client: client) }
  end

  records_by_identifier = records_by_deck_identifier(records, identifiers, identifier_field)
  entries.map do |entry|
    entry.merge(record: records_by_identifier[entry_identifier(entry)])
  end
end

#import_deck(input:) ⇒ Object

Import a decklist into an existing deck or dry-run resolution.



382
383
384
385
# File 'lib/carddb/resources/decks.rb', line 382

def import_deck(input:)
  data = connection.execute(QueryBuilder.import_deck, { input: input })
  DeckImportPayload.new(data['deckImport'], client: client)
end

#import_formats(game_id:, include_archived: nil, first: nil, after: nil, cache: nil) ⇒ Object



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# File 'lib/carddb/resources/decks.rb', line 387

def import_formats(game_id:, include_archived: nil, first: nil, after: nil, cache: nil)
  query = QueryBuilder.deck_import_formats(
    game_id: game_id,
    include_archived: include_archived,
    first: first,
    after: after
  )
  variables = build_variables(gameId: game_id, includeArchived: include_archived, first: first, after: after)
  key = cache_key('decks', 'import_formats', **variables)

  data = with_cache(key, resource: :decks, cache: cache) do
    connection.execute(query, variables)
  end

  Collection.new(
    data['deckImportFormats'],
    item_class: DeckImportFormatDefinition,
    next_page_loader: lambda { |cursor|
      import_formats(
        game_id: game_id,
        include_archived: include_archived,
        first: first,
        after: cursor,
        cache: cache
      )
    },
    client: client
  )
end

#list_app(filter: nil, first: nil, after: nil, cache: nil) ⇒ Object

List app-owned decks for the current secret-key API application.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/carddb/resources/decks.rb', line 51

def list_app(filter: nil, first: nil, after: nil, cache: nil)
  config.require_secret_credential!('decks.list_app')

  query = QueryBuilder.app_decks(filter: filter, first: first, after: after)
  variables = build_variables(filter: filter, first: first, after: after)
  key = cache_key('decks', 'list_app', **variables)

  data = with_cache(key, resource: :decks, cache: cache) do
    connection.execute(query, variables)
  end

  Collection.new(
    data['appDecks'],
    item_class: Deck,
    next_page_loader: ->(cursor) { list_app(filter: filter, first: first, after: cursor, cache: cache) },
    client: client
  )
end

#list_mine(first: nil, after: nil, include_archived: nil, cache: nil) ⇒ Object

List decks owned by the current account or API application.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/carddb/resources/decks.rb', line 13

def list_mine(first: nil, after: nil, include_archived: nil, cache: nil)
  query = QueryBuilder.list_my_decks(first: first, after: after, include_archived: include_archived)
  variables = build_variables(first: first, after: after, includeArchived: include_archived)
  key = cache_key('decks', 'list_mine', **variables)

  data = with_cache(key, resource: :decks, cache: cache) do
    connection.execute(query, variables)
  end

  Collection.new(
    data['myDecks'],
    item_class: Deck,
    next_page_loader: lambda { |cursor|
      list_mine(first: first, after: cursor, include_archived: include_archived, cache: cache)
    },
    client: client
  )
end

#list_public(filter: nil, first: nil, after: nil, cache: nil) ⇒ Object

List published live decks eligible for public discovery.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/carddb/resources/decks.rb', line 71

def list_public(filter: nil, first: nil, after: nil, cache: nil)
  query = QueryBuilder.public_decks(filter: filter, first: first, after: after)
  variables = build_variables(filter: filter, first: first, after: after)
  key = cache_key('decks', 'list_public', **variables)

  data = with_cache(key, resource: :decks, cache: cache) do
    connection.execute(query, variables)
  end

  Collection.new(
    data['publicDecks'],
    item_class: Deck,
    next_page_loader: ->(cursor) { list_public(filter: filter, first: first, after: cursor, cache: cache) },
    client: client
  )
end

#list_versions(deck_id:, first: nil, after: nil, cache: nil) ⇒ Object

List immutable published versions for a deck.



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/carddb/resources/decks.rb', line 193

def list_versions(deck_id:, first: nil, after: nil, cache: nil)
  query = QueryBuilder.deck_versions(first: first, after: after)
  variables = build_variables(deckId: deck_id, first: first, after: after)
  key = cache_key('decks', 'list_versions', **variables)

  data = with_cache(key, resource: :decks, cache: cache) do
    connection.execute(query, variables)
  end

  Collection.new(
    data['deckVersions'],
    item_class: DeckVersion,
    next_page_loader: ->(cursor) { list_versions(deck_id: deck_id, first: first, after: cursor, cache: cache) },
    client: client
  )
end

#list_viewer(filter: nil, first: nil, after: nil, cache: nil) ⇒ Object

List decks owned by the current account or OAuth grant.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/carddb/resources/decks.rb', line 33

def list_viewer(filter: nil, first: nil, after: nil, cache: nil)
  query = QueryBuilder.viewer_decks(filter: filter, first: first, after: after)
  variables = build_variables(filter: filter, first: first, after: after)
  key = cache_key('decks', 'list_viewer', **variables)

  data = with_cache(key, resource: :decks, cache: cache) do
    connection.execute(query, variables)
  end

  Collection.new(
    data['viewerDecks'],
    item_class: Deck,
    next_page_loader: ->(cursor) { list_viewer(filter: filter, first: first, after: cursor, cache: cache) },
    client: client
  )
end

#my_api_application_accesses(application_id: nil, cache: nil) ⇒ Object



303
304
305
306
307
308
309
310
311
312
# File 'lib/carddb/resources/decks.rb', line 303

def my_api_application_accesses(application_id: nil, cache: nil)
  variables = build_variables(applicationId: application_id)
  key = cache_key('decks', 'my_api_application_accesses', **variables)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(QueryBuilder.my_deck_api_application_accesses, variables)
    (data['myDeckApiApplicationAccesses'] || []).map do |access|
      DeckAPIApplicationAccess.new(access, client: client)
    end
  end
end

#publish(id:, input:) ⇒ Object

Publish the current draft as an immutable deck version.



451
452
453
454
# File 'lib/carddb/resources/decks.rb', line 451

def publish(id:, input:)
  data = connection.execute(QueryBuilder.publish_deck, { id: id, input: input })
  DeckPublishPayload.new(data['deckPublish'], client: client)
end

#remove_collaborator(deck_id:, account_id:) ⇒ Object

Remove a deck collaborator. rubocop:disable Naming/PredicateMethod



487
488
489
490
491
492
493
# File 'lib/carddb/resources/decks.rb', line 487

def remove_collaborator(deck_id:, account_id:)
  data = connection.execute(
    QueryBuilder.remove_deck_collaborator,
    { deckId: deck_id, accountId:  }
  )
  !!data['deckCollaboratorRemove']
end

#remove_entry(id:, expected_draft_revision:) ⇒ Object



363
364
365
366
367
368
369
# File 'lib/carddb/resources/decks.rb', line 363

def remove_entry(id:, expected_draft_revision:)
  data = connection.execute(
    QueryBuilder.remove_deck_entry,
    { id: id, expectedDraftRevision: expected_draft_revision }
  )
  DeckEntryMutationPayload.new(data['deckEntryRemove'], client: client)
end

#remove_invalid_entries(id:, input:) ⇒ Object



456
457
458
459
# File 'lib/carddb/resources/decks.rb', line 456

def remove_invalid_entries(id:, input:)
  data = connection.execute(QueryBuilder.remove_invalid_deck_entries, { id: id, input: input })
  Deck.new(data['deckRemoveInvalidEntries'], client: client)
end

#reorder_entries(deck_id:, input:) ⇒ Object



371
372
373
374
# File 'lib/carddb/resources/decks.rb', line 371

def reorder_entries(deck_id:, input:)
  data = connection.execute(QueryBuilder.reorder_deck_entries, { deckId: deck_id, input: input })
  DeckEntryReorderPayload.new(data['deckEntryReorder'], client: client)
end

#replace_entries(deck_id:, input:) ⇒ Object



376
377
378
379
# File 'lib/carddb/resources/decks.rb', line 376

def replace_entries(deck_id:, input:)
  data = connection.execute(QueryBuilder.replace_deck_entries, { deckId: deck_id, input: normalize_deck_json_input(input) })
  DeckEntriesReplacePayload.new(data['deckEntriesReplace'], client: client)
end

#restore(id:) ⇒ Object



466
467
468
469
# File 'lib/carddb/resources/decks.rb', line 466

def restore(id:)
  data = connection.execute(QueryBuilder.restore_deck, { id: id })
  Deck.new(data['deckRestore'], client: client)
end

#revoke_api_application_access(deck_id:, api_application_id:) ⇒ Object

rubocop:disable Naming/PredicateMethod



525
526
527
528
529
530
531
# File 'lib/carddb/resources/decks.rb', line 525

def revoke_api_application_access(deck_id:, api_application_id:)
  data = connection.execute(
    QueryBuilder.revoke_deck_api_application_access,
    { deckId: deck_id, apiApplicationId: api_application_id }
  )
  !!data['deckApiApplicationAccessRevoke']
end

#revoke_token(id:) ⇒ Object

rubocop:disable Naming/PredicateMethod



542
543
544
545
546
547
# File 'lib/carddb/resources/decks.rb', line 542

def revoke_token(id:)
  config.require_secret_credential!('decks.revoke_token')

  data = connection.execute(QueryBuilder.revoke_deck_token, { id: id })
  !!data['deckTokenRevoke']
end

#revoke_token_issuer(id:) ⇒ Object

rubocop:disable Naming/PredicateMethod



504
505
506
507
508
509
# File 'lib/carddb/resources/decks.rb', line 504

def revoke_token_issuer(id:)
  config.require_secret_credential!('decks.revoke_token_issuer')

  data = connection.execute(QueryBuilder.revoke_deck_token_issuer, { id: id })
  !!data['deckTokenIssuerRevoke']
end

#revoke_token_issuer_signing_key(id:) ⇒ Object

rubocop:enable Naming/PredicateMethod



512
513
514
515
516
517
# File 'lib/carddb/resources/decks.rb', line 512

def revoke_token_issuer_signing_key(id:)
  config.require_secret_credential!('decks.revoke_token_issuer_signing_key')

  data = connection.execute(QueryBuilder.revoke_deck_token_issuer_signing_key, { id: id })
  DeckTokenIssuer.new(data['deckTokenIssuerSigningKeyRevoke'], client: client)
end

#section_definitions(publisher_slug: nil, game_key: nil, game_id: nil, ruleset_key: nil, ruleset_version_id: nil, cache: nil) ⇒ Object



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/carddb/resources/decks.rb', line 254

def section_definitions(
  publisher_slug: nil,
  game_key: nil,
  game_id: nil,
  ruleset_key: nil,
  ruleset_version_id: nil,
  cache: nil
)
  query = QueryBuilder.deck_section_definitions(
    publisher_slug: publisher_slug,
    game_key: game_key,
    game_id: game_id,
    ruleset_key: ruleset_key,
    ruleset_version_id: ruleset_version_id
  )
  variables = build_variables(
    publisherSlug: publisher_slug,
    gameKey: game_key,
    gameId: game_id,
    rulesetKey: ruleset_key,
    rulesetVersionId: ruleset_version_id
  )
  key = cache_key('decks', 'section_definitions', **variables)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(query, variables)
    (data['deckSectionDefinitions'] || []).map { |definition| DeckSectionDefinition.new(definition, client: client) }
  end
end

#test_import_format(input:) ⇒ Object



425
426
427
428
# File 'lib/carddb/resources/decks.rb', line 425

def test_import_format(input:)
  data = connection.execute(QueryBuilder.deck_import_format_test, { input: input })
  DeckImportFormatTestPayload.new(data['deckImportFormatTest'], client: client)
end

#transfer_ownership(id:, input:) ⇒ Object



343
344
345
346
# File 'lib/carddb/resources/decks.rb', line 343

def transfer_ownership(id:, input:)
  data = connection.execute(QueryBuilder.transfer_deck_ownership, { id: id, input: input })
  DeckOwnershipTransferPayload.new(data['deckTransferOwnership'], client: client)
end

#unarchive_import_format(id:) ⇒ Object



445
446
447
448
# File 'lib/carddb/resources/decks.rb', line 445

def unarchive_import_format(id:)
  data = connection.execute(QueryBuilder.unarchive_deck_import_format, { id: id })
  DeckImportFormatDefinition.new(data['deckImportFormatUnarchive'], client: client)
end

#unpublish(id:) ⇒ Object



471
472
473
474
# File 'lib/carddb/resources/decks.rb', line 471

def unpublish(id:)
  data = connection.execute(QueryBuilder.unpublish_deck, { id: id })
  Deck.new(data['deckUnpublish'], client: client)
end

#update(id:, input:) ⇒ Object

Update a hosted deck.



321
322
323
324
# File 'lib/carddb/resources/decks.rb', line 321

def update(id:, input:)
  data = connection.execute(QueryBuilder.update_deck, { id: id, input: normalize_deck_json_input(input) })
  Deck.new(data['deckUpdate'], client: client)
end

#update_entry(id:, input:) ⇒ Object



358
359
360
361
# File 'lib/carddb/resources/decks.rb', line 358

def update_entry(id:, input:)
  data = connection.execute(QueryBuilder.update_deck_entry, { id: id, input: normalize_deck_json_input(input) })
  DeckEntryMutationPayload.new(data['deckEntryUpdate'], client: client)
end

#update_import_format(id:, input:) ⇒ Object



435
436
437
438
# File 'lib/carddb/resources/decks.rb', line 435

def update_import_format(id:, input:)
  data = connection.execute(QueryBuilder.update_deck_import_format, { id: id, input: input })
  DeckImportFormatDefinition.new(data['deckImportFormatUpdate'], client: client)
end

#update_metadata(id:, input:) ⇒ Object

Update deck-level metadata without mutating entries.



327
328
329
# File 'lib/carddb/resources/decks.rb', line 327

def (id:, input:)
  update(id: id, input: input)
end

#upsert_by_external_ref(input:) ⇒ Object



331
332
333
334
335
336
# File 'lib/carddb/resources/decks.rb', line 331

def upsert_by_external_ref(input:)
  config.require_secret_credential!('decks.upsert_by_external_ref')

  data = connection.execute(QueryBuilder.upsert_deck_by_external_ref, { input: normalize_deck_json_input(input) })
  DeckUpsertByExternalRefPayload.new(data['deckUpsertByExternalRef'], client: client)
end

#upsert_collaborator(deck_id:, account_id:, role:) ⇒ Object

Create or update a deck collaborator.



477
478
479
480
481
482
483
# File 'lib/carddb/resources/decks.rb', line 477

def upsert_collaborator(deck_id:, account_id:, role:)
  data = connection.execute(
    QueryBuilder.upsert_deck_collaborator,
    { deckId: deck_id, accountId: , role: role }
  )
  DeckCollaborator.new(data['deckCollaboratorUpsert'], client: client)
end

#validate(id:, input: nil, cache: nil) ⇒ Object



227
228
229
230
231
232
233
234
# File 'lib/carddb/resources/decks.rb', line 227

def validate(id:, input: nil, cache: nil)
  variables = build_variables(id: id, input: input)
  key = cache_key('decks', 'validate', **variables)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(QueryBuilder.deck_validate, variables)
    DeckValidation.new(data['deckValidate'], client: client)
  end
end

#version_diff(from_version_id:, to_version_id:, cache: nil) ⇒ Object



218
219
220
221
222
223
224
225
# File 'lib/carddb/resources/decks.rb', line 218

def version_diff(from_version_id:, to_version_id:, cache: nil)
  variables = { fromVersionId: from_version_id, toVersionId: to_version_id }
  key = cache_key('decks', 'version_diff', **variables)
  with_cache(key, resource: :decks, cache: cache) do
    data = connection.execute(QueryBuilder.deck_version_diff, variables)
    DeckDiff.new(data['deckVersionDiff'], client: client)
  end
end