middleman-cdn 0.3.0 → 0.3.1

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: 316430650f5872061c138b58a8762b27a35550e2
4
- data.tar.gz: c6899ae2f56b98123c61cac84d77fdb4f4f866d7
3
+ metadata.gz: f975832d615b4eadaa5cd9faeee9666f4ac7e28c
4
+ data.tar.gz: da8f4109334891f5baf7f5497fe8ac9c946512b8
5
5
  SHA512:
6
- metadata.gz: 4961cbebfbe185e75ec74612a4a8992f88cbda4a4814a1577ab5fdc48c31c04f80ab58ad3ebd1cbb456a13553343ddbb88ae7909f31997d8828f9301e2d35e11
7
- data.tar.gz: 3062f33bcad19b95088ffe2e161d7abd45994d62c1b0d9427f9e68532defa139367035c765d8f15f94a70d96890778e664a5faeea504d242159fa8f06ad92d03
6
+ metadata.gz: b59a7548cbb4fdfd2572bfe12c04bbf5bc85987b411d5a409a4f3329333975791fb2a1303703c97e13b6886d9a5b5ba91f6d5f40b86d302799609cdb2e656ff7
7
+ data.tar.gz: 744d1709675329e9494957f6ad43cf389c9117c2727225d0a41b888b7c9c3a021dfd9f871306defe01dad765a983a2827c1c33495ae1b22f25152673109098c8
@@ -39,29 +39,29 @@ module Middleman
39
39
  raise
40
40
  end
41
41
 
42
- cloudflare = ::Cloudflare::connection(options[:client_api_key], options[:email])
42
+ cloudflare = ::Cloudflare::connect(key: options[:client_api_key], email: options[:email])
43
+ zone = cloudflare.zones.find_by_name(options[:zone])
43
44
  if all || (options[:invalidate_zone_for_many_files] && files.count > INVALIDATE_ZONE_THRESHOLD)
44
45
  begin
45
- say_status("Invalidating zone #{options[:zone]}... ", newline: false)
46
- cloudflare.fpurge_ts(options[:zone])
46
+ say_status("Invalidating zone #{zone}... ", newline: false)
47
+ zone.purge_cache
47
48
  rescue => e
48
49
  say_status(", " + ANSI.red{ "error: #{e.message}" }, header: false)
49
50
  else
50
51
  say_status(ANSI.green{ "✔" }, header: false)
51
52
  end
52
53
  else
53
- options[:base_urls].each do |base_url|
54
- files.each do |file|
55
- begin
56
- url = "#{base_url}#{file}"
57
- say_status("Invalidating #{url}... ", newline: false)
58
- cloudflare.zone_file_purge(options[:zone], "#{base_url}#{file}")
59
- rescue => e
60
- say_status(", " + ANSI.red{ "error: #{e.message}" }, header: false)
61
- else
62
- say_status(ANSI.green{ "✔" }, header: false)
63
- end
54
+ begin
55
+ urls = options[:base_urls].map do |base_url|
56
+ files.map { |file| "#{base_url}#{file}" }
64
57
  end
58
+
59
+ say_status("Invalidating #{urls}... ", newline: false)
60
+ zone.purge_cache(files: urls.flatten)
61
+ rescue => e
62
+ say_status(", " + ANSI.red{ "error: #{e.message}" }, header: false)
63
+ else
64
+ say_status(ANSI.green{ "✔" }, header: false)
65
65
  end
66
66
  end
67
67
  end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module CDN
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
  end
5
5
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.require_paths = ["lib"]
18
18
 
19
19
  s.add_dependency 'fog-aws', '~> 1.4'
20
- s.add_dependency 'cloudflare', '~> 3.0'
20
+ s.add_dependency 'cloudflare', '~> 3.2.1'
21
21
  s.add_dependency 'fastly', '~> 1.1'
22
22
  s.add_dependency 'maxcdn', '~> 0.1'
23
23
  s.add_dependency 'ansi', '~> 1.5'
@@ -2,31 +2,25 @@ require 'spec_helper'
2
2
  require 'lib/middleman-cdn/cdns/base_protocol'
3
3
 
4
4
  shared_examples "invalidating the entire zone" do
5
- before do
6
- allow(double_cloudflare).to receive(:fpurge_ts)
7
- end
8
-
9
5
  it "should invalidate the entire zone" do
10
- expect(double_cloudflare).to receive(:fpurge_ts).once.with("example.com")
6
+ expect(double_zone).to receive(:purge_cache).once.with(no_args)
11
7
  subject.invalidate(options, files, all: all)
12
8
  end
13
9
 
14
10
  it "should not invalidate individual files" do
15
- expect(double_cloudflare).to_not receive(:zone_file_purge)
11
+ expect(double_zone).to_not receive(:purge_cache).with(files: file_urls)
16
12
  subject.invalidate(options, files, all: all)
17
13
  end
18
14
  end
19
15
 
20
16
  shared_examples "invalidating individual files" do
21
17
  it "should not invalidate the entire zone" do
22
- expect(double_cloudflare).to_not receive(:fpurge_ts)
18
+ expect(double_zone).to_not receive(:purge_cache).with(no_args)
23
19
  subject.invalidate(options, files, all: all)
24
20
  end
25
21
 
26
22
  it "should invalidate individual files" do
27
- files.each do |file|
28
- expect(double_cloudflare).to receive(:zone_file_purge).once.ordered.with("example.com", "http://example.com#{file}")
29
- end
23
+ expect(double_zone).to receive(:purge_cache).once.ordered.with(files: file_urls)
30
24
  subject.invalidate(options, files, all: all)
31
25
  end
32
26
  end
@@ -47,15 +41,61 @@ describe Middleman::Cli::CloudFlareCDN do
47
41
  end
48
42
  end
49
43
 
44
+ describe "Cloudflare API" do
45
+ let(:options) do
46
+ {
47
+ key: '000000000000000000000',
48
+ email: 'test@example.com'
49
+ }
50
+ end
51
+
52
+ let(:cloudflare_module) { ::Cloudflare }
53
+ let(:cloudflare) { cloudflare_module.connect(options) }
54
+
55
+ it "should have #connect method" do
56
+ expect(cloudflare_module).to respond_to(:connect).with_keywords(:key, :email)
57
+ end
58
+
59
+ context 'zones' do
60
+ it "should have #zones method" do
61
+ expect(cloudflare).to respond_to(:zones)
62
+ end
63
+
64
+ it "should have #zones.find_by_name method" do
65
+ expect(cloudflare.zones).to respond_to(:find_by_name).with(1).argument
66
+ end
67
+ end
68
+
69
+ context 'zone' do
70
+ before(:each) do
71
+ allow(cloudflare_response).to receive(:result) { double }
72
+ allow_any_instance_of(zone_class).to receive(:get) { cloudflare_response }
73
+ end
74
+
75
+ let(:zone_class) { ::Cloudflare::Zone }
76
+ let(:zone) { zone_class.new('http://example.com') }
77
+ let(:cloudflare_response) { double }
78
+
79
+ it "should have #purge_cache method" do
80
+ expect(zone).to respond_to(:purge_cache)
81
+ end
82
+ end
83
+ end
84
+
50
85
  describe '#invalidate' do
51
86
  let(:double_cloudflare) { double("::Cloudflare") }
87
+ let(:double_zone) { double("::Cloudflare::Zone") }
52
88
 
53
89
  before do
54
- allow(double_cloudflare).to receive(:zone_file_purge)
55
- allow(::Cloudflare).to receive(:connection).and_return(double_cloudflare)
90
+ allow(double_zone).to receive(:purge_cache)
91
+ allow(::Cloudflare).to receive(:connect).and_return(double_cloudflare)
92
+ allow(double_cloudflare).to receive_message_chain('zones.find_by_name').and_return(double_zone)
56
93
  end
57
94
 
58
95
  let(:files) { (1..50).map { |i| "/test/file_#{i}.txt" } }
96
+ let(:http_file_urls) { files.map { |file| "http://example.com#{file}" } }
97
+ let(:https_file_urls) { files.map { |file| "https://example.com#{file}" } }
98
+ let(:file_urls) { http_file_urls.concat(https_file_urls) }
59
99
  let(:all) { false }
60
100
 
61
101
  context "all options provided" do
@@ -69,7 +109,7 @@ describe Middleman::Cli::CloudFlareCDN do
69
109
  end
70
110
 
71
111
  it "should connect to cloudflare with credentails" do
72
- expect(::Cloudflare).to receive(:connection).with("000000000000000000000", "test@example.com")
112
+ expect(::Cloudflare).to receive(:connect).with(key: "000000000000000000000", email: "test@example.com")
73
113
  subject.invalidate(options, files)
74
114
  end
75
115
 
@@ -99,9 +139,7 @@ describe Middleman::Cli::CloudFlareCDN do
99
139
  it_behaves_like "invalidating individual files"
100
140
 
101
141
  it "should call cloudflare to purge each file for each base url" do
102
- files.each do |file|
103
- expect(double_cloudflare).to receive(:zone_file_purge).once.ordered.with("example.com", "http://example.com#{file}")
104
- end
142
+ expect(double_zone).to receive(:purge_cache).once.with(files: file_urls)
105
143
  subject.invalidate(options, files)
106
144
  end
107
145
  end
@@ -142,7 +180,7 @@ describe Middleman::Cli::CloudFlareCDN do
142
180
 
143
181
  context "and errors occurs when purging" do
144
182
  before do
145
- allow(double_cloudflare).to receive(:zone_file_purge).and_raise(StandardError)
183
+ allow(double_zone).to receive(:purge_cache).and_raise(StandardError)
146
184
  end
147
185
 
148
186
  it "should output saying error information" do
@@ -166,7 +204,7 @@ describe Middleman::Cli::CloudFlareCDN do
166
204
  end
167
205
 
168
206
  it "should connect to cloudflare with environment variable credentails" do
169
- expect(::Cloudflare).to receive(:connection).with("111111111111111111111", "test-env@example.com")
207
+ expect(::Cloudflare).to receive(:connect).with(key: "111111111111111111111", email: "test-env@example.com")
170
208
  subject.invalidate(options, files)
171
209
  end
172
210
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-cdn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leigh McCulloch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-05 00:00:00.000000000 Z
11
+ date: 2018-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-aws
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.0'
33
+ version: 3.2.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.0'
40
+ version: 3.2.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: fastly
43
43
  requirement: !ruby/object:Gem::Requirement