class WCC::Contentful::SimpleClient::Cdn

The CDN SimpleClient accesses 'cdn.contentful.com' to get raw JSON responses. It exposes methods to query entries, assets, and content_types. The responses are instances of WCC::Contentful::SimpleClient::Response which handles paging automatically.

@api Client

Public Class Methods

new(space:, access_token:, **options) click to toggle source
Calls superclass method WCC::Contentful::SimpleClient::new
# File lib/wcc/contentful/simple_client.rb, line 160
def initialize(space:, access_token:, **options)
  super(
    api_url: options[:api_url] || 'https://cdn.contentful.com/',
    space: space,
    access_token: access_token,
    **options
  )
end

Public Instance Methods

asset(key, query = {}) click to toggle source

Gets an asset by ID

# File lib/wcc/contentful/simple_client.rb, line 192
def asset(key, query = {})
  resp =
    _instrument 'entries', type: 'Asset', id: key, query: query do
      get("assets/#{key}", query)
    end
  resp.assert_ok!
end
assets(query = {}) click to toggle source

Queries assets with optional query parameters

# File lib/wcc/contentful/simple_client.rb, line 201
def assets(query = {})
  resp =
    _instrument 'entries', type: 'Asset', query: query do
      get('assets', query)
    end
  resp.assert_ok!
end
client_type() click to toggle source
# File lib/wcc/contentful/simple_client.rb, line 169
def client_type
  'cdn'
end
content_types(query = {}) click to toggle source

Queries content types with optional query parameters

# File lib/wcc/contentful/simple_client.rb, line 210
def content_types(query = {})
  resp =
    _instrument 'content_types', query: query do
      get('content_types', query)
    end
  resp.assert_ok!
end
entries(query = {}) click to toggle source

Queries entries with optional query parameters

# File lib/wcc/contentful/simple_client.rb, line 183
def entries(query = {})
  resp =
    _instrument 'entries', type: 'Entry', query: query do
      get('entries', query)
    end
  resp.assert_ok!
end
entry(key, query = {}) click to toggle source

Gets an entry by ID

# File lib/wcc/contentful/simple_client.rb, line 174
def entry(key, query = {})
  resp =
    _instrument 'entries', id: key, type: 'Entry', query: query do
      get("entries/#{key}", query)
    end
  resp.assert_ok!
end
sync(sync_token: nil, **query) click to toggle source

Accesses the Sync API to get a list of items that have changed since the last sync.

If `sync_token` is nil, an initial sync is performed. Returns a WCC::Contentful::SimpleClient::SyncResponse which handles paging automatically.

# File lib/wcc/contentful/simple_client.rb, line 224
def sync(sync_token: nil, **query)
  sync_token =
    if sync_token
      { sync_token: sync_token }
    else
      { initial: true }
    end
  query = query.merge(sync_token)
  resp =
    _instrument 'sync', sync_token: sync_token, query: query do
      get('sync', query)
    end
  resp = SyncResponse.new(resp)
  resp.assert_ok!
end