carddb 0.3.0 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec_status +171 -151
- data/CHANGELOG.md +7 -0
- data/README.md +189 -1
- data/examples/publisher_content_pipeline.rb +80 -0
- data/lib/carddb/client.rb +28 -0
- data/lib/carddb/collection.rb +517 -0
- data/lib/carddb/query_builder.rb +1030 -44
- data/lib/carddb/resources/datasets.rb +85 -0
- data/lib/carddb/resources/exports.rb +96 -0
- data/lib/carddb/resources/files.rb +43 -0
- data/lib/carddb/resources/games.rb +70 -0
- data/lib/carddb/resources/import_formats.rb +103 -0
- data/lib/carddb/resources/imports.rb +225 -0
- data/lib/carddb/resources/records.rb +157 -0
- data/lib/carddb/version.rb +1 -1
- data/lib/carddb.rb +32 -0
- metadata +6 -1
|
@@ -6,6 +6,163 @@ module CardDB
|
|
|
6
6
|
class Records < Base
|
|
7
7
|
include FilterOperators
|
|
8
8
|
|
|
9
|
+
# List records in a publisher-accessible dataset by dataset ID.
|
|
10
|
+
# rubocop:disable Metrics/MethodLength
|
|
11
|
+
def list(
|
|
12
|
+
dataset_id:,
|
|
13
|
+
filter: nil,
|
|
14
|
+
order_by: nil,
|
|
15
|
+
first: nil,
|
|
16
|
+
after: nil,
|
|
17
|
+
last: nil,
|
|
18
|
+
before: nil,
|
|
19
|
+
validate_schema: nil,
|
|
20
|
+
cache: nil,
|
|
21
|
+
&block
|
|
22
|
+
)
|
|
23
|
+
final_filter = block_given? ? FilterBuilder.build(&block) : filter
|
|
24
|
+
query = QueryBuilder.list_dataset_records(
|
|
25
|
+
dataset_id: dataset_id,
|
|
26
|
+
filter: final_filter,
|
|
27
|
+
order_by: order_by,
|
|
28
|
+
first: first,
|
|
29
|
+
after: after,
|
|
30
|
+
last: last,
|
|
31
|
+
before: before,
|
|
32
|
+
validate_schema: validate_schema
|
|
33
|
+
)
|
|
34
|
+
variables = build_variables(
|
|
35
|
+
datasetId: dataset_id,
|
|
36
|
+
filter: final_filter,
|
|
37
|
+
orderBy: order_by,
|
|
38
|
+
first: first,
|
|
39
|
+
after: after,
|
|
40
|
+
last: last,
|
|
41
|
+
before: before,
|
|
42
|
+
validateSchema: validate_schema
|
|
43
|
+
)
|
|
44
|
+
key = cache_key('records', 'list', **variables)
|
|
45
|
+
|
|
46
|
+
data = with_cache(key, resource: :records, cache: cache) { connection.execute(query, variables) }
|
|
47
|
+
|
|
48
|
+
Collection.new(
|
|
49
|
+
data['datasetRecords'],
|
|
50
|
+
item_class: Record,
|
|
51
|
+
next_page_loader: lambda { |cursor|
|
|
52
|
+
list(
|
|
53
|
+
dataset_id: dataset_id,
|
|
54
|
+
filter: final_filter,
|
|
55
|
+
order_by: order_by,
|
|
56
|
+
first: first,
|
|
57
|
+
after: cursor,
|
|
58
|
+
validate_schema: validate_schema,
|
|
59
|
+
cache: cache
|
|
60
|
+
)
|
|
61
|
+
},
|
|
62
|
+
client: client
|
|
63
|
+
)
|
|
64
|
+
end
|
|
65
|
+
# rubocop:enable Metrics/MethodLength
|
|
66
|
+
|
|
67
|
+
# Get a publisher-accessible record by dataset ID and identifier value.
|
|
68
|
+
def get_by_dataset_identifier(dataset_id:, identifier:, cache: nil, include_pricing: false)
|
|
69
|
+
key = cache_key(
|
|
70
|
+
'records',
|
|
71
|
+
'get_by_dataset_identifier',
|
|
72
|
+
dataset_id: dataset_id,
|
|
73
|
+
identifier: identifier,
|
|
74
|
+
include_pricing: include_pricing
|
|
75
|
+
)
|
|
76
|
+
with_cache(key, resource: :records, cache: cache) do
|
|
77
|
+
query = QueryBuilder.dataset_record(
|
|
78
|
+
dataset_id: dataset_id,
|
|
79
|
+
identifier: identifier,
|
|
80
|
+
include_pricing: include_pricing
|
|
81
|
+
)
|
|
82
|
+
data = connection.execute(query, { datasetId: dataset_id, identifier: identifier })
|
|
83
|
+
|
|
84
|
+
data['datasetRecord'] ? Record.new(data['datasetRecord'], client: client) : nil
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Start an import-backed batch upsert, or return a dry-run result.
|
|
89
|
+
def upsert_batch(input:)
|
|
90
|
+
config.require_secret_credential!('records.upsert_batch')
|
|
91
|
+
|
|
92
|
+
data = connection.execute(QueryBuilder.upsert_dataset_records, { input: input })
|
|
93
|
+
DatasetRecordsUpsertPayload.new(data['datasetRecordsUpsert'], client: client)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Create a dry-run or destructive bulk delete/reconciliation job.
|
|
97
|
+
def delete_batch(input:)
|
|
98
|
+
config.require_secret_credential!('records.delete_batch')
|
|
99
|
+
|
|
100
|
+
data = connection.execute(QueryBuilder.delete_dataset_records, { input: input })
|
|
101
|
+
DatasetRecordDeleteJob.new(data['datasetRecordsDelete'], client: client)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Get one bulk delete/reconciliation job.
|
|
105
|
+
def get_delete_job(id, cache: nil)
|
|
106
|
+
key = cache_key('records', 'get_delete_job', id: id)
|
|
107
|
+
with_cache(key, resource: :records, cache: cache) do
|
|
108
|
+
data = connection.execute(QueryBuilder.dataset_record_delete_job, { id: id })
|
|
109
|
+
data['datasetRecordDeleteJob'] ? DatasetRecordDeleteJob.new(data['datasetRecordDeleteJob'], client: client) : nil
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# List bulk delete/reconciliation jobs for a publisher.
|
|
114
|
+
def list_delete_jobs(publisher_id:, dataset_id: nil, status: nil, first: nil, after: nil, cache: nil)
|
|
115
|
+
query = QueryBuilder.dataset_record_delete_jobs(
|
|
116
|
+
publisher_id: publisher_id,
|
|
117
|
+
dataset_id: dataset_id,
|
|
118
|
+
status: status,
|
|
119
|
+
first: first,
|
|
120
|
+
after: after
|
|
121
|
+
)
|
|
122
|
+
variables = build_variables(
|
|
123
|
+
publisherId: publisher_id,
|
|
124
|
+
datasetId: dataset_id,
|
|
125
|
+
status: status,
|
|
126
|
+
first: first,
|
|
127
|
+
after: after
|
|
128
|
+
)
|
|
129
|
+
key = cache_key('records', 'list_delete_jobs', **variables)
|
|
130
|
+
|
|
131
|
+
data = with_cache(key, resource: :records, cache: cache) { connection.execute(query, variables) }
|
|
132
|
+
|
|
133
|
+
Collection.new(
|
|
134
|
+
data['datasetRecordDeleteJobs'],
|
|
135
|
+
item_class: DatasetRecordDeleteJob,
|
|
136
|
+
next_page_loader: lambda { |cursor|
|
|
137
|
+
list_delete_jobs(
|
|
138
|
+
publisher_id: publisher_id,
|
|
139
|
+
dataset_id: dataset_id,
|
|
140
|
+
status: status,
|
|
141
|
+
first: first,
|
|
142
|
+
after: cursor,
|
|
143
|
+
cache: cache
|
|
144
|
+
)
|
|
145
|
+
},
|
|
146
|
+
client: client
|
|
147
|
+
)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Poll a delete job until it reaches a terminal state.
|
|
151
|
+
def wait_for_delete_job(id, interval: 1, timeout: 300)
|
|
152
|
+
started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
153
|
+
|
|
154
|
+
loop do
|
|
155
|
+
job = get_delete_job(id, cache: false)
|
|
156
|
+
raise Error, "Delete job '#{id}' was not found" unless job
|
|
157
|
+
return job if job.completed? || job.failed?
|
|
158
|
+
|
|
159
|
+
elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started_at
|
|
160
|
+
raise Error, "Timed out waiting for delete job '#{id}'" if elapsed >= timeout
|
|
161
|
+
|
|
162
|
+
sleep interval
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
9
166
|
# Search for records in a dataset
|
|
10
167
|
#
|
|
11
168
|
# @param dataset_key [String] Dataset key (required)
|
data/lib/carddb/version.rb
CHANGED
data/lib/carddb.rb
CHANGED
|
@@ -13,6 +13,10 @@ require_relative 'carddb/resources/publishers'
|
|
|
13
13
|
require_relative 'carddb/resources/games'
|
|
14
14
|
require_relative 'carddb/resources/datasets'
|
|
15
15
|
require_relative 'carddb/resources/records'
|
|
16
|
+
require_relative 'carddb/resources/import_formats'
|
|
17
|
+
require_relative 'carddb/resources/imports'
|
|
18
|
+
require_relative 'carddb/resources/exports'
|
|
19
|
+
require_relative 'carddb/resources/files'
|
|
16
20
|
require_relative 'carddb/resources/decks'
|
|
17
21
|
require_relative 'carddb/resources/rules'
|
|
18
22
|
require_relative 'carddb/batch'
|
|
@@ -110,6 +114,34 @@ module CardDB
|
|
|
110
114
|
default_client.records
|
|
111
115
|
end
|
|
112
116
|
|
|
117
|
+
# Access the Import Formats resource via the default client.
|
|
118
|
+
#
|
|
119
|
+
# @return [Resources::ImportFormats]
|
|
120
|
+
def import_formats
|
|
121
|
+
default_client.import_formats
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Access the Imports resource via the default client.
|
|
125
|
+
#
|
|
126
|
+
# @return [Resources::Imports]
|
|
127
|
+
def imports
|
|
128
|
+
default_client.imports
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Access the Exports resource via the default client.
|
|
132
|
+
#
|
|
133
|
+
# @return [Resources::Exports]
|
|
134
|
+
def exports
|
|
135
|
+
default_client.exports
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Access the Files resource via the default client.
|
|
139
|
+
#
|
|
140
|
+
# @return [Resources::Files]
|
|
141
|
+
def files
|
|
142
|
+
default_client.files
|
|
143
|
+
end
|
|
144
|
+
|
|
113
145
|
# Access the Decks resource via the default client.
|
|
114
146
|
#
|
|
115
147
|
# @return [Resources::Decks]
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: carddb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- CardDB Team
|
|
@@ -57,6 +57,7 @@ files:
|
|
|
57
57
|
- examples/basic_usage.rb
|
|
58
58
|
- examples/filtering.rb
|
|
59
59
|
- examples/pagination.rb
|
|
60
|
+
- examples/publisher_content_pipeline.rb
|
|
60
61
|
- lib/carddb.rb
|
|
61
62
|
- lib/carddb/batch.rb
|
|
62
63
|
- lib/carddb/cache.rb
|
|
@@ -70,7 +71,11 @@ files:
|
|
|
70
71
|
- lib/carddb/resources/base.rb
|
|
71
72
|
- lib/carddb/resources/datasets.rb
|
|
72
73
|
- lib/carddb/resources/decks.rb
|
|
74
|
+
- lib/carddb/resources/exports.rb
|
|
75
|
+
- lib/carddb/resources/files.rb
|
|
73
76
|
- lib/carddb/resources/games.rb
|
|
77
|
+
- lib/carddb/resources/import_formats.rb
|
|
78
|
+
- lib/carddb/resources/imports.rb
|
|
74
79
|
- lib/carddb/resources/publishers.rb
|
|
75
80
|
- lib/carddb/resources/records.rb
|
|
76
81
|
- lib/carddb/resources/rules.rb
|