cloudflare 2.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +4 -0
- data/.travis.yml +19 -0
- data/Gemfile +13 -1
- data/README.md +50 -35
- data/Rakefile +19 -5
- data/cloudflare.gemspec +22 -20
- data/lib/cloudflare.rb +8 -5
- data/lib/cloudflare/connection.rb +31 -520
- data/lib/cloudflare/response.rb +73 -0
- data/lib/cloudflare/rspec/connection.rb +36 -0
- data/lib/cloudflare/user.rb +33 -0
- data/lib/cloudflare/version.rb +3 -2
- data/lib/cloudflare/zone.rb +110 -0
- data/spec/cloudflare/zone_spec.rb +41 -0
- data/spec/spec_helper.rb +30 -0
- metadata +54 -21
- data/LICENSE +0 -8
- data/test/test_cloudflare.rb +0 -24
@@ -0,0 +1,73 @@
|
|
1
|
+
# Copyright, 2012, by Marcin Prokop.
|
2
|
+
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'json'
|
23
|
+
|
24
|
+
module Cloudflare
|
25
|
+
class RequestError < StandardError
|
26
|
+
def initialize(what, response)
|
27
|
+
super("#{what}: #{response.errors.join(', ')}")
|
28
|
+
|
29
|
+
@response = response
|
30
|
+
end
|
31
|
+
|
32
|
+
attr :response
|
33
|
+
end
|
34
|
+
|
35
|
+
class Response
|
36
|
+
def initialize(what, content)
|
37
|
+
@what = what
|
38
|
+
|
39
|
+
@body = JSON.parse(content, symbolize_names: true)
|
40
|
+
end
|
41
|
+
|
42
|
+
attr :body
|
43
|
+
|
44
|
+
def result
|
45
|
+
unless successful?
|
46
|
+
raise RequestError.new(@what, self)
|
47
|
+
end
|
48
|
+
|
49
|
+
body[:result]
|
50
|
+
end
|
51
|
+
|
52
|
+
# Treat result as an array (often it is).
|
53
|
+
def results
|
54
|
+
Array(result)
|
55
|
+
end
|
56
|
+
|
57
|
+
def empty?
|
58
|
+
result.empty?
|
59
|
+
end
|
60
|
+
|
61
|
+
def successful?
|
62
|
+
body[:success]
|
63
|
+
end
|
64
|
+
|
65
|
+
def errors
|
66
|
+
body[:errors]
|
67
|
+
end
|
68
|
+
|
69
|
+
def messages
|
70
|
+
body[:messages]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require_relative '../../cloudflare'
|
22
|
+
|
23
|
+
module Cloudflare
|
24
|
+
module RSpec
|
25
|
+
module Connection
|
26
|
+
end
|
27
|
+
|
28
|
+
RSpec.shared_context Connection do
|
29
|
+
# You must specify these in order for the tests to run.
|
30
|
+
let(:email) {ENV['CLOUDFLARE_EMAIL']}
|
31
|
+
let(:key) {ENV['CLOUDFLARE_KEY']}
|
32
|
+
|
33
|
+
let(:connection) {Cloudflare.connect(key: key, email: email)}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Copyright, 2012, by Marcin Prokop.
|
2
|
+
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
|
22
|
+
require_relative 'connection'
|
23
|
+
|
24
|
+
module Cloudflare
|
25
|
+
class Connection < Resource
|
26
|
+
def user
|
27
|
+
@user ||= User.new(concat_urls(url, 'user'), options)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class User < Resource
|
32
|
+
end
|
33
|
+
end
|
data/lib/cloudflare/version.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Copyright, 2012, by Marcin Prokop.
|
2
|
+
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
3
|
#
|
3
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -18,6 +19,6 @@
|
|
18
19
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
20
|
# THE SOFTWARE.
|
20
21
|
|
21
|
-
module
|
22
|
-
|
22
|
+
module Cloudflare
|
23
|
+
VERSION = '3.0.0'
|
23
24
|
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# Copyright, 2012, by Marcin Prokop.
|
2
|
+
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
|
22
|
+
require_relative 'connection'
|
23
|
+
|
24
|
+
module Cloudflare
|
25
|
+
class Connection < Resource
|
26
|
+
def zones
|
27
|
+
@zones ||= Zones.new(concat_urls(url, 'zones'), options)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class DNSRecord < Resource
|
32
|
+
def initialize(url, record = nil, **options)
|
33
|
+
super(url, **options)
|
34
|
+
|
35
|
+
@record = record || self.get.result
|
36
|
+
end
|
37
|
+
|
38
|
+
attr :record
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
"#{@record[:name]} #{@record[:type]} #{@record[:content]}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class DNSRecords < Resource
|
46
|
+
def initialize(url, zone, **options)
|
47
|
+
super(url, **options)
|
48
|
+
|
49
|
+
@zone = zone
|
50
|
+
end
|
51
|
+
|
52
|
+
attr :zone
|
53
|
+
|
54
|
+
def all
|
55
|
+
self.get.results.map{|record| DNSRecord.new(concat_urls(url, record[:id]), record, **options)}
|
56
|
+
end
|
57
|
+
|
58
|
+
def find_by_name(name)
|
59
|
+
response = self.get(params: {name: name})
|
60
|
+
|
61
|
+
unless response.empty?
|
62
|
+
record = response.results.first
|
63
|
+
|
64
|
+
DNSRecord.new(concat_urls(url, record[:id]), record, **options)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def find_by_id(id)
|
69
|
+
DNSRecord.new(concat_urls(url, id), **options)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class Zone < Resource
|
74
|
+
def initialize(url, record = nil, **options)
|
75
|
+
super(url, **options)
|
76
|
+
|
77
|
+
@record = record || self.get.result
|
78
|
+
end
|
79
|
+
|
80
|
+
attr :record
|
81
|
+
|
82
|
+
def dns_records
|
83
|
+
@dns_records ||= DNSRecords.new(concat_urls(url, 'dns_records'), self, **options)
|
84
|
+
end
|
85
|
+
|
86
|
+
def to_s
|
87
|
+
@record[:name]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
class Zones < Resource
|
92
|
+
def all
|
93
|
+
self.get.results.map{|record| Zone.new(concat_urls(url, record[:id]), record, **options)}
|
94
|
+
end
|
95
|
+
|
96
|
+
def find_by_name(name)
|
97
|
+
record = self.get(params: {name: name}).result
|
98
|
+
|
99
|
+
unless response.empty?
|
100
|
+
record = response.results.first
|
101
|
+
|
102
|
+
Zone.new(concat_urls(url, record[:id]), record, **options)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def find_by_id(id)
|
107
|
+
Zone.new(concat_urls(url, id), **options)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
RSpec.describe "Cloudflare DNS Zones" do
|
3
|
+
include_context Cloudflare::RSpec::Connection
|
4
|
+
|
5
|
+
it "should list zones" do
|
6
|
+
zones = connection.zones.all
|
7
|
+
|
8
|
+
expect(zones).to be_any
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Cloudflare::DNSRecords, order: :defined do
|
12
|
+
let(:zone) {connection.zones.all.first}
|
13
|
+
let(:name) {"test"}
|
14
|
+
|
15
|
+
it "should create dns record" do
|
16
|
+
response = zone.dns_records.post({
|
17
|
+
type: "A",
|
18
|
+
name: name,
|
19
|
+
content: "127.0.0.1",
|
20
|
+
ttl: 240,
|
21
|
+
proxied: false
|
22
|
+
}.to_json, content_type: 'application/json')
|
23
|
+
|
24
|
+
expect(response).to be_successful
|
25
|
+
|
26
|
+
result = response.result
|
27
|
+
expect(result).to include(:id, :type, :name, :content, :ttl)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should delete dns record" do
|
31
|
+
dns_records = zone.dns_records.all
|
32
|
+
|
33
|
+
expect(dns_records).to be_any
|
34
|
+
|
35
|
+
dns_records.each do |record|
|
36
|
+
response = record.delete
|
37
|
+
expect(response).to be_successful
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
if ENV['COVERAGE'] || ENV['TRAVIS']
|
3
|
+
begin
|
4
|
+
require 'simplecov'
|
5
|
+
|
6
|
+
SimpleCov.start do
|
7
|
+
add_filter "/spec/"
|
8
|
+
end
|
9
|
+
|
10
|
+
if ENV['TRAVIS']
|
11
|
+
require 'coveralls'
|
12
|
+
Coveralls.wear!
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
warn "Could not load simplecov: #{$!}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require "bundler/setup"
|
20
|
+
require "cloudflare"
|
21
|
+
require "cloudflare/rspec/connection"
|
22
|
+
|
23
|
+
RSpec.configure do |config|
|
24
|
+
# Enable flags like --only-failures and --next-failure
|
25
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
26
|
+
|
27
|
+
config.expect_with :rspec do |c|
|
28
|
+
c.syntax = :expect
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudflare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin Prokop
|
8
|
+
- Samuel Williams
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2017-05-25 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
+
name: rest-client
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
|
-
- - "
|
18
|
+
- - ">="
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
+
version: '0'
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.6'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '3.6'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.3'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
22
51
|
version_requirements: !ruby/object:Gem::Requirement
|
23
52
|
requirements:
|
24
53
|
- - "~>"
|
25
54
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1'
|
55
|
+
version: '1.3'
|
27
56
|
- !ruby/object:Gem::Dependency
|
28
57
|
name: rake
|
29
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,39 +67,42 @@ dependencies:
|
|
38
67
|
- - ">="
|
39
68
|
- !ruby/object:Gem::Version
|
40
69
|
version: '0'
|
41
|
-
description:
|
42
|
-
email:
|
70
|
+
description:
|
71
|
+
email:
|
72
|
+
- marcin@prokop.co
|
73
|
+
- samuel.williams@oriontransfer.co.nz
|
43
74
|
executables: []
|
44
75
|
extensions: []
|
45
|
-
extra_rdoc_files:
|
46
|
-
- README.md
|
47
|
-
- LICENSE
|
76
|
+
extra_rdoc_files: []
|
48
77
|
files:
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
49
80
|
- Gemfile
|
50
|
-
- LICENSE
|
51
81
|
- README.md
|
52
82
|
- Rakefile
|
53
83
|
- cloudflare.gemspec
|
54
84
|
- lib/cloudflare.rb
|
55
85
|
- lib/cloudflare/connection.rb
|
86
|
+
- lib/cloudflare/response.rb
|
87
|
+
- lib/cloudflare/rspec/connection.rb
|
88
|
+
- lib/cloudflare/user.rb
|
56
89
|
- lib/cloudflare/version.rb
|
57
|
-
-
|
90
|
+
- lib/cloudflare/zone.rb
|
91
|
+
- spec/cloudflare/zone_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
58
93
|
homepage: https://github.com/b4k3r/cloudflare
|
59
94
|
licenses:
|
60
95
|
- MIT
|
61
96
|
metadata: {}
|
62
97
|
post_install_message:
|
63
|
-
rdoc_options:
|
64
|
-
- "--main"
|
65
|
-
- README.md
|
66
|
-
- "--charset=UTF-8"
|
98
|
+
rdoc_options: []
|
67
99
|
require_paths:
|
68
100
|
- lib
|
69
101
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
102
|
requirements:
|
71
103
|
- - ">="
|
72
104
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
105
|
+
version: 2.0.0
|
74
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
107
|
requirements:
|
76
108
|
- - ">="
|
@@ -78,9 +110,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
110
|
version: '0'
|
79
111
|
requirements: []
|
80
112
|
rubyforge_project:
|
81
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.6.10
|
82
114
|
signing_key:
|
83
115
|
specification_version: 4
|
84
|
-
summary: A Ruby wrapper for the
|
116
|
+
summary: A Ruby wrapper for the Cloudflare API.
|
85
117
|
test_files:
|
86
|
-
-
|
118
|
+
- spec/cloudflare/zone_spec.rb
|
119
|
+
- spec/spec_helper.rb
|