contentful_rails 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 287f62b00e44548213d22bc2bd365a1f961324a6
|
4
|
+
data.tar.gz: 280b863df836812bb18113e5ecab529f060c7007
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d19254615f19e2d81439f30d165c4d78a444d8dfaa9c93e66652b9b6b4c9818656db82f43712a8440966d30ad602e0ca531e05a2939dc101f4124674ded03cb
|
7
|
+
data.tar.gz: 40857c4ba6cb0565dab16183d8c57d27556a3d0ae6233cd5b2e50da6618466c46e99395767a4b3a6912ed86c13c2f3020a94f2fde7bb696884e1a149ea229cdf
|
@@ -1,10 +1,16 @@
|
|
1
1
|
class ContentfulRails::WebhooksController < ActionController::Base
|
2
|
+
protect_from_forgery with: :exception
|
3
|
+
|
2
4
|
if ContentfulRails.configuration.authenticate_webhooks
|
3
5
|
http_basic_authenticate_with name: ContentfulRails.configuration.webhooks_username,
|
4
6
|
password: ContentfulRails.configuration.webhooks_password
|
5
7
|
end
|
6
|
-
|
7
|
-
|
8
|
+
params = [:verify_authenticity_token, {:only => [:create], raise: false}]
|
9
|
+
if Rails::VERSION::MAJOR > 4
|
10
|
+
skip_before_action *params
|
11
|
+
else
|
12
|
+
skip_before_filter *params
|
13
|
+
end
|
8
14
|
|
9
15
|
#this is where we receive a webhook, via a POST
|
10
16
|
def create
|
@@ -39,4 +45,4 @@ class ContentfulRails::WebhooksController < ActionController::Base
|
|
39
45
|
|
40
46
|
|
41
47
|
|
42
|
-
end
|
48
|
+
end
|
@@ -4,12 +4,8 @@ module ContentfulRails
|
|
4
4
|
# to check the cache for its timestamp before making an expensive API call.
|
5
5
|
# Also includes a module method to remove an existing timestamp.
|
6
6
|
module Timestamps
|
7
|
-
def self.
|
7
|
+
def self.prepended(base)
|
8
8
|
base.extend ClassMethods
|
9
|
-
base.class_eval do
|
10
|
-
alias_method_chain :updated_at, :caching
|
11
|
-
alias_method_chain :cache_key, :preview
|
12
|
-
end
|
13
9
|
end
|
14
10
|
|
15
11
|
module ClassMethods
|
@@ -26,31 +22,28 @@ module ContentfulRails
|
|
26
22
|
end
|
27
23
|
end
|
28
24
|
|
25
|
+
def timestamp_cache_key
|
26
|
+
self.class.timestamp_cache_key(id)
|
27
|
+
end
|
28
|
+
|
29
29
|
|
30
|
-
|
31
|
-
def updated_at_with_caching
|
30
|
+
def updated_at
|
32
31
|
if ContentfulRails.configuration.perform_caching && !ContentfulModel.use_preview_api
|
33
32
|
Rails.cache.fetch(self.timestamp_cache_key) do
|
34
|
-
|
33
|
+
super
|
35
34
|
end
|
36
35
|
else
|
37
|
-
|
36
|
+
super
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
41
|
-
def
|
42
|
-
self.class.timestamp_cache_key(id)
|
43
|
-
end
|
44
|
-
|
45
|
-
def cache_key_with_preview
|
40
|
+
def cache_key
|
46
41
|
if ContentfulModel.use_preview_api
|
47
|
-
"preview/#{
|
42
|
+
"preview/#{super}"
|
48
43
|
else
|
49
|
-
|
44
|
+
super
|
50
45
|
end
|
51
46
|
end
|
52
|
-
|
53
|
-
|
54
47
|
end
|
55
48
|
end
|
56
49
|
end
|
@@ -23,8 +23,10 @@ module ContentfulRails
|
|
23
23
|
#Iterate through all models which inherit from ContentfulModel::Base
|
24
24
|
#and add an entry mapping for them, so calls to the Contentful API return
|
25
25
|
#the appropriate classes
|
26
|
+
#If eager_load_entry_mapping is false, engine assumes entry mapping is set manually by
|
27
|
+
#ContentfulRails.contentful_options[:entry_mapping] (passed through to Contentful.entry_mapping config)
|
26
28
|
initializer "add_entry_mappings", after: :configure_contentful do
|
27
|
-
if defined?(ContentfulModel)
|
29
|
+
if defined?(ContentfulModel) && ContentfulRails.configuration.eager_load_entry_mapping
|
28
30
|
Rails.application.eager_load!
|
29
31
|
ContentfulModel::Base.descendents.each do |klass|
|
30
32
|
klass.send(:add_entry_mapping)
|
@@ -48,8 +50,19 @@ module ContentfulRails
|
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
53
|
+
initializer "prepend_timestamps_module", after: :subscribe_to_webhook_events do
|
54
|
+
if defined?(::ContentfulModel)
|
55
|
+
ContentfulModel::Base.send(:prepend, ContentfulRails::Caching::Timestamps)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
51
59
|
initializer "add_contentful_mime_type" do
|
52
|
-
|
60
|
+
content_type = "application/vnd.contentful.management.v1+json"
|
61
|
+
Mime::Type.register content_type, :contentful_json, [content_type]
|
62
|
+
default_parsers = Rails::VERSION::MAJOR > 4 ? ActionDispatch::Http::Parameters::DEFAULT_PARSERS : ActionDispatch::ParamsParser::DEFAULT_PARSERS
|
63
|
+
default_parsers[Mime::Type.lookup(content_type)] = lambda do |body|
|
64
|
+
JSON.parse(body)
|
65
|
+
end
|
53
66
|
end
|
54
67
|
|
55
68
|
initializer "add_preview_support" do
|
@@ -57,12 +70,5 @@ module ContentfulRails
|
|
57
70
|
include ContentfulRails::Preview
|
58
71
|
end
|
59
72
|
end
|
60
|
-
|
61
|
-
config.to_prepare do
|
62
|
-
if defined?(::ContentfulModel)
|
63
|
-
ContentfulModel::Base.send(:include, ContentfulRails::Caching::Timestamps)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
73
|
end
|
68
74
|
end
|
data/lib/contentful_rails.rb
CHANGED
@@ -34,12 +34,14 @@ module ContentfulRails
|
|
34
34
|
:preview_username,
|
35
35
|
:preview_password,
|
36
36
|
:preview_domain,
|
37
|
-
:enable_preview_domain
|
37
|
+
:enable_preview_domain,
|
38
|
+
:eager_load_entry_mapping
|
38
39
|
|
39
40
|
def initialize
|
40
41
|
@authenticate = true
|
41
42
|
@slug_delimiter = "-"
|
42
43
|
@perform_caching = Rails.configuration.action_controller.perform_caching
|
44
|
+
@eager_load_entry_mapping = true
|
43
45
|
@contentful_options = {}
|
44
46
|
end
|
45
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contentful_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Error Creative Studio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: contentful_model
|