Class: WCC::Contentful::SimpleClient::Cdn

Inherits:
WCC::Contentful::SimpleClient show all
Defined in:
lib/wcc/contentful/simple_client.rb

Overview

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.

Direct Known Subclasses

Preview

Constant Summary

Constants inherited from WCC::Contentful::SimpleClient

ADAPTERS

Instance Attribute Summary

Attributes inherited from WCC::Contentful::SimpleClient

#api_url, #space

Instance Method Summary collapse

Methods inherited from WCC::Contentful::SimpleClient

#get, load_adapter

Constructor Details

#initialize(space:, access_token:, **options) ⇒ Cdn

Returns a new instance of Cdn.



123
124
125
126
127
128
129
130
# File 'lib/wcc/contentful/simple_client.rb', line 123

def initialize(space:, access_token:, **options)
  super(
    api_url: options[:api_url] || 'https://cdn.contentful.com/',
    space: space,
    access_token: access_token,
    **options
  )
end

Instance Method Details

#asset(key, query = {}) ⇒ Object

Gets an asset by ID



149
150
151
152
# File 'lib/wcc/contentful/simple_client.rb', line 149

def asset(key, query = {})
  resp = get("assets/#{key}", query)
  resp.assert_ok!
end

#assets(query = {}) ⇒ Object

Queries assets with optional query parameters



155
156
157
158
# File 'lib/wcc/contentful/simple_client.rb', line 155

def assets(query = {})
  resp = get('assets', query)
  resp.assert_ok!
end

#client_typeObject



132
133
134
# File 'lib/wcc/contentful/simple_client.rb', line 132

def client_type
  'cdn'
end

#content_types(query = {}) ⇒ Object

Queries content types with optional query parameters



161
162
163
164
# File 'lib/wcc/contentful/simple_client.rb', line 161

def content_types(query = {})
  resp = get('content_types', query)
  resp.assert_ok!
end

#entries(query = {}) ⇒ Object

Queries entries with optional query parameters



143
144
145
146
# File 'lib/wcc/contentful/simple_client.rb', line 143

def entries(query = {})
  resp = get('entries', query)
  resp.assert_ok!
end

#entry(key, query = {}) ⇒ Object

Gets an entry by ID



137
138
139
140
# File 'lib/wcc/contentful/simple_client.rb', line 137

def entry(key, query = {})
  resp = get("entries/#{key}", query)
  resp.assert_ok!
end

#sync(sync_token: nil, **query) ⇒ Object

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.



172
173
174
175
176
177
178
179
180
181
182
# File 'lib/wcc/contentful/simple_client.rb', line 172

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 = SyncResponse.new(get('sync', query))
  resp.assert_ok!
end