capistrano-cloudflare 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - ree
4
+ - 1.9.2
5
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+
3
+ group :development do
4
+ gem 'guard'
5
+ gem 'guard-rspec'
6
+ end
7
+
8
+ # Specify your gem's dependencies in capistrano-cloudflare.gemspec
9
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Nathan L Smith
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.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Capistrano CloudFlare [![Build Status](https://secure.travis-ci.org/cramerdev/capistrano-cloudflare.png)](https://secure.travis-ci.org/cramerdev/capistrano-cloudflare)
2
+
3
+ [CloudFlare](http://www.cloudflare.com/) is a service that protects and speeds up websites. Capistrano Cloudflare provides [Capistrano](https://github.com/capistrano/capistrano/wiki/Documentation-v2.x) tasks to update your CloudFlare settings.
4
+
5
+ Currently only cache purging is supported.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'capistrano-cloudflare'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install capistrano-cloudflare
20
+
21
+ ## Usage
22
+
23
+ When using Capistrano, add:
24
+
25
+ require 'capistrano/cloudflare'
26
+
27
+ set, :cloudflare_options, {
28
+ :domain => 'example.com',
29
+ :email => 'me@example.com',
30
+ :api_key => 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
31
+ }
32
+
33
+ to config/deploy.rb. These options can be found in your [CloudFlare account seetings](https://www.cloudflare.com/my-account).
34
+
35
+ The following Capistrano tasks should now be available:
36
+
37
+ * `cloudflare:cache:purge`
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
46
+
47
+ ## License
48
+
49
+ The MIT License (MIT)
50
+ Copyright (c) 2012 Cramer Development, Inc.
51
+
52
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
53
+
54
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
55
+
56
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ task :default => :spec
6
+
7
+ desc "Run the test suite"
8
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/capistrano/cloudflare/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Nathan L Smith"]
6
+ gem.email = ["nlloyds@gmail.com"]
7
+ gem.description = %q{Capistrano extensions for CloudFlare}
8
+ gem.summary = %q{Lets you make CloudFlare API calls when deploying with Capistrano.}
9
+ gem.homepage = "https://github.com/cramerdev/capistrano-cloudflare"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "capistrano-cloudflare"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Capistrano::CloudFlare::VERSION
17
+
18
+ gem.add_dependency 'capistrano', '>= 2.0'
19
+ gem.add_dependency 'json'
20
+
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'rspec'
23
+ gem.add_development_dependency 'capistrano-spec'
24
+ gem.add_development_dependency 'webmock'
25
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module CloudFlare
3
+ VERSION = '0.0.2'
4
+ end
5
+ end
@@ -0,0 +1,49 @@
1
+ require 'capistrano'
2
+ require 'capistrano/cloudflare/version'
3
+ require 'json'
4
+ require 'net/http'
5
+
6
+ module Capistrano
7
+ module CloudFlare
8
+ def self.send_request(options = {})
9
+ uri = URI('https://www.cloudflare.com/api_json.html')
10
+ http = Net::HTTP.new(uri.host, uri.port)
11
+ http.use_ssl = true
12
+ request = Net::HTTP::Post.new(uri.request_uri)
13
+ request.set_form_data({
14
+ :v => 1,
15
+ :a => 'fpurge_ts',
16
+ :z => options[:domain],
17
+ :tkn => options[:api_key],
18
+ :email => options[:email]
19
+
20
+ })
21
+ response = JSON.parse(http.request(request).body)
22
+ end
23
+
24
+ def self.load_into(configuration)
25
+ configuration.set :capistrano_cloudflare, self
26
+ configuration.load do
27
+ namespace :cloudflare do
28
+ namespace :cache do
29
+ desc "Purge the CloudFlare cache"
30
+ task :purge do
31
+ raise unless fetch(:cloudflare_options).respond_to?(:[])
32
+ response = capistrano_cloudflare.send_request(cloudflare_options)
33
+ if response['result'] == 'success'
34
+ logger.info("Purged CloudFlare cache for #{cloudflare_options[:domain]}")
35
+ else
36
+ logger.info("CloudFlare cache purge failed. Reason: #{response['msg'] || 'unknown.'}")
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ if Capistrano::Configuration.instance
48
+ Capistrano::CloudFlare.load_into(Capistrano::Configuration.instance)
49
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capistrano::CloudFlare do
4
+ before do
5
+ @configuration = Capistrano::Configuration.new
6
+ Capistrano::CloudFlare.load_into(@configuration)
7
+ @options = { :domain => 'example.com',
8
+ :email => 'me@example.com',
9
+ :api_key => 'F' }
10
+ stub_request(:post, 'https://www.cloudflare.com/api_json.html').to_return(
11
+ :status => 200, :body => '{}'
12
+ )
13
+
14
+ end
15
+
16
+ it { described_class.should be_a Module }
17
+
18
+ specify 'cloudflare:cache:purge' do
19
+ @configuration.find_task('cloudflare:cache:purge').should_not == nil
20
+ expect { @configuration.find_and_execute_task('cloudflare:cache:purge') }.to raise_error
21
+
22
+ @configuration.set(:cloudflare_options, @options)
23
+ expect { @configuration.find_and_execute_task('cloudflare:cache:purge') }.to_not raise_error
24
+ end
25
+
26
+ specify 'send_request' do
27
+ # TODO: Improve testing here
28
+ described_class.send_request(@options).should be_a_kind_of(Hash)
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+ end
12
+
13
+
14
+ require 'capistrano'
15
+ require 'capistrano-spec'
16
+ require 'capistrano/cloudflare'
17
+ require 'webmock/rspec'
18
+
19
+ WebMock.disable_net_connect!(:allow_localhost => true)
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-cloudflare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nathan L Smith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: capistrano-spec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: webmock
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Capistrano extensions for CloudFlare
111
+ email:
112
+ - nlloyds@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .rspec
119
+ - .travis.yml
120
+ - Gemfile
121
+ - Guardfile
122
+ - LICENSE
123
+ - README.md
124
+ - Rakefile
125
+ - capistrano-cloudflare.gemspec
126
+ - lib/capistrano/cloudflare.rb
127
+ - lib/capistrano/cloudflare/version.rb
128
+ - spec/capistrano/cloudflare_spec.rb
129
+ - spec/spec_helper.rb
130
+ homepage: https://github.com/cramerdev/capistrano-cloudflare
131
+ licenses: []
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 1.8.23
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: Lets you make CloudFlare API calls when deploying with Capistrano.
154
+ test_files:
155
+ - spec/capistrano/cloudflare_spec.rb
156
+ - spec/spec_helper.rb