contentful 2.12.0 → 2.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +69 -1
- data/README.md +24 -13
- data/lib/contentful/array.rb +14 -6
- data/lib/contentful/array_like.rb +11 -2
- data/lib/contentful/asset.rb +10 -4
- data/lib/contentful/base_resource.rb +29 -6
- data/lib/contentful/client.rb +4 -3
- data/lib/contentful/coercions.rb +1 -4
- data/lib/contentful/entry.rb +9 -5
- data/lib/contentful/fields_resource.rb +7 -11
- data/lib/contentful/includes.rb +74 -0
- data/lib/contentful/request.rb +6 -1
- data/lib/contentful/resource_builder.rb +15 -12
- data/lib/contentful/support.rb +0 -35
- data/lib/contentful/version.rb +1 -1
- metadata +15 -370
- data/.gitignore +0 -7
- data/.rspec +0 -1
- data/.rubocop.yml +0 -28
- data/.rubocop_todo.yml +0 -35
- data/.travis.yml +0 -13
- data/.yardopts +0 -4
- data/Gemfile +0 -9
- data/Gemfile.lock +0 -152
- data/Guardfile +0 -24
- data/RELEASE.md +0 -8
- data/Rakefile +0 -33
- data/contentful.gemspec +0 -44
- data/coverage/.last_run.json +0 -5
- data/coverage/.resultset.json +0 -2419
- data/coverage/.resultset.json.lock +0 -0
- data/coverage/assets/0.10.2/application.css +0 -799
- data/coverage/assets/0.10.2/application.js +0 -1707
- data/coverage/assets/0.10.2/colorbox/border.png +0 -0
- data/coverage/assets/0.10.2/colorbox/controls.png +0 -0
- data/coverage/assets/0.10.2/colorbox/loading.gif +0 -0
- data/coverage/assets/0.10.2/colorbox/loading_background.png +0 -0
- data/coverage/assets/0.10.2/favicon_green.png +0 -0
- data/coverage/assets/0.10.2/favicon_red.png +0 -0
- data/coverage/assets/0.10.2/favicon_yellow.png +0 -0
- data/coverage/assets/0.10.2/loading.gif +0 -0
- data/coverage/assets/0.10.2/magnify.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/index.html +0 -15071
- data/doc/Contentful/AccessDenied.html +0 -159
- data/doc/Contentful/Array.html +0 -765
- data/doc/Contentful/ArrayCoercion.html +0 -242
- data/doc/Contentful/ArrayLike.html +0 -625
- data/doc/Contentful/Asset.html +0 -487
- data/doc/Contentful/BadGateway.html +0 -159
- data/doc/Contentful/BadRequest.html +0 -159
- data/doc/Contentful/BaseCoercion.html +0 -445
- data/doc/Contentful/BaseResource.html +0 -599
- data/doc/Contentful/BooleanCoercion.html +0 -242
- data/doc/Contentful/Client.html +0 -1740
- data/doc/Contentful/ContentType.html +0 -618
- data/doc/Contentful/ContentTypeCache.html +0 -428
- data/doc/Contentful/DateCoercion.html +0 -244
- data/doc/Contentful/DeletedAsset.html +0 -157
- data/doc/Contentful/DeletedEntry.html +0 -157
- data/doc/Contentful/EmptyFieldError.html +0 -217
- data/doc/Contentful/Entry.html +0 -334
- data/doc/Contentful/Error.html +0 -410
- data/doc/Contentful/Field.html +0 -936
- data/doc/Contentful/FieldsResource.html +0 -583
- data/doc/Contentful/File.html +0 -218
- data/doc/Contentful/FloatCoercion.html +0 -238
- data/doc/Contentful/IntegerCoercion.html +0 -238
- data/doc/Contentful/Link.html +0 -249
- data/doc/Contentful/LinkCoercion.html +0 -158
- data/doc/Contentful/Locale.html +0 -537
- data/doc/Contentful/Location.html +0 -383
- data/doc/Contentful/LocationCoercion.html +0 -238
- data/doc/Contentful/NotFound.html +0 -159
- data/doc/Contentful/ObjectCoercion.html +0 -238
- data/doc/Contentful/RateLimitExceeded.html +0 -346
- data/doc/Contentful/Request.html +0 -887
- data/doc/Contentful/ResourceBuilder.html +0 -978
- data/doc/Contentful/ResourceReferences.html +0 -254
- data/doc/Contentful/Response.html +0 -710
- data/doc/Contentful/RichTextCoercion.html +0 -238
- data/doc/Contentful/ServerError.html +0 -159
- data/doc/Contentful/ServiceUnavailable.html +0 -159
- data/doc/Contentful/Space.html +0 -393
- data/doc/Contentful/StringCoercion.html +0 -242
- data/doc/Contentful/StructuredTextCoercion.html +0 -238
- data/doc/Contentful/Support.html +0 -788
- data/doc/Contentful/SymbolCoercion.html +0 -169
- data/doc/Contentful/Sync.html +0 -653
- data/doc/Contentful/SyncPage.html +0 -807
- data/doc/Contentful/TextCoercion.html +0 -169
- data/doc/Contentful/Unauthorized.html +0 -159
- data/doc/Contentful/UnparsableJson.html +0 -159
- data/doc/Contentful/UnparsableResource.html +0 -135
- data/doc/Contentful.html +0 -157
- data/doc/_index.html +0 -563
- data/doc/class_list.html +0 -51
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -58
- data/doc/css/style.css +0 -496
- data/doc/file.CHANGELOG.html +0 -729
- data/doc/file.LICENSE.html +0 -70
- data/doc/file.README.html +0 -925
- data/doc/file_list.html +0 -66
- data/doc/frames.html +0 -17
- data/doc/index.html +0 -925
- data/doc/js/app.js +0 -292
- data/doc/js/full_list.js +0 -216
- data/doc/js/jquery.js +0 -4
- data/doc/method_list.html +0 -1171
- data/doc/top-level-namespace.html +0 -110
- data/examples/custom_classes.rb +0 -39
- data/examples/example_queries.rb +0 -26
- data/examples/raise_errors.rb +0 -20
- data/examples/raw_mode.rb +0 -14
- data/spec/array_spec.rb +0 -122
- data/spec/asset_spec.rb +0 -192
- data/spec/auto_includes_spec.rb +0 -12
- data/spec/client_class_spec.rb +0 -86
- data/spec/client_configuration_spec.rb +0 -377
- data/spec/content_type_spec.rb +0 -49
- data/spec/deleted_asset_spec.rb +0 -38
- data/spec/deleted_entry_spec.rb +0 -38
- data/spec/entry_spec.rb +0 -688
- data/spec/error_class_spec.rb +0 -327
- data/spec/error_requests_spec.rb +0 -87
- data/spec/field_spec.rb +0 -95
- data/spec/file_spec.rb +0 -33
- data/spec/fixtures/json_responses/400_details_errors_object.json +0 -14
- data/spec/fixtures/json_responses/400_details_errors_string.json +0 -12
- data/spec/fixtures/json_responses/400_details_string.json +0 -8
- data/spec/fixtures/json_responses/403_reasons.json +0 -13
- data/spec/fixtures/json_responses/404_details_string.json +0 -8
- data/spec/fixtures/json_responses/404_id.json +0 -11
- data/spec/fixtures/json_responses/404_sys_type.json +0 -12
- data/spec/fixtures/json_responses/404_type.json +0 -10
- data/spec/fixtures/json_responses/content_type.json +0 -83
- data/spec/fixtures/json_responses/default_400.json +0 -7
- data/spec/fixtures/json_responses/default_401.json +0 -7
- data/spec/fixtures/json_responses/default_403.json +0 -7
- data/spec/fixtures/json_responses/default_404.json +0 -7
- data/spec/fixtures/json_responses/default_429.json +0 -7
- data/spec/fixtures/json_responses/default_500.json +0 -7
- data/spec/fixtures/json_responses/default_502.json +0 -7
- data/spec/fixtures/json_responses/default_503.json +0 -7
- data/spec/fixtures/json_responses/includes.json +0 -111
- data/spec/fixtures/json_responses/link_array.json +0 -43
- data/spec/fixtures/json_responses/not_found.json +0 -13
- data/spec/fixtures/json_responses/nyancat.json +0 -48
- data/spec/fixtures/json_responses/other_error.json +0 -9
- data/spec/fixtures/json_responses/other_error_no_details.json +0 -8
- data/spec/fixtures/json_responses/other_error_no_message.json +0 -8
- data/spec/fixtures/json_responses/other_error_no_request_id.json +0 -8
- data/spec/fixtures/json_responses/other_error_nothing.json +0 -6
- data/spec/fixtures/json_responses/self_link.json +0 -82
- data/spec/fixtures/json_responses/unparsable.json +0 -13
- data/spec/fixtures/vcr_cassettes/array/marshal_custom_classes.yml +0 -159
- data/spec/fixtures/vcr_cassettes/array/nested_resources.yml +0 -159
- data/spec/fixtures/vcr_cassettes/array.yml +0 -288
- data/spec/fixtures/vcr_cassettes/arrayField.yml +0 -87
- data/spec/fixtures/vcr_cassettes/array_page_1.yml +0 -106
- data/spec/fixtures/vcr_cassettes/array_page_2.yml +0 -73
- data/spec/fixtures/vcr_cassettes/asset/select_empty_array.yml +0 -104
- data/spec/fixtures/vcr_cassettes/asset/select_no_sys.yml +0 -119
- data/spec/fixtures/vcr_cassettes/asset/select_one_field.yml +0 -97
- data/spec/fixtures/vcr_cassettes/asset/select_only_sys.yml +0 -88
- data/spec/fixtures/vcr_cassettes/asset.yml +0 -96
- data/spec/fixtures/vcr_cassettes/assets/issues_129.yml +0 -90
- data/spec/fixtures/vcr_cassettes/assets/issues_jekyll_46.yml +0 -115
- data/spec/fixtures/vcr_cassettes/bad_request.yml +0 -76
- data/spec/fixtures/vcr_cassettes/content_type.yml +0 -147
- data/spec/fixtures/vcr_cassettes/entries/empty_fields.yml +0 -246
- data/spec/fixtures/vcr_cassettes/entries/issue_117.yml +0 -201
- data/spec/fixtures/vcr_cassettes/entries/issue_125.yml +0 -198
- data/spec/fixtures/vcr_cassettes/entries/rich_text.yml +0 -1707
- data/spec/fixtures/vcr_cassettes/entries/rich_text_hydration_issue.yml +0 -460
- data/spec/fixtures/vcr_cassettes/entries/rich_text_nested_fields.yml +0 -653
- data/spec/fixtures/vcr_cassettes/entries/rich_text_unresolved_relationships.yml +0 -983
- data/spec/fixtures/vcr_cassettes/entries/unresolvable_filter.yml +0 -159
- data/spec/fixtures/vcr_cassettes/entries/unresolvable_filter_deeply_nested.yml +0 -167
- data/spec/fixtures/vcr_cassettes/entries.yml +0 -561
- data/spec/fixtures/vcr_cassettes/entry/custom_resource.yml +0 -168
- data/spec/fixtures/vcr_cassettes/entry/include_resolution.yml +0 -101
- data/spec/fixtures/vcr_cassettes/entry/include_resolution_uniques.yml +0 -81
- data/spec/fixtures/vcr_cassettes/entry/json_objects.yml +0 -88
- data/spec/fixtures/vcr_cassettes/entry/json_objects_client.yml +0 -86
- data/spec/fixtures/vcr_cassettes/entry/marshal_138.yml +0 -159
- data/spec/fixtures/vcr_cassettes/entry/marshal_unpublished.yml +0 -303
- data/spec/fixtures/vcr_cassettes/entry/marshall.yml +0 -293
- data/spec/fixtures/vcr_cassettes/entry/raw.yml +0 -201
- data/spec/fixtures/vcr_cassettes/entry/search_link_to_asset.yml +0 -81
- data/spec/fixtures/vcr_cassettes/entry/search_link_to_entry.yml +0 -81
- data/spec/fixtures/vcr_cassettes/entry/search_link_to_entry_with_custom_query.yml +0 -115
- data/spec/fixtures/vcr_cassettes/entry/select_empty_array.yml +0 -111
- data/spec/fixtures/vcr_cassettes/entry/select_no_sys.yml +0 -102
- data/spec/fixtures/vcr_cassettes/entry/select_one_field.yml +0 -76
- data/spec/fixtures/vcr_cassettes/entry/select_one_field_proper.yml +0 -114
- data/spec/fixtures/vcr_cassettes/entry/select_only_sys.yml +0 -111
- data/spec/fixtures/vcr_cassettes/entry.yml +0 -102
- data/spec/fixtures/vcr_cassettes/entry_cache.yml +0 -288
- data/spec/fixtures/vcr_cassettes/entry_locales.yml +0 -104
- data/spec/fixtures/vcr_cassettes/field.yml +0 -147
- data/spec/fixtures/vcr_cassettes/human.yml +0 -118
- data/spec/fixtures/vcr_cassettes/linkField.yml +0 -83
- data/spec/fixtures/vcr_cassettes/locale.yml +0 -83
- data/spec/fixtures/vcr_cassettes/locale_from_environment.yml +0 -121
- data/spec/fixtures/vcr_cassettes/location.yml +0 -193
- data/spec/fixtures/vcr_cassettes/multi_locale_array_reference.yml +0 -196
- data/spec/fixtures/vcr_cassettes/multi_locale_reference.yml +0 -214
- data/spec/fixtures/vcr_cassettes/not_found.yml +0 -76
- data/spec/fixtures/vcr_cassettes/nyancat.yml +0 -102
- data/spec/fixtures/vcr_cassettes/ratelimit.yml +0 -64
- data/spec/fixtures/vcr_cassettes/ratelimit_retry.yml +0 -294
- data/spec/fixtures/vcr_cassettes/reloaded_entry.yml +0 -102
- data/spec/fixtures/vcr_cassettes/space.yml +0 -83
- data/spec/fixtures/vcr_cassettes/sync_deleted_asset.yml +0 -174
- data/spec/fixtures/vcr_cassettes/sync_deleted_entry.yml +0 -89
- data/spec/fixtures/vcr_cassettes/sync_deletion.yml +0 -191
- data/spec/fixtures/vcr_cassettes/sync_environment.yml +0 -81
- data/spec/fixtures/vcr_cassettes/sync_page.yml +0 -637
- data/spec/fixtures/vcr_cassettes/sync_page_2.yml +0 -71
- data/spec/fixtures/vcr_cassettes/sync_page_short.yml +0 -106
- data/spec/fixtures/vcr_cassettes/unauthorized.yml +0 -64
- data/spec/fixtures/vcr_cassettes/unavailable.yml +0 -76
- data/spec/link_spec.rb +0 -50
- data/spec/locale_spec.rb +0 -37
- data/spec/location_spec.rb +0 -25
- data/spec/request_spec.rb +0 -57
- data/spec/resource_building_spec.rb +0 -31
- data/spec/response_spec.rb +0 -62
- data/spec/space_spec.rb +0 -31
- data/spec/spec_helper.rb +0 -14
- data/spec/support/client.rb +0 -6
- data/spec/support/json_responses.rb +0 -18
- data/spec/support/vcr.rb +0 -16
- data/spec/sync_page_spec.rb +0 -103
- data/spec/sync_spec.rb +0 -180
data/doc/file.README.html
DELETED
@@ -1,925 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<meta charset="UTF-8">
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
-
<title>
|
7
|
-
File: README
|
8
|
-
|
9
|
-
— Documentation by YARD 0.9.18
|
10
|
-
|
11
|
-
</title>
|
12
|
-
|
13
|
-
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
-
|
15
|
-
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
-
|
17
|
-
<script type="text/javascript" charset="utf-8">
|
18
|
-
pathId = "README";
|
19
|
-
relpath = '';
|
20
|
-
</script>
|
21
|
-
|
22
|
-
|
23
|
-
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
-
|
25
|
-
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
-
|
27
|
-
|
28
|
-
</head>
|
29
|
-
<body>
|
30
|
-
<div class="nav_wrap">
|
31
|
-
<iframe id="nav" src="file_list.html?1"></iframe>
|
32
|
-
<div id="resizer"></div>
|
33
|
-
</div>
|
34
|
-
|
35
|
-
<div id="main" tabindex="-1">
|
36
|
-
<div id="header">
|
37
|
-
<div id="menu">
|
38
|
-
|
39
|
-
<a href="_index.html">Index</a> »
|
40
|
-
<span class="title">File: README</span>
|
41
|
-
|
42
|
-
</div>
|
43
|
-
|
44
|
-
<div id="search">
|
45
|
-
|
46
|
-
<a class="full_list_link" id="class_list_link"
|
47
|
-
href="class_list.html">
|
48
|
-
|
49
|
-
<svg width="24" height="24">
|
50
|
-
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
-
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
-
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
-
</svg>
|
54
|
-
</a>
|
55
|
-
|
56
|
-
</div>
|
57
|
-
<div class="clear"></div>
|
58
|
-
</div>
|
59
|
-
|
60
|
-
<div id="content"><div id='filecontents'>
|
61
|
-
<p><img src="./.github/header.png"> <p align=“center”> <a href=“<a
|
62
|
-
href="https://www.contentful.com/slack">www.contentful.com/slack</a>/”>
|
63
|
-
<img src=“<a
|
64
|
-
href="https://img.shields.io/badge/-Join%20Community%20Slack-2AB27B.svg?logo=slack&maxAge=31557600">img.shields.io/badge/-Join%20Community%20Slack-2AB27B.svg?logo=slack&maxAge=31557600</a>”
|
65
|
-
alt=“Join Contentful Community Slack”> </a> <a href=“<a
|
66
|
-
href="https://www.contentfulcommunity.com">www.contentfulcommunity.com</a>/”>
|
67
|
-
<img src=“<a
|
68
|
-
href="https://img.shields.io/badge/-Join%20Community%20Forum-3AB2E6.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MiA1OSI+CiAgPHBhdGggZmlsbD0iI0Y4RTQxOCIgZD0iTTE4IDQxYTE2IDE2IDAgMCAxIDAtMjMgNiA2IDAgMCAwLTktOSAyOSAyOSAwIDAgMCAwIDQxIDYgNiAwIDEgMCA5LTkiIG1hc2s9InVybCgjYikiLz4KICA8cGF0aCBmaWxsPSIjNTZBRUQyIiBkPSJNMTggMThhMTYgMTYgMCAwIDEgMjMgMCA2IDYgMCAxIDAgOS05QTI5IDI5IDAgMCAwIDkgOWE2IDYgMCAwIDAgOSA5Ii8+CiAgPHBhdGggZmlsbD0iI0UwNTM0RSIgZD0iTTQxIDQxYTE2IDE2IDAgMCAxLTIzIDAgNiA2IDAgMSAwLTkgOSAyOSAyOSAwIDAgMCA0MSAwIDYgNiAwIDAgMC05LTkiLz4KICA8cGF0aCBmaWxsPSIjMUQ3OEE0IiBkPSJNMTggMThhNiA2IDAgMSAxLTktOSA2IDYgMCAwIDEgOSA5Ii8+CiAgPHBhdGggZmlsbD0iI0JFNDMzQiIgZD0iTTE4IDUwYTYgNiAwIDEgMS05LTkgNiA2IDAgMCAxIDkgOSIvPgo8L3N2Zz4K&maxAge=31557600">img.shields.io/badge/-Join%20Community%20Forum-3AB2E6.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MiA1OSI+CiAgPHBhdGggZmlsbD0iI0Y4RTQxOCIgZD0iTTE4IDQxYTE2IDE2IDAgMCAxIDAtMjMgNiA2IDAgMCAwLTktOSAyOSAyOSAwIDAgMCAwIDQxIDYgNiAwIDEgMCA5LTkiIG1hc2s9InVybCgjYikiLz4KICA8cGF0aCBmaWxsPSIjNTZBRUQyIiBkPSJNMTggMThhMTYgMTYgMCAwIDEgMjMgMCA2IDYgMCAxIDAgOS05QTI5IDI5IDAgMCAwIDkgOWE2IDYgMCAwIDAgOSA5Ii8+CiAgPHBhdGggZmlsbD0iI0UwNTM0RSIgZD0iTTQxIDQxYTE2IDE2IDAgMCAxLTIzIDAgNiA2IDAgMSAwLTkgOSAyOSAyOSAwIDAgMCA0MSAwIDYgNiAwIDAgMC05LTkiLz4KICA8cGF0aCBmaWxsPSIjMUQ3OEE0IiBkPSJNMTggMThhNiA2IDAgMSAxLTktOSA2IDYgMCAwIDEgOSA5Ii8+CiAgPHBhdGggZmlsbD0iI0JFNDMzQiIgZD0iTTE4IDUwYTYgNiAwIDEgMS05LTkgNiA2IDAgMCAxIDkgOSIvPgo8L3N2Zz4K&maxAge=31557600</a>”
|
69
|
-
alt=“Join Contentful Community Forum”> </a> </p></p>
|
70
|
-
|
71
|
-
<h1 id="label-contentful.rb+-+Contentful+Ruby+Delivery+SDK">contentful.rb - Contentful Ruby Delivery SDK</h1>
|
72
|
-
|
73
|
-
<p><a href="http://badge.fury.io/rb/contentful"><img
|
74
|
-
src="https://badge.fury.io/rb/contentful.png"></a></p>
|
75
|
-
|
76
|
-
<blockquote>
|
77
|
-
<p>Ruby SDK for the Contentful <a
|
78
|
-
href="https://www.contentful.com/developers/docs/references/content-delivery-api/">Content
|
79
|
-
Delivery API</a> and <a
|
80
|
-
href="https://www.contentful.com/developers/docs/references/content-preview-api/">Content
|
81
|
-
Preview API</a>. It helps you to easily access your Content stored in
|
82
|
-
Contentful with your Ruby applications.</p>
|
83
|
-
</blockquote>
|
84
|
-
<p align="center">
|
85
|
-
<img src="https://img.shields.io/badge/Status-Maintained-green.svg" alt="This repository is actively maintained" />
|
86
|
-
<a href="LICENSE.txt">
|
87
|
-
<img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License" />
|
88
|
-
</a>
|
89
|
-
|
90
|
-
<a href="https://travis-ci.org/contentful/contentful.rb">
|
91
|
-
<img src="https://travis-ci.org/contentful/contentful.rb.svg?branch=master" alt="Build Status">
|
92
|
-
</a>
|
93
|
-
</p><p align="center">
|
94
|
-
<a href="https://rubygems.org/gems/contentful">
|
95
|
-
<img src="https://img.shields.io/gem/v/contentful.svg" alt="RubyGems version">
|
96
|
-
</a>
|
97
|
-
|
98
|
-
<a href="https://rubygems.org/gems/contentful">
|
99
|
-
<img src="https://img.shields.io/gem/dt/contentful.svg" alt="RubyGems downloads">
|
100
|
-
</a>
|
101
|
-
</p>
|
102
|
-
<p><strong>What is Contentful?</strong></p>
|
103
|
-
|
104
|
-
<p><a href="https://www.contentful.com/">Contentful</a> provides content
|
105
|
-
infrastructure for digital teams to power websites, apps, and devices.
|
106
|
-
Unlike a CMS, Contentful was built to integrate with the modern software
|
107
|
-
stack. It offers a central hub for structured content, powerful management
|
108
|
-
and delivery APIs, and a customizable web app that enable developers and
|
109
|
-
content creators to ship their products faster.</p>
|
110
|
-
|
111
|
-
<p><details> <summary>Table of contents</summary></p>
|
112
|
-
<!-- TOC --><ul><li>
|
113
|
-
<p><a href="#contentfulrb---contentful-ruby-delivery-sdk">contentful.rb -
|
114
|
-
Contentful Ruby Delivery SDK</a></p>
|
115
|
-
</li><li>
|
116
|
-
<p><a href="#core-features">Core Features</a></p>
|
117
|
-
</li><li>
|
118
|
-
<p><a href="#getting-started">Getting started</a></p>
|
119
|
-
<ul><li>
|
120
|
-
<p><a href="#installation">Installation</a></p>
|
121
|
-
</li><li>
|
122
|
-
<p><a href="#your-first-request">Your first request</a></p>
|
123
|
-
</li><li>
|
124
|
-
<p><a href="#using-this-sdk-with-the-preview-api">Using this SDK with the
|
125
|
-
Preview API</a></p>
|
126
|
-
</li><li>
|
127
|
-
<p><a href="#authentication">Authentication</a></p>
|
128
|
-
</li></ul>
|
129
|
-
</li><li>
|
130
|
-
<p><a href="#documentation--references">Documentation & References</a></p>
|
131
|
-
<ul><li>
|
132
|
-
<p><a href="#configuration">Configuration</a></p>
|
133
|
-
</li><li>
|
134
|
-
<p><a href="#reference-documentation">Reference documentation</a></p>
|
135
|
-
</li><li>
|
136
|
-
<p><a href="#basic-queries">Basic queries</a></p>
|
137
|
-
</li><li>
|
138
|
-
<p><a href="#filtering-options">Filtering options</a></p>
|
139
|
-
</li><li>
|
140
|
-
<p><a href="#accessing-fields-and-sys-properties">Accessing fields and sys
|
141
|
-
properties</a></p>
|
142
|
-
</li><li>
|
143
|
-
<p><a href="#dynamic-entries">Dynamic entries</a></p>
|
144
|
-
</li><li>
|
145
|
-
<p><a href="#using-different-locales">Using different locales</a></p>
|
146
|
-
</li><li>
|
147
|
-
<p><a href="#arrays">Arrays</a></p>
|
148
|
-
</li><li>
|
149
|
-
<p><a href="#links">Links</a></p>
|
150
|
-
</li><li>
|
151
|
-
<p><a href="#assets">Assets</a></p>
|
152
|
-
</li><li>
|
153
|
-
<p><a href="#resource-options">Resource options</a></p>
|
154
|
-
</li><li>
|
155
|
-
<p><a href="#field-type-object">Field type Object</a></p>
|
156
|
-
</li><li>
|
157
|
-
<p><a href="#advanced-concepts">Advanced concepts</a></p>
|
158
|
-
</li><li>
|
159
|
-
<p><a href="#proxy-example">Proxy example</a></p>
|
160
|
-
</li><li>
|
161
|
-
<p><a href="#custom-resource-classes">Custom resource classes</a></p>
|
162
|
-
</li><li>
|
163
|
-
<p><a href="#synchronization">Synchronization</a></p>
|
164
|
-
</li><li>
|
165
|
-
<p><a href="#migrating-to-2x">Migrating to 2.x</a></p>
|
166
|
-
</li><li>
|
167
|
-
<p><a href="#tutorials--other-resources">Tutorials & other resources</a></p>
|
168
|
-
</li></ul>
|
169
|
-
</li><li>
|
170
|
-
<p><a href="#reach-out-to-us">Reach out to us</a></p>
|
171
|
-
<ul><li>
|
172
|
-
<p><a href="#you-have-questions-about-how-to-use-this-library">You have
|
173
|
-
questions about how to use this library?</a></p>
|
174
|
-
</li><li>
|
175
|
-
<p><a href="#you-found-a-bug-or-want-to-propose-a-feature">You found a bug or
|
176
|
-
want to propose a feature?</a></p>
|
177
|
-
</li><li>
|
178
|
-
<p><a
|
179
|
-
href="#you-need-to-share-confidential-information-or-have-other-questions">You
|
180
|
-
need to share confidential information or have other questions?</a></p>
|
181
|
-
</li></ul>
|
182
|
-
</li><li>
|
183
|
-
<p><a href="#get-involved">Get involved</a></p>
|
184
|
-
</li><li>
|
185
|
-
<p><a href="#license">License</a></p>
|
186
|
-
</li><li>
|
187
|
-
<p><a href="#code-of-conduct">Code of Conduct</a></p>
|
188
|
-
</li></ul>
|
189
|
-
<!-- /TOC -->
|
190
|
-
<p></details></p>
|
191
|
-
|
192
|
-
<h2 id="label-Core+Features">Core Features</h2>
|
193
|
-
<ul><li>
|
194
|
-
<p>Content retrieval through <a
|
195
|
-
href="https://www.contentful.com/developers/docs/references/content-delivery-api/">Content
|
196
|
-
Delivery API</a> and <a
|
197
|
-
href="https://www.contentful.com/developers/docs/references/content-preview-api/">Content
|
198
|
-
Preview API</a>.</p>
|
199
|
-
</li><li>
|
200
|
-
<p><a
|
201
|
-
href="https://www.contentful.com/developers/docs/concepts/sync/">Synchronization</a></p>
|
202
|
-
</li><li>
|
203
|
-
<p><a
|
204
|
-
href="https://www.contentful.com/developers/docs/concepts/locales/">Localization
|
205
|
-
support</a></p>
|
206
|
-
</li><li>
|
207
|
-
<p><a href="https://www.contentful.com/developers/docs/concepts/links/">Link
|
208
|
-
resolution</a></p>
|
209
|
-
</li><li>
|
210
|
-
<p>Built in rate limiting recovery procedures</p>
|
211
|
-
</li><li>
|
212
|
-
<p>Supports <a
|
213
|
-
href="https://www.contentful.com/developers/docs/concepts/multiple-environments/">Environments</a>
|
214
|
-
(<strong>since v2.6.0 - 16. April 2018</strong>)</p>
|
215
|
-
</li></ul>
|
216
|
-
|
217
|
-
<h2 id="label-Getting+started">Getting started</h2>
|
218
|
-
|
219
|
-
<p>In order to get started with the Contentful Ruby SDK you'll need not
|
220
|
-
only to install it, but also to get credentials which will allow you to
|
221
|
-
have access to your content in Contentful.</p>
|
222
|
-
<ul><li>
|
223
|
-
<p><a href="#installation">Installation</a></p>
|
224
|
-
</li><li>
|
225
|
-
<p><a href="#your-first-request">Your first request</a></p>
|
226
|
-
</li><li>
|
227
|
-
<p><a href="#using-this-sdk-with-the-preview-api">Using this SDK with the
|
228
|
-
Preview API</a></p>
|
229
|
-
</li><li>
|
230
|
-
<p><a href="#authentication">Authentication</a></p>
|
231
|
-
</li><li>
|
232
|
-
<p><a href="#documentation--references">Documentation & References</a></p>
|
233
|
-
</li></ul>
|
234
|
-
|
235
|
-
<h3 id="label-Installation">Installation</h3>
|
236
|
-
|
237
|
-
<p>Add to your Gemfile and bundle:</p>
|
238
|
-
|
239
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>contentful</span><span class='tstring_end'>'</span></span>
|
240
|
-
</code></pre>
|
241
|
-
|
242
|
-
<p>Or install it directly from your console:</p>
|
243
|
-
|
244
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='id identifier rubyid_i'>i</span> <span class='id identifier rubyid_contentful'>contentful</span>
|
245
|
-
</code></pre>
|
246
|
-
|
247
|
-
<h3 id="label-Your+first+request">Your first request</h3>
|
248
|
-
|
249
|
-
<p>The following code snippet is the most basic one you can use to get some
|
250
|
-
content from Contentful with this SDK:</p>
|
251
|
-
|
252
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>contentful</span><span class='tstring_end'>'</span></span>
|
253
|
-
|
254
|
-
<span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Contentful.html" title="Contentful (module)">Contentful</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Contentful/Client.html" title="Contentful::Client (class)">Client</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Contentful/Client.html#initialize-instance_method" title="Contentful::Client#initialize (method)">new</a></span></span><span class='lparen'>(</span>
|
255
|
-
<span class='label'>space:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cfexampleapi</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='comment'># This is the space ID. A space is like a project folder in Contentful terms
|
256
|
-
</span> <span class='label'>access_token:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>b4c0n73n7fu1</span><span class='tstring_end'>'</span></span> <span class='comment'># This is the access token for this space. Normally you get both ID and the token in the Contentful web app
|
257
|
-
</span><span class='rparen'>)</span>
|
258
|
-
|
259
|
-
<span class='comment'># This API call will request an entry with the specified ID from the space defined at the top, using a space-specific access token.
|
260
|
-
</span><span class='id identifier rubyid_entry'>entry</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_entry'>entry</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>nyancat</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
261
|
-
</code></pre>
|
262
|
-
|
263
|
-
<h3 id="label-Using+this+SDK+with+the+Preview+API">Using this SDK with the Preview API</h3>
|
264
|
-
|
265
|
-
<p>This SDK can also be used with the Preview API. In order to do so, you need
|
266
|
-
to use the Preview API Access token, available on the same page where you
|
267
|
-
get the Delivery API token, and specify the host of the preview API, such
|
268
|
-
as:</p>
|
269
|
-
|
270
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>contentful</span><span class='tstring_end'>'</span></span>
|
271
|
-
|
272
|
-
<span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Contentful.html" title="Contentful (module)">Contentful</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Contentful/Client.html" title="Contentful::Client (class)">Client</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Contentful/Client.html#initialize-instance_method" title="Contentful::Client#initialize (method)">new</a></span></span><span class='lparen'>(</span>
|
273
|
-
<span class='label'>space:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cfexampleapi</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
274
|
-
<span class='label'>access_token:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>b4c0n73n7fu1</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
275
|
-
<span class='label'>api_url:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>preview.contentful.com</span><span class='tstring_end'>'</span></span>
|
276
|
-
<span class='rparen'>)</span>
|
277
|
-
</code></pre>
|
278
|
-
|
279
|
-
<p>You can query for entries, assets, etc. very similar as described in the <a
|
280
|
-
href="https://www.contentful.com/developers/docs/references/content-delivery-api/">Delivery
|
281
|
-
API Documentation</a>. Please note, that <strong>all methods of the Ruby
|
282
|
-
client library are snake_cased, instead of JavaScript's
|
283
|
-
camelCase</strong>:</p>
|
284
|
-
|
285
|
-
<h3 id="label-Authentication">Authentication</h3>
|
286
|
-
|
287
|
-
<p>To get your own content from Contentful, an app should authenticate with an
|
288
|
-
OAuth bearer token.</p>
|
289
|
-
|
290
|
-
<p>You can create API keys using the <a
|
291
|
-
href="https://app.contentful.com">Contentful web interface</a>. Go to the
|
292
|
-
app, open the space that you want to access (top left corner lists all the
|
293
|
-
spaces), and navigate to the APIs area. Open the API Keys section and
|
294
|
-
create your first token. Done.</p>
|
295
|
-
|
296
|
-
<p>Don't forget to also get your Space ID.</p>
|
297
|
-
|
298
|
-
<p>For more information, check the <a
|
299
|
-
href="https://www.contentful.com/developers/docs/references/authentication/">Contentful
|
300
|
-
REST API reference on Authentication</a>.</p>
|
301
|
-
|
302
|
-
<h2 id="label-Documentation+-26+References">Documentation & References</h2>
|
303
|
-
<ul><li>
|
304
|
-
<p><a href="#configuration">Configuration</a></p>
|
305
|
-
</li><li>
|
306
|
-
<p><a href="#reference-documentation">Reference documentation</a></p>
|
307
|
-
</li><li>
|
308
|
-
<p><a href="#tutorials--other-resources">Tutorials & other resources</a></p>
|
309
|
-
</li><li>
|
310
|
-
<p><a href="#advanced-concepts">Advanced Concepts</a></p>
|
311
|
-
</li><li>
|
312
|
-
<p><a href="#migrating-to-2x">Migrating to 2.x</a></p>
|
313
|
-
</li></ul>
|
314
|
-
|
315
|
-
<p>To help you get the most out of this SDK, we've prepared all available
|
316
|
-
client configuration options, reference documentation, tutorials and other
|
317
|
-
examples that will help you learn and understand how to use this library.</p>
|
318
|
-
|
319
|
-
<h3 id="label-Configuration">Configuration</h3>
|
320
|
-
|
321
|
-
<p>The client constructor supports several options you may set to achieve the
|
322
|
-
expected behavior:</p>
|
323
|
-
|
324
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Contentful.html" title="Contentful (module)">Contentful</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Contentful/Client.html" title="Contentful::Client (class)">Client</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Contentful/Client.html#initialize-instance_method" title="Contentful::Client#initialize (method)">new</a></span></span><span class='lparen'>(</span>
|
325
|
-
<span class='comment'># ... your options here ...
|
326
|
-
</span><span class='rparen'>)</span>
|
327
|
-
</code></pre>
|
328
|
-
<table>
|
329
|
-
<thead>
|
330
|
-
<tr>
|
331
|
-
<th>Name</th>
|
332
|
-
<th>Default</th>
|
333
|
-
<th>Description</th>
|
334
|
-
</tr>
|
335
|
-
</thead>
|
336
|
-
<tbody>
|
337
|
-
<tr>
|
338
|
-
<td><code>access_token</code></td>
|
339
|
-
<td></td>
|
340
|
-
<td><strong>Required</strong>. Your access token.</td>
|
341
|
-
</tr>
|
342
|
-
<tr>
|
343
|
-
<td><code>space</code></td>
|
344
|
-
<td></td>
|
345
|
-
<td><strong>Required</strong>. Your space ID.</td>
|
346
|
-
</tr>
|
347
|
-
<tr>
|
348
|
-
<td><code>environment</code></td>
|
349
|
-
<td>'master'</td>
|
350
|
-
<td>Your environment ID.</td>
|
351
|
-
</tr>
|
352
|
-
<tr>
|
353
|
-
<td><code>api_url</code></td>
|
354
|
-
<td><code>'cdn.contentful.com'</code></td>
|
355
|
-
<td>Set the host used to build the request URIs.</td>
|
356
|
-
</tr>
|
357
|
-
<tr>
|
358
|
-
<td><code>default_locale</code></td>
|
359
|
-
<td><code>'en-US'</code></td>
|
360
|
-
<td>Defines default locale for the client.</td>
|
361
|
-
</tr>
|
362
|
-
<tr>
|
363
|
-
<td><code>secure</code></td>
|
364
|
-
<td><code>true</code></td>
|
365
|
-
<td>Defines whether to use HTTPS or HTTP. By default we use HTTPS.</td>
|
366
|
-
</tr>
|
367
|
-
<tr>
|
368
|
-
<td><code>authentication_mechanism</code></td>
|
369
|
-
<td><code>:header</code></td>
|
370
|
-
<td>Sets the authentication mechanisms, valid options are <code>:header</code> or <code>:query_string</code></td>
|
371
|
-
</tr>
|
372
|
-
<tr>
|
373
|
-
<td><code>raise_errors</code></td>
|
374
|
-
<td><code>true</code></td>
|
375
|
-
<td>Determines whether errors are raised or returned.</td>
|
376
|
-
</tr>
|
377
|
-
<tr>
|
378
|
-
<td><code>raise_for_empty_fields</code></td>
|
379
|
-
<td><code>true</code></td>
|
380
|
-
<td>Determines whether <code>EmptyFieldError</code> is raised when empty fields are requested on an entry or <code>nil</code> is returned.</td>
|
381
|
-
</tr>
|
382
|
-
<tr>
|
383
|
-
<td><code>dynamic_entries</code></td>
|
384
|
-
<td><code>:manual</code></td>
|
385
|
-
<td>
|
386
|
-
Determines if content type caching is enabled automatically or not,
|
387
|
-
allowing for accessing of fields even when they are not present on the response.
|
388
|
-
Valid options are <code>:auto</code> and <code>:manual</code>.
|
389
|
-
</td>
|
390
|
-
</tr>
|
391
|
-
<tr>
|
392
|
-
<td><code>raw_mode</code></td>
|
393
|
-
<td><code>false</code></td>
|
394
|
-
<td>If enabled, API responses are not parsed and the raw response object is returned instead.</td>
|
395
|
-
</tr>
|
396
|
-
<tr>
|
397
|
-
<td><code>resource_mapping</code></td>
|
398
|
-
<td><code>{}</code></td>
|
399
|
-
<td>Allows for overriding default resource classes with custom ones.</td>
|
400
|
-
</tr>
|
401
|
-
<tr>
|
402
|
-
<td><code>entry_mapping</code></td>
|
403
|
-
<td><code>{}</code></td>
|
404
|
-
<td>Allows for overriding of specific entry classes by content type.</td>
|
405
|
-
</tr>
|
406
|
-
<tr>
|
407
|
-
<td><code>gzip_encoded</code></td>
|
408
|
-
<td><code>true</code></td>
|
409
|
-
<td>Enables gzip response content encoding.</td>
|
410
|
-
</tr>
|
411
|
-
<tr>
|
412
|
-
<td><code>max_rate_limit_retries</code></td>
|
413
|
-
<td><code>1</code></td>
|
414
|
-
<td>
|
415
|
-
To increase or decrease the retry attempts after a 429 Rate Limit error. Default value is 1. Using 0 will disable retry behaviour.
|
416
|
-
Each retry will be attempted after the value (in seconds) of the <code>X-Contentful-RateLimit-Reset</code> header,
|
417
|
-
which contains the amount of seconds until the next non rate limited request is available, has passed.
|
418
|
-
This is blocking per execution thread.
|
419
|
-
</td>
|
420
|
-
</tr>
|
421
|
-
<tr>
|
422
|
-
<td><code>max_rate_limit_wait</code></td>
|
423
|
-
<td><code>60</code></td>
|
424
|
-
<td>
|
425
|
-
Maximum time to wait for next available request (in seconds). Default value is 60 seconds.
|
426
|
-
Keep in mind that if you hit the hourly rate limit maximum, you can have up to 60 minutes of blocked requests.
|
427
|
-
It is set to a default of 60 seconds in order to avoid blocking processes for too long, as rate limit retry behaviour
|
428
|
-
is blocking per execution thread.
|
429
|
-
</td>
|
430
|
-
</tr>
|
431
|
-
<tr>
|
432
|
-
<td><code>max_include_resolution_depth</code></td>
|
433
|
-
<td><code>20</code></td>
|
434
|
-
<td>
|
435
|
-
Maximum amount of levels to resolve includes for SDK entities
|
436
|
-
(this is independent of API-level includes - it represents the maximum depth the include resolution
|
437
|
-
tree is allowed to resolved before falling back to <code>Link</code> objects).
|
438
|
-
This include resolution strategy is in place in order to avoid having infinite circular recursion on resources with circular dependencies.
|
439
|
-
<strong>Note</strong>: If you're using something like <code>Rails::cache</code> it's advisable to considerably lower this value
|
440
|
-
(around 5 has proven to be a good compromise - but keep it higher or equal than your maximum API-level include parameter if you need the entire tree resolution).
|
441
|
-
Note that when <code>reuse_entries</code> is enabled, the max include resolution depth only affects
|
442
|
-
deep chains of unique objects (ie, not simple circular references).
|
443
|
-
</td>
|
444
|
-
</tr>
|
445
|
-
<tr>
|
446
|
-
<td><code>reuse_entries</code></td>
|
447
|
-
<td><code>false</code></td>
|
448
|
-
<td>
|
449
|
-
When enabled, reuse hydrated Entry and Asset objects within the same request when possible.
|
450
|
-
Can result in a large speed increase and better handles cyclical object graphs.
|
451
|
-
This can be a good alternative to <code>max_include_resolution_depth</code> if your content model contains (or can contain) circular references.
|
452
|
-
<strong>Caching may break if this option is enabled, as it may generate stack errors.</strong>
|
453
|
-
When caching, deactivate this option and opt for a conservative <code>max_include_resolution_depth</code> value.
|
454
|
-
</td>
|
455
|
-
</tr>
|
456
|
-
<tr>
|
457
|
-
<td><code>use_camel_case</code></td>
|
458
|
-
<td><code>false</code></td>
|
459
|
-
<td>
|
460
|
-
When doing the v2 upgrade, all keys and accessors were changed to always use <code>snake_case</code>.
|
461
|
-
This option introduces the ability to use <code>camelCase</code> for keys and method accessors.
|
462
|
-
This is very useful for isomorphic applications.
|
463
|
-
</td>
|
464
|
-
</tr>
|
465
|
-
<tr>
|
466
|
-
<td><code>proxy_host</code></td>
|
467
|
-
<td><code>nil</code></td>
|
468
|
-
<td>To be able to perform a request behind a proxy, this needs to be set. It can be a domain or IP address of the proxy server.</td>
|
469
|
-
</tr>
|
470
|
-
<tr>
|
471
|
-
<td><code>proxy_port</code></td>
|
472
|
-
<td><code>nil</code></td>
|
473
|
-
<td>Specify the port number that is used by the proxy server for client connections.</td>
|
474
|
-
</tr>
|
475
|
-
<tr>
|
476
|
-
<td><code>proxy_username</code></td>
|
477
|
-
<td><code>nil</code></td>
|
478
|
-
<td>Username for proxy authentication.</td>
|
479
|
-
</tr>
|
480
|
-
<tr>
|
481
|
-
<td><code>proxy_password</code></td>
|
482
|
-
<td><code>nil</code></td>
|
483
|
-
<td>Password for proxy authentication.</td>
|
484
|
-
</tr>
|
485
|
-
<tr>
|
486
|
-
<td><code>timeout_read</code></td>
|
487
|
-
<td><code>nil</code></td>
|
488
|
-
<td>Number of seconds the request waits to read from the server before timing out.</td>
|
489
|
-
</tr>
|
490
|
-
<tr>
|
491
|
-
<td><code>timeout_write</code></td>
|
492
|
-
<td><code>nil</code></td>
|
493
|
-
<td>Number of seconds the request waits when writing to the server before timing out.</td>
|
494
|
-
</tr>
|
495
|
-
<tr>
|
496
|
-
<td><code>timeout_connect</code></td>
|
497
|
-
<td><code>nil</code></td>
|
498
|
-
<td>Number of seconds the request waits to connect to the server before timing out.</td>
|
499
|
-
</tr>
|
500
|
-
<tr>
|
501
|
-
<td><code>logger</code></td>
|
502
|
-
<td><code>nil</code></td>
|
503
|
-
<td>To enable logging pass a logger instance compatible with <code>::Logger</code>.</td>
|
504
|
-
</tr>
|
505
|
-
<tr>
|
506
|
-
<td><code>log_level</code></td>
|
507
|
-
<td><code>::Logger::INFO</code></td>
|
508
|
-
<td>
|
509
|
-
The default severity is set to INFO and logs only the request attributes (headers, parameters and url).
|
510
|
-
Setting it to DEBUG will also log the raw JSON response.
|
511
|
-
</td>
|
512
|
-
</tr>
|
513
|
-
</tbody>
|
514
|
-
</table>
|
515
|
-
<h3 id="label-Reference+documentation">Reference documentation</h3>
|
516
|
-
|
517
|
-
<h4 id="label-Basic+queries">Basic queries</h4>
|
518
|
-
|
519
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_content_types'>content_types</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_content_types'>content_types</span>
|
520
|
-
<span class='id identifier rubyid_cat_content_type'>cat_content_type</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_content_type'>content_type</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cat</span><span class='tstring_end'>'</span></span>
|
521
|
-
<span class='id identifier rubyid_nyancat'>nyancat</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_entry'>entry</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>nyancat</span><span class='tstring_end'>'</span></span>
|
522
|
-
<span class='id identifier rubyid_entries'>entries</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_entries'>entries</span>
|
523
|
-
<span class='id identifier rubyid_assets'>assets</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_assets'>assets</span>
|
524
|
-
<span class='id identifier rubyid_nyancat_asset'>nyancat_asset</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_asset'>asset</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>nyancat</span><span class='tstring_end'>'</span></span>
|
525
|
-
</code></pre>
|
526
|
-
|
527
|
-
<h4 id="label-Filtering+options">Filtering options</h4>
|
528
|
-
|
529
|
-
<p>You can pass the usual filter options to the query:</p>
|
530
|
-
|
531
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_entries'>entries</span><span class='lparen'>(</span><span class='label'>content_type:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cat</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># query for a content-type by its ID (not name)
|
532
|
-
</span><span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_entries'>entries</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>sys.id[ne]</span><span class='tstring_end'>'</span></span> <span class='op'>=></span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>nyancat</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># query for all entries except 'nyancat'
|
533
|
-
</span><span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_entries'>entries</span><span class='lparen'>(</span><span class='label'>include:</span> <span class='int'>1</span><span class='rparen'>)</span> <span class='comment'># include one level of linked resources
|
534
|
-
</span><span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_entries'>entries</span><span class='lparen'>(</span><span class='label'>content_type:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cat</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>include:</span> <span class='int'>1</span><span class='rparen'>)</span> <span class='comment'># you can also combine multiple parameters
|
535
|
-
</span></code></pre>
|
536
|
-
|
537
|
-
<p>To read more about filtering options you can check our <a
|
538
|
-
href="https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters">search
|
539
|
-
parameters documentation</a>.</p>
|
540
|
-
|
541
|
-
<p>The results are returned as <code>Contentful::BaseResource</code> objects.
|
542
|
-
Multiple results will be returned as <code>Contentful::Array</code>. The
|
543
|
-
properties of a resource can be accessed through Ruby methods.</p>
|
544
|
-
|
545
|
-
<h4 id="label-Accessing+fields+and+sys+properties">Accessing fields and sys properties</h4>
|
546
|
-
|
547
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_content_type'>content_type</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_content_type'>content_type</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cat</span><span class='tstring_end'>'</span></span>
|
548
|
-
<span class='id identifier rubyid_content_type'>content_type</span><span class='period'>.</span><span class='id identifier rubyid_description'>description</span> <span class='comment'># "Meow."
|
549
|
-
</span></code></pre>
|
550
|
-
|
551
|
-
<p>System Properties behave the same and can be accessed via the
|
552
|
-
<code>#sys</code> method.</p>
|
553
|
-
|
554
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_content_type'>content_type</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span> <span class='comment'># => 'cat'
|
555
|
-
</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_type'>type</span> <span class='comment'># => 'Entry'
|
556
|
-
</span><span class='id identifier rubyid_asset'>asset</span><span class='period'>.</span><span class='id identifier rubyid_sys'>sys</span> <span class='comment'># { id: '...', type: '...' }
|
557
|
-
</span></code></pre>
|
558
|
-
|
559
|
-
<p>Entry fields also have direct accessors and will be coerced to the type
|
560
|
-
defined in it's content type. However, if using <code>dynamic_entries:
|
561
|
-
:manual</code>, coercion will not be done.</p>
|
562
|
-
|
563
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_entry'>entry</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_entry'>entry</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>nyancat</span><span class='tstring_end'>'</span></span>
|
564
|
-
<span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_fields'>fields</span><span class='lbracket'>[</span><span class='symbol'>:color</span><span class='rbracket'>]</span> <span class='comment'># 'rainbow'
|
565
|
-
</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_color'>color</span> <span class='comment'># 'rainbow'
|
566
|
-
</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_birthday'>birthday</span> <span class='comment'># #<DateTime: 2011-04-04T22:00:00+00:00 ((2455656j,79200s,0n),+0s,2299161j)>
|
567
|
-
</span></code></pre>
|
568
|
-
|
569
|
-
<h4 id="label-Dynamic+entries">Dynamic entries</h4>
|
570
|
-
|
571
|
-
<p>However, you can (and should) set <code>:dynamic_entries</code> to
|
572
|
-
<code>:auto</code> in your client configuration. When using this option,
|
573
|
-
the client will cache all available content types and use them to hydrate
|
574
|
-
entries when fields are missing in the response and coerce fields to their
|
575
|
-
proper types.</p>
|
576
|
-
|
577
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Contentful.html" title="Contentful (module)">Contentful</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Contentful/Client.html" title="Contentful::Client (class)">Client</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Contentful/Client.html#initialize-instance_method" title="Contentful::Client#initialize (method)">new</a></span></span><span class='lparen'>(</span>
|
578
|
-
<span class='label'>access_token:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>b4c0n73n7fu1</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
579
|
-
<span class='label'>space:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cfexampleapi</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
580
|
-
<span class='label'>dynamic_entries:</span> <span class='symbol'>:auto</span>
|
581
|
-
<span class='rparen'>)</span>
|
582
|
-
|
583
|
-
<span class='id identifier rubyid_entry'>entry</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_entry'>entry</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>nyancat</span><span class='tstring_end'>'</span></span> <span class='comment'># => #<Contentful::Entry[cat]: ...>
|
584
|
-
</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_color'>color</span> <span class='comment'># => 'rainbow'
|
585
|
-
</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_birthday'>birthday</span> <span class='comment'># #<DateTime: 2011-04-04T22:00:00+00:00 ((2455656j,79200s,0n),+0s,2299161j)>
|
586
|
-
</span></code></pre>
|
587
|
-
|
588
|
-
<p>Dynamic entries will have getter classes for the fields and do type
|
589
|
-
conversions properly.</p>
|
590
|
-
|
591
|
-
<p>The <code>:auto</code> mode will fetch all content types on initialization.
|
592
|
-
If you want to do it by hand later, you will need to set the option to
|
593
|
-
<code>:manual</code> and call
|
594
|
-
<code>client.update_dynamic_entry_cache!</code> to initialize the cache.</p>
|
595
|
-
|
596
|
-
<h4 id="label-Using+different+locales">Using different locales</h4>
|
597
|
-
|
598
|
-
<p>Entries can have multiple locales, by default, the client only fetches the
|
599
|
-
entry with only its default locale. If you want to fetch a different locale
|
600
|
-
you can do the following:</p>
|
601
|
-
|
602
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_entries'>entries</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_entries'>entries</span><span class='lparen'>(</span><span class='label'>locale:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>de-DE</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
603
|
-
</code></pre>
|
604
|
-
|
605
|
-
<p>Then all the fields will be fetched for the requested locale.</p>
|
606
|
-
|
607
|
-
<p>Contentful Delivery API also allows to fetch all locales, you can do so by
|
608
|
-
doing:</p>
|
609
|
-
|
610
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_entries'>entries</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_entries'>entries</span><span class='lparen'>(</span><span class='label'>content_type:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cat</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>locale:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>*</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
611
|
-
|
612
|
-
<span class='comment'># assuming the entry has a field called name
|
613
|
-
</span><span class='id identifier rubyid_my_spanish_name'>my_spanish_name</span> <span class='op'>=</span> <span class='id identifier rubyid_entries'>entries</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_fields'>fields</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>es-AR</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='lbracket'>[</span><span class='symbol'>:name</span><span class='rbracket'>]</span>
|
614
|
-
</code></pre>
|
615
|
-
|
616
|
-
<p>When requesting multiple locales, the object accessor shortcuts only work
|
617
|
-
for the default locale.</p>
|
618
|
-
|
619
|
-
<h4 id="label-Arrays">Arrays</h4>
|
620
|
-
|
621
|
-
<p>Contentful::Array has an <code>#each</code> method that delegates to its
|
622
|
-
items. It also includes Ruby's Enumerable module, providing methods
|
623
|
-
like <code>#min</code> or <code>#first</code>. See the Ruby core
|
624
|
-
documentation for further details.</p>
|
625
|
-
|
626
|
-
<p>Arrays also have a <code>#next_page</code> URL, which will rerun the
|
627
|
-
request with a increased skip parameter, as described in <a
|
628
|
-
href="https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/skip">the
|
629
|
-
documentation</a>.</p>
|
630
|
-
|
631
|
-
<h4 id="label-Links">Links</h4>
|
632
|
-
|
633
|
-
<p>You can easily request a resource that is represented by a link by calling
|
634
|
-
<code>#resolve</code>:</p>
|
635
|
-
|
636
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_happycat'>happycat</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_entry'>entry</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>happycat</span><span class='tstring_end'>'</span></span>
|
637
|
-
<span class='id identifier rubyid_happycat'>happycat</span><span class='period'>.</span><span class='id identifier rubyid_image'>image</span>
|
638
|
-
<span class='comment'># => #<Contentful::Link: @sys={:type=>"Link", :linkType=>"Asset", :id=>"happycat"}>
|
639
|
-
</span><span class='id identifier rubyid_happycat'>happycat</span><span class='period'>.</span><span class='id identifier rubyid_image'>image</span><span class='period'>.</span><span class='id identifier rubyid_resolve'>resolve</span><span class='lparen'>(</span><span class='id identifier rubyid_client'>client</span><span class='rparen'>)</span> <span class='comment'># => #<Contentful::Asset: @fields={ ...
|
640
|
-
</span></code></pre>
|
641
|
-
|
642
|
-
<h3 id="label-Assets">Assets</h3>
|
643
|
-
|
644
|
-
<p>There is a helpful method to add image resize options for an asset image:</p>
|
645
|
-
|
646
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_asset'>asset</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>happycat</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_url'>url</span>
|
647
|
-
<span class='comment'># => "//images.contentful.com/cfexampleapi/3MZPnjZTIskAIIkuuosCss/
|
648
|
-
</span><span class='comment'># 382a48dfa2cb16c47aa2c72f7b23bf09/happycatw.jpg"
|
649
|
-
</span>
|
650
|
-
<span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_asset'>asset</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>happycat</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_url'>url</span><span class='lparen'>(</span><span class='label'>width:</span> <span class='int'>300</span><span class='comma'>,</span> <span class='label'>height:</span> <span class='int'>200</span><span class='comma'>,</span> <span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>jpg</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>quality:</span> <span class='int'>100</span><span class='rparen'>)</span>
|
651
|
-
<span class='comment'># => "//images.contentful.com/cfexampleapi/3MZPnjZTIskAIIkuuosCss/
|
652
|
-
</span><span class='comment'># 382a48dfa2cb16c47aa2c72f7b23bf09/happycatw.jpg?w=300&h=200&fm=jpg&q=100"
|
653
|
-
</span></code></pre>
|
654
|
-
|
655
|
-
<h4 id="label-Resource+options">Resource options</h4>
|
656
|
-
|
657
|
-
<p>Resources, that have been requested directly (i.e. no child resources), can
|
658
|
-
be fetched from the server again by calling <code>#reload</code>:</p>
|
659
|
-
|
660
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_entries'>entries</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_entries'>entries</span>
|
661
|
-
<span class='id identifier rubyid_entries'>entries</span><span class='period'>.</span><span class='id identifier rubyid_reload'>reload</span> <span class='comment'># Fetches the array of entries again
|
662
|
-
</span></code></pre>
|
663
|
-
|
664
|
-
<h4 id="label-Field+type+Object">Field type <code>Object</code></h4>
|
665
|
-
|
666
|
-
<p>While for known field types, the field data is accessible using methods or
|
667
|
-
the <code>#fields</code> hash with symbol keys, it behaves differently for
|
668
|
-
nested data of the type “Object”. The client will treat them as arbitrary
|
669
|
-
hashes and will not parse the data inside.</p>
|
670
|
-
|
671
|
-
<h3 id="label-Advanced+concepts">Advanced concepts</h3>
|
672
|
-
|
673
|
-
<h4 id="label-Proxy+example">Proxy example</h4>
|
674
|
-
|
675
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Contentful.html" title="Contentful (module)">Contentful</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Contentful/Client.html" title="Contentful::Client (class)">Client</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Contentful/Client.html#initialize-instance_method" title="Contentful::Client#initialize (method)">new</a></span></span><span class='lparen'>(</span>
|
676
|
-
<span class='label'>access_token:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>b4c0n73n7fu1</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
677
|
-
<span class='label'>space:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cfexampleapi</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
678
|
-
<span class='label'>proxy_host:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>127.0.0.1</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
679
|
-
<span class='label'>proxy_port:</span> <span class='int'>8080</span><span class='comma'>,</span>
|
680
|
-
<span class='label'>proxy_username:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>username</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
681
|
-
<span class='label'>proxy_password:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>secret_password</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
682
|
-
<span class='rparen'>)</span>
|
683
|
-
</code></pre>
|
684
|
-
|
685
|
-
<h4 id="label-Custom+resource+classes">Custom resource classes</h4>
|
686
|
-
|
687
|
-
<p>You can define your own classes that will be returned instead of the
|
688
|
-
predefined ones. Consider, you want to build a better Asset class. One way
|
689
|
-
to do this is:</p>
|
690
|
-
|
691
|
-
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>MyBetterAsset</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="Contentful.html" title="Contentful (module)">Contentful</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Contentful/Asset.html" title="Contentful::Asset (class)">Asset</a></span></span>
|
692
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_https_image_url'>https_image_url</span>
|
693
|
-
<span class='id identifier rubyid_image_url'>image_url</span><span class='period'>.</span><span class='id identifier rubyid_sub'>sub</span> <span class='tstring'><span class='regexp_beg'>%r<</span><span class='tstring_content'>\A//</span><span class='regexp_end'>></span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>https://</span><span class='tstring_end'>'</span></span>
|
694
|
-
<span class='kw'>end</span>
|
695
|
-
<span class='kw'>end</span>
|
696
|
-
</code></pre>
|
697
|
-
|
698
|
-
<p>You can register your custom class on client initialization:</p>
|
699
|
-
|
700
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Contentful.html" title="Contentful (module)">Contentful</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Contentful/Client.html" title="Contentful::Client (class)">Client</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Contentful/Client.html#initialize-instance_method" title="Contentful::Client#initialize (method)">new</a></span></span><span class='lparen'>(</span>
|
701
|
-
<span class='label'>space:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cfexampleapi</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
702
|
-
<span class='label'>access_token:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>b4c0n73n7fu1</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
703
|
-
<span class='label'>resource_mapping:</span> <span class='lbrace'>{</span>
|
704
|
-
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Asset</span><span class='tstring_end'>'</span></span> <span class='op'>=></span> <span class='const'>MyBetterAsset</span>
|
705
|
-
<span class='rbrace'>}</span>
|
706
|
-
<span class='rparen'>)</span>
|
707
|
-
</code></pre>
|
708
|
-
|
709
|
-
<p>More information on <code>:resource_mapping</code> can be found in <a
|
710
|
-
href="./examples/resource_mapping.rb">examples/resource_mapping.rb</a> and
|
711
|
-
more on custom classes in <a
|
712
|
-
href="./examples/custom_classes.rb">examples/custom_classes.rb</a>.</p>
|
713
|
-
|
714
|
-
<p>You can also register custom entry classes to be used based on the
|
715
|
-
entry's content_type using the <code>:entry_mapping</code>
|
716
|
-
configuration:</p>
|
717
|
-
|
718
|
-
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>Cat</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="Contentful.html" title="Contentful (module)">Contentful</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Contentful/Entry.html" title="Contentful::Entry (class)">Entry</a></span></span>
|
719
|
-
<span class='comment'># define methods based on :fields, etc
|
720
|
-
</span><span class='kw'>end</span>
|
721
|
-
|
722
|
-
<span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Contentful.html" title="Contentful (module)">Contentful</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Contentful/Client.html" title="Contentful::Client (class)">Client</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Contentful/Client.html#initialize-instance_method" title="Contentful::Client#initialize (method)">new</a></span></span><span class='lparen'>(</span>
|
723
|
-
<span class='label'>space:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cfexampleapi</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
724
|
-
<span class='label'>access_token:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>b4c0n73n7fu1</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
725
|
-
<span class='label'>entry_mapping:</span> <span class='lbrace'>{</span>
|
726
|
-
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cat</span><span class='tstring_end'>'</span></span> <span class='op'>=></span> <span class='const'>Cat</span>
|
727
|
-
<span class='rbrace'>}</span>
|
728
|
-
<span class='rparen'>)</span>
|
729
|
-
|
730
|
-
<span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_entry'>entry</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>nyancat</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># is instance of Cat
|
731
|
-
</span></code></pre>
|
732
|
-
|
733
|
-
<h4 id="label-Synchronization">Synchronization</h4>
|
734
|
-
|
735
|
-
<p>The client also includes a wrapper for the synchronization endpoint. You
|
736
|
-
can initialize it with the options described in the <a
|
737
|
-
href="https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/synchronization">Delivery
|
738
|
-
API Documentation</a> or an URL you received from a previous sync:</p>
|
739
|
-
|
740
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Contentful.html" title="Contentful (module)">Contentful</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Contentful/Client.html" title="Contentful::Client (class)">Client</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Contentful/Client.html#initialize-instance_method" title="Contentful::Client#initialize (method)">new</a></span></span><span class='lparen'>(</span>
|
741
|
-
<span class='label'>access_token:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>b4c0n73n7fu1</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
742
|
-
<span class='label'>space:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cfexampleapi</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
743
|
-
<span class='label'>default_locale:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>en-US</span><span class='tstring_end'>'</span></span>
|
744
|
-
<span class='rparen'>)</span>
|
745
|
-
|
746
|
-
<span class='id identifier rubyid_sync'>sync</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_sync'>sync</span><span class='lparen'>(</span><span class='label'>initial:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>type:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Deletion</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># Only returns deleted entries and assets
|
747
|
-
</span><span class='id identifier rubyid_sync'>sync</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_sync'>sync</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>https://cdn.contentful.com/spaces/cfexampleapi/sync?sync_token=w5ZGw6JFwqZmVcKsE8Kow4gr...sGPg</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='comment'># Continues a sync
|
748
|
-
</span></code></pre>
|
749
|
-
|
750
|
-
<p>You can access the results either wrapped in
|
751
|
-
<code>Contentful::SyncPage</code> objects:</p>
|
752
|
-
|
753
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_sync'>sync</span><span class='period'>.</span><span class='id identifier rubyid_each_page'>each_page</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_page'>page</span><span class='op'>|</span>
|
754
|
-
<span class='comment'># Find resources at: page.items
|
755
|
-
</span><span class='kw'>end</span>
|
756
|
-
|
757
|
-
<span class='comment'># More explicit version:
|
758
|
-
</span><span class='id identifier rubyid_page'>page</span> <span class='op'>=</span> <span class='id identifier rubyid_sync'>sync</span><span class='period'>.</span><span class='id identifier rubyid_first_page'>first_page</span>
|
759
|
-
<span class='kw'>until</span> <span class='id identifier rubyid_sync'>sync</span><span class='period'>.</span><span class='id identifier rubyid_completed?'>completed?</span>
|
760
|
-
<span class='id identifier rubyid_page'>page</span> <span class='op'>=</span> <span class='id identifier rubyid_sync'>sync</span><span class='period'>.</span><span class='id identifier rubyid_next_page'>next_page</span>
|
761
|
-
<span class='kw'>end</span>
|
762
|
-
</code></pre>
|
763
|
-
|
764
|
-
<p>Or directly iterative over all resources:</p>
|
765
|
-
|
766
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_sync'>sync</span><span class='period'>.</span><span class='id identifier rubyid_each_item'>each_item</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_resource'>resource</span><span class='op'>|</span>
|
767
|
-
<span class='comment'># ...
|
768
|
-
</span><span class='kw'>end</span>
|
769
|
-
</code></pre>
|
770
|
-
|
771
|
-
<p>When a sync is completed, the next sync url can be read from the Sync or
|
772
|
-
SyncPage object:</p>
|
773
|
-
|
774
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_sync'>sync</span><span class='period'>.</span><span class='id identifier rubyid_next_sync_url'>next_sync_url</span>
|
775
|
-
</code></pre>
|
776
|
-
|
777
|
-
<p><strong>Please note</strong> that synchronization entries come in all
|
778
|
-
locales, so make sure, you supply a :default_locale property to the client
|
779
|
-
configuration, when using the sync feature. This locale will be returned by
|
780
|
-
default, when you call <code>Entry#fields</code>. The other localized data
|
781
|
-
will also be saved and can be accessed by calling the fields method with a
|
782
|
-
locale parameter:</p>
|
783
|
-
|
784
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_first_entry'>first_entry</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_sync'>sync</span><span class='lparen'>(</span><span class='label'>initial:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>type:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Entry</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_first_page'>first_page</span><span class='period'>.</span><span class='id identifier rubyid_items'>items</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span>
|
785
|
-
<span class='id identifier rubyid_first_entry'>first_entry</span><span class='period'>.</span><span class='id identifier rubyid_fields'>fields</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>de-DE</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># Returns German localizations
|
786
|
-
</span></code></pre>
|
787
|
-
|
788
|
-
<h3 id="label-Migrating+to+2.x">Migrating to 2.x</h3>
|
789
|
-
|
790
|
-
<p>If you're a <code>0.x</code> or a <code>1.x</code> user of this gem,
|
791
|
-
and are planning to migrate to the current <code>2.x</code> branch. There
|
792
|
-
are a few breaking changes you have to take into account:</p>
|
793
|
-
<ul><li>
|
794
|
-
<p><code>Contentful::Link#resolve</code> and
|
795
|
-
<code>Contentful::Array#next_page</code> now require a
|
796
|
-
<code>Contentful::Client</code> instance as a parameter.</p>
|
797
|
-
</li><li>
|
798
|
-
<p><code>Contentful::CustomResource</code> does no longer exist, custom entry
|
799
|
-
classes can now inherit from <code>Contentful::Entry</code> and have proper
|
800
|
-
marshalling working.</p>
|
801
|
-
</li><li>
|
802
|
-
<p><code>Contentful::Resource</code> does no longer exist, all resource
|
803
|
-
classes now inherit from <code>Contentful::BaseResource</code>.
|
804
|
-
<code>Contentful::Entry</code> and <code>Contentful::Asset</code> inherit
|
805
|
-
from <code>Contentful::FieldsResource</code> which is a subclass of
|
806
|
-
<code>Contentful::BaseResource</code>.</p>
|
807
|
-
</li><li>
|
808
|
-
<p><code>Contentful::DynamicEntry</code> does no longer exist, if code checked
|
809
|
-
against that base class, it should now check against
|
810
|
-
<code>Contentful::Entry</code> instead.</p>
|
811
|
-
</li><li>
|
812
|
-
<p><code>Contentful::Client#dynamic_entry_cache</code> <em>(private)</em> has
|
813
|
-
been extracted to it's own class, and can be now manually cleared by
|
814
|
-
using <code>Contentful::ContentTypeCache::clear</code>.</p>
|
815
|
-
</li><li>
|
816
|
-
<p><code>Contentful::BaseResource#sys</code> and
|
817
|
-
<code>Contentful::FieldsResource#fields</code> internal representation for
|
818
|
-
keys are now snake cased to match the instance accessors. E.g.
|
819
|
-
<code>entry.fields[:myField]</code> previously had the accessor
|
820
|
-
<code>entry.my_field</code>, now it is
|
821
|
-
<code>entry.fields[:my_field]</code>. The value in both cases would
|
822
|
-
correspond to the same field, only change is to unify the style. If code
|
823
|
-
accessed the values through the <code>#sys</code> or <code>#fields</code>
|
824
|
-
methods, keys now need to be snake cased.</p>
|
825
|
-
</li><li>
|
826
|
-
<p>Circular references are handled as individual objects to simplify
|
827
|
-
marshalling and reduce stack errors, this introduces a performance hit on
|
828
|
-
extremely interconnected content. Therefore, to limit the impact of
|
829
|
-
circular references, an additional configuration flag
|
830
|
-
<code>max_include_resolution_depth</code> has been added. It is set to 20
|
831
|
-
by default (which corresponds to the maximum include level value * 2). This
|
832
|
-
allows for non-circular but highly connected content to resolve properly.
|
833
|
-
In very interconnected content, it also allows to reduce this number to
|
834
|
-
improve performance. For a more in depth look into this you can read <a
|
835
|
-
href="https://github.com/contentful/contentful.rb/issues/124#issuecomment-287002469">this
|
836
|
-
issue</a>.</p>
|
837
|
-
</li><li>
|
838
|
-
<p><code>#inspect</code> now offers a clearer and better output for all
|
839
|
-
resources. If your code had assertions based on the string representation
|
840
|
-
of the resources, update to the new format
|
841
|
-
<code><Contentful::#{RESOURCE_CLASS}#{additional_info}
|
842
|
-
id="#{RESOURCE_ID}"></code>.</p>
|
843
|
-
</li></ul>
|
844
|
-
|
845
|
-
<p>For more information on the internal changes present in the 2.x release,
|
846
|
-
please read the <a href="CHANGELOG.md">CHANGELOG</a></p>
|
847
|
-
|
848
|
-
<h3 id="label-Tutorials+-26+other+resources">Tutorials & other resources</h3>
|
849
|
-
<ul><li>
|
850
|
-
<p>This library is a wrapper around our Contentful Delivery REST API. Some
|
851
|
-
more specific details such as search parameters and pagination are better
|
852
|
-
explained on the <a
|
853
|
-
href="https://www.contentful.com/developers/docs/references/content-delivery-api/">REST
|
854
|
-
API reference</a>, and you can also get a better understanding of how the
|
855
|
-
requests look under the hood.</p>
|
856
|
-
</li><li>
|
857
|
-
<p>Check the <a
|
858
|
-
href="https://www.contentful.com/developers/docs/ruby/">Contentful for
|
859
|
-
Ruby</a> page for Tutorials, Demo Apps, and more information on other ways
|
860
|
-
of using Ruby with Contentful</p>
|
861
|
-
</li></ul>
|
862
|
-
|
863
|
-
<h2 id="label-Reach+out+to+us">Reach out to us</h2>
|
864
|
-
|
865
|
-
<h3 id="label-You+have+questions+about+how+to+use+this+library-3F">You have questions about how to use this library?</h3>
|
866
|
-
<ul><li>
|
867
|
-
<p>Reach out to our community forum: <a
|
868
|
-
href="https://support.contentful.com/"><img
|
869
|
-
src="https://img.shields.io/badge/-Join%20Community%20Forum-3AB2E6.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MiA1OSI+CiAgPHBhdGggZmlsbD0iI0Y4RTQxOCIgZD0iTTE4IDQxYTE2IDE2IDAgMCAxIDAtMjMgNiA2IDAgMCAwLTktOSAyOSAyOSAwIDAgMCAwIDQxIDYgNiAwIDEgMCA5LTkiIG1hc2s9InVybCgjYikiLz4KICA8cGF0aCBmaWxsPSIjNTZBRUQyIiBkPSJNMTggMThhMTYgMTYgMCAwIDEgMjMgMCA2IDYgMCAxIDAgOS05QTI5IDI5IDAgMCAwIDkgOWE2IDYgMCAwIDAgOSA5Ii8+CiAgPHBhdGggZmlsbD0iI0UwNTM0RSIgZD0iTTQxIDQxYTE2IDE2IDAgMCAxLTIzIDAgNiA2IDAgMSAwLTkgOSAyOSAyOSAwIDAgMCA0MSAwIDYgNiAwIDAgMC05LTkiLz4KICA8cGF0aCBmaWxsPSIjMUQ3OEE0IiBkPSJNMTggMThhNiA2IDAgMSAxLTktOSA2IDYgMCAwIDEgOSA5Ii8+CiAgPHBhdGggZmlsbD0iI0JFNDMzQiIgZD0iTTE4IDUwYTYgNiAwIDEgMS05LTkgNiA2IDAgMCAxIDkgOSIvPgo8L3N2Zz4K&maxAge=31557600"></a></p>
|
870
|
-
</li><li>
|
871
|
-
<p>Jump into our community slack channel: <a
|
872
|
-
href="https://www.contentful.com/slack/"><img
|
873
|
-
src="https://img.shields.io/badge/-Join%20Community%20Slack-2AB27B.svg?logo=slack&maxAge=31557600"></a></p>
|
874
|
-
</li></ul>
|
875
|
-
|
876
|
-
<h3 id="label-You+found+a+bug+or+want+to+propose+a+feature-3F">You found a bug or want to propose a feature?</h3>
|
877
|
-
<ul><li>
|
878
|
-
<p>File an issue here on GitHub: <a
|
879
|
-
href="https://github.com/contentful/contentful.rb/issues/new"><img
|
880
|
-
src="https://img.shields.io/badge/-Create%20Issue-6cc644.svg?logo=github&maxAge=31557600"></a>.
|
881
|
-
Make sure to remove any credential from your code before sharing it.</p>
|
882
|
-
</li></ul>
|
883
|
-
|
884
|
-
<h3 id="label-You+need+to+share+confidential+information+or+have+other+questions-3F">You need to share confidential information or have other questions?</h3>
|
885
|
-
<ul><li>
|
886
|
-
<p>File a support ticket at our Contentful Customer Support: <a
|
887
|
-
href="https://www.contentful.com/support/"><img
|
888
|
-
src="https://img.shields.io/badge/-Submit%20Support%20Ticket-3AB2E6.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MiA1OSI+CiAgPHBhdGggZmlsbD0iI0Y4RTQxOCIgZD0iTTE4IDQxYTE2IDE2IDAgMCAxIDAtMjMgNiA2IDAgMCAwLTktOSAyOSAyOSAwIDAgMCAwIDQxIDYgNiAwIDEgMCA5LTkiIG1hc2s9InVybCgjYikiLz4KICA8cGF0aCBmaWxsPSIjNTZBRUQyIiBkPSJNMTggMThhMTYgMTYgMCAwIDEgMjMgMCA2IDYgMCAxIDAgOS05QTI5IDI5IDAgMCAwIDkgOWE2IDYgMCAwIDAgOSA5Ii8+CiAgPHBhdGggZmlsbD0iI0UwNTM0RSIgZD0iTTQxIDQxYTE2IDE2IDAgMCAxLTIzIDAgNiA2IDAgMSAwLTkgOSAyOSAyOSAwIDAgMCA0MSAwIDYgNiAwIDAgMC05LTkiLz4KICA8cGF0aCBmaWxsPSIjMUQ3OEE0IiBkPSJNMTggMThhNiA2IDAgMSAxLTktOSA2IDYgMCAwIDEgOSA5Ii8+CiAgPHBhdGggZmlsbD0iI0JFNDMzQiIgZD0iTTE4IDUwYTYgNiAwIDEgMS05LTkgNiA2IDAgMCAxIDkgOSIvPgo8L3N2Zz4K&maxAge=31557600"></a></p>
|
889
|
-
</li></ul>
|
890
|
-
|
891
|
-
<h2 id="label-Get+involved">Get involved</h2>
|
892
|
-
|
893
|
-
<p><a href="http://makeapullrequest.com"><img
|
894
|
-
src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?maxAge=31557600"></a></p>
|
895
|
-
|
896
|
-
<p>We appreciate any help on our repositories. For more details about how to
|
897
|
-
contribute see our <a href="CONTRIBUTING.md">CONTRIBUTING.md</a> document.</p>
|
898
|
-
|
899
|
-
<h2 id="label-License">License</h2>
|
900
|
-
|
901
|
-
<p>This repository is published under the <a href="LICENSE.txt">MIT</a>
|
902
|
-
license.</p>
|
903
|
-
|
904
|
-
<h2 id="label-Code+of+Conduct">Code of Conduct</h2>
|
905
|
-
|
906
|
-
<p>We want to provide a safe, inclusive, welcoming, and harassment-free space
|
907
|
-
and experience for all participants, regardless of gender identity and
|
908
|
-
expression, sexual orientation, disability, physical appearance,
|
909
|
-
socioeconomic status, body size, ethnicity, nationality, level of
|
910
|
-
experience, age, religion (or lack thereof), or other identity markers.</p>
|
911
|
-
|
912
|
-
<p><a
|
913
|
-
href="https://github.com/contentful-developer-relations/community-code-of-conduct">Read
|
914
|
-
our full Code of Conduct</a>.</p>
|
915
|
-
</div></div>
|
916
|
-
|
917
|
-
<div id="footer">
|
918
|
-
Generated on Tue Apr 9 10:49:55 2019 by
|
919
|
-
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
920
|
-
0.9.18 (ruby-2.5.3).
|
921
|
-
</div>
|
922
|
-
|
923
|
-
</div>
|
924
|
-
</body>
|
925
|
-
</html>
|