cloudflair 0.0.7 → 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: 56fd1197bf91ccbbbc25632cc55246356689b74f
4
- data.tar.gz: 77fc8bb524ef60c7a64e089799a3b32ed17b49b7
3
+ metadata.gz: 0640657c68c426446004505f4a0d6267f33fce54
4
+ data.tar.gz: f05ed55855749550cf313803694dcb098d957ae3
5
5
  SHA512:
6
- metadata.gz: cdf21b581458669d7c5a41df55ca8e9cd4f6547564e691af98afec05f86b45f9b77eff79b1fd5995679eba1946022a9ebba31a66a509dc52b3f6a0f4e28e94c3
7
- data.tar.gz: e55e62b873549576a13b085afd5fbd0bb3fbf53f6e12091d009929d47e03bb00f16958a8ab72db69073cef116839956830b4c1a6de5ed9f8f91e960112fa8b03
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,24 +48,92 @@ 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
 
58
- # https://api.cloudflare.com/client/v4/zones/cd7d068de3012345da9420df9514dad0
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
+
64
+ # GET https://api.cloudflare.com/client/v4/zones/cd7d068de3012345da9420df9514dad0
59
65
  Cloudflair.zone('023e105f4ecef8ad9ca31a8372d0c353').name
60
- # :=> "blog.example.com"
66
+ # => "blog.example.com"
61
67
 
62
- # https://api.cloudflare.com/client/v4/zones/cd7d068de3012345da9420df9514dad0/settings/development_mode
68
+ # GET https://api.cloudflare.com/client/v4/zones/cd7d068de3012345da9420df9514dad0/settings/development_mode
63
69
  Cloudflair.zone('023e105f4ecef8ad9ca31a8372d0c353').settings.development_mode.value
64
- # :=> "on"
65
- # :=> "off"
66
- ```
70
+ # => "on"
71
+ # => "off"
72
+
73
+ # PATCH https://api.cloudflare.com/client/v4/zones/cd7d068de3012345da9420df9514dad0/settings/development_mode
74
+ # {"value"="on"}
75
+ Cloudflair.zone('023e105f4ecef8ad9ca31a8372d0c353').settings.development_mode.tap do |dm|
76
+ dm.value = 'on'
77
+ dm.save
78
+ end
67
79
 
68
- You can use any field that Cloudflare's API returns. If a field is covered by some internal field, use `_field`.
80
+ # GET https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59
81
+ Cloudflair.zone('023e105f4ecef8ad9ca31a8372d0c353').dns_record('372e67954025e0ba6aaa6d586b9e0b59').name
82
+ # => "examples.com"
83
+ ```
69
84
 
70
- 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
71
137
 
72
138
  ## Development
73
139
 
@@ -75,24 +141,27 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
75
141
 
76
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).
77
143
 
78
- ## Contributing
144
+ ### Developing Guidelines
79
145
 
80
- Bug reports and pull requests are welcome on GitHub at [ninech/cloudflair](https://github.com/ninech/cloudflair).
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.
81
150
 
82
- ## License
151
+ ## Contributing
83
152
 
84
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
153
+ Bug reports and pull requests are welcome on GitHub at [ninech/cloudflair](https://github.com/ninech/cloudflair).
85
154
 
86
- ## Roadmap
155
+ ### Whishlist
87
156
 
88
- * Pull Zone Information
89
- * Zone Name to Zone ID Lookup
90
- * Developer Mode, Cache Purge, Selective Cache Purge
91
- * Airbrake error reporting
92
157
  * Full API support
93
158
  * Metrics reporting
94
159
  * Rate Limit Tracking
95
- * (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).
96
165
 
97
166
  ## About
98
167
 
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'cloudflair'
5
+ require 'dotenv'
6
+
7
+ Dotenv.load
8
+
9
+ Cloudflair.configure do |c|
10
+ c.cloudflare.auth.key = ENV['AUTH_KEY']
11
+ c.cloudflare.auth.email = ENV['AUTH_MAIL']
12
+ c.faraday.logger = :detailed_logger
13
+ end
14
+
15
+ if ENV['CF_ZONE']
16
+ def z
17
+ @z ||= Cloudflair.zone ENV['CF_ZONE']
18
+ end
19
+ end
20
+
21
+ require 'irb'
22
+ IRB.start
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = %w(christian.maeder@nine.ch)
11
11
 
12
12
  spec.summary = "Wrapper to CloudFlare's v4 REST API."
13
- spec.description = 'Cloudflair aims to provide easy access to CloudFlares public API.'
13
+ spec.description = "Cloudflair aims to provide easy access to CloudFlare's public API."
14
14
  spec.homepage = 'https://github.com/ninech/cloudflair'
15
15
  spec.license = 'MIT'
16
16
 
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency 'bundler', '~> 1.12'
30
30
  spec.add_development_dependency 'rake', '~> 10.0'
31
31
  spec.add_development_dependency 'rspec', '~> 3.0'
32
+ spec.add_development_dependency 'dotenv', '~> 2.1'
32
33
  end
@@ -1,4 +1,5 @@
1
1
  require 'cloudflair/api/zone'
2
+ require 'cloudflair/api/railguns'
2
3
  require 'cloudflair/communication'
3
4
 
4
5
  module Cloudflair
@@ -9,7 +10,7 @@ module Cloudflair
9
10
  end
10
11
 
11
12
  def self.zones(filter = {})
12
- raw_zones = response connection.get('zones', filter)
13
+ raw_zones = response connection.get 'zones', filter
13
14
 
14
15
  raw_zones.map do |raw_zone|
15
16
  zone = Zone.new(raw_zone['id'])
@@ -17,4 +18,18 @@ module Cloudflair
17
18
  zone
18
19
  end
19
20
  end
21
+
22
+ def self.railgun(railgun_id)
23
+ Railguns.new railgun_id
24
+ end
25
+
26
+ def self.railguns(filter = {})
27
+ raw_railguns = response connection.get 'railguns', filter
28
+
29
+ raw_railguns.map do |raw_railgun|
30
+ railgun = Railguns.new(raw_railgun['id'])
31
+ railgun.data = raw_railgun
32
+ railgun
33
+ end
34
+ end
20
35
  end
@@ -0,0 +1,24 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class Railguns
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :railgun_id
8
+ patchable_fields :enabled
9
+ deletable true
10
+ path 'railguns/:railgun_id'
11
+
12
+ def initialize(railgun_id)
13
+ @railgun_id = railgun_id
14
+ end
15
+
16
+ def zones
17
+ raw_response = connection.get "#{path}/zones"
18
+ parsed_responses = response raw_response
19
+ parsed_responses.map do |parsed_response|
20
+ hash_to_object parsed_response
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,4 @@
1
+ require 'cloudflair/api/zone/analytics'
1
2
  require 'cloudflair/api/zone/available_plan'
2
3
  require 'cloudflair/api/zone/available_rate_plan'
3
4
  require 'cloudflair/api/zone/purge_cache'
@@ -8,6 +9,10 @@ module Cloudflair
8
9
  class Zone
9
10
  include Cloudflair::Entity
10
11
 
12
+ require 'cloudflair/api/zone__dns_records'
13
+ require 'cloudflair/api/zone__available_plans'
14
+ require 'cloudflair/api/zone__railguns'
15
+
11
16
  attr_reader :zone_id
12
17
 
13
18
  patchable_fields :paused, :vanity_name_servers, :plan
@@ -31,14 +36,8 @@ module Cloudflair
31
36
  Cloudflair::AvailableRatePlan.new zone_id
32
37
  end
33
38
 
34
- def available_plans
35
- raw_plans = response connection.get("#{path}/available_plans")
36
-
37
- raw_plans.map do |raw_plan|
38
- zone = Cloudflair::AvailablePlan.new(zone_id, raw_plan['id'])
39
- zone.data = raw_plan
40
- zone
41
- end
39
+ def analytics
40
+ Cloudflair::Analytics.new zone_id
42
41
  end
43
42
  end
44
43
  end
@@ -0,0 +1,25 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class Analytics
5
+ include Cloudflair::Communication
6
+
7
+ def initialize(zone_id)
8
+ @path = "zones/#{zone_id}/analytics"
9
+ end
10
+
11
+ def dashboard(filter = {})
12
+ raw_response = connection.get "#{@path}/dashboard", filter
13
+ parsed_response = response raw_response
14
+ hash_to_object parsed_response
15
+ end
16
+
17
+ def colos(filter = {})
18
+ raw_response = connection.get "#{@path}/colos", filter
19
+ parsed_responses = response raw_response
20
+ parsed_responses.map do |parsed_response|
21
+ hash_to_object parsed_response
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class DnsRecord
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id, :record_id
8
+ deletable true
9
+ path 'zones/:zone_id/dns_records/:record_id'
10
+
11
+ def initialize(zone_id, record_id)
12
+ @zone_id = zone_id
13
+ @record_id = record_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class Railgun
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id, :railgun_id
8
+ patchable_fields :connected
9
+ path 'zones/:zone_id/railguns/:railgun_id'
10
+
11
+ def initialize(zone_id, railgun_id)
12
+ @zone_id = zone_id
13
+ @railgun_id = railgun_id
14
+ end
15
+
16
+ def diagnose
17
+ raw_response = connection.get "#{path}/diagnose"
18
+ parsed_response = response raw_response
19
+ hash_to_object parsed_response
20
+ end
21
+ end
22
+ end
@@ -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,
@@ -0,0 +1,19 @@
1
+ require 'cloudflair/api/zone/available_plan'
2
+
3
+ module Cloudflair
4
+ class Zone
5
+ def available_plans
6
+ raw_plans = response connection.get("#{path}/available_plans")
7
+
8
+ raw_plans.map do |raw_plan|
9
+ zone = available_plan raw_plan['id']
10
+ zone.data = raw_plan
11
+ zone
12
+ end
13
+ end
14
+
15
+ def available_plan(plan_id)
16
+ Cloudflair::AvailablePlan.new zone_id, plan_id
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ require 'cloudflair/api/zone/dns_record'
2
+
3
+ module Cloudflair
4
+ class Zone
5
+ def dns_records(filter = {})
6
+ raw_records = response connection.get("#{path}/dns_records", filter)
7
+
8
+ raw_records.map { |raw_record| build_dns_record(raw_record) }
9
+ end
10
+
11
+ def dns_record(record_id)
12
+ Cloudflair::DnsRecord.new zone_id, record_id
13
+ end
14
+
15
+ def new_dns_record(record_data)
16
+ raw_record = response connection.post("#{path}/dns_records", record_data)
17
+
18
+ build_dns_record raw_record
19
+ end
20
+
21
+ private
22
+
23
+ def build_dns_record(raw_record)
24
+ record = dns_record raw_record['id']
25
+ record.data = raw_record
26
+ record
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ require 'cloudflair/api/zone/railgun'
2
+
3
+ module Cloudflair
4
+ class Zone
5
+ def railguns(filter = {})
6
+ raw_railguns = response connection.get("#{path}/railguns", filter)
7
+
8
+ raw_railguns.map do |raw_railgun|
9
+ railgun = railgun raw_railgun['id']
10
+ railgun.data = raw_railgun
11
+ railgun
12
+ end
13
+ end
14
+
15
+ def railgun(railgun_id)
16
+ Cloudflair::Railgun.new zone_id, railgun_id
17
+ end
18
+ end
19
+ end
@@ -16,6 +16,19 @@ module Cloudflair
16
16
  Cloudflair::Connection.new
17
17
  end
18
18
 
19
+ def hash_to_object(hash)
20
+ objectified_class = Class.new
21
+ objectified_instance = objectified_class.new
22
+ hash.each do |k, v|
23
+ variable_name = sanitize_variable_name(k)
24
+ variable_name = "_#{variable_name}" if objectified_instance.methods.map(&:to_s).include?(variable_name)
25
+
26
+ objectified_instance.instance_variable_set("@#{variable_name}", v)
27
+ objectified_class.send :define_method, variable_name, proc { instance_variable_get("@#{variable_name}") }
28
+ end
29
+ objectified_instance
30
+ end
31
+
19
32
  private
20
33
 
21
34
  def read(response)
@@ -59,5 +72,9 @@ module Cloudflair
59
72
  fail Cloudflair::CloudflairError, "#{status} Request Error"
60
73
  end
61
74
  end
75
+
76
+ def sanitize_variable_name(raw_name)
77
+ raw_name.gsub(/[^a-zA-Z0-9_]/, '_')
78
+ end
62
79
  end
63
80
  end
@@ -1,6 +1,7 @@
1
1
  require 'faraday'
2
2
  require 'faraday_middleware'
3
3
  require 'faraday/detailed_logger'
4
+ require 'cloudflair/error/cloudflair_error'
4
5
 
5
6
  module Cloudflair
6
7
  class Connection
@@ -13,11 +14,13 @@ module Cloudflair
13
14
  def self.headers
14
15
  headers = {}
15
16
  cloudflare_auth_config = Cloudflair.config.cloudflare.auth
16
- if cloudflare_auth_config.user_service_key.nil?
17
+ if !(cloudflare_auth_config.key.nil? || cloudflare_auth_config.email.nil?)
17
18
  headers['X-Auth-Key'] = cloudflare_auth_config.key
18
19
  headers['X-Auth-Email'] = cloudflare_auth_config.email
19
- else
20
+ elsif !cloudflare_auth_config.user_service_key.nil?
20
21
  headers['X-Auth-User-Service-Key'] = cloudflare_auth_config.user_service_key
22
+ else
23
+ fail CloudflairError, 'Neither email & key nor user_service_key have been defined.'
21
24
  end
22
25
  headers
23
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
 
@@ -212,16 +217,7 @@ module Cloudflair
212
217
  hash_to_object data[name]
213
218
  end
214
219
 
215
- def hash_to_object(hash)
216
- objectified = Class.new
217
- hash.each do |k, v|
218
- objectified.instance_variable_set("@#{k}", v)
219
- objectified.class.send(:define_method, k, proc { self.instance_variable_get("@#{k}") })
220
- end
221
- objectified
222
- end
223
-
224
- def arrayify(name, klass_or_proc=nil)
220
+ def arrayify(name, klass_or_proc = nil)
225
221
  data[name].map do |data|
226
222
  if klass_or_proc.nil?
227
223
  hash_to_object data
@@ -9,8 +9,12 @@ module Cloudflair
9
9
  end
10
10
 
11
11
  def to_s
12
- strings = cloudflare_errors.map { |cf_e| "\"#{cf_e[:message]}\" (Code: #{cf_e[:code]})" }
13
- "[ #{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
14
18
  end
15
19
  end
16
20
  end
@@ -1,3 +1,3 @@
1
1
  module Cloudflair
2
- VERSION = '0.0.7'.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.7
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-25 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
@@ -108,7 +108,21 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '3.0'
111
- description: Cloudflair aims to provide easy access to CloudFlares public API.
111
+ - !ruby/object:Gem::Dependency
112
+ name: dotenv
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.1'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.1'
125
+ description: Cloudflair aims to provide easy access to CloudFlare's public API.
112
126
  email:
113
127
  - christian.maeder@nine.ch
114
128
  executables: []
@@ -123,15 +137,20 @@ files:
123
137
  - LICENSE.txt
124
138
  - README.md
125
139
  - Rakefile
140
+ - bin/cloudflair
126
141
  - bin/console
127
142
  - bin/setup
128
143
  - cloudflair.gemspec
129
144
  - lib/cloudflair.rb
130
145
  - lib/cloudflair/api.rb
146
+ - lib/cloudflair/api/railguns.rb
131
147
  - lib/cloudflair/api/zone.rb
148
+ - lib/cloudflair/api/zone/analytics.rb
132
149
  - lib/cloudflair/api/zone/available_plan.rb
133
150
  - lib/cloudflair/api/zone/available_rate_plan.rb
151
+ - lib/cloudflair/api/zone/dns_record.rb
134
152
  - lib/cloudflair/api/zone/purge_cache.rb
153
+ - lib/cloudflair/api/zone/railgun.rb
135
154
  - lib/cloudflair/api/zone/settings.rb
136
155
  - lib/cloudflair/api/zone/settings/advanced_ddos.rb
137
156
  - lib/cloudflair/api/zone/settings/always_online.rb
@@ -163,6 +182,9 @@ files:
163
182
  - lib/cloudflair/api/zone/settings/true_client_ip_header.rb
164
183
  - lib/cloudflair/api/zone/settings/waf.rb
165
184
  - lib/cloudflair/api/zone/settings/websockets.rb
185
+ - lib/cloudflair/api/zone__available_plans.rb
186
+ - lib/cloudflair/api/zone__dns_records.rb
187
+ - lib/cloudflair/api/zone__railguns.rb
166
188
  - lib/cloudflair/communication.rb
167
189
  - lib/cloudflair/connection.rb
168
190
  - lib/cloudflair/entity.rb
@@ -190,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
212
  version: '0'
191
213
  requirements: []
192
214
  rubyforge_project:
193
- rubygems_version: 2.5.1
215
+ rubygems_version: 2.6.7
194
216
  signing_key:
195
217
  specification_version: 4
196
218
  summary: Wrapper to CloudFlare's v4 REST API.