jekyll-cloudflare-cache-purge 0.0.1.pre.rc3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1e6c5226bfb21d9e21c68d041dc50b442d005375b7a0d533f2e0c4e47c8854de
4
+ data.tar.gz: c1284f4e9aefb30b345bfb88d138921cfdb0c90b5a36370869190c20d4b6d236
5
+ SHA512:
6
+ metadata.gz: 8121aad238c3881fb072421bfb4a51d9fbe3a3bab4a0c58fecb322e6dc59700f0a338752a8019077018b7702c1a0a6a4aed19cfe1d6b819a2e9d999bdbacc864
7
+ data.tar.gz: cef3cd6c11af98c5b352ac5ff3c6f9b57df49e6168e4dfe319ad9b293ced4d4abff894fb2bbe37d36d8f0cfb7ecfe8297e2596993ea5ff934d13c2013e647845
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module CloudflareCachePurge
5
+ VERSION = "0.0.1-rc3"
6
+ end
7
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CloudflareCachePurge
4
+ def self.run
5
+ new.tap(&:run)
6
+ end
7
+
8
+ def run
9
+ if env_vars_missing?
10
+ return Jekyll.logger.warn("Cloudflare Cache:",
11
+ "Skipping - please set CLOUDFLARE_API_TOKEN " \
12
+ "and CLOUDFLARE_ZONE to enable")
13
+ end
14
+
15
+ if response.is_a?(Net::HTTPSuccess)
16
+ Jekyll.logger.info "Cloudflare Cache:", "Purged"
17
+ else
18
+ Jekyll.logger.warn "Cloudflare Cache:", "FAILED: #{response.body}"
19
+ end
20
+ end
21
+
22
+ def response
23
+ @response ||= http.request(request)
24
+ end
25
+
26
+ def request
27
+ @request ||= Net::HTTP::Post.new(uri.request_uri).tap do |req|
28
+ req["Authorization"] = "Bearer #{ENV.fetch("CLOUDFLARE_API_TOKEN")}"
29
+ req["Content-Type"] = "application/json"
30
+ req.body = '{"purge_everything":true}'
31
+ end
32
+ end
33
+
34
+ def http
35
+ @http ||= Net::HTTP.new(uri.host, uri.port).tap do |h|
36
+ h.use_ssl = true
37
+ h.verify_mode = OpenSSL::SSL::VERIFY_PEER
38
+ end
39
+ end
40
+
41
+ def uri
42
+ @uri ||= URI("https://api.cloudflare.com/client/v4/zones/#{ENV.fetch("CLOUDFLARE_ZONE")}/purge_cache")
43
+ end
44
+
45
+ def env_vars_missing?
46
+ %w(CLOUDFLARE_API_TOKEN CLOUDFLARE_ZONE).each do |key|
47
+ return true unless ENV.key?(key)
48
+ end
49
+
50
+ false
51
+ end
52
+ end
53
+
54
+ Jekyll::Hooks.register :site, :post_write do |_page|
55
+ CloudflareCachePurge.run
56
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-cloudflare-cache-purge
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre.rc3
5
+ platform: ruby
6
+ authors:
7
+ - Matt Hall
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.7'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.7'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '13.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '13.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rubocop-jekyll
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.12.0
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.12.0
89
+ - !ruby/object:Gem::Dependency
90
+ name: typhoeus
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0.7'
96
+ - - "<"
97
+ - !ruby/object:Gem::Version
98
+ version: '2.0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0.7'
106
+ - - "<"
107
+ - !ruby/object:Gem::Version
108
+ version: '2.0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: webmock
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: 3.18.1
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: 3.18.1
123
+ description:
124
+ email:
125
+ - matt@codebeef.com
126
+ executables: []
127
+ extensions: []
128
+ extra_rdoc_files: []
129
+ files:
130
+ - lib/jekyll-cloudflare-cache-purge.rb
131
+ - lib/jekyll-cloudflare-cache-purge/version.rb
132
+ homepage: https://github.com/codebeef/jekyll-cloudflare-cache-purge
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 2.5.0
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">"
148
+ - !ruby/object:Gem::Version
149
+ version: 1.3.1
150
+ requirements: []
151
+ rubygems_version: 3.0.3.1
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: A Jekyll plugin to purge the cloudflare cache on build
155
+ test_files: []