cloudflair 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/Rakefile +1 -1
- data/cloudflair.gemspec +1 -1
- data/lib/cloudflair/api/zone/settings/development_mode.rb +0 -1
- data/lib/cloudflair/api.rb +13 -0
- data/lib/cloudflair/communication.rb +18 -12
- data/lib/cloudflair/connection.rb +11 -7
- data/lib/cloudflair/entity.rb +12 -3
- data/lib/cloudflair/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0026c99261c0b4e103318525b4ae84d4a355ee3
|
4
|
+
data.tar.gz: ea221bddb6dad9ff7d3a34c6e9c7c4d5950d9c8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c00fb8e18dcd6fb0ffd246782a4cd814d7d0bf09a1c67a12deceab171b5c0b9ad0948b31d2371e5bc9440d8e8f19eed8558fc2370d9f99cb1404346ba0765894
|
7
|
+
data.tar.gz: 887e4a0fd254b061c1777c73d505a4a0588e8b86c2e623a70a9bcbc5b5c3b6e5f9c6bf60b90aafc735633bb7641a87b826db9c4777a6d68918864fa31968b8dc
|
data/README.md
CHANGED
@@ -93,3 +93,11 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
93
93
|
* Metrics reporting
|
94
94
|
* Rate Limit Tracking
|
95
95
|
* (Global) Rate Limit Tracking (redis?)
|
96
|
+
|
97
|
+
## About
|
98
|
+
|
99
|
+
This gem is currently maintained and funded by [nine.ch](https://nine.ch).
|
100
|
+
|
101
|
+
[![nine.ch Logo](https://blog.nine.ch/assets/logo.png)](https://nine.ch)
|
102
|
+
|
103
|
+
We run your Linux server infrastructure – without interruptions, around the clock.
|
data/Rakefile
CHANGED
data/cloudflair.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_runtime_dependency 'faraday', '~> 0.9.0'
|
25
25
|
spec.add_runtime_dependency 'faraday_middleware', '~> 0.10.0'
|
26
26
|
spec.add_runtime_dependency 'dry-configurable', '~> 0.1'
|
27
|
-
spec.add_runtime_dependency 'faraday-detailed_logger', '~> 2.1
|
27
|
+
spec.add_runtime_dependency 'faraday-detailed_logger', '~> 2.1'
|
28
28
|
|
29
29
|
spec.add_development_dependency 'bundler', '~> 1.12'
|
30
30
|
spec.add_development_dependency 'rake', '~> 10.0'
|
data/lib/cloudflair/api.rb
CHANGED
@@ -1,7 +1,20 @@
|
|
1
1
|
require 'cloudflair/api/zone'
|
2
|
+
require 'cloudflair/communication'
|
2
3
|
|
3
4
|
module Cloudflair
|
5
|
+
extend Cloudflair::Communication
|
6
|
+
|
4
7
|
def self.zone(zone_id)
|
5
8
|
Zone.new zone_id
|
6
9
|
end
|
10
|
+
|
11
|
+
def self.zones(filter = {})
|
12
|
+
json_hashes = response connection.get('zones', filter)
|
13
|
+
|
14
|
+
json_hashes.map do |json|
|
15
|
+
zone = Zone.new(json['id'])
|
16
|
+
zone.data = json
|
17
|
+
zone
|
18
|
+
end
|
19
|
+
end
|
7
20
|
end
|
@@ -7,9 +7,9 @@ module Cloudflair
|
|
7
7
|
def response(response)
|
8
8
|
return nil if response.status == 304
|
9
9
|
|
10
|
-
|
10
|
+
raise_on_http_error response.status
|
11
11
|
|
12
|
-
|
12
|
+
read response
|
13
13
|
end
|
14
14
|
|
15
15
|
def connection
|
@@ -18,7 +18,7 @@ module Cloudflair
|
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
def
|
21
|
+
def read(response)
|
22
22
|
body = response.body
|
23
23
|
|
24
24
|
unless body['success']
|
@@ -29,28 +29,34 @@ module Cloudflair
|
|
29
29
|
body['result']
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def raise_on_http_error(status)
|
33
33
|
case status
|
34
34
|
when 200..399 then
|
35
|
-
|
35
|
+
when 400..499 then
|
36
|
+
raise_on_http_client_error status
|
37
|
+
when 500..599 then
|
38
|
+
fail Cloudflair::CloudflairError, "#{status} Remote Error"
|
39
|
+
else
|
40
|
+
fail Cloudflair::CloudflairError, "#{status} Unknown Error Code"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def raise_on_http_client_error(status)
|
45
|
+
case status
|
36
46
|
when 400 then
|
37
47
|
fail Cloudflair::CloudflairError, '400 Bad Request'
|
38
48
|
when 401 then
|
39
49
|
fail Cloudflair::CloudflairError, '401 Unauthorized'
|
40
50
|
when 403 then
|
41
51
|
fail Cloudflair::CloudflairError, '403 Forbidden'
|
42
|
-
when 429 then
|
43
|
-
fail Cloudflair::CloudflairError, '429 Too Many Requests'
|
44
52
|
when 405 then
|
45
53
|
fail Cloudflair::CloudflairError, '405 Method Not Allowed'
|
46
54
|
when 415 then
|
47
55
|
fail Cloudflair::CloudflairError, '415 Unsupported Media Type'
|
48
|
-
when
|
49
|
-
fail Cloudflair::CloudflairError,
|
50
|
-
when 500..599 then
|
51
|
-
fail Cloudflair::CloudflairError, "#{status} Remote Error"
|
56
|
+
when 429 then
|
57
|
+
fail Cloudflair::CloudflairError, '429 Too Many Requests'
|
52
58
|
else
|
53
|
-
fail Cloudflair::CloudflairError, "#{status}
|
59
|
+
fail Cloudflair::CloudflairError, "#{status} Request Error"
|
54
60
|
end
|
55
61
|
end
|
56
62
|
end
|
@@ -7,13 +7,7 @@ module Cloudflair
|
|
7
7
|
def self.new
|
8
8
|
config = Cloudflair.config
|
9
9
|
|
10
|
-
|
11
|
-
faraday.request :json
|
12
|
-
faraday.response config.faraday.adapter if config.faraday.logger
|
13
|
-
faraday.response :json, content_type: /\bjson$/
|
14
|
-
|
15
|
-
faraday.adapter config.faraday.adapter || Faraday.default_adapter
|
16
|
-
end
|
10
|
+
new_faraday_from config
|
17
11
|
end
|
18
12
|
|
19
13
|
def self.headers
|
@@ -27,5 +21,15 @@ module Cloudflair
|
|
27
21
|
end
|
28
22
|
headers
|
29
23
|
end
|
24
|
+
|
25
|
+
private_class_method def self.new_faraday_from(config)
|
26
|
+
Faraday.new(url: config.cloudflare.api_base_url, headers: headers) do |faraday|
|
27
|
+
faraday.request :json
|
28
|
+
faraday.response config.faraday.logger if config.faraday.logger
|
29
|
+
faraday.response :json, content_type: /\bjson$/
|
30
|
+
|
31
|
+
faraday.adapter config.faraday.adapter || Faraday.default_adapter
|
32
|
+
end
|
33
|
+
end
|
30
34
|
end
|
31
35
|
end
|
data/lib/cloudflair/entity.rb
CHANGED
@@ -111,6 +111,12 @@ module Cloudflair
|
|
111
111
|
super
|
112
112
|
end
|
113
113
|
|
114
|
+
##
|
115
|
+
# :internal: Used to pre-populate an entity
|
116
|
+
def data=(data)
|
117
|
+
@data = data
|
118
|
+
end
|
119
|
+
|
114
120
|
alias get! reload
|
115
121
|
alias save patch
|
116
122
|
|
@@ -143,12 +149,15 @@ module Cloudflair
|
|
143
149
|
def path
|
144
150
|
return @path if @path
|
145
151
|
|
146
|
-
path = self.class.path
|
152
|
+
@path = replace_path_variables_in self.class.path
|
153
|
+
end
|
154
|
+
|
155
|
+
def replace_path_variables_in(path)
|
147
156
|
interpreted_path = path.clone
|
148
|
-
path.scan
|
157
|
+
path.scan(/:([a-zA-Z_][a-zA-Z0-9_]+[!?=]?)/) do |match, *|
|
149
158
|
interpreted_path.gsub! ":#{match}", send(match).to_s
|
150
159
|
end
|
151
|
-
|
160
|
+
interpreted_path
|
152
161
|
end
|
153
162
|
|
154
163
|
def dirty
|
data/lib/cloudflair/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.6
|
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-
|
11
|
+
date: 2016-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 2.1
|
61
|
+
version: '2.1'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 2.1
|
68
|
+
version: '2.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|