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, dynamic_entries: :manual, api_url: 'cdn.contentful.com', api_version: 1, authentication_mechanism: :header, resource_builder: ResourceBuilder, resource_mapping: {}, entry_mapping: {}, default_locale: 'en-US', raw_mode: false, gzip_encoded: true, logger: false, log_level: Logger::INFO, proxy_host: nil, proxy_username: nil, proxy_password: nil, proxy_port: nil }
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#dynamic_entry_cache ⇒ Object
readonly
Returns the value of attribute dynamic_entry_cache.
-
#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.
-
#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.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/contentful/client.rb', line 67 def initialize(given_configuration = {}) @configuration = default_configuration.merge(given_configuration) normalize_configuration! validate_configuration! setup_logger if configuration[:dynamic_entries] == :auto update_dynamic_entry_cache! else @dynamic_entry_cache = {} end end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
36 37 38 |
# File 'lib/contentful/client.rb', line 36 def configuration @configuration end |
#dynamic_entry_cache ⇒ Object (readonly)
Returns the value of attribute dynamic_entry_cache.
36 37 38 |
# File 'lib/contentful/client.rb', line 36 def dynamic_entry_cache @dynamic_entry_cache end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
36 37 38 |
# File 'lib/contentful/client.rb', line 36 def logger @logger end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
36 37 38 |
# File 'lib/contentful/client.rb', line 36 def proxy @proxy end |
Instance Method Details
#asset(id, query = {}) ⇒ Contentful::Asset
Gets a specific asset
155 156 157 |
# File 'lib/contentful/client.rb', line 155 def asset(id, query = {}) Request.new(self, '/assets', query, id).get end |
#assets(query = {}) ⇒ Contentful::Array<Contentful::Asset>
Gets a collection of assets
164 165 166 |
# File 'lib/contentful/client.rb', line 164 def assets(query = {}) Request.new(self, '/assets', query).get end |
#content_type(id, query = {}) ⇒ Contentful::ContentType
Gets a specific content type
117 118 119 |
# File 'lib/contentful/client.rb', line 117 def content_type(id, query = {}) Request.new(self, '/content_types', query, id).get end |
#content_types(query = {}) ⇒ Contentful::Array<Contentful::ContentType>
Gets a collection of content types
126 127 128 |
# File 'lib/contentful/client.rb', line 126 def content_types(query = {}) Request.new(self, '/content_types', query).get end |
#entries(query = {}) ⇒ Contentful::Array<Contentful::Entry>
Gets a collection of entries
145 146 147 |
# File 'lib/contentful/client.rb', line 145 def entries(query = {}) Request.new(self, '/entries', query).get end |
#entry(id, query = {}) ⇒ Contentful::Entry
Gets a specific entry
136 137 138 |
# File 'lib/contentful/client.rb', line 136 def entry(id, query = {}) Request.new(self, '/entries', query, id).get end |
#space(query = {}) ⇒ Contentful::Space
Gets the client’s space
107 108 109 |
# File 'lib/contentful/client.rb', line 107 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
252 253 254 |
# File 'lib/contentful/client.rb', line 252 def sync( = { initial: true }) Sync.new(self, ) end |