Class: Contentful::Management::Locale
- Inherits:
-
Object
- Object
- Contentful::Management::Locale
- Includes:
- Resource, Resource::Refresher, Resource::SystemProperties
- Defined in:
- lib/contentful/management/locale.rb
Overview
Resource class for Locale.
Constant Summary
Constants included from Resource::SystemProperties
Resource::SystemProperties::SYS_COERCIONS
Constants included from Resource
Instance Attribute Summary
Attributes included from Resource::SystemProperties
Attributes included from Resource
#client, #default_locale, #properties, #request
Class Method Summary collapse
-
.all(space_id = nil) ⇒ Object
Gets a collection of locales.
-
.create(space_id, attributes) ⇒ Object
Creates a locale.
-
.find(space_id, locale_id) ⇒ Object
Gets a specific locale.
Instance Method Summary collapse
-
#update(attributes) ⇒ Object
Updates a locale.
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
Class Method Details
.all(space_id = nil) ⇒ Object
Gets a collection of locales. Takes an id of a space. Returns a Contentful::Management::Array of Contentful::Management::Locale.
21 22 23 24 25 26 |
# File 'lib/contentful/management/locale.rb', line 21 def self.all(space_id = nil) request = Request.new("/#{ space_id }/locales") response = request.get result = ResourceBuilder.new(response, { 'Locale' => Locale }, {}) result.run end |
.create(space_id, attributes) ⇒ Object
Creates a locale. Takes a space id and hash with attributes:
:name
:code
:contentManagementApi
:contentDeliveryApi
:publish
Returns a Contentful::Management::Locale.
46 47 48 49 50 51 |
# File 'lib/contentful/management/locale.rb', line 46 def self.create(space_id, attributes) request = Request.new("/#{ space_id }/locales", { 'name' => attributes.fetch(:name), 'code' => attributes.fetch(:code) }) response = request.post result = ResourceBuilder.new(response, { 'Locale' => Locale }, {}) result.run end |
.find(space_id, locale_id) ⇒ Object
Gets a specific locale. Takes an id of a space and locale id. Returns a Contentful::Management::Locale.
31 32 33 34 35 36 |
# File 'lib/contentful/management/locale.rb', line 31 def self.find(space_id, locale_id) request = Request.new("/#{ space_id }/locales/#{ locale_id }") response = request.get result = ResourceBuilder.new(response, { 'Locale' => Locale }, {}) result.run end |
Instance Method Details
#update(attributes) ⇒ Object
Updates a locale. Takes a hash with attributes. Returns a Contentful::Management::Locale.
56 57 58 59 60 61 |
# File 'lib/contentful/management/locale.rb', line 56 def update(attributes) request = Request.new("/#{ space.id }/locales/#{ id }", { 'name' => attributes.fetch(:name) }, id = nil, version: sys[:version]) response = request.put result = ResourceBuilder.new(response, { 'Locale' => Locale }, {}) refresh_data(result.run) end |