Module: Contentful::Resource

Included in:
Array, Asset, ContentType, DeletedAsset, DeletedEntry, Entry, Field, File, Link, Locale, Location, Space, SyncPage
Defined in:
lib/contentful/resource.rb,
lib/contentful/resource/fields.rb,
lib/contentful/resource/array_like.rb,
lib/contentful/resource/asset_fields.rb,
lib/contentful/resource/custom_resource.rb,
lib/contentful/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

See Also:

  • examples/custom_classes.rb Custom Class as Resource
  • examples/resource_mapping.rb Mapping a Custom Class

Defined Under Namespace

Modules: ArrayLike, AssetFields, CustomResource, Fields, SystemProperties

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject (readonly)

rubocop:enable Style/DoubleNegation



29
30
31
# File 'lib/contentful/resource.rb', line 29

def client
  @client
end

#default_localeObject (readonly)

rubocop:enable Style/DoubleNegation



29
30
31
# File 'lib/contentful/resource.rb', line 29

def default_locale
  @default_locale
end

#propertiesObject (readonly)

rubocop:enable Style/DoubleNegation



29
30
31
# File 'lib/contentful/resource.rb', line 29

def properties
  @properties
end

#rawObject (readonly)

rubocop:enable Style/DoubleNegation



29
30
31
# File 'lib/contentful/resource.rb', line 29

def raw
  @raw
end

#requestObject (readonly)

rubocop:enable Style/DoubleNegation



29
30
31
# File 'lib/contentful/resource.rb', line 29

def request
  @request
end

Instance Method Details

#array?Boolean

Returns true for resources that behave like an array

Returns:

  • (Boolean)


65
66
67
# File 'lib/contentful/resource.rb', line 65

def array?
  false
end

#entry?Boolean

Returns true for resources that are entries

Returns:

  • (Boolean)


60
61
62
# File 'lib/contentful/resource.rb', line 60

def entry?
  false
end

#fieldsObject

Resources that don't include Fields or AssetFields return nil for #fields



75
76
77
# File 'lib/contentful/resource.rb', line 75

def fields
  nil
end

#reloadObject

Issues the request that was made to fetch this response again. Only works for top-level resources



81
82
83
84
85
86
87
# File 'lib/contentful/resource.rb', line 81

def reload
  if request
    request.get
  else
    false
  end
end

#sysObject

Resources that don't include SystemProperties return nil for #sys



70
71
72
# File 'lib/contentful/resource.rb', line 70

def sys
  nil
end