cloudflare_api 0.1.0alpha0 → 0.1.0alpha1

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: 163df6cf5dc968f9acd19e94f32739f2888a973a
4
- data.tar.gz: c77e528065619e6b3a9479d6e936be35d58bf5f6
3
+ metadata.gz: 4b66d862c40009907dd5905d162e6675807e79a7
4
+ data.tar.gz: 61feb382746e8531b3733a166ec94501a98c67eb
5
5
  SHA512:
6
- metadata.gz: b0604155ce17485ad0182c80104b14ef2a6812d5016f72bf39b4db9ec124523b5108527b21a8a727d7d8ab1fff4ae85e20ba7bd89fe6776aba14f5253294969b
7
- data.tar.gz: e4e4fba5773013076f90404b6c14e0af8573bd73ca3a01876428fa2b3c3978fbba56a1885669686f3da16dcbf450d98edb76bdac675e3fdf4fd23bd4409ff92e
6
+ metadata.gz: 7251bed84a00bdaffaf5acf599055e8c053106e4db8de02070b6b0440c0abea34a74a118012028869dd9bc7b1f7c42fb47d305e0330f3ec73552ef032a1b8916
7
+ data.tar.gz: ba7ce286bcde6093d1a10d78dac14a5998eb0c37fc8e684d8e6175c8f1363126a006405e66cfa6ce74e35b3c0a9e1986949fcd6ba73d63c366cb3ef6949fa18c
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'cloudflare_api.gemspec'
4
+ - 'Rakefile'
data/Gemfile CHANGED
@@ -2,3 +2,9 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in cloudflare_api.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-rubocop'
10
+ end
data/Guardfile ADDED
@@ -0,0 +1,82 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features)
6
+
7
+ ## Uncomment to clear the screen before every task
8
+ # clearing :on
9
+
10
+ ## Guard internally checks for changes in the Guardfile and exits.
11
+ ## If you want Guard to automatically start up again, run guard in a
12
+ ## shell loop, e.g.:
13
+ ##
14
+ ## $ while bundle exec guard; do echo "Restarting Guard..."; done
15
+ ##
16
+ ## Note: if you are using the `directories` clause above and you are not
17
+ ## watching the project directory ('.'), then you will want to move
18
+ ## the Guardfile to a watched dir and symlink it back, e.g.
19
+ #
20
+ # $ mkdir config
21
+ # $ mv Guardfile config/
22
+ # $ ln -s config/Guardfile .
23
+ #
24
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
25
+
26
+ # Note: The cmd option is now required due to the increasing number of ways
27
+ # rspec may be run, below are examples of the most common uses.
28
+ # * bundler: 'bundle exec rspec'
29
+ # * bundler binstubs: 'bin/rspec'
30
+ # * spring: 'bin/rspec' (This will use spring if running and you have
31
+ # installed the spring binstubs per the docs)
32
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
33
+ # * 'just' rspec: 'rspec'
34
+
35
+ guard :rspec, cmd: 'bundle exec rspec' do
36
+ require 'guard/rspec/dsl'
37
+ dsl = Guard::RSpec::Dsl.new(self)
38
+
39
+ # Feel free to open issues for suggestions and improvements
40
+
41
+ # RSpec files
42
+ rspec = dsl.rspec
43
+ watch(rspec.spec_helper) { rspec.spec_dir }
44
+ watch(rspec.spec_support) { rspec.spec_dir }
45
+ watch(rspec.spec_files)
46
+
47
+ # Ruby files
48
+ ruby = dsl.ruby
49
+ dsl.watch_spec_files_for(ruby.lib_files)
50
+
51
+ # Rails files
52
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
53
+ dsl.watch_spec_files_for(rails.app_files)
54
+ dsl.watch_spec_files_for(rails.views)
55
+
56
+ watch(rails.controllers) do |m|
57
+ [
58
+ rspec.spec.call("routing/#{m[1]}_routing"),
59
+ rspec.spec.call("controllers/#{m[1]}_controller"),
60
+ rspec.spec.call("acceptance/#{m[1]}")
61
+ ]
62
+ end
63
+
64
+ # Rails config changes
65
+ watch(rails.spec_helper) { rspec.spec_dir }
66
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
67
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
68
+
69
+ # Capybara features specs
70
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
71
+
72
+ # Turnip features and steps
73
+ watch(%r{^spec/acceptance/(.+)\.feature$})
74
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
75
+ Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
76
+ end
77
+ end
78
+
79
+ guard :rubocop, cli: '-a' do
80
+ watch(/.+\.rb$/)
81
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
82
+ end
data/Rakefile CHANGED
@@ -1 +1,15 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ rescue LoadError
7
+ end
8
+
9
+ begin
10
+ require 'rubocop/rake_task'
11
+ RuboCop::RakeTask.new
12
+ rescue LoadError
13
+ end
14
+
15
+ task default: %w( spec rubocop )
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "cloudflare_api"
3
+ require 'bundler/setup'
4
+ require 'cloudflare_api'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "cloudflare_api"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -4,21 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'cloudflare_api/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "cloudflare_api"
8
- spec.version = CloudflareApi::VERSION
9
- spec.authors = ["Roland Moriz"]
10
- spec.email = ["roland@moriz.de"]
7
+ spec.name = 'cloudflare_api'
8
+ spec.version = CloudFlareAPI::VERSION
9
+ spec.authors = ['Roland Moriz']
10
+ spec.email = ['roland@moriz.de']
11
11
 
12
- spec.summary = %q{not-yet-ready}
13
- spec.description = %q{not-yet-ready}
14
- spec.homepage = "https://github.com/rmoriz/cloudflare_api"
15
- spec.license = "MIT"
12
+ spec.summary = 'not-yet-ready'
13
+ spec.description = 'not-yet-ready'
14
+ spec.homepage = 'https://github.com/rmoriz/cloudflare_api'
15
+ spec.license = 'MIT'
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
18
+ spec.bindir = 'exe'
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.9"
23
- spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_dependency 'httparty', '~> 0.13.5'
23
+ spec.add_development_dependency 'bundler', '~> 1.9'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.2'
26
+ spec.add_development_dependency 'rubocop', '~> 0.31.0'
27
+ spec.add_development_dependency 'vcr', '~> 2.9.3'
28
+ spec.add_development_dependency 'webmock', '~> 1.21'
24
29
  end
@@ -1,5 +1,6 @@
1
- require "cloudflare_api/version"
1
+ require 'cloudflare_api/version'
2
+ require 'cloudflare_api/client'
2
3
 
3
- module CloudflareApi
4
- # Your code goes here...
4
+ # :nodoc:
5
+ module CloudFlareAPI
5
6
  end
@@ -0,0 +1,220 @@
1
+ require 'httparty'
2
+ require 'logger'
3
+
4
+ module CloudFlareAPI # :nodoc:
5
+ # the client
6
+ class Client
7
+ include ::HTTParty
8
+ base_uri 'www.cloudflare.com'
9
+
10
+ def initialize(email, token)
11
+ @auth = { email: email, tkn: token }
12
+ end
13
+
14
+ def post(query)
15
+ query.merge!(@auth)
16
+
17
+ # TODO: error handling
18
+ self.class.post('/api_json.html', query: query).parsed_response
19
+ end
20
+
21
+ # 3.1 - "stats" - Retrieve domain statistics for a given time frame
22
+ def stats(zone, interval)
23
+ post(
24
+ a: 'stats',
25
+ z: zone,
26
+ interval: interval
27
+ )
28
+ end
29
+
30
+ # 3.2 - "zone_load_multi" - Retrieve the list of domains
31
+ def zone_load_multi
32
+ post(
33
+ a: 'zone_load_multi'
34
+ )
35
+ end
36
+ alias_method :list_zones, :zone_load_multi
37
+
38
+ # 3.3 - "rec_load_all" - Retrieve DNS Records of a given domain
39
+ def rec_load_all(zone, offset = nil)
40
+ post(
41
+ a: 'rec_load_all',
42
+ z: zone,
43
+ o: offset
44
+ )
45
+ end
46
+ alias_method :list_zone_records, :rec_load_all
47
+
48
+ # 3.4 - "zone_check" - Checks for active zones and returns their corresponding zids
49
+ def zone_check(zones)
50
+ post(
51
+ a: 'zone_check',
52
+ zones: zones.is_a?(Array) ? zones.join(',') : zones
53
+ )
54
+ end
55
+ alias_method :check_zone, :zone_check
56
+
57
+ # 3.6 - "ip_lkup" - Check threat score for a given IP
58
+ def ip_lkup(ip)
59
+ post(
60
+ a: 'ip_lkup',
61
+ ip: ip
62
+ )
63
+ end
64
+ alias_method :check_ip, :ip_lkup
65
+
66
+ # 3.7 - "zone_settings" - List all current setting values
67
+ def zone_settings(zone)
68
+ post(
69
+ a: 'zone_settings',
70
+ z: zone
71
+ )
72
+ end
73
+
74
+ # 4.1 - "sec_lvl" - Set the security level
75
+ def sec_lvl(zone, level)
76
+ post(
77
+ a: 'sec_lvl',
78
+ z: zone,
79
+ v: level
80
+ )
81
+ end
82
+ alias_method :security_level, :sec_lvl
83
+
84
+ # 4.2 - "cache_lvl" - Set the cache level
85
+ def cache_lvl(zone, level)
86
+ post(
87
+ a: 'cache_lvl',
88
+ z: zone,
89
+ v: level
90
+ )
91
+ end
92
+ alias_method :cache_level, :cache_lvl
93
+
94
+ # 4.3 - "devmode" - Toggling Development Mode
95
+ def devmode(zone, level)
96
+ post(
97
+ a: 'devmode',
98
+ z: zone,
99
+ v: level
100
+ )
101
+ end
102
+ alias_method :dev_mode, :devmode
103
+
104
+ # 4.4 - "fpurge_ts" -- Clear CloudFlare's cache
105
+ def fpurge_ts(zone, level = 1)
106
+ post(
107
+ a: 'fpurge_ts',
108
+ z: zone,
109
+ v: level
110
+ )
111
+ end
112
+ alias_method :purge_cache, :fpurge_ts
113
+
114
+ # 4.5 - "zone_file_purge" -- Purge a single file in CloudFlare's cache
115
+ def zone_file_purge(zone, url)
116
+ post(
117
+ a: 'zone_file_purge',
118
+ z: zone,
119
+ url: url
120
+ )
121
+ end
122
+ alias_method :purge_file, :zone_file_purge
123
+
124
+ # 4.6 - "wl" / "ban" / "nul" -- Whitelist/Blacklist/Unlist IPs
125
+ def wl(ip)
126
+ post(
127
+ a: 'wl',
128
+ key: ip
129
+ )
130
+ end
131
+ alias_method :whitelist, :wl
132
+
133
+ def ban(ip)
134
+ post(
135
+ a: 'ban',
136
+ key: ip
137
+ )
138
+ end
139
+ alias_method :blacklist, :ban
140
+
141
+ def nul(ip)
142
+ post(
143
+ a: 'nul',
144
+ key: ip
145
+ )
146
+ end
147
+ alias_method :unlist, :nul
148
+
149
+ # 4.7 - "ipv46" -- Toggle IPv6 support
150
+ def ipv46(zone, value)
151
+ post(
152
+ a: 'ipv46',
153
+ z: zone,
154
+ v: value
155
+ )
156
+ end
157
+
158
+ # 4.8 - "async" -- Set Rocket Loader
159
+ def async(zone, value)
160
+ post(
161
+ a: 'async',
162
+ z: zone,
163
+ v: value
164
+ )
165
+ end
166
+
167
+ # 4.9 - "minify" -- Set Minification
168
+ def minify(zone, value)
169
+ post(
170
+ a: 'minify',
171
+ z: zone,
172
+ v: value
173
+ )
174
+ end
175
+
176
+ # 4.10 - "mirage2" -- Set Mirage2
177
+ def mirage2(zone, value)
178
+ post(
179
+ a: 'minify',
180
+ z: zone,
181
+ v: value
182
+ )
183
+ end
184
+
185
+ # 5.1 - "rec_new" -- Add a DNS record
186
+ def rec_new(zone, params = {})
187
+ post(
188
+ {
189
+ a: 'rec_new',
190
+ z: zone
191
+ }.merge(params)
192
+ )
193
+ end
194
+ alias_method :new_dns_record, :rec_new
195
+ alias_method :create_dns_record, :rec_new
196
+
197
+ # 5.2 - "rec_edit" -- Edit a DNS record
198
+ def rec_edit(zone, params = {})
199
+ post(
200
+ {
201
+ a: 'rec_edit',
202
+ z: zone
203
+ }.merge(params)
204
+ )
205
+ end
206
+ alias_method :edit_dns_record, :rec_edit
207
+
208
+ # 5.3 - "rec_delete" -- Delete a DNS record
209
+ def rec_delete(zone, id)
210
+ post(
211
+ {
212
+ a: 'rec_delete',
213
+ z: zone,
214
+ id: id
215
+ }.merge(params)
216
+ )
217
+ end
218
+ alias_method :delete_zone, :rec_delete
219
+ end
220
+ end
@@ -1,3 +1,3 @@
1
- module CloudflareApi
2
- VERSION = "0.1.0alpha0"
1
+ module CloudFlareAPI # :nodoc:
2
+ VERSION = '0.1.0alpha1'
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudflare_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0alpha0
4
+ version: 0.1.0alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roland Moriz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-24 00:00:00.000000000 Z
11
+ date: 2015-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.13.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.13.5
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,62 @@ dependencies:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.31.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.31.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.9.3
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.9.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.21'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.21'
41
111
  description: not-yet-ready
42
112
  email:
43
113
  - roland@moriz.de
@@ -47,8 +117,10 @@ extra_rdoc_files: []
47
117
  files:
48
118
  - ".gitignore"
49
119
  - ".rspec"
120
+ - ".rubocop.yml"
50
121
  - ".travis.yml"
51
122
  - Gemfile
123
+ - Guardfile
52
124
  - LICENSE.txt
53
125
  - README.md
54
126
  - Rakefile
@@ -56,6 +128,7 @@ files:
56
128
  - bin/setup
57
129
  - cloudflare_api.gemspec
58
130
  - lib/cloudflare_api.rb
131
+ - lib/cloudflare_api/client.rb
59
132
  - lib/cloudflare_api/version.rb
60
133
  homepage: https://github.com/rmoriz/cloudflare_api
61
134
  licenses: