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 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
Constructor Details
#initialize(space:, access_token:, **options) ⇒ Cdn
Returns a new instance of Cdn.
96 97 98 99 100 101 102 103 |
# File 'lib/wcc/contentful/simple_client.rb', line 96 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
125 126 127 128 |
# File 'lib/wcc/contentful/simple_client.rb', line 125 def asset(key, query = {}) resp = get("assets/#{key}", query) resp.assert_ok! end |
#assets(query = {}) ⇒ Object
Queries assets with optional query parameters
132 133 134 135 |
# File 'lib/wcc/contentful/simple_client.rb', line 132 def assets(query = {}) resp = get('assets', query) resp.assert_ok! end |
#client_type ⇒ Object
105 106 107 |
# File 'lib/wcc/contentful/simple_client.rb', line 105 def client_type 'cdn' end |
#content_types(query = {}) ⇒ Object
Queries content types with optional query parameters
139 140 141 142 |
# File 'lib/wcc/contentful/simple_client.rb', line 139 def content_types(query = {}) resp = get('content_types', query) resp.assert_ok! end |
#entries(query = {}) ⇒ Object
Queries entries with optional query parameters
118 119 120 121 |
# File 'lib/wcc/contentful/simple_client.rb', line 118 def entries(query = {}) resp = get('entries', query) resp.assert_ok! end |
#entry(key, query = {}) ⇒ Object
Gets an entry by ID
111 112 113 114 |
# File 'lib/wcc/contentful/simple_client.rb', line 111 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.
151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/wcc/contentful/simple_client.rb', line 151 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 |