middleman-cloudflare_purge 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.ruby-version +1 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/lib/middleman-cloudflare_purge.rb +7 -0
- data/lib/middleman-cloudflare_purge/commands.rb +29 -0
- data/lib/middleman-cloudflare_purge/extension.rb +71 -0
- data/middleman-cloudflare_purge.gemspec +15 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 53b2be249041aeb9675a4a8238a08b542536b62a
|
4
|
+
data.tar.gz: 3814254541177f6a0a71edf9f61a9e39ba8e025b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 89e8fe062e60146690b4e1e8eff0554dc88751e9343cbacd7bc05c2b705d9174339550f59dd4b14c2bdea95f29e7b4171fa344cac350259e837656d7cddb21cc
|
7
|
+
data.tar.gz: 222a22acfbbf41c9299b2df3e0d571ac90936ecc483e14b63f2cdc153a37714bf5f2169ac99886f129128cea410797e15023560ed21fa2941f603a34d50bebec
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.1
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Michael McLellan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'middleman-core/cli'
|
2
|
+
require 'middleman-cloudflare_purge/extension'
|
3
|
+
|
4
|
+
module Middleman
|
5
|
+
module Cli
|
6
|
+
class CloudflarePurge < Thor
|
7
|
+
include Thor::Actions
|
8
|
+
|
9
|
+
check_unknown_options!
|
10
|
+
|
11
|
+
namespace :cloudflare_purge
|
12
|
+
|
13
|
+
def self.exit_on_failure?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'cloudflare_purge', 'Purges all files from the Cloudflare cache'
|
18
|
+
def cloudflare_purge
|
19
|
+
shared_inst = ::Middleman::Application.server.inst
|
20
|
+
|
21
|
+
if shared_inst.respond_to? :cloudflare_purge_activated
|
22
|
+
::Middleman::CloudflarePurge.purge(options)
|
23
|
+
else
|
24
|
+
raise Thor::Error.new 'You need to activate the cloudflare_purge extension in config.rb'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'middleman-core'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module Middleman
|
5
|
+
module CloudflarePurge
|
6
|
+
class Options < Struct.new(
|
7
|
+
:token,
|
8
|
+
:email,
|
9
|
+
:domain,
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def options
|
15
|
+
@@options
|
16
|
+
end
|
17
|
+
|
18
|
+
def registered(app, options_hash = {}, &block)
|
19
|
+
options = Options.new(options_hash)
|
20
|
+
yield options if block_given?
|
21
|
+
|
22
|
+
@@options = options
|
23
|
+
|
24
|
+
app.send :include, Helpers
|
25
|
+
|
26
|
+
load_config
|
27
|
+
end
|
28
|
+
alias :included :registered
|
29
|
+
|
30
|
+
def load_config
|
31
|
+
root_path = ::Middleman::Application.root
|
32
|
+
config_file = File.join(root_path, '.cloudflare_purge')
|
33
|
+
|
34
|
+
if File.exists?(config_file)
|
35
|
+
config = YAML.load(File.open(config_file, 'r'))
|
36
|
+
config.each do |k, v|
|
37
|
+
options[k] = v
|
38
|
+
end
|
39
|
+
else
|
40
|
+
return {}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def purge(opts)
|
45
|
+
uri = URI('https://www.cloudflare.com/api_json.html')
|
46
|
+
params = {
|
47
|
+
tkn: options.token,
|
48
|
+
email: options.email,
|
49
|
+
z: options.domain,
|
50
|
+
a: 'fpurge_ts',
|
51
|
+
v: 1
|
52
|
+
}
|
53
|
+
|
54
|
+
res = Net::HTTP.post_form(uri, params)
|
55
|
+
body = JSON.parse(res.body)
|
56
|
+
|
57
|
+
if body['result'] == 'success'
|
58
|
+
puts 'Success!'
|
59
|
+
else
|
60
|
+
abort body['msg']
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
module Helpers
|
65
|
+
def cloudflare_purge_activated
|
66
|
+
true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = 'middleman-cloudflare_purge'
|
3
|
+
gem.version = '0.0.5'
|
4
|
+
gem.authors = ['Michael McLellan']
|
5
|
+
gem.email = 'jmikem825@gmail.com'
|
6
|
+
gem.description = 'Cloudflare cache purging for Middleman'
|
7
|
+
gem.summary = 'Purge files from your Cloudflare cache'
|
8
|
+
gem.homepage = 'https://github.com/jmmk/middleman-cloudflare_purge'
|
9
|
+
gem.license = 'MIT'
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($/)
|
12
|
+
gem.require_paths = ['lib']
|
13
|
+
|
14
|
+
gem.add_runtime_dependency 'middleman-core', '~> 3.0'
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-cloudflare_purge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael McLellan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: middleman-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
description: Cloudflare cache purging for Middleman
|
28
|
+
email: jmikem825@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ".gitignore"
|
34
|
+
- ".ruby-version"
|
35
|
+
- Gemfile
|
36
|
+
- Gemfile.lock
|
37
|
+
- LICENSE
|
38
|
+
- lib/middleman-cloudflare_purge.rb
|
39
|
+
- lib/middleman-cloudflare_purge/commands.rb
|
40
|
+
- lib/middleman-cloudflare_purge/extension.rb
|
41
|
+
- middleman-cloudflare_purge.gemspec
|
42
|
+
homepage: https://github.com/jmmk/middleman-cloudflare_purge
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.2.2
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Purge files from your Cloudflare cache
|
66
|
+
test_files: []
|