Class: Contentstack::Entry
- Inherits:
-
Object
- Object
- Contentstack::Entry
- Defined in:
- lib/contentstack/entry.rb
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Instance Method Summary collapse
-
#except(fields, fields_with_base = nil) ⇒ Contentstack::Entry
Specifies list of field uids that would be 'excluded' from the response.
-
#fetch ⇒ Contentstack::EntryCollection
Execute entry.
- #get(field_uid) ⇒ Object
- #include(field_uids) ⇒ Contentstack::Query
-
#include_branch(flag = true) ⇒ Contentstack::Entry
Include the branch for publish content.
-
#include_content_type(flag = true) ⇒ Contentstack::Entry
Include object's content_type in response.
-
#include_embedded_items ⇒ Contentstack::Query
Include Embedded Objects (Entries and Assets) along with entry/entries details.
-
#include_fallback(flag = true) ⇒ Contentstack::Entry
Include the fallback locale publish content, if specified locale content is not publish.
-
#include_owner(flag = true) ⇒ Contentstack::Entry
Include object owner's profile in the objects data.
-
#include_reference(reference_field_uids) ⇒ Contentstack::Entry
Add a constraint that requires a particular reference key details.
-
#include_schema(flag = true) ⇒ Contentstack::Entry
Include schemas of all returned objects along with objects themselves.
-
#initialize(attrs, content_type_uid = nil) ⇒ Entry
constructor
A new instance of Entry.
-
#locale(code) ⇒ Contentstack::Entry
Get entries from the specified locale.
-
#only(fields, fields_with_base = nil) ⇒ Contentstack::Entry
Specifies an array of 'only' keys in BASE object that would be 'included' in the response.
Constructor Details
#initialize(attrs, content_type_uid = nil) ⇒ Entry
Returns a new instance of Entry.
8 9 10 |
# File 'lib/contentstack/entry.rb', line 8 def initialize(attrs, content_type_uid=nil) setup(attrs, content_type_uid) end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
7 8 9 |
# File 'lib/contentstack/entry.rb', line 7 def content_type @content_type end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
7 8 9 |
# File 'lib/contentstack/entry.rb', line 7 def fields @fields end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
7 8 9 |
# File 'lib/contentstack/entry.rb', line 7 def owner @owner end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
7 8 9 |
# File 'lib/contentstack/entry.rb', line 7 def query @query end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
7 8 9 |
# File 'lib/contentstack/entry.rb', line 7 def schema @schema end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
7 8 9 |
# File 'lib/contentstack/entry.rb', line 7 def uid @uid end |
Instance Method Details
#except(fields, fields_with_base = nil) ⇒ Contentstack::Entry
Specifies list of field uids that would be 'excluded' from the response.
Example
# Exclude 'description' field in response
@entry = @stack.content_type('category').entry(entry_uid)
@entry.except(['description'])
# Query product and exclude the 'description' from category reference
@entry = @stack.content_type('product').entry(entry_uid)
@entry.include_reference('category')
.except('category', ['description'])
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/contentstack/entry.rb', line 72 def except(fields, fields_with_base=nil) q = {} if [Array, String].include?(fields_with_base.class) fields_with_base = [fields_with_base] if fields_with_base.class == String q[fields.to_sym] = fields_with_base else fields = [fields] if fields.class == String q = {BASE: fields} end @query[:except] = q self end |
#fetch ⇒ Contentstack::EntryCollection
Execute entry
Example
@entry = @stack.content_type('product').entry(entry_uid)
@entry.fetch
200 201 202 203 204 205 206 |
# File 'lib/contentstack/entry.rb', line 200 def fetch entry = API.fetch_entry(@content_type, self.fields[:uid], @query) setup(entry["entry"]) @schema = entry["schema"].symbolize_keys if entry["schema"] @content_type = entry["content_type"].symbolize_keys if entry["content_type"] self end |
#get(field_uid) ⇒ Object
208 209 210 211 |
# File 'lib/contentstack/entry.rb', line 208 def get(field_uid) raise Contentstack::Error("Please send a valid Field UID") if field_uid.class != String @fields[field_uid.to_sym] end |
#include(field_uids) ⇒ Contentstack::Query
185 186 187 188 189 190 |
# File 'lib/contentstack/entry.rb', line 185 def include(field_uids) field_uids = [field_uids] if field_uids.class == String @query[:include] ||= [] @query[:include] = @query[:include] | field_uids self end |
#include_branch(flag = true) ⇒ Contentstack::Entry
Include the branch for publish content.
Example
@entry = @stack.content_type('product').entry(entry_uid)
@entry.include_branch
165 166 167 168 |
# File 'lib/contentstack/entry.rb', line 165 def include_branch(flag=true) @query[:include_branch] = flag self end |
#include_content_type(flag = true) ⇒ Contentstack::Entry
Include object's content_type in response
Example
@entry = @stack.content_type('product').entry(entry_uid)
@entry.include_content_type
139 140 141 142 |
# File 'lib/contentstack/entry.rb', line 139 def include_content_type(flag=true) @query[:include_content_type] = flag self end |
#include_embedded_items ⇒ Contentstack::Query
Include Embedded Objects (Entries and Assets) along with entry/entries details.
Example
@entry = @stack.content_type('product').entry(entry_uid)
@entry.
178 179 180 181 |
# File 'lib/contentstack/entry.rb', line 178 def () @query[:include_embedded_items] = ['BASE'] self end |
#include_fallback(flag = true) ⇒ Contentstack::Entry
Include the fallback locale publish content, if specified locale content is not publish.
Example
@entry = @stack.content_type('product').entry(entry_uid)
@entry.include_fallback
152 153 154 155 |
# File 'lib/contentstack/entry.rb', line 152 def include_fallback(flag=true) @query[:include_fallback] = flag self end |
#include_owner(flag = true) ⇒ Contentstack::Entry
Include object owner's profile in the objects data.
Example
@entry = @stack.content_type('product').entry(entry_uid)
@entry.include_owner
126 127 128 129 |
# File 'lib/contentstack/entry.rb', line 126 def include_owner(flag=true) @query[:include_owner] = flag self end |
#include_reference(reference_field_uids) ⇒ Contentstack::Entry
Add a constraint that requires a particular reference key details.
Example
# Include reference of 'category'
@entry = @stack.content_type('product').entry(entry_uid)
@entry.include_reference('category')
# Include reference of 'category' and 'reviews'
@entry = @stack.content_type('product').entry(entry_uid)
@entry.include_reference(['category', 'reviews'])
101 102 103 |
# File 'lib/contentstack/entry.rb', line 101 def include_reference(reference_field_uids) self.include(reference_field_uids) end |
#include_schema(flag = true) ⇒ Contentstack::Entry
Include schemas of all returned objects along with objects themselves.
Example
@entry = @stack.content_type('product').entry(entry_uid)
@entry.include_schema
113 114 115 116 |
# File 'lib/contentstack/entry.rb', line 113 def include_schema(flag=true) @query[:include_schema] = flag self end |
#locale(code) ⇒ Contentstack::Entry
Get entries from the specified locale.
Example
@entry = @stack.content_type('category').entry(entry_uid)
@entry.locale('en-us')
21 22 23 24 |
# File 'lib/contentstack/entry.rb', line 21 def locale(code) @query[:locale] = code self end |
#only(fields, fields_with_base = nil) ⇒ Contentstack::Entry
Specifies an array of 'only' keys in BASE object that would be 'included' in the response.
Example
# Include only title and description field in response
@entry = @stack.content_type('category').entry(entry_uid)
@entry.only(['title', 'description'])
# Query product and include only the title and description from category reference
@entry = @stack.content_type('product').entry(entry_uid)
@entry.include_reference('category')
.only('category', ['title', 'description'])
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/contentstack/entry.rb', line 42 def only(fields, fields_with_base=nil) q = {} if [Array, String].include?(fields_with_base.class) fields_with_base = [fields_with_base] if fields_with_base.class == String q[fields.to_sym] = fields_with_base else fields = [fields] if fields.class == String q = {BASE: fields} end @query[:only] = q self end |