chartquery 0.1.0
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +167 -0
- data/examples/README.md +12 -0
- data/examples/binary.rb +12 -0
- data/examples/json.rb +8 -0
- data/examples/request.rb +11 -0
- data/examples/wait_for_job.rb +8 -0
- data/lib/chartquery/client.rb +266 -0
- data/lib/chartquery/endpoints.rb +149 -0
- data/lib/chartquery/errors.rb +56 -0
- data/lib/chartquery/operations.rb +372 -0
- data/lib/chartquery/responses.rb +45 -0
- data/lib/chartquery/serialization.rb +66 -0
- data/lib/chartquery/transport.rb +27 -0
- data/lib/chartquery/version.rb +5 -0
- data/lib/chartquery.rb +14 -0
- data/sig/chartquery.rbs +98 -0
- metadata +66 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ChartQuery
|
|
4
|
+
# Base class for every SDK-defined error.
|
|
5
|
+
class Error < StandardError; end
|
|
6
|
+
|
|
7
|
+
# The client configuration is missing or unusable.
|
|
8
|
+
class ConfigurationError < Error; end
|
|
9
|
+
|
|
10
|
+
# A request value cannot be represented safely on the wire.
|
|
11
|
+
class SerializationError < Error
|
|
12
|
+
attr_reader :param
|
|
13
|
+
|
|
14
|
+
def initialize(message, param = nil)
|
|
15
|
+
super(message)
|
|
16
|
+
@param = param
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# The request failed before a complete HTTP response was received.
|
|
21
|
+
class TransportError < Error; end
|
|
22
|
+
|
|
23
|
+
# ChartQuery returned a non-success HTTP status.
|
|
24
|
+
class APIError < Error
|
|
25
|
+
attr_reader :status, :error_message, :response_body, :raw_response
|
|
26
|
+
|
|
27
|
+
def initialize(raw_response:, response_body: nil, error_message: nil)
|
|
28
|
+
super(error_message || "ChartQuery API request failed with status #{raw_response.status}.")
|
|
29
|
+
@status = raw_response.status
|
|
30
|
+
@error_message = error_message
|
|
31
|
+
@response_body = response_body
|
|
32
|
+
@raw_response = raw_response
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# A successful response could not be decoded as the documented representation.
|
|
37
|
+
class ResponseDecodingError < Error
|
|
38
|
+
attr_reader :raw_response
|
|
39
|
+
|
|
40
|
+
def initialize(message, raw_response)
|
|
41
|
+
super(message)
|
|
42
|
+
@raw_response = raw_response
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# An async job did not reach a terminal status before the deadline.
|
|
47
|
+
class JobTimeoutError < Error
|
|
48
|
+
attr_reader :job_id, :last_response
|
|
49
|
+
|
|
50
|
+
def initialize(job_id, last_response = nil)
|
|
51
|
+
super("Job #{job_id} did not finish before the deadline.")
|
|
52
|
+
@job_id = job_id
|
|
53
|
+
@last_response = last_response
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Generated from the ChartQuery OpenAPI document. Do not edit by hand.
|
|
4
|
+
|
|
5
|
+
module ChartQuery
|
|
6
|
+
# One method per documented endpoint. Mixed into {Client}.
|
|
7
|
+
module Operations
|
|
8
|
+
# Barcode. Generate a barcode image via GET. Output: SVG (default) or PNG. Supports 25+ formats: EAN-13, Code 128, ITF-14, GS1-128, postal codes and more. Credit cost: 3 credits per call.
|
|
9
|
+
#
|
|
10
|
+
# +GET / POST /v1/barcode+
|
|
11
|
+
#
|
|
12
|
+
# @param data [String] (required) The data to encode in the barcode. Examples by type:
|
|
13
|
+
# @param type [String] Barcode format. Default: code128.
|
|
14
|
+
# @param height [Numeric] Bar height in pixels. Default: 80. Typical values: 50 (compact), 80 (standard), 100–120 (tall labels). Example: ?height=100
|
|
15
|
+
# @param color [String] Bar color as a CSS color string. Default: #000. Examples: ?color=%231e293b (dark slate), ?color=%230f172a (near black), ?color=%237c3aed (purple), ?color=%23dc2626 (red). Use %23 to URL-encode the #…
|
|
16
|
+
# @param show_text [Boolean] Show human-readable text below the bars. Example: ?show_text=true. Combine with font_size and text_align for print labels.
|
|
17
|
+
# @param text_position [String] Position of the human-readable text label. Default: bottom. Example: ?text_position=top
|
|
18
|
+
# @param text_align [String] Horizontal alignment of the text label. Default: center. Example: ?text_align=left
|
|
19
|
+
# @param font_size [Numeric] Font size of the text label in pixels. Default: 14. Example: ?font_size=12
|
|
20
|
+
# @param font_family [String] Font family of the text label. Default: monospace. Examples: ?font_family=monospace, ?font_family=sans-serif, ?font_family=Arial
|
|
21
|
+
# @param bar_width [Numeric] Width multiplier per module (bar). Default: 2. Increase for wider, more scannable barcodes. Example: ?bar_width=3
|
|
22
|
+
# @param bar_gap [Numeric] Extra horizontal spacing between bars in pixels. Default: 0. Example: ?bar_gap=1
|
|
23
|
+
# @param background [String] Background fill color. Default: #fff. Use transparent for no background. Example: ?background=%23f8fafc
|
|
24
|
+
# @param margin [Numeric] Uniform margin around the barcode in pixels. Default: 10. Overridden per side by margin_top/bottom/left/right. Example: ?margin=6
|
|
25
|
+
# @param margin_top [Numeric] Top margin in pixels (overrides margin). Example: ?margin_top=4
|
|
26
|
+
# @param margin_bottom [Numeric] Bottom margin in pixels (overrides margin). Example: ?margin_bottom=4
|
|
27
|
+
# @param margin_left [Numeric] Left margin in pixels (overrides margin). Example: ?margin_left=8
|
|
28
|
+
# @param margin_right [Numeric] Right margin in pixels (overrides margin). Example: ?margin_right=8
|
|
29
|
+
# @param rotation [Numeric] Rotate the barcode by 0, 90, 180 or 270 degrees. Default: 0. Use 90 or 270 for vertical label orientation. Example: ?rotation=90
|
|
30
|
+
# @param bearer_bars [Boolean] Add horizontal bearer bars above and below the barcode. Required for ITF-14. Default: false. Example: ?bearer_bars=true
|
|
31
|
+
# @param unit [String] Measurement unit for dimensions. Default: px. Use mm, in or cm for print-ready output. Example: ?unit=mm
|
|
32
|
+
# @param aria_label [String] Accessible label added as aria-label on the SVG element. Improves screen reader support. Example: ?aria_label=EAN-13+barcode+for+product+4006381333931
|
|
33
|
+
# @param title [String] SVG <title> element for tooltip and accessibility. Example: ?title=Product+Barcode
|
|
34
|
+
# @param desc [String] SVG <desc> element for extended accessibility description. Example: ?desc=EAN-13+encoding+GTIN+for+Nivea+cream+75ml
|
|
35
|
+
# @param format [String] Output format. Default: svg. Use png to get a raster image. SVG is lossless and scalable; PNG is pixel-based and suitable for email, PDF or messaging. Example: ?format=png
|
|
36
|
+
# @param share [Boolean] Set share=true to persist the config and receive JSON instead of an image: { id, render_url, view_url, embed_url, expires_in }. Free plan: 3-day expiry with watermark. Paid plan: 6-month expiry, no b…
|
|
37
|
+
# @param fields [String] Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
|
|
38
|
+
# @param is_async [Boolean] Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob).
|
|
39
|
+
# @param soft_fail [Boolean] Return HTTP 200 even when an error occurs; the error is then in the response body.
|
|
40
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
41
|
+
# @return [JsonResponse, BinaryResponse]
|
|
42
|
+
def barcode(request_options: nil, **params)
|
|
43
|
+
call_operation("barcode", params, request_options)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Chart. Render a Chart.js image via GET. Pass the full chart object as URL-encoded JSON in query. Prefer format png for ChatGPT. POST sends the same object as a JSON body, not query. Credit cost: 5 credits per call.
|
|
47
|
+
#
|
|
48
|
+
# +GET / POST /v1/chart+
|
|
49
|
+
#
|
|
50
|
+
# @param query [String] (required) Full chart config as URL-encoded JSON. Pass ?version= or ?v= separately to pin the chart version.
|
|
51
|
+
# @param version [String] Chart.js version to use. Alias: ?v=. Only v4.x is supported. Defaults to the installed version (4.5.1). Example: "4", "4.5", "4.5.1". The installed version is always returned in the X-ChartJS-Version…
|
|
52
|
+
# @param share [Boolean] If true, persist the result and return share URLs instead of an image. Leave false to get the image.
|
|
53
|
+
# @param fields [String] Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
|
|
54
|
+
# @param is_async [Boolean] Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob).
|
|
55
|
+
# @param soft_fail [Boolean] Return HTTP 200 even when an error occurs; the error is then in the response body.
|
|
56
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
57
|
+
# @return [JsonResponse, BinaryResponse]
|
|
58
|
+
def chart(request_options: nil, **params)
|
|
59
|
+
call_operation("chart", params, request_options)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Chart AI. Describe a chart in plain English via GET and get a rendered image back. Powered by AI. Credit cost: 10 credits per call.
|
|
63
|
+
#
|
|
64
|
+
# +GET / POST /v1/chart/ai+
|
|
65
|
+
#
|
|
66
|
+
# @param prompt [String] (required) Describe your chart in plain English (max 1000 chars). Be specific: mention chart type, data topic, colors, style.
|
|
67
|
+
# @param raw_data [String] Raw data for the chart. URL-encoded string, CSV, or JSON. AI will parse and structure it.
|
|
68
|
+
# @param title [String] Override the chart title generated by AI.
|
|
69
|
+
# @param subtitle [String] Override the chart subtitle.
|
|
70
|
+
# @param legend [String] Legend position or visibility. Use "false" to hide.
|
|
71
|
+
# @param format [String] Output format. Default: "png".
|
|
72
|
+
# @param width [Numeric] Image width in pixels (50–4000). Default: 1200.
|
|
73
|
+
# @param height [Numeric] Image height in pixels (50–4000). Default: 600.
|
|
74
|
+
# @param background [String] Background color as a hex value. Default: #ffffff.
|
|
75
|
+
# @param device_pixel_ratio [Numeric] Device pixel ratio for the rendered image. Default: 1.
|
|
76
|
+
# @param share [Boolean] Set share=true to persist the config and receive JSON instead of an image: { id, render_url, view_url, embed_url, expires_in }. Free plan: 3-day expiry with watermark. Paid plan: 6-month expiry, no b…
|
|
77
|
+
# @param fields [String] Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
|
|
78
|
+
# @param is_async [Boolean] Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob).
|
|
79
|
+
# @param soft_fail [Boolean] Return HTTP 200 even when an error occurs; the error is then in the response body.
|
|
80
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
81
|
+
# @return [JsonResponse]
|
|
82
|
+
def chart_ai(request_options: nil, **params)
|
|
83
|
+
call_operation("chart_ai", params, request_options)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Chart Render. Render a previously saved chart by ID. Public, no API key required. Supports URL overrides for templates (?data1=, ?labels=, ?title=…).
|
|
87
|
+
#
|
|
88
|
+
# +GET /v1/chart/render/{id}+
|
|
89
|
+
#
|
|
90
|
+
# @param id [String] (required) The chart ID returned in the X-Chart-Render-URL header when saving a chart. Format: cq-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
|
|
91
|
+
# @param title [String] Override the chart title.
|
|
92
|
+
# @param labels [String] Override X-axis labels. Comma-separated.
|
|
93
|
+
# @param data1 [String] Override first dataset values. Comma-separated numbers. Use data2, data3… for additional datasets.
|
|
94
|
+
# @param width [String] Override output width in pixels (50–4000).
|
|
95
|
+
# @param height [String] Override output height in pixels (50–4000).
|
|
96
|
+
# @param format [String] Override output format.
|
|
97
|
+
# @param fields [String] Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
|
|
98
|
+
# @param is_async [Boolean] Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob).
|
|
99
|
+
# @param soft_fail [Boolean] Return HTTP 200 even when an error occurs; the error is then in the response body.
|
|
100
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
101
|
+
# @return [JsonResponse, BinaryResponse]
|
|
102
|
+
def chart_render(request_options: nil, **params)
|
|
103
|
+
call_operation("chart_render", params, request_options)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Chart View. View a previously saved chart as an interactive HTML page. Public, no API key required. Iframe-embeddable.
|
|
107
|
+
#
|
|
108
|
+
# +GET /v1/chart/view/{id}+
|
|
109
|
+
#
|
|
110
|
+
# @param id [String] (required) The chart ID returned in the X-Chart-View-URL header when saving a chart. Format: cq-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
|
|
111
|
+
# @param share [Boolean] Set share=true to persist the config and receive JSON instead of an image: { id, render_url, view_url, embed_url, expires_in }. Free plan: 3-day expiry with watermark. Paid plan: 6-month expiry, no b…
|
|
112
|
+
# @param fields [String] Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
|
|
113
|
+
# @param is_async [Boolean] Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob).
|
|
114
|
+
# @param soft_fail [Boolean] Return HTTP 200 even when an error occurs; the error is then in the response body.
|
|
115
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
116
|
+
# @return [JsonResponse]
|
|
117
|
+
def chart_view(request_options: nil, **params)
|
|
118
|
+
call_operation("chart_view", params, request_options)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Diagram. Render a diagram via GET. Use type (mermaid, d2, …), query (source code), and format=png for ChatGPT. POST uses diagram_type and diagram_source instead. Credit cost: 5 credits per call.
|
|
122
|
+
#
|
|
123
|
+
# +GET / POST /v1/diagram+
|
|
124
|
+
#
|
|
125
|
+
# @param type [String] (required) Diagram language.
|
|
126
|
+
# @param query [String] (required) Diagram source code (URL-encoded).
|
|
127
|
+
# @param format [String] Use png so ChatGPT can display the image. svg is for download or infinite scale.
|
|
128
|
+
# @param share [Boolean] If true, persist the result and return share URLs instead of an image. Leave false to get the image.
|
|
129
|
+
# @param fields [String] Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
|
|
130
|
+
# @param is_async [Boolean] Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob).
|
|
131
|
+
# @param soft_fail [Boolean] Return HTTP 200 even when an error occurs; the error is then in the response body.
|
|
132
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
133
|
+
# @return [JsonResponse, BinaryResponse]
|
|
134
|
+
def diagram(request_options: nil, **params)
|
|
135
|
+
call_operation("diagram", params, request_options)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Diagram AI. Describe a diagram in plain English via GET and get a rendered image back. Powered by AI. Credit cost: 10 credits per call.
|
|
139
|
+
#
|
|
140
|
+
# +GET / POST /v1/diagram/ai+
|
|
141
|
+
#
|
|
142
|
+
# @param prompt [String] (required) Describe your diagram in plain English (max 1000 chars). Be specific: mention the diagram type, key entities, and relationships.
|
|
143
|
+
# @param diagram_type [String] Preferred diagram language. AI chooses if omitted. Examples: "mermaid", "d2", "plantuml", "graphviz".
|
|
144
|
+
# @param output_format [String] Output format. Default: "svg".
|
|
145
|
+
# @param share [Boolean] Set share=true to persist the config and receive JSON instead of an image: { id, render_url, view_url, embed_url, expires_in }. Free plan: 3-day expiry. Paid plan: 6-month expiry.
|
|
146
|
+
# @param fields [String] Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
|
|
147
|
+
# @param is_async [Boolean] Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob).
|
|
148
|
+
# @param soft_fail [Boolean] Return HTTP 200 even when an error occurs; the error is then in the response body.
|
|
149
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
150
|
+
# @return [JsonResponse]
|
|
151
|
+
def diagram_ai(request_options: nil, **params)
|
|
152
|
+
call_operation("diagram_ai", params, request_options)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Diagram Render. Render a previously saved diagram by ID. Public, no API key required. Supports ?format= and ?query= overrides.
|
|
156
|
+
#
|
|
157
|
+
# +GET /v1/diagram/render/{id}+
|
|
158
|
+
#
|
|
159
|
+
# @param id [String] (required) The diagram ID returned in the X-Diagram-Render-URL header when saving a diagram. Format: cq-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
|
|
160
|
+
# @param format [String] Override output format.
|
|
161
|
+
# @param query [String] Override the diagram source code (URL-encoded).
|
|
162
|
+
# @param share [Boolean] Set share=true to persist the config and receive JSON instead of an image: { id, render_url, view_url, embed_url, expires_in }. Free plan: 3-day expiry with watermark. Paid plan: 6-month expiry, no b…
|
|
163
|
+
# @param fields [String] Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
|
|
164
|
+
# @param is_async [Boolean] Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob).
|
|
165
|
+
# @param soft_fail [Boolean] Return HTTP 200 even when an error occurs; the error is then in the response body.
|
|
166
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
167
|
+
# @return [JsonResponse, BinaryResponse]
|
|
168
|
+
def diagram_render(request_options: nil, **params)
|
|
169
|
+
call_operation("diagram_render", params, request_options)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# Diagram View. View a previously saved diagram as an HTML page. Public, no API key required. Iframe-embeddable with inline SVG rendering.
|
|
173
|
+
#
|
|
174
|
+
# +GET /v1/diagram/view/{id}+
|
|
175
|
+
#
|
|
176
|
+
# @param id [String] (required) The diagram ID returned in the X-Diagram-View-URL header when saving a diagram. Format: cq-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
|
|
177
|
+
# @param share [Boolean] Set share=true to persist the config and receive JSON instead of an image: { id, render_url, view_url, embed_url, expires_in }. Free plan: 3-day expiry with watermark. Paid plan: 6-month expiry, no b…
|
|
178
|
+
# @param fields [String] Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
|
|
179
|
+
# @param is_async [Boolean] Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob).
|
|
180
|
+
# @param soft_fail [Boolean] Return HTTP 200 even when an error occurs; the error is then in the response body.
|
|
181
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
182
|
+
# @return [JsonResponse]
|
|
183
|
+
def diagram_view(request_options: nil, **params)
|
|
184
|
+
call_operation("diagram_view", params, request_options)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# Jobs. Poll the status, progress (0–100) and result of a job started with is_async=true. Polling is free. Poll until status is terminal: CompletedJob, Error, NotFound or BadRequest.
|
|
188
|
+
#
|
|
189
|
+
# +GET /v1/jobs/{id}+
|
|
190
|
+
#
|
|
191
|
+
# @param id [String] (required) The job_id returned by an endpoint called with is_async=true.
|
|
192
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
193
|
+
# @return [JsonResponse]
|
|
194
|
+
def jobs(request_options: nil, **params)
|
|
195
|
+
call_operation("jobs", params, request_options)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# Label Preview. Preview a thermal label via GET. Pass the same label object as a URL-encoded JSON string in query. Inside that JSON, text items use content and size (1-10), not text or fontSize. Prefer format=png for ChatGPT. Credit cost: 3 credits per call.
|
|
199
|
+
#
|
|
200
|
+
# +GET / POST /v1/label+
|
|
201
|
+
#
|
|
202
|
+
# @param format [String] Use png so ChatGPT can display the image. svg is for download or infinite scale.
|
|
203
|
+
# @param share [Boolean] If true, persist the result and return share URLs instead of an image. Leave false to get the image.
|
|
204
|
+
# @param query [String] (required) Full label config as URL-encoded JSON. Must include width and elements. Text items use content and size (1-10), not text or fontSize.
|
|
205
|
+
# @param fields [String] Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
|
|
206
|
+
# @param is_async [Boolean] Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob).
|
|
207
|
+
# @param soft_fail [Boolean] Return HTTP 200 even when an error occurs; the error is then in the response body.
|
|
208
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
209
|
+
# @return [JsonResponse, BinaryResponse]
|
|
210
|
+
def label(request_options: nil, **params)
|
|
211
|
+
call_operation("label", params, request_options)
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
# Label Compile. Compile a label to printer commands (tsc, zpl, epl, …). POST width, language, and elements. Text uses content and size (1-10), not text or fontSize. No barcode element. Example: {"width":40,"height":30,"unit":"mm","language":"zpl","element… Credit cost: 3 credits per call.
|
|
215
|
+
#
|
|
216
|
+
# +POST /v1/label/compile+
|
|
217
|
+
#
|
|
218
|
+
# @param width [Numeric] (required) Label width. Required. Default unit is mm. Example: 40. Do not send query instead of width.
|
|
219
|
+
# @param height [Numeric] Label height in the same unit. Example: 30. Omit for receipt / continuous mode.
|
|
220
|
+
# @param unit [String] Measurement unit for width and height. Default mm. Use mm unless you are working in printer dots.
|
|
221
|
+
# @param dpi [Numeric] Printer DPI. Default 203.
|
|
222
|
+
# @param gap [Numeric] Gap between labels in mm. Ignored for receipts.
|
|
223
|
+
# @param speed [Numeric] Print speed, 1-18.
|
|
224
|
+
# @param density [Numeric] Print darkness, 0-15.
|
|
225
|
+
# @param direction [Numeric] Print direction. 0 = normal, 1 = reversed.
|
|
226
|
+
# @param copies [Numeric] Number of copies. Minimum 1.
|
|
227
|
+
# @param printer [String] Printer profile id (tsc-te210, zebra-zd420, …).
|
|
228
|
+
# @param elements [Array<Hash>] (required) Required array. Text items need type=text, content, and size (1-10 magnification). Do not use text, fontSize, or type=barcode. Positions x/y are in dots. Example item: {"type":"text","content":"Order…
|
|
229
|
+
# @param language [String] (required) Required printer language. Example: zpl or tsc. Do not omit.
|
|
230
|
+
# @param fields [String] Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
|
|
231
|
+
# @param is_async [Boolean] Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob).
|
|
232
|
+
# @param soft_fail [Boolean] Return HTTP 200 even when an error occurs; the error is then in the response body.
|
|
233
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
234
|
+
# @return [JsonResponse]
|
|
235
|
+
def label_compile(request_options: nil, **params)
|
|
236
|
+
call_operation("label_compile", params, request_options)
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
# Label Convert. Convert printer commands from one language to another. POST source, from, and to. from is the source language (tsc, zpl, epl, …). to is the target (tsc, zpl, escpos, …). Credit cost: 5 credits per call.
|
|
240
|
+
#
|
|
241
|
+
# +POST /v1/label/convert+
|
|
242
|
+
#
|
|
243
|
+
# @param source [String] (required) Raw printer commands to convert. Also send from and to.
|
|
244
|
+
# @param from [String] (required) Source language.
|
|
245
|
+
# @param to [String] (required) Target language.
|
|
246
|
+
# @param dpi [Numeric] Override DPI on the converted output.
|
|
247
|
+
# @param speed [Numeric] Override print speed, 1-18.
|
|
248
|
+
# @param density [Numeric] Override print darkness, 0-15.
|
|
249
|
+
# @param copies [Numeric] Override copies. Minimum 1.
|
|
250
|
+
# @param fields [String] Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
|
|
251
|
+
# @param is_async [Boolean] Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob).
|
|
252
|
+
# @param soft_fail [Boolean] Return HTTP 200 even when an error occurs; the error is then in the response body.
|
|
253
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
254
|
+
# @return [JsonResponse]
|
|
255
|
+
def label_convert(request_options: nil, **params)
|
|
256
|
+
call_operation("label_convert", params, request_options)
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
# Label Parse. Parse printer commands into structured elements. POST source and language (tsc, zpl, epl, …). Credit cost: 1 credit per call.
|
|
260
|
+
#
|
|
261
|
+
# +POST /v1/label/parse+
|
|
262
|
+
#
|
|
263
|
+
# @param source [String] (required) Raw printer commands to parse. Also send language.
|
|
264
|
+
# @param language [String] (required) Language of the source commands. Example: tsc or zpl.
|
|
265
|
+
# @param fields [String] Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
|
|
266
|
+
# @param is_async [Boolean] Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob).
|
|
267
|
+
# @param soft_fail [Boolean] Return HTTP 200 even when an error occurs; the error is then in the response body.
|
|
268
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
269
|
+
# @return [JsonResponse]
|
|
270
|
+
def label_parse(request_options: nil, **params)
|
|
271
|
+
call_operation("label_parse", params, request_options)
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
# Label Render. Render a previously saved label by ID. Public, no API key required. Supports ?format= override.
|
|
275
|
+
#
|
|
276
|
+
# +GET /v1/label/render/{id}+
|
|
277
|
+
#
|
|
278
|
+
# @param id [String] (required)
|
|
279
|
+
# @param format [String] Override output format.
|
|
280
|
+
# @param fields [String] Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
|
|
281
|
+
# @param is_async [Boolean] Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob).
|
|
282
|
+
# @param soft_fail [Boolean] Return HTTP 200 even when an error occurs; the error is then in the response body.
|
|
283
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
284
|
+
# @return [JsonResponse, BinaryResponse]
|
|
285
|
+
def label_render(request_options: nil, **params)
|
|
286
|
+
call_operation("label_render", params, request_options)
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
# Label Validate. Validate printer commands. POST source (the raw commands) and language (tsc, zpl, epl, …). Credit cost: 1 credit per call.
|
|
290
|
+
#
|
|
291
|
+
# +POST /v1/label/validate+
|
|
292
|
+
#
|
|
293
|
+
# @param source [String] (required) Raw printer commands to validate. Also send language.
|
|
294
|
+
# @param language [String] (required) Language of the source commands. Example: tsc or zpl.
|
|
295
|
+
# @param fields [String] Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
|
|
296
|
+
# @param is_async [Boolean] Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob).
|
|
297
|
+
# @param soft_fail [Boolean] Return HTTP 200 even when an error occurs; the error is then in the response body.
|
|
298
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
299
|
+
# @return [JsonResponse]
|
|
300
|
+
def label_validate(request_options: nil, **params)
|
|
301
|
+
call_operation("label_validate", params, request_options)
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
# Label View. View a previously saved label as an HTML page. Public, no API key required. Iframe-embeddable with inline SVG rendering.
|
|
305
|
+
#
|
|
306
|
+
# +GET /v1/label/view/{id}+
|
|
307
|
+
#
|
|
308
|
+
# @param id [String] (required)
|
|
309
|
+
# @param fields [String] Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
|
|
310
|
+
# @param is_async [Boolean] Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob).
|
|
311
|
+
# @param soft_fail [Boolean] Return HTTP 200 even when an error occurs; the error is then in the response body.
|
|
312
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
313
|
+
# @return [JsonResponse]
|
|
314
|
+
def label_view(request_options: nil, **params)
|
|
315
|
+
call_operation("label_view", params, request_options)
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
# QR Code. Generate a styled QR code via GET. Output: SVG (default) or PNG. Supports dot styles, gradients, custom corners and all QR versions. Credit cost: 3 credits per call.
|
|
319
|
+
#
|
|
320
|
+
# +GET / POST /v1/qrcode+
|
|
321
|
+
#
|
|
322
|
+
# @param data [String] (required) Data to encode in the QR code. Examples:
|
|
323
|
+
# @param size [Numeric] Output size in pixels (width = height). Default: 200. Examples: ?size=200 (thumbnail), ?size=300 (standard), ?size=400 (large), ?size=600 (poster). For print, use the unit param with mm/cm instead.
|
|
324
|
+
# @param ec_level [String] Error correction level. Default: M. Higher levels allow more damage/obscuring before the code becomes unreadable.
|
|
325
|
+
# @param dot_type [String] Module (dot) shape. Default: square. Controls the visual style of each QR code module.
|
|
326
|
+
# @param color [String] Module color as CSS hex. Default: #000. Examples: ?color=%236366f1 (indigo), ?color=%23dc2626 (red), ?color=%23059669 (green), ?color=%230891b2 (teal). Use %23 to URL-encode #. For gradient objects,…
|
|
327
|
+
# @param shape [String] Overall QR code shape. Default: square. Use circle to clip the entire QR into a circle: great for profile/avatar-style codes. Example: ?shape=circle&dot_type=dots
|
|
328
|
+
# @param dot_size [Numeric] Module size ratio between 0.1 and 1. Default: 1 (full). Values below 1 add spacing between modules for a lighter look. Example: ?dot_size=0.85
|
|
329
|
+
# @param background [String] Background color. Default: #fff. Set to transparent for no background. Example: ?background=%230f172a for dark background. Use %23 to encode #.
|
|
330
|
+
# @param margin [Numeric] Quiet zone width in modules around the QR code. Default: 4. Minimum recommended by the QR standard: 4. Example: ?margin=2 (compact) or ?margin=6 (extra padding).
|
|
331
|
+
# @param version [Numeric] QR version from 1 to 40 (determines grid size and data capacity). Leave unset for auto-selection based on data length and ec_level. Example: ?version=5
|
|
332
|
+
# @param mode [String] Encoding mode. Default: auto (best mode selected for the data). Use numeric for digits-only, alphanumeric for uppercase + digits, byte for arbitrary text/UTF-8. Example: ?mode=numeric
|
|
333
|
+
# @param mask [Numeric] Mask pattern from 0 to 7. Default: auto (best mask selected to minimize visual patterns). Only set manually if you need a deterministic output. Example: ?mask=3
|
|
334
|
+
# @param unit [String] Measurement unit for the size param. Default: px. Use mm, in or cm with the size param for print-ready output. Example: ?size=50&unit=mm
|
|
335
|
+
# @param xml_declaration [Boolean] Prepend an XML declaration (<?xml version="1.0" encoding="UTF-8"?>) to the SVG output. Useful when the SVG will be used as a standalone XML file. Default: false. Example: ?xml_declaration=true
|
|
336
|
+
# @param aria_label [String] Accessible label added as aria-label on the SVG element. Example: ?aria_label=QR+code+linking+to+chartquery.com
|
|
337
|
+
# @param title [String] SVG <title> element shown as a browser tooltip and used by screen readers. Example: ?title=ChartQuery+Website
|
|
338
|
+
# @param desc [String] SVG <desc> element for extended accessibility description. Example: ?desc=Scan+to+visit+https://chartquery.com
|
|
339
|
+
# @param format [String] Output format. Default: svg. Use png to get a raster image. SVG is lossless and scalable; PNG is pixel-based and suitable for email, PDF or messaging. Example: ?format=png
|
|
340
|
+
# @param share [Boolean] Set share=true to persist the config and receive JSON instead of an image: { id, render_url, view_url, embed_url, expires_in }. Free plan: 3-day expiry with watermark. Paid plan: 6-month expiry, no b…
|
|
341
|
+
# @param fields [String] Comma-separated list of fields to keep in the response, with dot notation for nested fields (e.g. name,location.city). Does not change the credit cost.
|
|
342
|
+
# @param is_async [Boolean] Process the request asynchronously: the response is a job_id to poll on /v1/jobs/{id} (see waitForJob).
|
|
343
|
+
# @param soft_fail [Boolean] Return HTTP 200 even when an error occurs; the error is then in the response body.
|
|
344
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
345
|
+
# @return [JsonResponse, BinaryResponse]
|
|
346
|
+
def qrcode(request_options: nil, **params)
|
|
347
|
+
call_operation("qrcode", params, request_options)
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
# Stats. Infrastructure health for an engine or endpoint over the last hour. Not scoped to your account or tenant. Enabled per account: HTTP 403 means contact support to activate it.
|
|
351
|
+
#
|
|
352
|
+
# +GET /v1/stats+
|
|
353
|
+
#
|
|
354
|
+
# @param engine [String] API family to check, for example chart. Provide at least engine or path.
|
|
355
|
+
# @param path [String] Specific endpoint to check, for example /v1/chart. If you also pass engine, use an endpoint from that API.
|
|
356
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
357
|
+
# @return [JsonResponse]
|
|
358
|
+
def stats(request_options: nil, **params)
|
|
359
|
+
call_operation("stats", params, request_options)
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
# Usage. Return this account's Chartquery usage and credit balance. No body. Requires an API key.
|
|
363
|
+
#
|
|
364
|
+
# +GET /v1/usage+
|
|
365
|
+
#
|
|
366
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
367
|
+
# @return [JsonResponse]
|
|
368
|
+
def usage(request_options: nil, **params)
|
|
369
|
+
call_operation("usage", params, request_options)
|
|
370
|
+
end
|
|
371
|
+
end
|
|
372
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ChartQuery
|
|
4
|
+
# Buffered HTTP response: status, lower-cased multi-value headers, content type and body bytes.
|
|
5
|
+
RawResponse = Struct.new(:status, :headers, :content_type, :body, keyword_init: true)
|
|
6
|
+
|
|
7
|
+
# Outcome of one Client#batch item: +value+ when +ok?+, else +error+.
|
|
8
|
+
BatchResult = Struct.new(:index, :value, :error, keyword_init: true) do
|
|
9
|
+
def ok? = error.nil?
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# A successful JSON response; +data+ is the parsed body (string keys).
|
|
13
|
+
class JsonResponse
|
|
14
|
+
attr_reader :data, :raw_response
|
|
15
|
+
|
|
16
|
+
def initialize(data:, raw_response:)
|
|
17
|
+
@data = data
|
|
18
|
+
@raw_response = raw_response
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def kind = :json
|
|
22
|
+
def json? = true
|
|
23
|
+
def binary? = false
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# A successful non-JSON response (image, PDF, HTML…).
|
|
27
|
+
class BinaryResponse
|
|
28
|
+
attr_reader :bytes, :content_type, :raw_response
|
|
29
|
+
|
|
30
|
+
def initialize(bytes:, content_type:, raw_response:)
|
|
31
|
+
@bytes = bytes
|
|
32
|
+
@content_type = content_type
|
|
33
|
+
@raw_response = raw_response
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def kind = :binary
|
|
37
|
+
def json? = false
|
|
38
|
+
def binary? = true
|
|
39
|
+
|
|
40
|
+
# Writes the body to +path+ and returns the number of bytes written.
|
|
41
|
+
def save(path)
|
|
42
|
+
File.binwrite(path, bytes)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "uri"
|
|
5
|
+
|
|
6
|
+
module ChartQuery
|
|
7
|
+
# Request serialization: path filling, query pairs and JSON bodies.
|
|
8
|
+
module Serialization
|
|
9
|
+
QUERY_STRING_PARAMS = %w[fields is_async soft_fail].freeze
|
|
10
|
+
|
|
11
|
+
module_function
|
|
12
|
+
|
|
13
|
+
# Fills {name} path segments, then returns [path, query_pairs, body].
|
|
14
|
+
# nil values are omitted; false and 0 are sent.
|
|
15
|
+
def serialize(method, path_template, params)
|
|
16
|
+
raise SerializationError, "Request parameters must be a Hash." unless params.nil? || params.is_a?(Hash)
|
|
17
|
+
|
|
18
|
+
remaining = {}
|
|
19
|
+
(params || {}).each { |name, value| remaining[name.to_s] = value unless value.nil? }
|
|
20
|
+
path = path_template.gsub(/\{([^}]+)\}/) do
|
|
21
|
+
name = Regexp.last_match(1)
|
|
22
|
+
raise SerializationError.new("The \"#{name}\" path parameter is required.", name) unless remaining.key?(name)
|
|
23
|
+
|
|
24
|
+
URI.encode_www_form_component(wire_string(name, remaining.delete(name))).gsub("+", "%20")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
if method == "POST"
|
|
28
|
+
# The API reads the global parameters from the query string, whatever the method.
|
|
29
|
+
globals = QUERY_STRING_PARAMS.filter_map { |name| [name, wire_string(name, remaining.delete(name))] if remaining.key?(name) }
|
|
30
|
+
return [path, globals, remaining]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
pairs = []
|
|
34
|
+
remaining.each do |name, value|
|
|
35
|
+
if value.is_a?(Array)
|
|
36
|
+
value.each { |item| pairs << [name, wire_string(name, item)] unless item.nil? }
|
|
37
|
+
else
|
|
38
|
+
pairs << [name, wire_string(name, value)]
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
[path, pairs, nil]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def wire_string(name, value)
|
|
45
|
+
case value
|
|
46
|
+
when String then value
|
|
47
|
+
when true, false, Integer, Symbol then value.to_s
|
|
48
|
+
when Float
|
|
49
|
+
raise SerializationError.new("The \"#{name}\" parameter must be a finite number.", name) unless value.finite?
|
|
50
|
+
|
|
51
|
+
value == value.floor ? value.to_i.to_s : value.to_s
|
|
52
|
+
when Hash, Array then JSON.generate(value)
|
|
53
|
+
else
|
|
54
|
+
raise SerializationError.new("The \"#{name}\" parameter has an unsupported type (#{value.class}).", name)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def encode_query(pairs)
|
|
59
|
+
pairs.map { |name, value| "#{escape(name)}=#{escape(value)}" }.join("&")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def escape(value)
|
|
63
|
+
URI.encode_www_form_component(value).gsub("+", "%20")
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "uri"
|
|
5
|
+
|
|
6
|
+
module ChartQuery
|
|
7
|
+
# Default transport on Net::HTTP. A custom transport is any object with
|
|
8
|
+
# +call(method:, url:, headers:, body:, timeout:)+ returning +[status, headers, body]+,
|
|
9
|
+
# where headers is a Hash of lower-cased names to arrays of values.
|
|
10
|
+
class NetHTTPTransport
|
|
11
|
+
def call(method:, url:, headers:, body:, timeout:)
|
|
12
|
+
uri = URI(url)
|
|
13
|
+
request = (method == "POST" ? Net::HTTP::Post : Net::HTTP::Get).new(uri)
|
|
14
|
+
headers.each { |name, value| request[name] = value }
|
|
15
|
+
request.body = body if body
|
|
16
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
17
|
+
http.use_ssl = uri.scheme == "https"
|
|
18
|
+
if timeout
|
|
19
|
+
http.open_timeout = timeout
|
|
20
|
+
http.read_timeout = timeout
|
|
21
|
+
http.write_timeout = timeout
|
|
22
|
+
end
|
|
23
|
+
response = http.start { |connection| connection.request(request) }
|
|
24
|
+
[response.code.to_i, response.to_hash, response.body || ""]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/chartquery.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "chartquery/version"
|
|
4
|
+
require_relative "chartquery/errors"
|
|
5
|
+
require_relative "chartquery/responses"
|
|
6
|
+
require_relative "chartquery/serialization"
|
|
7
|
+
require_relative "chartquery/transport"
|
|
8
|
+
require_relative "chartquery/endpoints"
|
|
9
|
+
require_relative "chartquery/operations"
|
|
10
|
+
require_relative "chartquery/client"
|
|
11
|
+
|
|
12
|
+
# Official Ruby SDK for the ChartQuery API (https://www.chartquery.com).
|
|
13
|
+
module ChartQuery
|
|
14
|
+
end
|