Class: WCC::Contentful::SimpleClient::Cdn
- Inherits:
-
WCC::Contentful::SimpleClient
- Object
- WCC::Contentful::SimpleClient
- WCC::Contentful::SimpleClient::Cdn
- 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
Constant Summary
Constants inherited from WCC::Contentful::SimpleClient
Instance Attribute Summary
Attributes inherited from WCC::Contentful::SimpleClient
Instance Method Summary collapse
-
#asset(key, query = {}) ⇒ Object
Gets an asset by ID.
-
#assets(query = {}) ⇒ Object
Queries assets with optional query parameters.
- #client_type ⇒ Object
-
#content_types(query = {}) ⇒ Object
Queries content types with optional query parameters.
-
#entries(query = {}) ⇒ Object
Queries entries with optional query parameters.
-
#entry(key, query = {}) ⇒ Object
Gets an entry by ID.
-
#initialize(space:, access_token:, **options) ⇒ Cdn
constructor
A new instance of Cdn.
-
#sync(sync_token: nil, **query) ⇒ Object
Accesses the Sync API to get a list of items that have changed since the last sync.
Methods inherited from WCC::Contentful::SimpleClient
Methods included from Instrumentation
#_instrumentation_event_prefix, instrument
Constructor Details
#initialize(space:, access_token:, **options) ⇒ Cdn
Returns a new instance of Cdn.
160 161 162 163 164 165 166 167 |
# File 'lib/wcc/contentful/simple_client.rb', line 160 def initialize(space:, access_token:, **) super( api_url: [:api_url] || 'https://cdn.contentful.com/', space: space, access_token: access_token, ** ) end |
Instance Method Details
#asset(key, query = {}) ⇒ Object
Gets an asset by ID
192 193 194 195 196 197 198 |
# 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 = {}) ⇒ Object
Queries assets with optional query parameters
201 202 203 204 205 206 207 |
# 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 ⇒ Object
169 170 171 |
# File 'lib/wcc/contentful/simple_client.rb', line 169 def client_type 'cdn' end |
#content_types(query = {}) ⇒ Object
Queries content types with optional query parameters
210 211 212 213 214 215 216 |
# 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 = {}) ⇒ Object
Queries entries with optional query parameters
183 184 185 186 187 188 189 |
# 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 = {}) ⇒ Object
Gets an entry by ID
174 175 176 177 178 179 180 |
# 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) ⇒ 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.
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# 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 |