Class: ContentfulLite::Client
- Inherits:
-
Object
- Object
- ContentfulLite::Client
- Defined in:
- lib/contentful_lite/client.rb
Defined Under Namespace
Classes: NotFoundError, RequestError
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#preview ⇒ Object
readonly
Returns the value of attribute preview.
-
#space_id ⇒ Object
readonly
Returns the value of attribute space_id.
Instance Method Summary collapse
-
#asset(id, query = {}) ⇒ ContentfulLite::Asset
Gets a single asset from Contentful API.
-
#assets(query = {}) ⇒ ContentfulLite::AssetsArray
Gets an array of assets from Contentful API.
-
#build_resource(raw) ⇒ ContentfulLite::Entry, ...
Build an entry resource from a raw Contentful API response.
-
#entries(query = {}) ⇒ ContentfulLite::EntriesArray
Gets an array of entries from Contentful API.
-
#entry(id, query = {}) ⇒ ContentfulLite::Entry
Gets a single entry from Contentful API.
-
#initialize(space_id:, access_token:, environment: nil, preview: false) ⇒ Client
constructor
Creates the Contentful Client.
Constructor Details
#initialize(space_id:, access_token:, environment: nil, preview: false) ⇒ Client
Creates the Contentful Client
23 24 25 26 27 28 |
# File 'lib/contentful_lite/client.rb', line 23 def initialize(space_id:, access_token:, environment: nil, preview: false) @space_id = space_id @environment = environment @preview = preview @access_token = access_token end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
16 17 18 |
# File 'lib/contentful_lite/client.rb', line 16 def environment @environment end |
#preview ⇒ Object (readonly)
Returns the value of attribute preview.
16 17 18 |
# File 'lib/contentful_lite/client.rb', line 16 def preview @preview end |
#space_id ⇒ Object (readonly)
Returns the value of attribute space_id.
16 17 18 |
# File 'lib/contentful_lite/client.rb', line 16 def space_id @space_id end |
Instance Method Details
#asset(id, query = {}) ⇒ ContentfulLite::Asset
Gets a single asset from Contentful API
49 50 51 |
# File 'lib/contentful_lite/client.rb', line 49 def asset(id, query = {}) ContentfulLite::Asset.new(request("assets/#{id}", query)) end |
#assets(query = {}) ⇒ ContentfulLite::AssetsArray
Gets an array of assets from Contentful API
56 57 58 |
# File 'lib/contentful_lite/client.rb', line 56 def assets(query = {}) ContentfulLite::AssetsArray.new(request(:assets, query)) end |
#build_resource(raw) ⇒ ContentfulLite::Entry, ...
Build an entry resource from a raw Contentful API response
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/contentful_lite/client.rb', line 63 def build_resource(raw) case raw['sys']['type'] when 'Entry' parse_entry(raw) when 'Asset' ContentfulLite::Asset.new(raw) when 'DeletedEntry' ContentfulLite::DeletedEntry.new(raw) end end |
#entries(query = {}) ⇒ ContentfulLite::EntriesArray
Gets an array of entries from Contentful API
33 34 35 |
# File 'lib/contentful_lite/client.rb', line 33 def entries(query = {}) ContentfulLite::EntriesArray.new(request(:entries, query)) end |
#entry(id, query = {}) ⇒ ContentfulLite::Entry
Gets a single entry from Contentful API
41 42 43 |
# File 'lib/contentful_lite/client.rb', line 41 def entry(id, query = {}) parse_entry request("entries/#{id}", query) end |