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



373
374
375
376
# File 'lib/carddb/resources/decks.rb', line 373

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



312
313
314
315
316
317
318
319
320
321
# File 'lib/carddb/resources/decks.rb', line 312

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



481
482
483
484
# File 'lib/carddb/resources/decks.rb', line 481

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

#archive_import_format(id:) ⇒ Object



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

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



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

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.



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

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



368
369
370
371
# File 'lib/carddb/resources/decks.rb', line 368

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.



335
336
337
338
# File 'lib/carddb/resources/decks.rb', line 335

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



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

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



516
517
518
519
520
521
# File 'lib/carddb/resources/decks.rb', line 516

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



572
573
574
575
# File 'lib/carddb/resources/decks.rb', line 572

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

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



230
231
232
233
234
235
236
# File 'lib/carddb/resources/decks.rb', line 230

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



554
555
556
557
558
559
# File 'lib/carddb/resources/decks.rb', line 554

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



265
266
267
268
269
270
271
272
# File 'lib/carddb/resources/decks.rb', line 265

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.



177
178
179
180
181
182
183
# File 'lib/carddb/resources/decks.rb', line 177

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.



145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/carddb/resources/decks.rb', line 145

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



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

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.



136
137
138
139
140
141
142
# File 'lib/carddb/resources/decks.rb', line 136

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.



204
205
206
207
208
209
210
# File 'lib/carddb/resources/decks.rb', line 204

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.



186
187
188
189
190
191
192
193
# File 'lib/carddb/resources/decks.rb', line 186

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.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/carddb/resources/decks.rb', line 161

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



127
128
129
# File 'lib/carddb/resources/decks.rb', line 127

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

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



195
196
197
# File 'lib/carddb/resources/decks.rb', line 195

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



131
132
133
# File 'lib/carddb/resources/decks.rb', line 131

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



199
200
201
# File 'lib/carddb/resources/decks.rb', line 199

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



539
540
541
542
# File 'lib/carddb/resources/decks.rb', line 539

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



256
257
258
259
260
261
262
263
# File 'lib/carddb/resources/decks.rb', line 256

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.



579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
# File 'lib/carddb/resources/decks.rb', line 579

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.



402
403
404
405
# File 'lib/carddb/resources/decks.rb', line 402

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



407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# File 'lib/carddb/resources/decks.rb', line 407

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.



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/carddb/resources/decks.rb', line 213

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



323
324
325
326
327
328
329
330
331
332
# File 'lib/carddb/resources/decks.rb', line 323

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.



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

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



507
508
509
510
511
512
513
# File 'lib/carddb/resources/decks.rb', line 507

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



383
384
385
386
387
388
389
# File 'lib/carddb/resources/decks.rb', line 383

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



476
477
478
479
# File 'lib/carddb/resources/decks.rb', line 476

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



391
392
393
394
# File 'lib/carddb/resources/decks.rb', line 391

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



396
397
398
399
# File 'lib/carddb/resources/decks.rb', line 396

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



486
487
488
489
# File 'lib/carddb/resources/decks.rb', line 486

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



545
546
547
548
549
550
551
# File 'lib/carddb/resources/decks.rb', line 545

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



562
563
564
565
566
567
# File 'lib/carddb/resources/decks.rb', line 562

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



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

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



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

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



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/carddb/resources/decks.rb', line 274

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



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

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



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

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



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

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



491
492
493
494
# File 'lib/carddb/resources/decks.rb', line 491

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.



341
342
343
344
# File 'lib/carddb/resources/decks.rb', line 341

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



378
379
380
381
# File 'lib/carddb/resources/decks.rb', line 378

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



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

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.



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

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

#upsert_by_external_ref(input:) ⇒ Object



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

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.



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

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



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

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

#valuation(id:, read_state:, input:, version: nil, cache: nil) ⇒ DeckValuation?

Return current TCGPlayer valuation for a draft or published deck representation.

The returned priced total includes only entries with usable prices. Check its status and coverage counts before treating it as the complete deck value.

Parameters:

  • id (String)

    Deck UUID

  • read_state (String)

    DRAFT or PUBLISHED

  • input (Hash)

    Valuation subtype and optional metric

  • version (Hash, nil) (defaults to: nil)

    Optional published version selector

  • cache (Boolean, nil) (defaults to: nil)

    Whether to use the client cache; use false for the freshest available value

Returns:



118
119
120
121
122
123
124
125
# File 'lib/carddb/resources/decks.rb', line 118

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

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



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

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