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 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.



96
97
98
99
100
101
102
103
# File 'lib/wcc/contentful/simple_client.rb', line 96

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



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_typeObject



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