class Renderful::Provider::Contentful

Public Class Methods

new(options) click to toggle source
Calls superclass method Renderful::Provider::Base::new
# File lib/renderful/provider/contentful.rb, line 6
def initialize(options)
  super

  fail ArgumentError, 'contentful option is required!' unless contentful
end

Public Instance Methods

cache_keys_to_invalidate(webhook_body) click to toggle source
# File lib/renderful/provider/contentful.rb, line 23
def cache_keys_to_invalidate(webhook_body)
  params = webhook_body.is_a?(String) ? JSON.parse(webhook_body) : webhook_body

  keys_to_invalidate = [ContentEntry.build_cache_key(self, id: params['sys']['id'])]
  keys_to_invalidate += contentful.entries(links_to_entry: params['sys']['id']).map do |entry|
    ContentEntry.build_cache_key(self, id: entry.id)
  end

  {
    keys: keys_to_invalidate,
    patterns: [],
  }
end
cache_prefix() click to toggle source
# File lib/renderful/provider/contentful.rb, line 12
def cache_prefix
  :contentful
end
find_entry(entry_id) click to toggle source
# File lib/renderful/provider/contentful.rb, line 16
def find_entry(entry_id)
  entry = contentful.entry(entry_id)
  raise Error::EntryNotFoundError, entry_id unless entry

  wrap_entry(entry)
end

Private Instance Methods

contentful() click to toggle source
# File lib/renderful/provider/contentful.rb, line 50
def contentful
  options[:contentful]
end
entries_linking_to(entry_id) click to toggle source
# File lib/renderful/provider/contentful.rb, line 48
def entries_linking_to(entry_id); end
wrap_entry(entry) click to toggle source
# File lib/renderful/provider/contentful.rb, line 39
def wrap_entry(entry)
  ContentEntry.new(
    provider: self,
    id: entry.id,
    content_type: entry.content_type.id,
    fields: entry.fields,
  )
end