cloudflair 0.0.8 → 0.0.9

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: 67a0d783e6d7240e8f30e85be978a8627fe4c6b0
4
- data.tar.gz: ec8881baddadb7e284d235a94c2f1652d2b06235
3
+ metadata.gz: 0640657c68c426446004505f4a0d6267f33fce54
4
+ data.tar.gz: f05ed55855749550cf313803694dcb098d957ae3
5
5
  SHA512:
6
- metadata.gz: 24335795c9cb61c816efd5afa6d1e1e9ec915ce9642ad2601b6f0e65141fc13d4f3bad3f784f1e16ae032f65d8ce67e0f463dc5d8bc02074cb17779717a4cace
7
- data.tar.gz: ff1fa5d1789e5db5c3c2dae30d556242b8e8b0b83f113b7359f8cbf76d293142ee0da42a6a9b72616c465c728580d0cdda39fde591112c42118693134c1e5d4d
6
+ metadata.gz: 4514e38db0d4502bbdebbd5fb6c6db83fd5b8c96a1251804c644ca416d7f817b1ea8d5e50c03fb8e08e8463bdfaf92878155dcd2fc246f8ef51a01ff80827eef
7
+ data.tar.gz: c68a2f703a277480ac68e34da528f27c7c59ceea93456a2eb73715eba8980045ec194616e66feac598400df73bd648937c66955043b6db81515627c6802eae45
data/README.md CHANGED
@@ -3,9 +3,7 @@
3
3
  [![Build Status](https://travis-ci.org/ninech/cloudflair.svg?branch=master)](https://travis-ci.org/ninech/cloudflair)
4
4
  [![Gem Version](https://badge.fury.io/rb/cloudflair.svg)](https://badge.fury.io/rb/cloudflair)
5
5
 
6
- **UNDER CONSTRUCTION**
7
-
8
- A simple Ruby-wrapper around CloudFlare's v4 API.
6
+ A simple Ruby-wrapper around Cloudflare's v4 API.
9
7
 
10
8
  ![Animation of Homer Simpson using of a rescue flare.](https://media.giphy.com/media/n8A8omwp1mVAA/giphy.gif)
11
9
 
@@ -50,11 +48,19 @@ end
50
48
 
51
49
  ### Call An API Endpoint
52
50
 
53
- This gem is organized along the URL schema of CloudFlare.
51
+ This gem is organized along the URL schema of Cloudflare (as shown in the examples below). So you're good off to check the original Cloudflare [API documentation](https://api.cloudflare.com) for more information on the URL schema.
54
52
 
55
53
  ```ruby
56
54
  require 'cloudflair'
57
55
 
56
+ # GET https://api.cloudflare.com/client/v4/railguns
57
+ Cloudflair.railguns
58
+ # => [...]
59
+
60
+ # GET https://api.cloudflare.com/client/v4/zones
61
+ Cloudflair.zones
62
+ # => [...]
63
+
58
64
  # GET https://api.cloudflare.com/client/v4/zones/cd7d068de3012345da9420df9514dad0
59
65
  Cloudflair.zone('023e105f4ecef8ad9ca31a8372d0c353').name
60
66
  # => "blog.example.com"
@@ -73,11 +79,61 @@ end
73
79
 
74
80
  # GET https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59
75
81
  Cloudflair.zone('023e105f4ecef8ad9ca31a8372d0c353').dns_record('372e67954025e0ba6aaa6d586b9e0b59').name
82
+ # => "examples.com"
76
83
  ```
77
84
 
78
- You can use any field that Cloudflare's API returns. If a field is covered by some internal field, use `_field`.
79
-
80
- A good reference are also the specs.
85
+ You can use any field that Cloudflare's API returns. If a field is covered by some internal field, use `_field`. When you set a new value for a field and then want to access original value, you can use `field!` and `_field!`, respectively.
86
+
87
+ A good reference on how to use this wrapper are also the Rspecs.
88
+
89
+ ## Implemented Endpoints
90
+
91
+ * `/railguns` GET, POST
92
+ * `/railguns/:railgun_id` GET, PATCH, DELETE
93
+ * `/railguns/:railgun_id/zones` GET
94
+ * `/zones` GET, POST
95
+ * `/zones/:zone_id` GET, PATCH, DELETE
96
+ * `/zones/:zone_id/analytics/dashboard` GET
97
+ * `/zones/:zone_id/analytics/colos` GET
98
+ * `/zones/:zone_id/available_plans` GET
99
+ * `/zones/:zone_id/available_plans/:plan_id` GET
100
+ * `/zones/:zone_id/available_rate_plans`
101
+ * `/zones/:zone_id/dns_records` GET, POST
102
+ * `/zones/:zone_id/dns_records/:record_id` GET, DELETE (PUT not implemented)
103
+ * `/zones/:zone_id/purge_cache` DELETE
104
+ * `/zones/:zone_id/railguns` GET
105
+ * `/zones/:zone_id/railguns/:railgun_id` GET
106
+ * `/zones/:zone_id/railguns/:railgun_id/diagnose` GET, PATCH
107
+ * `/zones/:zone_id/settings/advanced_ddos` GET
108
+ * `/zones/:zone_id/settings/always_online` GET, PATCH
109
+ * `/zones/:zone_id/settings/browser_cache_ttl` GET, PATCH
110
+ * `/zones/:zone_id/settings/browser_check` GET, PATCH
111
+ * `/zones/:zone_id/settings/cache_level` GET, PATCH
112
+ * `/zones/:zone_id/settings/challenge_ttl` GET, PATCH
113
+ * `/zones/:zone_id/settings/development_mode` GET, PATCH
114
+ * `/zones/:zone_id/settings/email_obfuscation` GET, PATCH
115
+ * `/zones/:zone_id/settings/hotlink_protection` GET, PATCH
116
+ * `/zones/:zone_id/settings/ip_geolocation` GET, PATCH
117
+ * `/zones/:zone_id/settings/ipv6` GET, PATCH
118
+ * `/zones/:zone_id/settings/minify` GET, PATCH
119
+ * `/zones/:zone_id/settings/mirage` GET, PATCH
120
+ * `/zones/:zone_id/settings/mobile_redirect` GET, PATCH
121
+ * `/zones/:zone_id/settings/origin_error_page_pass_thru` GET, PATCH
122
+ * `/zones/:zone_id/settings/polish` GET, PATCH
123
+ * `/zones/:zone_id/settings/prefetch_preload` GET, PATCH
124
+ * `/zones/:zone_id/settings/response_buffering` GET, PATCH
125
+ * `/zones/:zone_id/settings/rocket_loader` GET, PATCH
126
+ * `/zones/:zone_id/settings/security_header` GET, PATCH
127
+ * `/zones/:zone_id/settings/server_side_exclude` GET, PATCH
128
+ * `/zones/:zone_id/settings/server_level` GET, PATCH
129
+ * `/zones/:zone_id/settings/sort_query_string_for_cache` GET, PATCH
130
+ * `/zones/:zone_id/settings/ssl` GET, PATCH
131
+ * `/zones/:zone_id/settings/tls_1_2_only` GET, PATCH
132
+ * `/zones/:zone_id/settings/tls_1_3` GET, PATCH
133
+ * `/zones/:zone_id/settings/tls_client_auth` GET, PATCH
134
+ * `/zones/:zone_id/settings/true_client_ip_header` GET, PATCH
135
+ * `/zones/:zone_id/settings/waf` GET, PATCH
136
+ * `/zones/:zone_id/settings/websockets` GET, PATCH
81
137
 
82
138
  ## Development
83
139
 
@@ -85,28 +141,27 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
85
141
 
86
142
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
87
143
 
88
- ## Contributing
89
-
90
- Bug reports and pull requests are welcome on GitHub at [ninech/cloudflair](https://github.com/ninech/cloudflair).
91
-
92
- ## License
144
+ ### Developing Guidelines
93
145
 
94
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
146
+ * The number one aim of this API wrapper is to mimic the Cloudflare API as it is laid out in the URL. So if the url is `/zones/:zone_id/analytics/dashboard`, then the corresponding Ruby code should become `Cloudflair.zones('abcdefg').analytics.dashboard`.
147
+ * The API should load resources only when required to. So `Cloudflair.zones('abcdefg')` alone would not call out to Cloudflare, but only when `Cloudflair.zones('abcdefg').name` is called. Likewise, `Cloudflair.zones` will immediately call Cloudflare, as it requires the result immediately. (Unless we begin to introduce a kind of 'delayed Array'. Yet we probably don't want that.)
148
+ * Adding additional wrappers for the API shall be easy and done in only a few minutes. (Most of the `/zones/:zone_id/settings/*` API calls were implemented in about five minutes.) So the cloudflair internal API should hide the complexity away. (E.g. the complexity of the fetching, parsing, error handling, etc. should be hidden away. See `Connection`, `Communication` and `Entity`, which contain almost all of the complexity of this Gem.)
149
+ * Please write Rspecs for each new API endpoint. Use the JSON provided in the official Cloudflare API documentation as test data.
95
150
 
96
- ## Roadmap
151
+ ## Contributing
97
152
 
98
- * ~~Pull Zone Information~~
99
- * ~~Zone Name to Zone ID Lookup~~ ✅
100
- * ~~Developer Mode, Cache Purge, Selective Cache Purge~~ ✅
101
- * ~~Airbrake error reporting~~ ❌ (It's the responsibility of the application, not the Gem)
102
- * Full read-only `/zones` API support
103
- * Full API support
153
+ Bug reports and pull requests are welcome on GitHub at [ninech/cloudflair](https://github.com/ninech/cloudflair).
104
154
 
105
155
  ### Whishlist
106
156
 
157
+ * Full API support
107
158
  * Metrics reporting
108
159
  * Rate Limit Tracking
109
- * (Global) Rate Limit Tracking (redis?)
160
+ * (Global/Distributed) Rate Limit Tracking
161
+
162
+ ## License
163
+
164
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
110
165
 
111
166
  ## About
112
167
 
@@ -18,7 +18,5 @@ if ENV['CF_ZONE']
18
18
  end
19
19
  end
20
20
 
21
- #p.everything true
22
-
23
21
  require 'irb'
24
22
  IRB.start
@@ -37,7 +37,8 @@ module Cloudflair
37
37
  @zone_id = zone_id
38
38
  end
39
39
 
40
- { advanced_ddos: Cloudflair::AdvancedDdos,
40
+ {
41
+ advanced_ddos: Cloudflair::AdvancedDdos,
41
42
  always_online: Cloudflair::AlwaysOnline,
42
43
  browser_cache_ttl: Cloudflair::BrowserCacheTtl,
43
44
  browser_check: Cloudflair::BrowserCheck,
@@ -2,7 +2,7 @@ require 'cloudflair/api/zone/dns_record'
2
2
 
3
3
  module Cloudflair
4
4
  class Zone
5
- def dns_records(filter={})
5
+ def dns_records(filter = {})
6
6
  raw_records = response connection.get("#{path}/dns_records", filter)
7
7
 
8
8
  raw_records.map { |raw_record| build_dns_record(raw_record) }
@@ -2,7 +2,7 @@ require 'cloudflair/api/zone/railgun'
2
2
 
3
3
  module Cloudflair
4
4
  class Zone
5
- def railguns(filter={})
5
+ def railguns(filter = {})
6
6
  raw_railguns = response connection.get("#{path}/railguns", filter)
7
7
 
8
8
  raw_railguns.map do |raw_railgun|
@@ -17,15 +17,16 @@ module Cloudflair
17
17
  end
18
18
 
19
19
  def hash_to_object(hash)
20
- objectified = (Class.new).new
20
+ objectified_class = Class.new
21
+ objectified_instance = objectified_class.new
21
22
  hash.each do |k, v|
22
23
  variable_name = sanitize_variable_name(k)
23
- variable_name = "_#{variable_name}" if objectified.methods.map(&:to_s).include?(variable_name)
24
+ variable_name = "_#{variable_name}" if objectified_instance.methods.map(&:to_s).include?(variable_name)
24
25
 
25
- objectified.instance_variable_set("@#{variable_name}", v)
26
- objectified.class.send :define_method, variable_name, proc { self.instance_variable_get("@#{variable_name}") }
26
+ objectified_instance.instance_variable_set("@#{variable_name}", v)
27
+ objectified_class.send :define_method, variable_name, proc { instance_variable_get("@#{variable_name}") }
27
28
  end
28
- objectified
29
+ objectified_instance
29
30
  end
30
31
 
31
32
  private
@@ -73,7 +74,7 @@ module Cloudflair
73
74
  end
74
75
 
75
76
  def sanitize_variable_name(raw_name)
76
- raw_name.gsub /[^a-zA-Z0-9_]/, '_'
77
+ raw_name.gsub(/[^a-zA-Z0-9_]/, '_')
77
78
  end
78
79
  end
79
80
  end
@@ -20,7 +20,7 @@ module Cloudflair
20
20
  elsif !cloudflare_auth_config.user_service_key.nil?
21
21
  headers['X-Auth-User-Service-Key'] = cloudflare_auth_config.user_service_key
22
22
  else
23
- raise CloudflairError, 'Neither email & key nor user_service_key have been defined.'
23
+ fail CloudflairError, 'Neither email & key nor user_service_key have been defined.'
24
24
  end
25
25
  headers
26
26
  end
@@ -65,18 +65,23 @@ module Cloudflair
65
65
  if fields_to_class_map.nil? || fields_to_class_map.empty?
66
66
  @array_object_fields = {}
67
67
  else
68
- fields_map = {}
69
- fields_to_class_map.each do |field|
70
- if field.is_a?(Hash)
71
- fields_to_class_map[0].each do |field, klass_or_proc|
72
- fields_map[field.to_s] = klass_or_proc
73
- end
74
- else
75
- fields_map[field.to_s] = nil
68
+ fields_map = turn_all_items_into_a_single_hash(fields_to_class_map)
69
+ @array_object_fields = fields_map
70
+ end
71
+ end
72
+
73
+ def turn_all_items_into_a_single_hash(fields_to_class_map)
74
+ fields_map = {}
75
+ fields_to_class_map.each do |field_definition|
76
+ if field_definition.is_a?(Hash)
77
+ fields_to_class_map[0].each do |field, klass_or_proc|
78
+ fields_map[field.to_s] = klass_or_proc
76
79
  end
80
+ else
81
+ fields_map[field_definition.to_s] = nil
77
82
  end
78
- @array_object_fields = fields_map
79
83
  end
84
+ fields_map
80
85
  end
81
86
  end
82
87
 
@@ -211,7 +216,8 @@ module Cloudflair
211
216
  def objectify(name)
212
217
  hash_to_object data[name]
213
218
  end
214
- def arrayify(name, klass_or_proc=nil)
219
+
220
+ def arrayify(name, klass_or_proc = nil)
215
221
  data[name].map do |data|
216
222
  if klass_or_proc.nil?
217
223
  hash_to_object data
@@ -9,10 +9,12 @@ module Cloudflair
9
9
  end
10
10
 
11
11
  def to_s
12
- return '[ "An error happened, but no error message/code was given by CloudFlare." (Code: 0000) ]' if cloudflare_errors.empty?
13
-
14
- strings = cloudflare_errors.map { |cf_e| "\"#{cf_e[:message]}\" (Code: #{cf_e[:code]})" }
15
- "[ #{strings.join ', '} ]"
12
+ if cloudflare_errors.empty?
13
+ '[ "An error happened, but no error message/code was given by CloudFlare." (Code: 0000) ]'
14
+ else
15
+ strings = cloudflare_errors.map { |error| "\"#{error['message']}\" (Code: #{error['code']})" }
16
+ "[ #{strings.join ', '} ]"
17
+ end
16
18
  end
17
19
  end
18
20
  end
@@ -1,3 +1,3 @@
1
1
  module Cloudflair
2
- VERSION = '0.0.8'.freeze
2
+ VERSION = '0.0.9'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudflair
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Mäder
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-27 00:00:00.000000000 Z
11
+ date: 2016-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -212,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
212
  version: '0'
213
213
  requirements: []
214
214
  rubyforge_project:
215
- rubygems_version: 2.5.1
215
+ rubygems_version: 2.6.7
216
216
  signing_key:
217
217
  specification_version: 4
218
218
  summary: Wrapper to CloudFlare's v4 REST API.