Class: Contentful::Client
- Inherits:
-
Object
- Object
- Contentful::Client
- Defined in:
- lib/contentful/client.rb
Overview
The client object is initialized with a space and a key and then used for querying resources from this space. See README for details
Constant Summary collapse
- DEFAULT_CONFIGURATION =
Default configuration for Contentful::Client
{ secure: true, raise_errors: true, raise_for_empty_fields: true, dynamic_entries: :manual, api_url: 'cdn.contentful.com', api_version: 1, environment: 'master', authentication_mechanism: :header, resource_builder: ResourceBuilder, resource_mapping: {}, entry_mapping: {}, default_locale: 'en-US', raw_mode: false, gzip_encoded: true, logger: false, proxy_host: nil, proxy_username: nil, proxy_password: nil, proxy_port: nil, timeout_connect: nil, timeout_read: nil, timeout_write: nil, max_rate_limit_retries: 1, max_rate_limit_wait: 60, max_include_resolution_depth: 20, use_camel_case: false, application_name: nil, application_version: nil, integration_name: nil, integration_version: nil }
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
Instance Method Summary collapse
-
#asset(id, query = {}) ⇒ Contentful::Asset
Gets a specific asset.
-
#assets(query = {}) ⇒ Contentful::Array<Contentful::Asset>
Gets a collection of assets.
-
#content_type(id, query = {}) ⇒ Contentful::ContentType
Gets a specific content type.
-
#content_types(query = {}) ⇒ Contentful::Array<Contentful::ContentType>
Gets a collection of content types.
-
#entries(query = {}) ⇒ Contentful::Array<Contentful::Entry>
Gets a collection of entries.
-
#entry(id, query = {}) ⇒ Contentful::Entry
Gets a specific entry.
-
#initialize(given_configuration = {}) ⇒ Client
constructor
A new instance of Client.
-
#locales(query = {}) ⇒ Contentful::Array<Contentful::Locale>
Gets a collection of locales for the current environment.
-
#space(query = {}) ⇒ Contentful::Space
Gets the client’s space.
-
#sync(options = { initial: true }) ⇒ Contentful::Sync
Create a new synchronisation object.
Constructor Details
#initialize(given_configuration = {}) ⇒ Client
Returns a new instance of Client.
95 96 97 98 99 100 101 102 |
# File 'lib/contentful/client.rb', line 95 def initialize(given_configuration = {}) @configuration = default_configuration.merge(given_configuration) normalize_configuration! validate_configuration! setup_logger update_dynamic_entry_cache! if configuration[:dynamic_entries] == :auto end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
50 51 52 |
# File 'lib/contentful/client.rb', line 50 def configuration @configuration end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
50 51 52 |
# File 'lib/contentful/client.rb', line 50 def logger @logger end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
50 51 52 |
# File 'lib/contentful/client.rb', line 50 def proxy @proxy end |
Instance Method Details
#asset(id, query = {}) ⇒ Contentful::Asset
Gets a specific asset
195 196 197 |
# File 'lib/contentful/client.rb', line 195 def asset(id, query = {}) Request.new(self, environment_url('/assets'), query, id).get end |
#assets(query = {}) ⇒ Contentful::Array<Contentful::Asset>
Gets a collection of assets
204 205 206 207 |
# File 'lib/contentful/client.rb', line 204 def assets(query = {}) normalize_select!(query) Request.new(self, environment_url('/assets'), query).get end |
#content_type(id, query = {}) ⇒ Contentful::ContentType
Gets a specific content type
150 151 152 |
# File 'lib/contentful/client.rb', line 150 def content_type(id, query = {}) Request.new(self, environment_url('/content_types'), query, id).get end |
#content_types(query = {}) ⇒ Contentful::Array<Contentful::ContentType>
Gets a collection of content types
159 160 161 |
# File 'lib/contentful/client.rb', line 159 def content_types(query = {}) Request.new(self, environment_url('/content_types'), query).get end |
#entries(query = {}) ⇒ Contentful::Array<Contentful::Entry>
Gets a collection of entries
184 185 186 187 |
# File 'lib/contentful/client.rb', line 184 def entries(query = {}) normalize_select!(query) Request.new(self, environment_url('/entries'), query).get end |
#entry(id, query = {}) ⇒ Contentful::Entry
Gets a specific entry
169 170 171 172 173 174 175 176 177 |
# File 'lib/contentful/client.rb', line 169 def entry(id, query = {}) normalize_select!(query) query['sys.id'] = id entries = Request.new(self, environment_url('/entries'), query).get return entries if configuration[:raw_mode] entries.first end |
#locales(query = {}) ⇒ Contentful::Array<Contentful::Locale>
Gets a collection of locales for the current environment
214 215 216 |
# File 'lib/contentful/client.rb', line 214 def locales(query = {}) Request.new(self, environment_url('/locales'), query).get end |
#space(query = {}) ⇒ Contentful::Space
Gets the client’s space
140 141 142 |
# File 'lib/contentful/client.rb', line 140 def space(query = {}) Request.new(self, '', query).get end |
#sync(options = { initial: true }) ⇒ Contentful::Sync
You will need to call #each_page or #first_page on it
Create a new synchronisation object
418 419 420 |
# File 'lib/contentful/client.rb', line 418 def sync( = { initial: true }) Sync.new(self, ) end |