Class: ContentfulMiddleman::Tools::PreviewProxy
- Inherits:
-
Contentful::Client
- Object
- Contentful::Client
- ContentfulMiddleman::Tools::PreviewProxy
- Defined in:
- lib/contentful_middleman/tools/preview_proxy.rb
Constant Summary collapse
- CACHE_MAPPINGS =
{ entries: { cache: :cached_entry_collection }, assets: { cache: :cached_asset_collection }, entry: { cache: :cached_entries }, asset: { cache: :cached_assets } }
- @@instances =
[]
Class Method Summary collapse
- .days(amount) ⇒ Object
- .hours(amount) ⇒ Object
- .instance(space: '', access_token: '', tries: 3, expires_in: hours(2)) ⇒ Object
- .minutes(amount) ⇒ Object
- .seconds(amount) ⇒ Object
Instance Method Summary collapse
- #asset(id, query = {}) ⇒ Object
- #assets(query = {}) ⇒ Object
- #clear_cache ⇒ Object
- #entries(query = {}) ⇒ Object
- #entry(id, query = {}) ⇒ Object
-
#initialize(space: '', access_token: '', tries: 3, expires_in: self.class.hours(2)) ⇒ PreviewProxy
constructor
A new instance of PreviewProxy.
Constructor Details
#initialize(space: '', access_token: '', tries: 3, expires_in: self.class.hours(2)) ⇒ PreviewProxy
Returns a new instance of PreviewProxy.
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/contentful_middleman/tools/preview_proxy.rb', line 50 def initialize(space: '', access_token: '', tries: 3, expires_in: self.class.hours(2)) super( space: space, access_token: access_token, dynamic_entries: :auto, preview: true ) @cache_tries = tries @expires_in = expires_in clear_cache end |
Class Method Details
.days(amount) ⇒ Object
19 20 21 |
# File 'lib/contentful_middleman/tools/preview_proxy.rb', line 19 def self.days(amount) amount end |
.hours(amount) ⇒ Object
23 24 25 |
# File 'lib/contentful_middleman/tools/preview_proxy.rb', line 23 def self.hours(amount) amount / 24.0 end |
.instance(space: '', access_token: '', tries: 3, expires_in: hours(2)) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/contentful_middleman/tools/preview_proxy.rb', line 7 def self.instance(space: '', access_token: '', tries: 3, expires_in: hours(2)) possible_instance = @@instances.detect { |i| i[:space] == space && i[:access_token] == access_token } if possible_instance.nil? preview_client = PreviewProxy.new(space: space, access_token: access_token, tries: tries, expires_in: expires_in) @@instances << {space: space, access_token: access_token, instance: preview_client} else preview_client = possible_instance[:instance] end preview_client end |
.minutes(amount) ⇒ Object
27 28 29 |
# File 'lib/contentful_middleman/tools/preview_proxy.rb', line 27 def self.minutes(amount) hours(amount) / 60.0 end |
.seconds(amount) ⇒ Object
31 32 33 |
# File 'lib/contentful_middleman/tools/preview_proxy.rb', line 31 def self.seconds(amount) minutes(amount) / 60.0 end |
Instance Method Details
#asset(id, query = {}) ⇒ Object
76 77 78 |
# File 'lib/contentful_middleman/tools/preview_proxy.rb', line 76 def asset(id, query = {}) cache(:asset, ->(query, id) { super(id, query) }, query, id) end |
#assets(query = {}) ⇒ Object
72 73 74 |
# File 'lib/contentful_middleman/tools/preview_proxy.rb', line 72 def assets(query = {}) cache(:assets, ->(query, id) { super(query) }, query) end |
#clear_cache ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/contentful_middleman/tools/preview_proxy.rb', line 80 def clear_cache @cached_entry_collection = {} @cached_asset_collection = {} @cached_entries = {} @cached_assets = {} end |
#entries(query = {}) ⇒ Object
64 65 66 |
# File 'lib/contentful_middleman/tools/preview_proxy.rb', line 64 def entries(query = {}) cache(:entries, ->(query, id) { super(query) }, query) end |
#entry(id, query = {}) ⇒ Object
68 69 70 |
# File 'lib/contentful_middleman/tools/preview_proxy.rb', line 68 def entry(id, query = {}) cache(:entry, ->(query, id) { super(id, query) }, query, id) end |