zammad_api 1.3.1 → 2.0.0.alpha1

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +11 -0
  3. data/CHANGELOG.md +235 -0
  4. data/LICENSE.AGPL.txt +661 -0
  5. data/LICENSE.MIT.txt +7 -0
  6. data/LICENSE.md +6 -0
  7. data/README.md +794 -0
  8. data/UPGRADING.md +158 -0
  9. data/lib/zammad_api/attribute_access.rb +121 -0
  10. data/lib/zammad_api/client.rb +243 -43
  11. data/lib/zammad_api/collection.rb +233 -0
  12. data/lib/zammad_api/config.rb +239 -0
  13. data/lib/zammad_api/deep_copy.rb +43 -0
  14. data/lib/zammad_api/errors.rb +124 -0
  15. data/lib/zammad_api/resource_proxy.rb +195 -0
  16. data/lib/zammad_api/resources/base.rb +196 -99
  17. data/lib/zammad_api/resources/group.rb +12 -2
  18. data/lib/zammad_api/resources/organization.rb +12 -2
  19. data/lib/zammad_api/resources/ticket.rb +43 -19
  20. data/lib/zammad_api/resources/ticket_article.rb +14 -7
  21. data/lib/zammad_api/resources/ticket_article_attachment.rb +29 -14
  22. data/lib/zammad_api/resources/ticket_priority.rb +10 -2
  23. data/lib/zammad_api/resources/ticket_state.rb +9 -2
  24. data/lib/zammad_api/resources/user.rb +16 -2
  25. data/lib/zammad_api/resources.rb +13 -13
  26. data/lib/zammad_api/response.rb +52 -0
  27. data/lib/zammad_api/transport.rb +212 -40
  28. data/lib/zammad_api/version.rb +4 -1
  29. data/lib/zammad_api.rb +16 -2
  30. data/sig/zammad_api/attribute_access.rbs +31 -0
  31. data/sig/zammad_api/client.rbs +42 -0
  32. data/sig/zammad_api/collection.rbs +46 -0
  33. data/sig/zammad_api/config.rbs +69 -0
  34. data/sig/zammad_api/deep_copy.rbs +7 -0
  35. data/sig/zammad_api/errors.rbs +61 -0
  36. data/sig/zammad_api/resource_proxy.rbs +41 -0
  37. data/sig/zammad_api/resources/base.rbs +66 -0
  38. data/sig/zammad_api/resources/resources.rbs +201 -0
  39. data/sig/zammad_api/response.rbs +16 -0
  40. data/sig/zammad_api/transport.rbs +47 -0
  41. data/sig/zammad_api.rbs +3 -0
  42. metadata +70 -15
  43. data/lib/zammad_api/dispatcher.rb +0 -12
  44. data/lib/zammad_api/json_helper.rb +0 -11
  45. data/lib/zammad_api/list_all.rb +0 -11
  46. data/lib/zammad_api/list_base.rb +0 -83
  47. data/lib/zammad_api/list_search.rb +0 -11
  48. data/lib/zammad_api/log.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e210909fb0d53e8184097f0ac41021ae674a5981b80e4e405631d33d6d07623e
4
- data.tar.gz: 83e7ac5be2b238ce682b9f478d0bc7dbab3a00308367a01b95e5fc3c9ee586f5
3
+ metadata.gz: 3501727c192aa8444da070f22623d19a3d705a80aa09836975f8603413c54957
4
+ data.tar.gz: 34de53c43d920209e2c5c12f8122d0d3583fd7b5ea93d32ac4476f156ec92e89
5
5
  SHA512:
6
- metadata.gz: c8122abe30faebe219bea0e71ac5220a060b6c2f1ac08e2d86783987c4de5280daccd9341627a49da41e2e9eb24d88e7db84350b21d0f9f47feda364066deb8b
7
- data.tar.gz: 72f47ce52a5f80a4a17f56bb652324cebee7b07c32ae944901065b09b5850d634081b0ae7278327074f6e546c9be6a68714ce842c078979c13294650f9b771f9
6
+ metadata.gz: 5f5e63a09028a4d1a60f06edf4f7ed7a4b5b7abf1c6ec2f19c26a5d04f43e6c21d6ea21a260470c3c6ae3b6d0d41a76b58892c49b1f271a39c8f7aff2ba2533c
7
+ data.tar.gz: 4442e9ab5806f240e186f424878f80bffab98772b1a381efa5c2b16accec48d3c4e0a56e0c4757a6832dea056b1559706817e2e2f156d23f9398a6595d973fa5
data/.yardopts ADDED
@@ -0,0 +1,11 @@
1
+ --markup markdown
2
+ --readme README.md
3
+ --output-dir doc
4
+ --no-private
5
+ --query '@api.text != "private"'
6
+ --protected
7
+ lib/**/*.rb
8
+ -
9
+ UPGRADING.md
10
+ CHANGELOG.md
11
+ LICENSE.md
data/CHANGELOG.md ADDED
@@ -0,0 +1,235 @@
1
+ # Changelog
2
+
3
+ ## [2.0.0.alpha1] - 2026-12-02
4
+
5
+ The first prerelease of 2.0, a breaking release that modernises the whole gem. See
6
+ [UPGRADING.md][upgrading] for the complete before/after guide.
7
+
8
+ Everything below is what changed since 1.4.0. It is published as an alpha so that it can
9
+ still change: names, defaults and behaviour may differ in 2.0.0. A prerelease has to be
10
+ asked for, with `gem install zammad_api --pre` or `gem 'zammad_api', '~> 2.0.0.alpha'`.
11
+
12
+ ### Breaking
13
+
14
+ - Ruby 3.4 or later is required.
15
+ - `Client.new` takes keyword arguments: `Client.new(**config)`. A positional Hash or an
16
+ unknown option raises `ArgumentError`.
17
+ - `logger:` takes a `Logger`, or anything that responds to `debug`, rather than `true`.
18
+ - The resource readers are plural: `client.tickets`, `client.users`, `client.groups`,
19
+ `client.organizations`, `client.ticket_articles`, `client.ticket_priorities` and
20
+ `client.ticket_states`. The singular names raise `NoMethodError`.
21
+ - The readers are a fixed list; 1.x resolved any `client.<name>` to a class under
22
+ `ZammadAPI::Resources`. For another endpoint, use `client.resource(YourClass)`.
23
+ - `client.on_behalf_of = 'login'` and `client.perform_on_behalf_of` are
24
+ `client.on_behalf_of('login')`, which returns a new client and takes a block. A blank
25
+ identifier raises `ArgumentError`.
26
+ - A configuration with more than one kind of credentials raises `ConfigurationError`.
27
+ 1.x sent the first and ignored the rest.
28
+ - A collection walks every page. `each` used to stop after the first: 100 records for
29
+ `all`, 10 for `search`.
30
+ - A collection fetches as many records per request as the endpoint serves (1000 on most
31
+ index endpoints, 100 on tickets, 200 on a search) rather than a fixed 100. `page(n)`
32
+ without `per_page:` is a page of that size.
33
+ - `all` and `search` take no paging or filter keywords: `all(per_page: 50)` is
34
+ `find_each(batch_size: 50)` or `page(1, per_page: 50)`, `search(query: 'zammad')` is
35
+ `search('zammad')`, and `search(query: 'z', page: 2, per_page: 50)` is
36
+ `search('z').page(2, per_page: 50)`. `all(active: true)` never filtered; use `search` or
37
+ `detect`.
38
+ - `page(number, per_page)` with a block is `page(number, per_page: size)`, which returns a
39
+ new collection. `page_next`, `page_prev` and `Collection#[]` were removed.
40
+ - `Collection#find` with an id raises `ArgumentError`: it is `Enumerable#find`. Look a
41
+ record up with `client.tickets.find(1)`.
42
+ - `search` raises `ZammadAPI::Error` on `ticket_states`, `ticket_priorities` and
43
+ `ticket_articles`, which Zammad has no search endpoint for.
44
+ - `record.save` returns `false` on a validation failure and leaves it in `record.error`.
45
+ `save!` raises, and so does `create`. Every other failure raises from both.
46
+ - `record.destroy` and `record.reload` raise for a record that was never saved. `destroy`
47
+ marks the record `destroyed?`, and `persisted?` is false for it.
48
+ - `record.id = ...` raises `ZammadAPI::Error`.
49
+ - `record.attributes` and `record.changes` are frozen, and `record.to_h` is a deep copy.
50
+ Assign through a writer to stage a change.
51
+ - `record.attributes = {...}` is no longer a writer: it stages an attribute called
52
+ `attributes`. Use `assign_attributes` or `update`.
53
+ - A reader for an attribute the record does not carry raises `NoMethodError` instead of
54
+ answering `nil`. Use `record[:x]`, `fetch(:x, nil)` or `key?(:x)` where an attribute may
55
+ be absent.
56
+ - `record.new_instance` is `new_record?` and `persisted?`, and the instance-level `url` is
57
+ the class-level `resource_path`.
58
+ - `ticket.article(…)` is `ticket.add_article(…)`.
59
+ - `ZammadAPI::Error` descends from `StandardError` instead of `RuntimeError`.
60
+ - `ZammadAPI::ResourceNotFoundError` is `ZammadAPI::UnknownResourceError`, raised by
61
+ `client.resource(:name)` for a name that is no resource. A 404 is
62
+ `ZammadAPI::NotFoundError`.
63
+ - No Faraday exception leaves a request: an unreachable host raises
64
+ `ZammadAPI::ConnectionError` and a timeout `ZammadAPI::TimeoutError`.
65
+ - `ResponseError#response` is a `ZammadAPI::Response`, not a Faraday object, and `#body` is
66
+ the decoded payload.
67
+ - An error message names the request that failed:
68
+ `GET api/v1/tickets/1 failed: Couldn't find Ticket with 'id'="1"`.
69
+ `ResponseError#operation` and `#resource_class` were removed.
70
+ - `ZammadAPI::ListBase`, `ListAll` and `ListSearch` are `ZammadAPI::Collection`, and
71
+ `ZammadAPI::Dispatcher` is `ZammadAPI::ResourceProxy`. `ZammadAPI::Log` and
72
+ `ZammadAPI::JsonHelper` were removed.
73
+
74
+ ### Added
75
+
76
+ - `client.get`, `client.post`, `client.put` and `client.delete` reach any endpoint of the
77
+ Zammad API, with `query:`, `body:` and `headers:`. They return a `ZammadAPI::Response`
78
+ and keep authentication, timeouts, retries, credential redaction, JSON decoding and the
79
+ error classes. A path is relative to the instance URL, and one that opens with a scheme
80
+ raises `ArgumentError`, so the credentials stay with the configured instance.
81
+ - Request and connection timeouts (`timeout`, `open_timeout`), on by default at 60 and
82
+ 10 seconds. 1.x waited as long as the server took, so a call that used to hang now
83
+ raises `TimeoutError`, or `ConnectionError` when the connection is not opened in time.
84
+ - Automatic retry with exponential backoff for a `GET` on connection failures, timeouts
85
+ and the statuses 429, 500, 502, 503 and 504. A `Retry-After` within `timeout` is
86
+ honoured, and a longer one ends the retries. A write is never retried: a repeated ticket
87
+ update carrying an `article` adds that article, and sends its e-mail, twice.
88
+ - A specific error class per status: `AuthenticationError` (401), `AuthorizationError`
89
+ (403), `NotFoundError` (404), `ValidationError` (422) and `RateLimitError` (429, with
90
+ `#retry_after`). Network failures raise `ConnectionError` or `TimeoutError`.
91
+ - `Collection#order`, `#page`, `#in_batches`, `#find_each`, `#count`, `#pluck` and
92
+ `#empty?`, plus `client.x.order(...)` as a shorthand for `all.order(...)`.
93
+ - `order` sorts on the server: `order(:name)`, `order(name: :desc)`,
94
+ `order(:active, name: :desc)`, read the way ActiveRecord reads them, and a second
95
+ `order` sorts within the first. `/api/v1/tickets` and `/api/v1/users` hardcode id order,
96
+ so `order` on those raises `ArgumentError`; a search sorts for every resource that can be
97
+ searched.
98
+ - `search(term, **filters)` passes its keywords on to the search endpoint, for what it
99
+ narrows by besides the term: `condition:` and `ids:`, and `role_ids:`, `group_ids:` and
100
+ `permissions:` on users. A blank term raises `ArgumentError`; `'*'` asks for every record.
101
+ - A resource proxy is `Enumerable` over `all`, so `client.tickets.each`,
102
+ `client.tickets.first(5)`, `client.tickets.map`, `#find_each`, `#in_batches`, `#page`,
103
+ `#pluck` and `#count` all work without naming `all`. `client.x.find(id)` keeps
104
+ its own meaning rather than becoming `Enumerable#find`; `detect` is the block form.
105
+ - `Collection#count` costs a single request on a search endpoint, which Zammad can count
106
+ without returning the records. Elsewhere it walks.
107
+ - `Collection#first` sizes its own request: `all.first` is one request for one record and
108
+ `all.first(5)` one request for five. `empty?` asks for one record the same way.
109
+ - A walk of an index ends at the first page shorter than the size it asked for, and a
110
+ search walk at the first empty page, since Zammad can serve a short page with more hits
111
+ behind it.
112
+ - `client.<resource>.find_by(**params)` and `#find_by!`, which look a record up by
113
+ attribute value, and `client.<resource>.exists?(id)`. `find_by` answers with the first
114
+ record that carries all the values, or `nil`: by its id where `id:` is given, through a
115
+ search for the longest String value where the resource has a search endpoint, and by
116
+ walking the index everywhere else.
117
+ - The page size is clamped to what an endpoint serves (100 for `/api/v1/tickets`, 200 for
118
+ a search, 1000 for the other index endpoints). Asking for more used to end iteration
119
+ after the first page, because Zammad capped the response and the short page read as the
120
+ end of the list.
121
+ - `ZammadAPI::PaginationError`, raised when an endpoint answers a page with the records of
122
+ the page before it, instead of paging forever.
123
+ - `Base#reload`, `#persisted?`, `#destroyed?`, `#[]`, `#[]=`, `#fetch`, `#key?`, `#to_h` and
124
+ a readable `#inspect` that blanks attributes naming a credential.
125
+ - `record.update(attributes)`, `record.update!(attributes)` and
126
+ `record.assign_attributes(attributes)`. Attributes can be a Hash or anything with
127
+ `to_hash`, such as permitted `ActionController::Parameters`.
128
+ - `ssl_verify`, `proxy`, `user_agent`, `retries` and `retry_interval` client options.
129
+ The default `User-Agent` is now `zammad_api-ruby/<version>` rather than
130
+ `Zammad API Ruby`.
131
+ - `adapter` and `middleware` client options, the seam into the Faraday stack, for a
132
+ persistent-connection adapter or instrumentation. An adapter set inside the
133
+ `middleware:` callable takes the place of `adapter:`. A Faraday error while building the
134
+ connection surfaces as `ConfigurationError`.
135
+ - RBS signatures in `sig/`, verified by Steep in CI.
136
+ - `respond_to?` answers correctly for attribute readers and resource methods.
137
+ - Records implement `deconstruct_keys`, so they can be used with `case/in` pattern
138
+ matching. `Config` and `Response` are `Data` objects and match as well.
139
+ - `Client#with(**options)` derives a new client with changed options. The options are
140
+ re-validated, any `on_behalf_of` scope is carried over, and naming credentials replaces
141
+ the ones the client has.
142
+ - `Client.from_env` builds a client from `ZAMMAD_URL`, `ZAMMAD_TOKEN`,
143
+ `ZAMMAD_OAUTH2_TOKEN`, `ZAMMAD_USER` and `ZAMMAD_PASSWORD`, with
144
+ passed-in options winning. A blank variable counts as unset.
145
+ - `Client#me`, the user the credentials authenticate as, and `Client#version`, the version
146
+ of the Zammad instance.
147
+ - `Response#decoded(:object | :array)` checks the shape of a response body in one place,
148
+ so an unexpected payload raises `ParseError`.
149
+ - Records compare as the Zammad records they came from: two records of the same kind with
150
+ the same id are equal, and `#hash` agrees, so `uniq`, `Set`, `include?` and records as
151
+ Hash keys all work. A record with no id stays equal only to itself.
152
+ - `record.to_json` and `record.as_json` render a record's attributes. `to_json` previously
153
+ fell through to `Object#to_json`, which serialized a record as the string
154
+ `"#<ZammadAPI::Resources::Ticket:0x...>"`.
155
+ - `client.resource(SomeClass)` takes a subclass of `ZammadAPI::Resources::Base` and answers
156
+ with a proxy for it, so an endpoint this gem does not model gets records, pagination,
157
+ `find_by`, change tracking and `save` from a class that declares its `path`. `searchable`,
158
+ `max_per_page` and `sortable` say what else is true of the endpoint.
159
+ - Typed records. `ResourceProxy` and `Collection` are generic over the resource they hold,
160
+ so `client.tickets` is a `ResourceProxy[Resources::Ticket]` and `find`, `first`,
161
+ `find_by`, the block of `each` and a search all answer with a `Ticket`. Each resource
162
+ declares the long-standing attributes of its kind, so `ticket.title` is a
163
+ `String` and `ticket.titel` is a type error. `spec/typed/usage.rb` is checked by
164
+ `rake steep` the way a caller's code is.
165
+
166
+ ### Fixed
167
+
168
+ - Credentials no longer reach the debug log or `inspect`: 1.x logged `user:password` when a
169
+ client was built and wrote payloads out as they stood. Keys, query parameters and headers
170
+ that name a credential are redacted, and a path is logged without its query string.
171
+ - An exception inside the block of `perform_on_behalf_of` no longer leaves the `From`
172
+ header set on every later request; the block form of `on_behalf_of` scopes a client of
173
+ its own.
174
+ - A Zammad served from a sub-path (`https://example.com/zammad/`) works; 1.x sent every
175
+ request to the root of the host.
176
+ - Query parameters are encoded by Faraday; 1.x sent a list or a Hash, such as a search
177
+ `condition`, as its Ruby `inspect`.
178
+ - A Hash inside an Array attribute has Symbol keys like every other; 1.x left it the
179
+ String keys Zammad sent.
180
+ - A response body that is not JSON is no longer read as an empty Hash: a 2xx where a
181
+ record was expected raises `ParseError`.
182
+ - A name that is no resource raises rather than resolving to a class that is not a
183
+ resource, as `client.base` resolved to `Resources::Base`.
184
+ - Record ids are percent-encoded wherever they go into a path, attachment downloads and
185
+ article lists included.
186
+ - `save` on a record with nothing staged sends no request; 1.x sent an empty `PUT`, which
187
+ bumped `updated_at` and `updated_by`.
188
+ - `record[:x] = 1` stages the attribute it names; 1.x took it for an attribute called `[]`.
189
+ - `add_article` on a ticket that has not been saved raises `ZammadAPI::Error`, where 1.x's
190
+ `article` posted it with `ticket_id: null`.
191
+ - A `url` carrying `user:password@` raises `ConfigurationError`, where 1.x sent those in
192
+ place of a configured token, and so does one without a host, such as `http://:3000/`,
193
+ which 1.x sent to localhost.
194
+ - A subclass of a resource inherits its API path; in 1.x `class MyTicket < Ticket; end`
195
+ had none.
196
+
197
+ ### Changed
198
+
199
+ - `client.<resource>.destroy(id)` deletes directly instead of fetching the record first.
200
+ - `client.<resource>` returns the same proxy each time rather than allocating one per call.
201
+ The proxies are built with the client, so a client stays immutable once built and safe to
202
+ share between threads.
203
+ - A String request body is sent as it is rather than encoded as a JSON string.
204
+
205
+ ## [1.4.0] - 2026-08-25
206
+ - Follow up - c3af2a9 - Fixes #29 - [JSON::ParserError on gateway timeout when proxy responds with HTML](https://github.com/zammad/zammad-api-client-ruby/issues/29)
207
+ - Dependencies updated
208
+
209
+ ## [1.3.1] - 2026-04-28
210
+ - Fixes #29 - [JSON::ParserError on gateway timeout when proxy responds with HTML](https://github.com/zammad/zammad-api-client-ruby/issues/29)
211
+
212
+ ## [1.3.0] - 2026-04-28
213
+ - Maintenance update, added minimum Ruby version 3.0.
214
+
215
+ ## [1.2.0] - 2023-07-20
216
+ - Updated dependency `faraday` to `v2`.
217
+
218
+ ## [1.1.0] - 2023-05-11
219
+ - Switch to dual licensing under AGPL-3.0 or MIT licenses.
220
+
221
+ ## [1.0.8] - 2022-04-28
222
+ - Fixed Faraday deprecation warnings.
223
+
224
+ ## [1.0.7] - 2022-04-14
225
+ - Updated package dependencies and tests.
226
+
227
+ [upgrading]: https://github.com/zammad/zammad-api-client-ruby/blob/master/UPGRADING.md
228
+ [2.0.0.alpha1]: https://github.com/zammad/zammad-api-client-ruby/compare/v1.4.0...v2.0.0.alpha1
229
+ [1.4.0]: https://github.com/zammad/zammad-api-client-ruby/compare/v1.3.1...v1.4.0
230
+ [1.3.1]: https://github.com/zammad/zammad-api-client-ruby/compare/v1.3.0...v1.3.1
231
+ [1.3.0]: https://github.com/zammad/zammad-api-client-ruby/compare/v1.2.0...v1.3.0
232
+ [1.2.0]: https://github.com/zammad/zammad-api-client-ruby/compare/v1.1.0...v1.2.0
233
+ [1.1.0]: https://github.com/zammad/zammad-api-client-ruby/compare/v1.0.8...v1.1.0
234
+ [1.0.8]: https://github.com/zammad/zammad-api-client-ruby/compare/v1.0.7...v1.0.8
235
+ [1.0.7]: https://github.com/zammad/zammad-api-client-ruby/compare/v1.0.6...v1.0.7