delivery-sdk-ruby 0.14.6 → 0.14.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +21 -21
  3. data/README.md +461 -461
  4. data/bin/console +14 -14
  5. data/bin/setup +8 -8
  6. data/lib/delivery-sdk-ruby.rb +17 -17
  7. data/lib/delivery/builders/image_transformation_builder.rb +141 -141
  8. data/lib/delivery/builders/url_builder.rb +73 -73
  9. data/lib/delivery/client/delivery_client.rb +85 -85
  10. data/lib/delivery/client/delivery_query.rb +183 -183
  11. data/lib/delivery/models/content_item.rb +96 -96
  12. data/lib/delivery/models/content_type.rb +26 -26
  13. data/lib/delivery/models/pagination.rb +13 -13
  14. data/lib/delivery/models/taxonomy_group.rb +24 -24
  15. data/lib/delivery/query_parameters/filters.rb +87 -87
  16. data/lib/delivery/query_parameters/parameter_base.rb +30 -30
  17. data/lib/delivery/query_parameters/query_string.rb +49 -49
  18. data/lib/delivery/resolvers/content_link_resolver.rb +62 -62
  19. data/lib/delivery/resolvers/inline_content_item_resolver.rb +50 -50
  20. data/lib/delivery/resolvers/linked_item_resolver.rb +27 -27
  21. data/lib/delivery/responses/delivery_element_response.rb +23 -23
  22. data/lib/delivery/responses/delivery_item_listing_response.rb +39 -39
  23. data/lib/delivery/responses/delivery_item_response.rb +29 -29
  24. data/lib/delivery/responses/delivery_taxonomy_listing_response.rb +32 -32
  25. data/lib/delivery/responses/delivery_taxonomy_response.rb +22 -22
  26. data/lib/delivery/responses/delivery_type_listing_response.rb +31 -31
  27. data/lib/delivery/responses/delivery_type_response.rb +21 -21
  28. data/lib/delivery/responses/response_base.rb +20 -20
  29. data/lib/delivery/version.rb +3 -3
  30. metadata +13 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d629f5135c30a1950c2f91e3a559c205f20edc82e76c2aadae762ab2dd9be27
4
- data.tar.gz: c0a0f5e4e6eaea332d0a0bd1e8fbdc7ebd84b23570180ac1f098bc3d9e10af70
3
+ metadata.gz: c662f36d7a4d321a864bc25605869b7c9be676c209cf57fa359d12cd181b1180
4
+ data.tar.gz: 6a5c8d0f0afedb3b58ab902189d59100714d6b2d6314304f4fac827f83f69da1
5
5
  SHA512:
6
- metadata.gz: 4d537d34794c7e29ab9b5dc34982710d6815869e44d114fc1ab6e148ebb4764ecc561fe4b4231c754438f62968ec5af8765c39b8d99bfda35134d7b4b2c066de
7
- data.tar.gz: 38fc3d99d69db752d90d8c94b0da2d2fb9bfab73154afe06be62ff746050d2b6b46abc90dcd4e30bd93277589fa2510c714192d6d9780428e9f1397c27e5f3f6
6
+ metadata.gz: b04e98791dc66499364a4e56251bbea68ad4fa117f6dddb6ea83b19270d887c7d3cf506c6c7f9ead64ca49cc4364a4026a53d33f41c672bdc99cf067884f2d65
7
+ data.tar.gz: f18b48f3ee713b2eda13a45632d4e33532bc95a546ed46ba831311eb5b108235db5853849402d5ee7a2383c16751ed0d7df486602fd11468bbe226f32b2f1457
data/LICENSE.md CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2019 Eric Dugre
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Eric Dugre
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,461 +1,461 @@
1
- [![Build Status](https://api.travis-ci.com/Kentico/delivery-sdk-ruby.svg?branch=master)](https://travis-ci.com/Kentico/delivery-sdk-ruby)
2
- [![Join the chat at https://kentico-community.slack.com](https://img.shields.io/badge/join-slack-E6186D.svg)](https://kentico-community.slack.com)
3
- [![Stack Overflow](https://img.shields.io/badge/Stack%20Overflow-ASK%20NOW-FE7A16.svg?logo=stackoverflow&logoColor=white)](https://stackoverflow.com/tags/kentico-cloud)
4
- [![Version](https://img.shields.io/gem/v/delivery-sdk-ruby.svg?style=flat)](https://rubygems.org/gems/delivery-sdk-ruby)
5
- [![Maintainability](https://api.codeclimate.com/v1/badges/b2e3fae28a2b2601d815/maintainability)](https://codeclimate.com/github/Kentico/delivery-sdk-ruby/maintainability)
6
-
7
- # Delivery Ruby SDK
8
-
9
- The Delivery Ruby SDK can be used in Ruby/Rails projects to retrieve content from Kentico Cloud. This is a community project and not an official Kentico SDK. If you find a bug in the SDK or have a feature request, please submit a GitHub issue.
10
-
11
- See [environment setup fo Windows](https://github.com/Kentico/delivery-sdk-ruby/wiki/How-to-setup-development-environment-on-Windows) for local development.
12
-
13
-
14
- ## Demo Rails application
15
-
16
- This repository contains a very basic Rails application that you can run locally to see how the SDK can be used. To run the Dancing Goat demo application, clone this repository and open `/dancing_goat/app/controllers/application_controller.rb`. Add your project ID to the file here:
17
-
18
- ```ruby
19
- class ApplicationController < ActionController::Base
20
- PROJECT_ID = '<your-project-id>'.freeze
21
- ```
22
-
23
- If you don't have the sample project installed in Kentico Cloud, you can generate a new project [here](https://app.kenticocloud.com/sample-project-generator). Save the file, then open a terminal in the `/dancing_goat` directory and run the following commands:
24
-
25
- ```
26
- bundle install
27
- rails server
28
- ```
29
-
30
- The site should be accessible at localhost:3000.
31
-
32
- ## Installation
33
-
34
- To use the SDK in your own project, add the gem to your Gemfile:
35
-
36
- ```ruby
37
- gem 'delivery-sdk-ruby'
38
- ```
39
-
40
- Then run `bundle install`. You can also download the gem from [RubyGems.org](https://rubygems.org/gems/delivery-sdk-ruby). To use the SDK in an `.rb` file, you need to require it:
41
-
42
- ```ruby
43
- require 'delivery-sdk-ruby'
44
- ```
45
-
46
- ## Creating a client
47
-
48
- You will use `Delivery::DeliveryClient` to obtain content from Kentico Cloud. Create an instance of the client and pass your project ID:
49
-
50
- ```ruby
51
- delivery_client = Delivery::DeliveryClient.new project_id: '<your-project-id>'
52
- ```
53
-
54
- ### Previewing unpublished content
55
-
56
- To enable [preview](https://developer.kenticocloud.com/docs/previewing-content-in-a-separate-environment "preview"), pass the Preview API Key to the constructor:
57
-
58
- ```ruby
59
- delivery_client = Delivery::DeliveryClient.new project_id: '<your-project-id>',
60
- preview_key: '<your-preview-key>'
61
- ```
62
-
63
- This enables preview, but you can toggle preview at any time by setting the `use_preview` attribute of DeliveryClient which is propogated to all queries created by the client, _or_ per-query by setting it's `use_preview` attribute:
64
-
65
- ```ruby
66
- # For all queries created by client
67
- delivery_client.use_preview = false
68
-
69
- # Per-query
70
- query = delivery_client.items
71
- query.use_preview = false
72
- query.execute do |response|
73
- # Do something
74
- end
75
- ```
76
-
77
- ### Making secure requests
78
-
79
- If you've [secured access](https://developer.kenticocloud.com/docs/securing-public-access "Securing public access") to your project, you need to provide the DeliveryClient with the primary or secondary key:
80
-
81
- ```ruby
82
- Delivery::DeliveryClient.new project_id: '<your-project-id>',
83
- secure_key: '<your-secure-key>'
84
- ```
85
-
86
- ## Listing items
87
-
88
-
89
- Use `.item` or `.items` to create a `Delivery::DeliveryQuery`, then call `.execute` to perform the request.
90
-
91
- ```ruby
92
- delivery_client.items.execute do |response|
93
- response.items.each do |item|
94
- # Do something
95
- end
96
- end
97
- ```
98
-
99
- You can also execute the query without a block and just get the response:
100
-
101
- ```ruby
102
- response = delivery_client.items.execute
103
- ```
104
-
105
- ### Filtering
106
-
107
- You can use [filtering](https://developer.kenticocloud.com/v1/reference#content-filtering "filtering") to retrieve particular items. The filtering methods are applied directly to a string and the available methods are:
108
-
109
- |Method|Example|REST equivalent|
110
- |--|--|--|
111
- |all|`'elements.product_status'.all %w[bestseller on_sale]`|?elements.product_status[all]=bestseller,on_sale|
112
- |any|`'elements.processing'.any %w[dry__natural_ semi_dry]`|?elements.processing[any]=dry__natural_,semi_dry|
113
- |contains|`'elements.related_articles'.contains 'on_roasts'`|?elements.related_articles[contains]=on_roasts|
114
- |eq|`'system.type'.eq 'grinder'`|?system.type=grinder|
115
- |gt|`'elements.price'.gt 20`|?elements.price[gt]=20|
116
- |gt_or_eq|`'elements.price'.gt_or_eq 20`|?elements.price[gte]=20|
117
- |in|`'system.type'.in %w[coffee brewer]`|?system.type[in]=coffee,brewer|
118
- |lt|`'elements.price'.lt 20`|?elements.price[lt]=20|
119
- |lt_or_eq|`'elements.price'.lt_or_eq 20`|?elements.price[lte]=20|
120
- |range|`'system.last_modified'.range %w[2018-02-01 2018-03-31]`|?system.last_modified[range]=2018-02-01,2018-03-31|
121
-
122
- You can pass a single filter or multiple filters in the DeliveryClient methods. For example:
123
-
124
- ```ruby
125
- # Single filter
126
- delivery_client.items('elements.price'.gt 20)
127
-
128
- # Multiple filters
129
- delivery_client.items [
130
- ('elements.price'.gt 20),
131
- ('system.type'.eq 'grinder')
132
- ]
133
- ```
134
-
135
- ### Parameters
136
-
137
- The `.item` and `.items` methods return a `Delivery::DeliveryQuery` object which you can further configure before executing. The methods you can call are:
138
-
139
- |Method|Example|REST equivalent
140
- |--|--|--|
141
- |[order_by](https://developer.kenticocloud.com/v1/reference#content-ordering "order_by")|`order_by 'system.last_modified' '[desc]'`|?order=system.last_modified[desc]
142
- |[skip](https://developer.kenticocloud.com/v1/reference#listing-response-paging "skip")|`skip 5`|?skip=5
143
- |[limit](https://developer.kenticocloud.com/v1/reference#listing-response-paging "limit")|`limit 5`|?limit=5
144
- |[elements](https://developer.kenticocloud.com/v1/reference#projection "elements")|`elements %w[price product_name image]`|?elements=price,product_name,image
145
- |[depth](https://developer.kenticocloud.com/v1/reference#linked-content "depth")|`depth 0`|?depth=0
146
- |[language](https://developer.kenticocloud.com/docs/understanding-language-fallbacks "language")|`language 'en'`|?language=en
147
-
148
- For example:
149
-
150
- ```ruby
151
- delivery_client.items('system.type'.eq 'coffee')
152
- .depth(0)
153
- .limit(5)
154
- .elements(%W[price product_name])
155
- .execute do |response|
156
- # Do something
157
- end
158
- ```
159
-
160
- ### Custom URLs
161
-
162
- When you have a URL (i.e. `next_page` for paging, for testing purposes, or if you prefer to build it on your own) and still want to leverage SDK functionality such as rich text resolving, use the .url method:
163
-
164
- ```ruby
165
- delivery_client.items
166
- .url('https://deliver.kenticocloud.com/<your-project-id>/items?system.type=grinder')
167
- .execute do |response|
168
- # Do something
169
- end
170
- ```
171
-
172
- ### Responses
173
-
174
- All responses from the `.execute` method will be/extend the `Delivery::Responses::ResponseBase` class which contains an `http_code` attribute and a friendly message that can be displayed by calling `.to_s`. You can check the code to determine if the request was successful:
175
-
176
- ```ruby
177
- delivery_client.items.execute do |response|
178
- case response.http_code
179
- when 200
180
- # Success!
181
- when 401
182
- # Did you forget the secure key?
183
- else
184
- puts response.to_s
185
- end
186
- end
187
- ```
188
-
189
- You can also view the raw JSON response of the the query using the `.json` attribute.
190
-
191
- For successful content item queries, you will get either `DeliveryItemResponse` for single item queries, or `DeliveryItemListingResponse` for multiple item queries. You can access the returned content item(s) at `.item` or `.items` respectively.
192
-
193
- The `ContentItem` object gives you access to all system elements and content type elements at the `.system` and `.elements` properies. These are dynamic objects, so you can simply type the name of the element you need:
194
-
195
- ```ruby
196
- price = response.item.elements.price.value
197
- ```
198
-
199
- ### Assets
200
-
201
- You can use `.get_assets(code_name)` to get one or more assets from the specified element. This method will always return an array, so use `.first` to get the first asset:
202
-
203
- ```ruby
204
- url = response.item.get_assets('teaser_image').first.url
205
- ```
206
-
207
- ### Linked items
208
-
209
- You can get a simple array of code names by accessing the element's value:
210
-
211
- ```ruby
212
- links = response.item.elements.facts.value
213
- ```
214
-
215
- The `.get_links(element)` method will return an array of ContentItems instead:
216
-
217
- ```ruby
218
- response.item.get_links('facts').each do |link|
219
- title = link.elements.title.value
220
- end
221
- ```
222
-
223
- ### Pagination
224
-
225
- The `DeliveryItemListingResponse` also contains a `pagination` attribute to access the [paging](https://developer.kenticocloud.com/v1/reference#listing-response-paging "paging") data for the Delivery query. This object contains the following attributes:
226
-
227
- - **skip**
228
- - **limit**
229
- - **count**
230
- - **next_page**
231
-
232
- For example, to access the next page URL you can use:
233
-
234
- ```ruby
235
- delivery_client.items
236
- .skip(0)
237
- .limit(5)
238
- .execute do |response|
239
- next_page_url = response.pagination.next_page
240
- end
241
- ```
242
-
243
- You can then request the secure published content in your project. Be sure to not expose the key if the file(s) it appears in are publicly-available.
244
-
245
- ## Retrieving content types
246
-
247
- You can use the `.type` and `.types` methods to request your content types from Kentico Cloud:
248
-
249
- ```ruby
250
- delivery_client.types.execute do |response|
251
- # Do something
252
- end
253
- delivery_client.type('coffee').execute do |response|
254
- # Do something
255
- end
256
- ```
257
-
258
- ### Responses
259
-
260
- As with content item queries, all content type queries will return a `Delivery::Responses::ResponseBase` of the class `DeliveryTypeResponse` or `DeliveryTypeListingResponse` for single and multiple type queries, respectively.
261
-
262
- For multiple type queries, you can access the array of `ContentType` objects at `.types`, and at `.type` for singe type queries. You can access information about the type(s) dynamically:
263
-
264
- ```ruby
265
- delivery_client.type('coffee').execute do |response|
266
- field_type = response.type.elements.product_status.type # taxonomy
267
- end
268
- ```
269
- The DeliveryTypeListingResponse also contains pagination data, similar to DeliveryItemListingResponse.
270
-
271
- ## Taxonomy
272
-
273
- Use the `.taxonomies` and `.taxonomy(code_name)` endpoints to get information about the taxonomy in your project:
274
-
275
- ```ruby
276
- # Get all taxonomies
277
- delivery_client.taxonomies.execute do |response|
278
- response.taxonomies.each do |tax|
279
- puts "#{tax.system.name} (#{tax.terms.length})"
280
- end
281
- end
282
-
283
- # Get terms of specific taxonomy
284
- delivery_client.taxonomy('personas').execute do |response|
285
- puts response.taxonomy.terms.length
286
- end
287
- ```
288
-
289
- Each response will return either a single `Delivery::TaxonomyGroup` or an array of groups. The taxonomy group(s) are accessible at `.taxonomy` and `.taxonomies` for single and multiple queries, respectively.
290
-
291
- The `TaxonomyGroup` object contains two attributes `.system` and `.terms` which are dynamic OStruct objects containing the same elements as a standard JSON reponse. For example, given a successful query you could access information about the first term of a group using:
292
-
293
- ```ruby
294
- taxonomy_group.terms[0].codename
295
- ```
296
-
297
- Note that the terms of a taxonomy group may also contain terms, for example in Dancing Goat's __Personas__ taxonomy group, which looks like this:
298
-
299
- - Coffee expert
300
- - Barista
301
- - Cafe owner
302
- - Coffee enthusiast
303
- - Coffee lover
304
- - Coffee blogger
305
-
306
- To get the code name of the first term under the "Coffee expert" term, you could do this:
307
-
308
- ```ruby
309
- delivery_client.taxonomy('personas').execute do |response|
310
- puts response.taxonomy.terms[0].terms[0].codename
311
- end
312
- ```
313
-
314
- ## Retreiveing content type elements
315
-
316
- Kentico Cloud provides an [endpoint](https://developer.kenticocloud.com/v1/reference#view-a-content-type-element) for obtaining details about a specific element of a content type. In the Ruby SDK, you can use the `.element` method:
317
-
318
- ```ruby
319
- delivery_client.element('brewer', 'product_status').execute do |response|
320
- puts response.element.type # taxonomy
321
- end
322
- ```
323
-
324
- This returns a `Delivery::Responses::DeliveryElementResponse` where the `element` attribute is a dynamic OStruct representation of the JSON response. This means that you can access any property of the element by simply typing the name as in the above example.
325
-
326
- The element will always contain __codename__, __type__, and __name__, but multiple choice elements will also contain __options__ and taxonomy elements will contain __taxonomy_group__.
327
-
328
- ## Resolving links
329
-
330
- If a rich text element contains links to other content items, you will need to generate the URLs to those items. You can do this by registering a `Delivery::Resolvers::ContentLinkResolver` when you instantiate the DeliveryClient. When you create a ContentLinkResolver, you must pass a method that will return the URL:
331
-
332
- ```ruby
333
- link_resolver = Delivery::Resolvers::ContentLinkResolver.new(lambda do |link|
334
- return "/coffees/#{link.url_slug}" if link.type.eql? 'coffee'
335
- return "/brewers/#{link.url_slug}" if link.type.eql? 'brewer'
336
- end)
337
- delivery_client = Delivery::DeliveryClient.new project_id: '<your-project-id>',
338
- content_link_url_resolver: link_resolver
339
- ```
340
-
341
- You can also build the logic for your resolver in a separate class and register an instance of that class in the DeliveryClient. The class must extend `Delivery::Resolvers::ContentLinkResolver` and contain a `resolve_link(link)` method. For example, you can create `MyLinkResolver.rb`:
342
-
343
- ```ruby
344
- class MyLinkResolver < Delivery::Resolvers::ContentLinkResolver
345
- def resolve_link(link)
346
- return "/coffees/#{link.url_slug}" if link.type.eql? 'coffee'
347
- return "/brewers/#{link.url_slug}" if link.type.eql? 'brewer'
348
- end
349
- end
350
- ```
351
-
352
- Then create an object of this class when instantiating the DeliveryClient:
353
-
354
- ```ruby
355
- delivery_client = Delivery::DeliveryClient.new project_id: '<your-project-id>',
356
- content_link_url_resolver: MyLinkResolver.new
357
- ```
358
-
359
- You can pass a `ContentLinkResolver` to the DeliveryQuery instead of the client if you only want to resolve links for that query, or they should be resolved differently:
360
-
361
- ```ruby
362
- delivery_client = Delivery::DeliveryClient.new project_id: '<your-project-id>'
363
- # Client doesn't use ContentLinkResolver, but query below will
364
- delivery_client.items
365
- .with_link_resolver MyLinkResolver.new
366
- ```
367
-
368
- The `ContentLink` object that is passed to your resolver contains the following attributes:
369
-
370
- - **id**: the system.id of the linked content item
371
- - **code_name**: the system.codename of the linked content item
372
- - **type**: the content type of the linked content item
373
- - **url_slug**: the URL slug of the linked content item, or nil if there is none
374
-
375
- To resolve links in rich text elements, you must retrieve the text using `get_string`:
376
-
377
- ```ruby
378
- item_resolver = Delivery::Resolvers::ContentLinkResolver.new(lambda do |link|
379
- return "/coffees/#{link.url_slug}" if link.type.eql? 'coffee'
380
- return "/brewers/#{link.url_slug}" if link.type.eql? 'brewer'
381
- end)
382
- delivery_client = Delivery::DeliveryClient.new project_id: '<your-project-id>',
383
- content_link_url_resolver: item_resolver
384
- delivery_client.item('coffee_processing_techniques').execute do |response|
385
- text = response.item.get_string 'body_copy'
386
- end
387
- ```
388
-
389
- ## Resolving inline content
390
-
391
- Existing content items can be inserted into a rich text element, or you can create new content items as components. You need to resolve these in your application just as with content links. You can register a resolver when you instantiate the client by passing it with the hash key `inline_content_item_resolver`:
392
-
393
- ```ruby
394
- item_resolver = Delivery::Resolvers::InlineContentItemResolver.new(lambda do |item|
395
- return "<h1>#{item.elements.zip_code.value}</h1>" if item.system.type.eql? 'cafe'
396
- return "<div>$#{item.elements.price.value}</div>" if item.system.type.eql? 'brewer'
397
- end)
398
- delivery_client = Delivery::DeliveryClient.new project_id: '<your-project-id>',
399
- inline_content_item_resolver: item_resolver
400
- ```
401
-
402
- The object passed to the resolving method is a complete ContentItem. Similar to content link resolvers, you can create your own class which extends `Delivery::Resolvers::InlineContentItemResolver` and implements the `resolve_item` method:
403
-
404
- ```ruby
405
- class MyItemResolver < Delivery::Resolvers::InlineContentItemResolver
406
- def resolve_item(item)
407
- return "<h1>#{item.elements.zip_code.value}</h1>" if item.system.type.eql? 'cafe'
408
- return "<div>$#{item.elements.price.value}</div>" if item.system.type.eql? 'brewer'
409
- end
410
- end
411
- ```
412
-
413
- You can also set the inline content resolver per-query:
414
-
415
- ```ruby
416
- delivery_client = Delivery::DeliveryClient.new project_id: '<your-project-id>'
417
- # Client doesn't use InlineContentItemResolver, but query below will
418
- delivery_client.items
419
- .with_inline_content_item_resolver MyItemResolver.new
420
- ```
421
-
422
- ## Image transformation
423
-
424
- When you've obtained the URL for an asset, you can use our [Image Transformation API](https://developer.kenticocloud.com/v1/reference#image-transformation) to make on-the-fly modifications to the image. To do this, use the static `.transform` method of `Delivery::Builders::ImageTransformationBuilder`, then call the transformation methods. When you're done, call the `.url` method to get the new URL:
425
-
426
- ```ruby
427
- url = response.item.get_assets('teaser_image').first.url
428
- url = Delivery::Builders::ImageTransformationBuilder.transform(url)
429
- # methods...
430
- .url
431
- ```
432
-
433
- The available methods are:
434
-
435
- |Method|Possible values|REST example
436
- |--|--|--|
437
- |`.with_width`| positive integer, or float between 0 and 1| ?w=200
438
- |`.with_height`| positive integer, or float between 0 and 1| ?h=200
439
- |`.with_pixel_ratio`| float greater than 0 but less than 5| ?dpr=1.5
440
- |`.with_fit_mode`| constants available at `Delivery::Builders::ImageTransformationBuilder` <ul><li>FITMODE_CROP</li><li>FITMODE_CLIP</li><li>FITMODE_SCALE</li></ul>| ?fit=crop
441
- |`.with_rect`| 4 integer values representing pixels or floats representing percentages|rect=100,100,0.7,0.7
442
- |`.with_focal_point`| 2 floats between 0 and 1 and one integer between 1 and 100| ?fp-x=0.2&fp-y=0.7&fp-z=5
443
- |`.with_background_color`| string containing 3, 4, 6, or 8 characters | ?bg=7A0099EE
444
- |`.with_output_format`| constants available at `Delivery::Builders::ImageTransformationBuilder` <ul><li>FORMAT_GIF</li><li>FORMAT_PNG</li><li>FORMAT_PNG8</li><li>FORMAT_JPG</li><li>FORMAT_PJPG</li><li>FORMAT_WEBP</li></ul> | ?fm=webp
445
- |`.with_quality`| integer between 1 to 100 | ?quality=50
446
- |`.with_lossless`| 'true', 'false', 0, or 1| ?lossless=1
447
- |`.with_auto_format_selection`| 'true', 'false', 0, or 1 | ?auto=format
448
-
449
- ## Feedback & Contributing
450
-
451
- Check out the [contributing](https://github.com/Kentico/delivery-sdk-ruby/blob/master/CONTRIBUTING.md) page to see the best places to file issues, start discussions, and begin contributing.
452
-
453
- ## License
454
-
455
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
456
-
457
- ## Code of Conduct
458
-
459
- Everyone interacting in the Delivery project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Kentico/delivery-sdk-net/blob/master/CODE_OF_CONDUCT.md).
460
-
461
- ![Analytics](https://kentico-ga-beacon.azurewebsites.net/api/UA-69014260-4/Kentico/delivery-sdk-ruby?pixel)
1
+ [![Build Status](https://api.travis-ci.com/Kentico/delivery-sdk-ruby.svg?branch=master)](https://travis-ci.com/Kentico/delivery-sdk-ruby)
2
+ [![Join the chat at https://kentico-community.slack.com](https://img.shields.io/badge/join-slack-E6186D.svg)](https://kentico-community.slack.com)
3
+ [![Stack Overflow](https://img.shields.io/badge/Stack%20Overflow-ASK%20NOW-FE7A16.svg?logo=stackoverflow&logoColor=white)](https://stackoverflow.com/tags/kentico-cloud)
4
+ [![Version](https://img.shields.io/gem/v/delivery-sdk-ruby.svg?style=flat)](https://rubygems.org/gems/delivery-sdk-ruby)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/b2e3fae28a2b2601d815/maintainability)](https://codeclimate.com/github/Kentico/delivery-sdk-ruby/maintainability)
6
+
7
+ # Delivery Ruby SDK
8
+
9
+ The Delivery Ruby SDK can be used in Ruby/Rails projects to retrieve content from Kentico Cloud. This is a community project and not an official Kentico SDK. If you find a bug in the SDK or have a feature request, please submit a GitHub issue.
10
+
11
+ See [environment setup fo Windows](https://github.com/Kentico/delivery-sdk-ruby/wiki/How-to-setup-development-environment-on-Windows) for local development.
12
+
13
+
14
+ ## Demo Rails application
15
+
16
+ This repository contains a very basic Rails application that you can run locally to see how the SDK can be used. To run the Dancing Goat demo application, clone this repository and open `/dancing_goat/app/controllers/application_controller.rb`. Add your project ID to the file here:
17
+
18
+ ```ruby
19
+ class ApplicationController < ActionController::Base
20
+ PROJECT_ID = '<your-project-id>'.freeze
21
+ ```
22
+
23
+ If you don't have the sample project installed in Kentico Cloud, you can generate a new project [here](https://app.kenticocloud.com/sample-project-generator). Save the file, then open a terminal in the `/dancing_goat` directory and run the following commands:
24
+
25
+ ```
26
+ bundle install
27
+ rails server
28
+ ```
29
+
30
+ The site should be accessible at localhost:3000.
31
+
32
+ ## Installation
33
+
34
+ To use the SDK in your own project, add the gem to your Gemfile:
35
+
36
+ ```ruby
37
+ gem 'delivery-sdk-ruby'
38
+ ```
39
+
40
+ Then run `bundle install`. You can also download the gem from [RubyGems.org](https://rubygems.org/gems/delivery-sdk-ruby). To use the SDK in an `.rb` file, you need to require it:
41
+
42
+ ```ruby
43
+ require 'delivery-sdk-ruby'
44
+ ```
45
+
46
+ ## Creating a client
47
+
48
+ You will use `Delivery::DeliveryClient` to obtain content from Kentico Cloud. Create an instance of the client and pass your project ID:
49
+
50
+ ```ruby
51
+ delivery_client = Delivery::DeliveryClient.new project_id: '<your-project-id>'
52
+ ```
53
+
54
+ ### Previewing unpublished content
55
+
56
+ To enable [preview](https://developer.kenticocloud.com/docs/previewing-content-in-a-separate-environment "preview"), pass the Preview API Key to the constructor:
57
+
58
+ ```ruby
59
+ delivery_client = Delivery::DeliveryClient.new project_id: '<your-project-id>',
60
+ preview_key: '<your-preview-key>'
61
+ ```
62
+
63
+ This enables preview, but you can toggle preview at any time by setting the `use_preview` attribute of DeliveryClient which is propogated to all queries created by the client, _or_ per-query by setting it's `use_preview` attribute:
64
+
65
+ ```ruby
66
+ # For all queries created by client
67
+ delivery_client.use_preview = false
68
+
69
+ # Per-query
70
+ query = delivery_client.items
71
+ query.use_preview = false
72
+ query.execute do |response|
73
+ # Do something
74
+ end
75
+ ```
76
+
77
+ ### Making secure requests
78
+
79
+ If you've [secured access](https://developer.kenticocloud.com/docs/securing-public-access "Securing public access") to your project, you need to provide the DeliveryClient with the primary or secondary key:
80
+
81
+ ```ruby
82
+ Delivery::DeliveryClient.new project_id: '<your-project-id>',
83
+ secure_key: '<your-secure-key>'
84
+ ```
85
+
86
+ ## Listing items
87
+
88
+
89
+ Use `.item` or `.items` to create a `Delivery::DeliveryQuery`, then call `.execute` to perform the request.
90
+
91
+ ```ruby
92
+ delivery_client.items.execute do |response|
93
+ response.items.each do |item|
94
+ # Do something
95
+ end
96
+ end
97
+ ```
98
+
99
+ You can also execute the query without a block and just get the response:
100
+
101
+ ```ruby
102
+ response = delivery_client.items.execute
103
+ ```
104
+
105
+ ### Filtering
106
+
107
+ You can use [filtering](https://developer.kenticocloud.com/v1/reference#content-filtering "filtering") to retrieve particular items. The filtering methods are applied directly to a string and the available methods are:
108
+
109
+ |Method|Example|REST equivalent|
110
+ |--|--|--|
111
+ |all|`'elements.product_status'.all %w[bestseller on_sale]`|?elements.product_status[all]=bestseller,on_sale|
112
+ |any|`'elements.processing'.any %w[dry__natural_ semi_dry]`|?elements.processing[any]=dry__natural_,semi_dry|
113
+ |contains|`'elements.related_articles'.contains 'on_roasts'`|?elements.related_articles[contains]=on_roasts|
114
+ |eq|`'system.type'.eq 'grinder'`|?system.type=grinder|
115
+ |gt|`'elements.price'.gt 20`|?elements.price[gt]=20|
116
+ |gt_or_eq|`'elements.price'.gt_or_eq 20`|?elements.price[gte]=20|
117
+ |in|`'system.type'.in %w[coffee brewer]`|?system.type[in]=coffee,brewer|
118
+ |lt|`'elements.price'.lt 20`|?elements.price[lt]=20|
119
+ |lt_or_eq|`'elements.price'.lt_or_eq 20`|?elements.price[lte]=20|
120
+ |range|`'system.last_modified'.range %w[2018-02-01 2018-03-31]`|?system.last_modified[range]=2018-02-01,2018-03-31|
121
+
122
+ You can pass a single filter or multiple filters in the DeliveryClient methods. For example:
123
+
124
+ ```ruby
125
+ # Single filter
126
+ delivery_client.items('elements.price'.gt 20)
127
+
128
+ # Multiple filters
129
+ delivery_client.items [
130
+ ('elements.price'.gt 20),
131
+ ('system.type'.eq 'grinder')
132
+ ]
133
+ ```
134
+
135
+ ### Parameters
136
+
137
+ The `.item` and `.items` methods return a `Delivery::DeliveryQuery` object which you can further configure before executing. The methods you can call are:
138
+
139
+ |Method|Example|REST equivalent
140
+ |--|--|--|
141
+ |[order_by](https://developer.kenticocloud.com/v1/reference#content-ordering "order_by")|`order_by 'system.last_modified' '[desc]'`|?order=system.last_modified[desc]
142
+ |[skip](https://developer.kenticocloud.com/v1/reference#listing-response-paging "skip")|`skip 5`|?skip=5
143
+ |[limit](https://developer.kenticocloud.com/v1/reference#listing-response-paging "limit")|`limit 5`|?limit=5
144
+ |[elements](https://developer.kenticocloud.com/v1/reference#projection "elements")|`elements %w[price product_name image]`|?elements=price,product_name,image
145
+ |[depth](https://developer.kenticocloud.com/v1/reference#linked-content "depth")|`depth 0`|?depth=0
146
+ |[language](https://developer.kenticocloud.com/docs/understanding-language-fallbacks "language")|`language 'en'`|?language=en
147
+
148
+ For example:
149
+
150
+ ```ruby
151
+ delivery_client.items('system.type'.eq 'coffee')
152
+ .depth(0)
153
+ .limit(5)
154
+ .elements(%W[price product_name])
155
+ .execute do |response|
156
+ # Do something
157
+ end
158
+ ```
159
+
160
+ ### Custom URLs
161
+
162
+ When you have a URL (i.e. `next_page` for paging, for testing purposes, or if you prefer to build it on your own) and still want to leverage SDK functionality such as rich text resolving, use the .url method:
163
+
164
+ ```ruby
165
+ delivery_client.items
166
+ .url('https://deliver.kenticocloud.com/<your-project-id>/items?system.type=grinder')
167
+ .execute do |response|
168
+ # Do something
169
+ end
170
+ ```
171
+
172
+ ### Responses
173
+
174
+ All responses from the `.execute` method will be/extend the `Delivery::Responses::ResponseBase` class which contains an `http_code` attribute and a friendly message that can be displayed by calling `.to_s`. You can check the code to determine if the request was successful:
175
+
176
+ ```ruby
177
+ delivery_client.items.execute do |response|
178
+ case response.http_code
179
+ when 200
180
+ # Success!
181
+ when 401
182
+ # Did you forget the secure key?
183
+ else
184
+ puts response.to_s
185
+ end
186
+ end
187
+ ```
188
+
189
+ You can also view the raw JSON response of the the query using the `.json` attribute.
190
+
191
+ For successful content item queries, you will get either `DeliveryItemResponse` for single item queries, or `DeliveryItemListingResponse` for multiple item queries. You can access the returned content item(s) at `.item` or `.items` respectively.
192
+
193
+ The `ContentItem` object gives you access to all system elements and content type elements at the `.system` and `.elements` properies. These are dynamic objects, so you can simply type the name of the element you need:
194
+
195
+ ```ruby
196
+ price = response.item.elements.price.value
197
+ ```
198
+
199
+ ### Assets
200
+
201
+ You can use `.get_assets(code_name)` to get one or more assets from the specified element. This method will always return an array, so use `.first` to get the first asset:
202
+
203
+ ```ruby
204
+ url = response.item.get_assets('teaser_image').first.url
205
+ ```
206
+
207
+ ### Linked items
208
+
209
+ You can get a simple array of code names by accessing the element's value:
210
+
211
+ ```ruby
212
+ links = response.item.elements.facts.value
213
+ ```
214
+
215
+ The `.get_links(element)` method will return an array of ContentItems instead:
216
+
217
+ ```ruby
218
+ response.item.get_links('facts').each do |link|
219
+ title = link.elements.title.value
220
+ end
221
+ ```
222
+
223
+ ### Pagination
224
+
225
+ The `DeliveryItemListingResponse` also contains a `pagination` attribute to access the [paging](https://developer.kenticocloud.com/v1/reference#listing-response-paging "paging") data for the Delivery query. This object contains the following attributes:
226
+
227
+ - **skip**
228
+ - **limit**
229
+ - **count**
230
+ - **next_page**
231
+
232
+ For example, to access the next page URL you can use:
233
+
234
+ ```ruby
235
+ delivery_client.items
236
+ .skip(0)
237
+ .limit(5)
238
+ .execute do |response|
239
+ next_page_url = response.pagination.next_page
240
+ end
241
+ ```
242
+
243
+ You can then request the secure published content in your project. Be sure to not expose the key if the file(s) it appears in are publicly-available.
244
+
245
+ ## Retrieving content types
246
+
247
+ You can use the `.type` and `.types` methods to request your content types from Kentico Cloud:
248
+
249
+ ```ruby
250
+ delivery_client.types.execute do |response|
251
+ # Do something
252
+ end
253
+ delivery_client.type('coffee').execute do |response|
254
+ # Do something
255
+ end
256
+ ```
257
+
258
+ ### Responses
259
+
260
+ As with content item queries, all content type queries will return a `Delivery::Responses::ResponseBase` of the class `DeliveryTypeResponse` or `DeliveryTypeListingResponse` for single and multiple type queries, respectively.
261
+
262
+ For multiple type queries, you can access the array of `ContentType` objects at `.types`, and at `.type` for singe type queries. You can access information about the type(s) dynamically:
263
+
264
+ ```ruby
265
+ delivery_client.type('coffee').execute do |response|
266
+ field_type = response.type.elements.product_status.type # taxonomy
267
+ end
268
+ ```
269
+ The DeliveryTypeListingResponse also contains pagination data, similar to DeliveryItemListingResponse.
270
+
271
+ ## Taxonomy
272
+
273
+ Use the `.taxonomies` and `.taxonomy(code_name)` endpoints to get information about the taxonomy in your project:
274
+
275
+ ```ruby
276
+ # Get all taxonomies
277
+ delivery_client.taxonomies.execute do |response|
278
+ response.taxonomies.each do |tax|
279
+ puts "#{tax.system.name} (#{tax.terms.length})"
280
+ end
281
+ end
282
+
283
+ # Get terms of specific taxonomy
284
+ delivery_client.taxonomy('personas').execute do |response|
285
+ puts response.taxonomy.terms.length
286
+ end
287
+ ```
288
+
289
+ Each response will return either a single `Delivery::TaxonomyGroup` or an array of groups. The taxonomy group(s) are accessible at `.taxonomy` and `.taxonomies` for single and multiple queries, respectively.
290
+
291
+ The `TaxonomyGroup` object contains two attributes `.system` and `.terms` which are dynamic OStruct objects containing the same elements as a standard JSON reponse. For example, given a successful query you could access information about the first term of a group using:
292
+
293
+ ```ruby
294
+ taxonomy_group.terms[0].codename
295
+ ```
296
+
297
+ Note that the terms of a taxonomy group may also contain terms, for example in Dancing Goat's __Personas__ taxonomy group, which looks like this:
298
+
299
+ - Coffee expert
300
+ - Barista
301
+ - Cafe owner
302
+ - Coffee enthusiast
303
+ - Coffee lover
304
+ - Coffee blogger
305
+
306
+ To get the code name of the first term under the "Coffee expert" term, you could do this:
307
+
308
+ ```ruby
309
+ delivery_client.taxonomy('personas').execute do |response|
310
+ puts response.taxonomy.terms[0].terms[0].codename
311
+ end
312
+ ```
313
+
314
+ ## Retreiveing content type elements
315
+
316
+ Kentico Cloud provides an [endpoint](https://developer.kenticocloud.com/v1/reference#view-a-content-type-element) for obtaining details about a specific element of a content type. In the Ruby SDK, you can use the `.element` method:
317
+
318
+ ```ruby
319
+ delivery_client.element('brewer', 'product_status').execute do |response|
320
+ puts response.element.type # taxonomy
321
+ end
322
+ ```
323
+
324
+ This returns a `Delivery::Responses::DeliveryElementResponse` where the `element` attribute is a dynamic OStruct representation of the JSON response. This means that you can access any property of the element by simply typing the name as in the above example.
325
+
326
+ The element will always contain __codename__, __type__, and __name__, but multiple choice elements will also contain __options__ and taxonomy elements will contain __taxonomy_group__.
327
+
328
+ ## Resolving links
329
+
330
+ If a rich text element contains links to other content items, you will need to generate the URLs to those items. You can do this by registering a `Delivery::Resolvers::ContentLinkResolver` when you instantiate the DeliveryClient. When you create a ContentLinkResolver, you must pass a method that will return the URL:
331
+
332
+ ```ruby
333
+ link_resolver = Delivery::Resolvers::ContentLinkResolver.new(lambda do |link|
334
+ return "/coffees/#{link.url_slug}" if link.type.eql? 'coffee'
335
+ return "/brewers/#{link.url_slug}" if link.type.eql? 'brewer'
336
+ end)
337
+ delivery_client = Delivery::DeliveryClient.new project_id: '<your-project-id>',
338
+ content_link_url_resolver: link_resolver
339
+ ```
340
+
341
+ You can also build the logic for your resolver in a separate class and register an instance of that class in the DeliveryClient. The class must extend `Delivery::Resolvers::ContentLinkResolver` and contain a `resolve_link(link)` method. For example, you can create `MyLinkResolver.rb`:
342
+
343
+ ```ruby
344
+ class MyLinkResolver < Delivery::Resolvers::ContentLinkResolver
345
+ def resolve_link(link)
346
+ return "/coffees/#{link.url_slug}" if link.type.eql? 'coffee'
347
+ return "/brewers/#{link.url_slug}" if link.type.eql? 'brewer'
348
+ end
349
+ end
350
+ ```
351
+
352
+ Then create an object of this class when instantiating the DeliveryClient:
353
+
354
+ ```ruby
355
+ delivery_client = Delivery::DeliveryClient.new project_id: '<your-project-id>',
356
+ content_link_url_resolver: MyLinkResolver.new
357
+ ```
358
+
359
+ You can pass a `ContentLinkResolver` to the DeliveryQuery instead of the client if you only want to resolve links for that query, or they should be resolved differently:
360
+
361
+ ```ruby
362
+ delivery_client = Delivery::DeliveryClient.new project_id: '<your-project-id>'
363
+ # Client doesn't use ContentLinkResolver, but query below will
364
+ delivery_client.items
365
+ .with_link_resolver MyLinkResolver.new
366
+ ```
367
+
368
+ The `ContentLink` object that is passed to your resolver contains the following attributes:
369
+
370
+ - **id**: the system.id of the linked content item
371
+ - **code_name**: the system.codename of the linked content item
372
+ - **type**: the content type of the linked content item
373
+ - **url_slug**: the URL slug of the linked content item, or nil if there is none
374
+
375
+ To resolve links in rich text elements, you must retrieve the text using `get_string`:
376
+
377
+ ```ruby
378
+ item_resolver = Delivery::Resolvers::ContentLinkResolver.new(lambda do |link|
379
+ return "/coffees/#{link.url_slug}" if link.type.eql? 'coffee'
380
+ return "/brewers/#{link.url_slug}" if link.type.eql? 'brewer'
381
+ end)
382
+ delivery_client = Delivery::DeliveryClient.new project_id: '<your-project-id>',
383
+ content_link_url_resolver: item_resolver
384
+ delivery_client.item('coffee_processing_techniques').execute do |response|
385
+ text = response.item.get_string 'body_copy'
386
+ end
387
+ ```
388
+
389
+ ## Resolving inline content
390
+
391
+ Existing content items can be inserted into a rich text element, or you can create new content items as components. You need to resolve these in your application just as with content links. You can register a resolver when you instantiate the client by passing it with the hash key `inline_content_item_resolver`:
392
+
393
+ ```ruby
394
+ item_resolver = Delivery::Resolvers::InlineContentItemResolver.new(lambda do |item|
395
+ return "<h1>#{item.elements.zip_code.value}</h1>" if item.system.type.eql? 'cafe'
396
+ return "<div>$#{item.elements.price.value}</div>" if item.system.type.eql? 'brewer'
397
+ end)
398
+ delivery_client = Delivery::DeliveryClient.new project_id: '<your-project-id>',
399
+ inline_content_item_resolver: item_resolver
400
+ ```
401
+
402
+ The object passed to the resolving method is a complete ContentItem. Similar to content link resolvers, you can create your own class which extends `Delivery::Resolvers::InlineContentItemResolver` and implements the `resolve_item` method:
403
+
404
+ ```ruby
405
+ class MyItemResolver < Delivery::Resolvers::InlineContentItemResolver
406
+ def resolve_item(item)
407
+ return "<h1>#{item.elements.zip_code.value}</h1>" if item.system.type.eql? 'cafe'
408
+ return "<div>$#{item.elements.price.value}</div>" if item.system.type.eql? 'brewer'
409
+ end
410
+ end
411
+ ```
412
+
413
+ You can also set the inline content resolver per-query:
414
+
415
+ ```ruby
416
+ delivery_client = Delivery::DeliveryClient.new project_id: '<your-project-id>'
417
+ # Client doesn't use InlineContentItemResolver, but query below will
418
+ delivery_client.items
419
+ .with_inline_content_item_resolver MyItemResolver.new
420
+ ```
421
+
422
+ ## Image transformation
423
+
424
+ When you've obtained the URL for an asset, you can use our [Image Transformation API](https://developer.kenticocloud.com/v1/reference#image-transformation) to make on-the-fly modifications to the image. To do this, use the static `.transform` method of `Delivery::Builders::ImageTransformationBuilder`, then call the transformation methods. When you're done, call the `.url` method to get the new URL:
425
+
426
+ ```ruby
427
+ url = response.item.get_assets('teaser_image').first.url
428
+ url = Delivery::Builders::ImageTransformationBuilder.transform(url)
429
+ # methods...
430
+ .url
431
+ ```
432
+
433
+ The available methods are:
434
+
435
+ |Method|Possible values|REST example
436
+ |--|--|--|
437
+ |`.with_width`| positive integer, or float between 0 and 1| ?w=200
438
+ |`.with_height`| positive integer, or float between 0 and 1| ?h=200
439
+ |`.with_pixel_ratio`| float greater than 0 but less than 5| ?dpr=1.5
440
+ |`.with_fit_mode`| constants available at `Delivery::Builders::ImageTransformationBuilder` <ul><li>FITMODE_CROP</li><li>FITMODE_CLIP</li><li>FITMODE_SCALE</li></ul>| ?fit=crop
441
+ |`.with_rect`| 4 integer values representing pixels or floats representing percentages|rect=100,100,0.7,0.7
442
+ |`.with_focal_point`| 2 floats between 0 and 1 and one integer between 1 and 100| ?fp-x=0.2&fp-y=0.7&fp-z=5
443
+ |`.with_background_color`| string containing 3, 4, 6, or 8 characters | ?bg=7A0099EE
444
+ |`.with_output_format`| constants available at `Delivery::Builders::ImageTransformationBuilder` <ul><li>FORMAT_GIF</li><li>FORMAT_PNG</li><li>FORMAT_PNG8</li><li>FORMAT_JPG</li><li>FORMAT_PJPG</li><li>FORMAT_WEBP</li></ul> | ?fm=webp
445
+ |`.with_quality`| integer between 1 to 100 | ?quality=50
446
+ |`.with_lossless`| 'true', 'false', 0, or 1| ?lossless=1
447
+ |`.with_auto_format_selection`| 'true', 'false', 0, or 1 | ?auto=format
448
+
449
+ ## Feedback & Contributing
450
+
451
+ Check out the [contributing](https://github.com/Kentico/delivery-sdk-ruby/blob/master/CONTRIBUTING.md) page to see the best places to file issues, start discussions, and begin contributing.
452
+
453
+ ## License
454
+
455
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
456
+
457
+ ## Code of Conduct
458
+
459
+ Everyone interacting in the Delivery project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Kentico/delivery-sdk-net/blob/master/CODE_OF_CONDUCT.md).
460
+
461
+ ![Analytics](https://kentico-ga-beacon.azurewebsites.net/api/UA-69014260-4/Kentico/delivery-sdk-ruby?pixel)