Module: Contentful::Management::Resource
- Included in:
- ApiKey, Array, Asset, ContentType, EditorInterface, Entry, Environment, Field, File, Link, Locale, Location, Organization, OrganizationPeriodicUsage, PersonalAccessToken, PreviewApiKey, Role, Snapshot, Space, SpaceMembership, SpacePeriodicUsage, Tag, UIExtension, Upload, User, Validation, Webhook, WebhookCall, WebhookHealth
- Defined in:
- lib/contentful/management/resource.rb,
lib/contentful/management/resource/fields.rb,
lib/contentful/management/resource/archiver.rb,
lib/contentful/management/resource/metadata.rb,
lib/contentful/management/resource/publisher.rb,
lib/contentful/management/resource/refresher.rb,
lib/contentful/management/resource/array_like.rb,
lib/contentful/management/resource/field_aware.rb,
lib/contentful/management/resource/asset_fields.rb,
lib/contentful/management/resource/entry_fields.rb,
lib/contentful/management/resource/all_published.rb,
lib/contentful/management/resource/environment_aware.rb,
lib/contentful/management/resource/system_properties.rb
Overview
Include this module to declare a class to be a contentful resource. This is done by the default in the existing resource classes
You can define your own classes that behave like contentful resources: See examples/custom_classes.rb to see how.
Take a look at examples/resource_mapping.rb on how to register them to be returned by the client by default
Defined Under Namespace
Modules: AllPublished, Archiver, ArrayLike, AssetFields, ClassMethods, EntryFields, EnvironmentAware, FieldAware, Fields, Metadata, Publisher, Refresher, SystemProperties
Instance Attribute Summary collapse
-
#client ⇒ Object
Shared instance of the API client.
-
#properties ⇒ Object
readonly
rubocop:enable Style/DoubleNegation.
-
#raw_object ⇒ Object
readonly
rubocop:enable Style/DoubleNegation.
-
#request ⇒ Object
readonly
rubocop:enable Style/DoubleNegation.
Instance Method Summary collapse
-
#array? ⇒ Boolean
Returns true for resources that behave like an array.
-
#default_locale ⇒ Object
Get default_locale from client.
-
#destroy ⇒ true, Contentful::Management::Error
Destroys a resource.
-
#environment_id ⇒ Object
Returns the Environment ID.
-
#fields ⇒ Object
Resources that don’t include Fields or AssetFields return nil for #fields.
-
#nested_locale_fields? ⇒ Boolean
By default, fields come flattened in the current locale.
- #resource? ⇒ true
-
#save ⇒ Contentful::Management::Resource
Creates or updates a resource.
-
#sys ⇒ Object
Resources that don’t include SystemProperties return nil for #sys.
-
#update(attributes) ⇒ Contentful::Management::Resource
Updates a resource.
Instance Attribute Details
#client ⇒ Object
Shared instance of the API client
123 124 125 |
# File 'lib/contentful/management/resource.rb', line 123 def client @client end |
#properties ⇒ Object (readonly)
rubocop:enable Style/DoubleNegation
32 33 34 |
# File 'lib/contentful/management/resource.rb', line 32 def properties @properties end |
#raw_object ⇒ Object (readonly)
rubocop:enable Style/DoubleNegation
32 33 34 |
# File 'lib/contentful/management/resource.rb', line 32 def raw_object @raw_object end |
#request ⇒ Object (readonly)
rubocop:enable Style/DoubleNegation
32 33 34 |
# File 'lib/contentful/management/resource.rb', line 32 def request @request end |
Instance Method Details
#array? ⇒ Boolean
Returns true for resources that behave like an array
101 102 103 |
# File 'lib/contentful/management/resource.rb', line 101 def array? false end |
#default_locale ⇒ Object
Get default_locale from client
138 139 140 |
# File 'lib/contentful/management/resource.rb', line 138 def default_locale client.default_locale end |
#destroy ⇒ true, Contentful::Management::Error
Destroys a resource.
86 87 88 89 90 91 92 |
# File 'lib/contentful/management/resource.rb', line 86 def destroy ResourceRequester.new(client, self.class).destroy( space_id: space.id, environment_id: environment_id, resource_id: id ) end |
#environment_id ⇒ Object
Returns the Environment ID
133 134 135 |
# File 'lib/contentful/management/resource.rb', line 133 def environment_id nil end |
#fields ⇒ Object
Resources that don’t include Fields or AssetFields return nil for #fields
118 119 120 |
# File 'lib/contentful/management/resource.rb', line 118 def fields nil end |
#nested_locale_fields? ⇒ Boolean
By default, fields come flattened in the current locale. This is different for syncs
106 107 108 109 110 |
# File 'lib/contentful/management/resource.rb', line 106 def nested_locale_fields? # rubocop:disable Style/DoubleNegation !!@nested_locale_fields # rubocop:enable Style/DoubleNegation end |
#resource? ⇒ true
128 129 130 |
# File 'lib/contentful/management/resource.rb', line 128 def resource? true end |
#save ⇒ Contentful::Management::Resource
Creates or updates a resource.
79 80 81 |
# File 'lib/contentful/management/resource.rb', line 79 def save update({}) end |
#sys ⇒ Object
Resources that don’t include SystemProperties return nil for #sys
113 114 115 |
# File 'lib/contentful/management/resource.rb', line 113 def sys nil end |
#update(attributes) ⇒ Contentful::Management::Resource
Updates a resource.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/contentful/management/resource.rb', line 64 def update(attributes) headers = self.class.create_headers(client, attributes, self) headers = headers.merge(update_headers) ResourceRequester.new(client, self.class).update( self, update_url_attributes, query_attributes(attributes), headers ) end |