Skip to content

Commit 632c8ca

Browse files
committed
Merge branch 'sideloading'
2 parents 38ffa5b + 3b67fec commit 632c8ca

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Readme.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,44 @@ ticket.new_record? # => true
151151
ticket.save # Will POST
152152
```
153153

154+
### Side-loading
155+
156+
**Warning: this is an experimental feature. Abuse it and lose it.**
157+
158+
To facilitate a smaller number of requests and easier manipulation of associated data we allow "side-loading", or inclusion, of selected resources.
159+
160+
For example:
161+
A ZendeskAPI::Ticket is associated with ZendeskAPI::User through the requester_id field.
162+
API requests for that ticket return a structure similar to this:
163+
```json
164+
"ticket": {
165+
"id": 1,
166+
"url": "http.....",
167+
"requester_id": 7,
168+
...
169+
}
170+
```
171+
172+
Calling ZendeskAPI::Ticket#requester automatically fetches and loads the user referenced above (`/api/v2/users/7`).
173+
Using side-loading, however, the user can be partially loaded in the same request as the ticket.
174+
175+
```ruby
176+
tickets = client.tickets.include(:users)
177+
# Or client.tickets(include: :users)
178+
# Does *NOT* make a request to the server since it is already loaded
179+
tickets.first.requester # => #<ZendeskAPI::User id=...>
180+
```
181+
182+
OR
183+
184+
```ruby
185+
ticket = client.tickets.find(:id => 1, :include => :users)
186+
ticket.requester # => #<ZendeskAPI::User id=...>
187+
```
188+
189+
Currently, this feature is limited to only a few resources and their associations.
190+
They are documented on [developer.zendesk.com](http://developer.zendesk.com/documentation/rest_api/introduction.html#side-loading).
191+
154192
### Special case: Custom resources paths
155193

156194
API endpoints such as tickets/recent or topics/show_many can be accessed through chaining.

0 commit comments

Comments
 (0)