Class: Contentful::Management::Space
- Inherits:
-
Object
- Object
- Contentful::Management::Space
- Includes:
- Resource, Resource::Refresher, Resource::SystemProperties
- Defined in:
- lib/contentful/management/space.rb
Overview
Resource class for Space. www.contentful.com/developers/documentation/content-management-api/#resources-spaces
Constant Summary
Constants included from Resource::SystemProperties
Resource::SystemProperties::SYS_COERCIONS
Constants included from Resource
Instance Attribute Summary collapse
-
#found_locale ⇒ Object
Returns the value of attribute found_locale.
Attributes included from Resource::SystemProperties
Attributes included from Resource
#client, #properties, #raw_object, #request
Class Method Summary collapse
-
.all ⇒ Object
Gets a collection of spaces.
-
.create(attributes) ⇒ Object
Create a space.
-
.find(space_id) ⇒ Object
Gets a specific space.
Instance Method Summary collapse
-
#assets ⇒ Object
Allows manipulation of assets in context of the current space Allows listing all assets of space, creating new and finding one by id.
-
#content_types ⇒ Object
Allows manipulation of content types in context of the current space Allows listing all content types of space, creating new and finding one by id.
-
#default_locale ⇒ Object
Retrieves Default Locale for current Space and leaves it cached.
-
#destroy ⇒ Object
Destroys a space.
-
#entries ⇒ Object
Allows manipulation of entries in context of the current space Allows listing all entries for space and finding one by id.
-
#find_locale ⇒ Object
Finds Default Locale Code for current Space This request makes an API call to the Locale endpoint.
-
#locales ⇒ Object
Allows manipulation of locales in context of the current space Allows listing all locales of space, creating new and finding one by id.
-
#save ⇒ Object
If a space is new, an object gets created in the Contentful, otherwise the existing space gets updated.
-
#update(attributes) ⇒ Object
Updates a space.
-
#webhooks ⇒ Object
Allows manipulation of webhooks in context of the current space Allows listing all webhooks for space and finding one by id.
Methods included from Resource::Refresher
Methods included from Resource::SystemProperties
included, #initialize, #inspect
Methods included from Resource
#array?, #fields, #initialize, #inspect, #nested_locale_fields?, #sys
Instance Attribute Details
#found_locale ⇒ Object
Returns the value of attribute found_locale.
26 27 28 |
# File 'lib/contentful/management/space.rb', line 26 def found_locale @found_locale end |
Class Method Details
.all ⇒ Object
Gets a collection of spaces. Returns a Contentful::Management::Array of Contentful::Management::Space.
30 31 32 33 34 35 36 37 |
# File 'lib/contentful/management/space.rb', line 30 def self.all request = Request.new('') response = request.get result = ResourceBuilder.new(response, {}, {}) spaces = result.run client.update_dynamic_entry_cache_for_spaces!(spaces) spaces end |
.create(attributes) ⇒ Object
Create a space. Takes a hash of attributes with optional organization id if client has more than one organization. Returns a Contentful::Management::Space.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/contentful/management/space.rb', line 54 def self.create(attributes) default_locale = attributes[:default_locale] || client.default_locale request = Request.new( '', {'name' => attributes.fetch(:name), defaultLocale: default_locale}, id = nil, organization_id: attributes[:organization_id] ) response = request.post result = ResourceBuilder.new(response, {}, {}) space = result.run space.found_locale = default_locale if space.is_a? Space space end |
.find(space_id) ⇒ Object
Gets a specific space. Takes an id of space. Returns a Contentful::Management::Space.
42 43 44 45 46 47 48 49 |
# File 'lib/contentful/management/space.rb', line 42 def self.find(space_id) request = Request.new("/#{ space_id }") response = request.get result = ResourceBuilder.new(response, {}, {}) space = result.run client.update_dynamic_entry_cache_for_space!(space) if space.is_a? Space space end |
Instance Method Details
#assets ⇒ Object
Allows manipulation of assets in context of the current space Allows listing all assets of space, creating new and finding one by id. See README for details.
125 126 127 |
# File 'lib/contentful/management/space.rb', line 125 def assets SpaceAssetMethodsFactory.new(self) end |
#content_types ⇒ Object
Allows manipulation of content types in context of the current space Allows listing all content types of space, creating new and finding one by id. See README for details.
111 112 113 |
# File 'lib/contentful/management/space.rb', line 111 def content_types SpaceContentTypeMethodsFactory.new(self) end |
#default_locale ⇒ Object
Retrieves Default Locale for current Space and leaves it cached
144 145 146 |
# File 'lib/contentful/management/space.rb', line 144 def default_locale self.found_locale ||= find_locale end |
#destroy ⇒ Object
Destroys a space. Returns true if succeed.
98 99 100 101 102 103 104 105 106 |
# File 'lib/contentful/management/space.rb', line 98 def destroy request = Request.new("/#{ id }") response = request.delete if response.status == :no_content return true else ResourceBuilder.new(response, {}, {}).run end end |
#entries ⇒ Object
Allows manipulation of entries in context of the current space Allows listing all entries for space and finding one by id. See README for details.
132 133 134 |
# File 'lib/contentful/management/space.rb', line 132 def entries SpaceEntryMethodsFactory.new(self) end |
#find_locale ⇒ Object
Finds Default Locale Code for current Space This request makes an API call to the Locale endpoint
150 151 152 153 154 |
# File 'lib/contentful/management/space.rb', line 150 def find_locale locale = ::Contentful::Management::Locale.all(self.id).detect { |l| l.default } return locale.code unless locale.nil? @default_locale end |
#locales ⇒ Object
Allows manipulation of locales in context of the current space Allows listing all locales of space, creating new and finding one by id. See README for details.
118 119 120 |
# File 'lib/contentful/management/space.rb', line 118 def locales SpaceLocaleMethodsFactory.new(self) end |
#save ⇒ Object
If a space is new, an object gets created in the Contentful, otherwise the existing space gets updated. See README for details.
87 88 89 90 91 92 93 94 |
# File 'lib/contentful/management/space.rb', line 87 def save if id update(name: name, organization_id: organization) else new_instance = self.class.create(name: name, organization_id: organization) refresh_data(new_instance) end end |
#update(attributes) ⇒ Object
Updates a space. Takes a hash of attributes with optional organization id if client has more than one organization. Returns a Contentful::Management::Space.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/contentful/management/space.rb', line 72 def update(attributes) request = Request.new( "/#{ id }", {'name' => attributes.fetch(:name)}, id = nil, version: sys[:version], organization_id: attributes[:organization_id] ) response = request.put result = ResourceBuilder.new(response, {}, {}) refresh_data(result.run) end |
#webhooks ⇒ Object
Allows manipulation of webhooks in context of the current space Allows listing all webhooks for space and finding one by id. See README for details.
139 140 141 |
# File 'lib/contentful/management/space.rb', line 139 def webhooks SpaceWebhookMethodsFactory.new(self) end |