Class: CardDB::Resources::ImportFormats
- Defined in:
- lib/carddb/resources/import_formats.rb
Overview
Publisher-managed import format resource.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#archive(id:) ⇒ Object
Archive an import format.
-
#create(input:) ⇒ Object
Create an import format.
-
#get(id, cache: nil) ⇒ Object
Get one import format by UUID.
-
#get_by_key(game_id:, key:, cache: nil) ⇒ Object
Get one import format by game ID and stable key.
-
#list(publisher_id: nil, game_id: nil, include_archived: nil, first: nil, after: nil, cache: nil) ⇒ Object
List import formats scoped by publisher or game.
-
#test(input:) ⇒ Object
Preview parsing and record resolution for a configured import format.
-
#unarchive(id:) ⇒ Object
Restore an archived import format.
-
#update(id:, input:) ⇒ Object
Update an import format.
Methods inherited from Base
Constructor Details
This class inherits a constructor from CardDB::Resources::Base
Instance Method Details
#archive(id:) ⇒ Object
Archive an import format. Requires a server-side secret credential.
87 88 89 90 91 92 |
# File 'lib/carddb/resources/import_formats.rb', line 87 def archive(id:) config.require_secret_credential!('import_formats.archive') data = connection.execute(QueryBuilder.archive_deck_import_format, { id: id }) DeckImportFormatDefinition.new(data['deckImportFormatArchive'], client: client) end |
#create(input:) ⇒ Object
Create an import format. Requires a server-side secret credential.
71 72 73 74 75 76 |
# File 'lib/carddb/resources/import_formats.rb', line 71 def create(input:) config.require_secret_credential!('import_formats.create') data = connection.execute(QueryBuilder.create_deck_import_format, { input: input }) DeckImportFormatDefinition.new(data['deckImportFormatCreate'], client: client) end |
#get(id, cache: nil) ⇒ Object
Get one import format by UUID.
47 48 49 50 51 52 53 |
# File 'lib/carddb/resources/import_formats.rb', line 47 def get(id, cache: nil) key = cache_key('import_formats', 'get', id: id) with_cache(key, resource: :import_formats, cache: cache) do data = connection.execute(QueryBuilder.deck_import_format, { id: id }) data['deckImportFormat'] ? DeckImportFormatDefinition.new(data['deckImportFormat'], client: client) : nil end end |
#get_by_key(game_id:, key:, cache: nil) ⇒ Object
Get one import format by game ID and stable key.
56 57 58 59 60 61 62 |
# File 'lib/carddb/resources/import_formats.rb', line 56 def get_by_key(game_id:, key:, cache: nil) cache_key_value = cache_key('import_formats', 'get_by_key', game_id: game_id, key: key) with_cache(cache_key_value, resource: :import_formats, cache: cache) do data = connection.execute(QueryBuilder.deck_import_format, { gameId: game_id, key: key }) data['deckImportFormat'] ? DeckImportFormatDefinition.new(data['deckImportFormat'], client: client) : nil end end |
#list(publisher_id: nil, game_id: nil, include_archived: nil, first: nil, after: nil, cache: nil) ⇒ Object
List import formats scoped by publisher or game.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/carddb/resources/import_formats.rb', line 8 def list(publisher_id: nil, game_id: nil, include_archived: nil, first: nil, after: nil, cache: nil) query = QueryBuilder.deck_import_formats( publisher_id: publisher_id, game_id: game_id, include_archived: include_archived, first: first, after: after ) variables = build_variables( publisherId: publisher_id, gameId: game_id, includeArchived: include_archived, first: first, after: after ) key = cache_key('import_formats', 'list', **variables) data = with_cache(key, resource: :import_formats, cache: cache) do connection.execute(query, variables) end Collection.new( data['deckImportFormats'], item_class: DeckImportFormatDefinition, next_page_loader: lambda { |cursor| list( publisher_id: publisher_id, game_id: game_id, include_archived: include_archived, first: first, after: cursor, cache: cache ) }, client: client ) end |
#test(input:) ⇒ Object
Preview parsing and record resolution for a configured import format.
65 66 67 68 |
# File 'lib/carddb/resources/import_formats.rb', line 65 def test(input:) data = connection.execute(QueryBuilder.deck_import_format_test, { input: input }) DeckImportFormatTestPayload.new(data['deckImportFormatTest'], client: client) end |
#unarchive(id:) ⇒ Object
Restore an archived import format. Requires a server-side secret credential.
95 96 97 98 99 100 |
# File 'lib/carddb/resources/import_formats.rb', line 95 def unarchive(id:) config.require_secret_credential!('import_formats.unarchive') data = connection.execute(QueryBuilder.unarchive_deck_import_format, { id: id }) DeckImportFormatDefinition.new(data['deckImportFormatUnarchive'], client: client) end |
#update(id:, input:) ⇒ Object
Update an import format. Requires a server-side secret credential.
79 80 81 82 83 84 |
# File 'lib/carddb/resources/import_formats.rb', line 79 def update(id:, input:) config.require_secret_credential!('import_formats.update') data = connection.execute(QueryBuilder.update_deck_import_format, { id: id, input: input }) DeckImportFormatDefinition.new(data['deckImportFormatUpdate'], client: client) end |