cloudflair 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +38 -0
  3. data/.ruby-gemset +1 -0
  4. data/Gemfile +2 -0
  5. data/Rakefile +2 -0
  6. data/VERSION +1 -1
  7. data/cloudflair.gemspec +7 -6
  8. data/lib/cloudflair.rb +2 -0
  9. data/lib/cloudflair/api.rb +2 -0
  10. data/lib/cloudflair/api/railguns.rb +2 -0
  11. data/lib/cloudflair/api/zone.rb +2 -0
  12. data/lib/cloudflair/api/zone/analytics.rb +2 -0
  13. data/lib/cloudflair/api/zone/available_plan.rb +2 -0
  14. data/lib/cloudflair/api/zone/available_rate_plan.rb +2 -0
  15. data/lib/cloudflair/api/zone/custom_hostname.rb +2 -0
  16. data/lib/cloudflair/api/zone/dns_record.rb +3 -0
  17. data/lib/cloudflair/api/zone/purge_cache.rb +2 -0
  18. data/lib/cloudflair/api/zone/railgun.rb +2 -0
  19. data/lib/cloudflair/api/zone/settings.rb +30 -28
  20. data/lib/cloudflair/api/zone/settings/advanced_ddos.rb +2 -0
  21. data/lib/cloudflair/api/zone/settings/always_online.rb +2 -0
  22. data/lib/cloudflair/api/zone/settings/browser_cache_ttl.rb +2 -0
  23. data/lib/cloudflair/api/zone/settings/browser_check.rb +2 -0
  24. data/lib/cloudflair/api/zone/settings/cache_level.rb +2 -0
  25. data/lib/cloudflair/api/zone/settings/challenge_ttl.rb +2 -0
  26. data/lib/cloudflair/api/zone/settings/development_mode.rb +2 -0
  27. data/lib/cloudflair/api/zone/settings/email_obfuscation.rb +2 -0
  28. data/lib/cloudflair/api/zone/settings/hotlink_protection.rb +2 -0
  29. data/lib/cloudflair/api/zone/settings/ip_geolocation.rb +2 -0
  30. data/lib/cloudflair/api/zone/settings/ipv6.rb +2 -0
  31. data/lib/cloudflair/api/zone/settings/minify.rb +2 -0
  32. data/lib/cloudflair/api/zone/settings/mirage.rb +2 -0
  33. data/lib/cloudflair/api/zone/settings/mobile_redirect.rb +2 -0
  34. data/lib/cloudflair/api/zone/settings/origin_error_page_pass_thru.rb +2 -0
  35. data/lib/cloudflair/api/zone/settings/polish.rb +2 -0
  36. data/lib/cloudflair/api/zone/settings/prefetch_preload.rb +2 -0
  37. data/lib/cloudflair/api/zone/settings/response_buffering.rb +2 -0
  38. data/lib/cloudflair/api/zone/settings/rocket_loader.rb +2 -0
  39. data/lib/cloudflair/api/zone/settings/security_header.rb +2 -0
  40. data/lib/cloudflair/api/zone/settings/security_level.rb +2 -0
  41. data/lib/cloudflair/api/zone/settings/server_side_exclude.rb +2 -0
  42. data/lib/cloudflair/api/zone/settings/sort_query_string_for_cache.rb +2 -0
  43. data/lib/cloudflair/api/zone/settings/ssl.rb +2 -0
  44. data/lib/cloudflair/api/zone/settings/tls_1_2_only.rb +2 -0
  45. data/lib/cloudflair/api/zone/settings/tls_1_3.rb +2 -0
  46. data/lib/cloudflair/api/zone/settings/tls_client_auth.rb +2 -0
  47. data/lib/cloudflair/api/zone/settings/true_client_ip_header.rb +2 -0
  48. data/lib/cloudflair/api/zone/settings/waf.rb +2 -0
  49. data/lib/cloudflair/api/zone/settings/websockets.rb +2 -0
  50. data/lib/cloudflair/api/zone__available_plans.rb +2 -0
  51. data/lib/cloudflair/api/zone__custom_hostnames.rb +2 -0
  52. data/lib/cloudflair/api/zone__dns_records.rb +2 -2
  53. data/lib/cloudflair/api/zone__railguns.rb +2 -0
  54. data/lib/cloudflair/communication.rb +23 -20
  55. data/lib/cloudflair/connection.rb +21 -12
  56. data/lib/cloudflair/entity.rb +41 -42
  57. data/lib/cloudflair/error/cloudflair_error.rb +2 -0
  58. data/lib/cloudflair/error/cloudflare_error.rb +2 -0
  59. data/lib/cloudflair/version.rb +2 -0
  60. metadata +40 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2a69b1e26a488661affa4013c362307968f083f6e688bc3d63519de57415b58
4
- data.tar.gz: c3383bd0be796d11c49e11da606fbe4bbc6e2ae75c89a20c159b3479ebf9f629
3
+ metadata.gz: a94ec96903e9723de8176769d1ca3fa0a3d51fda907b6d53b17b7ad163cb73b0
4
+ data.tar.gz: 73d08b577e5c0bbd77d8f79afec19cb407882c03c6775aefa2da37ced0e60f22
5
5
  SHA512:
6
- metadata.gz: 130d30780e3df7779780f9240371fe936e24e99c4ba5e97203a3b15af88a978d1ad85a39d1738786068d1431cd9cc93fb2ab49e186a342b231f8360bbca26c9b
7
- data.tar.gz: 1d4737127f23eac7423dcf43f6be698e379d91fcd1402607477efd1fad7c6949897b3946962c6ca8803d8d28d2c0d3f0808ec3184d16ba593c741d886e587aca
6
+ metadata.gz: 521bc18990e5dd9d733da59353377385d95dc9c7e3d3342a9e79ff6dde48fa07ccc91be13420456fd4fc823c1bfdd92e1b1c20187cc9b76e7b1be865edc9415b
7
+ data.tar.gz: 76e763b2a0ad7614217b214ff19521af5c75b6ccfe4235a09450ce0878499632e32d172149fe6e1b855d90ff6db71b4338173ed3ff7e562bdeab38551280d893
@@ -0,0 +1,38 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ Exclude:
7
+ - 'bin/**/*'
8
+ - 'db/**/*'
9
+ TargetRubyVersion: 2.6.1
10
+
11
+ Layout/AlignHash:
12
+ EnforcedColonStyle: table
13
+ EnforcedHashRocketStyle: table
14
+
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - Guardfile
18
+ - 'spec/**/*spec.rb'
19
+
20
+ Metrics/LineLength:
21
+ Exclude:
22
+ - Guardfile
23
+ Max: 110
24
+
25
+ Rails:
26
+ Enabled: true
27
+
28
+ Rails/HttpPositionalArguments:
29
+ Exclude:
30
+
31
+ Rails/SkipsModelValidations:
32
+ Enabled: false
33
+
34
+ RSpec/MultipleExpectations:
35
+ Enabled: false
36
+
37
+ Style/Documentation:
38
+ Enabled: false
@@ -0,0 +1 @@
1
+ cloudflair
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in cloudflair.gemspec
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.3.0
@@ -1,6 +1,6 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'cloudflair/version'
6
6
 
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.name = 'cloudflair'
9
9
  spec.version = File.read('VERSION')
10
10
  spec.authors = ['Christian Mäder']
11
- spec.email = %w(christian.maeder@nine.ch)
11
+ spec.email = %w[christian.maeder@nine.ch]
12
12
 
13
13
  spec.summary = "Wrapper to CloudFlare's v4 REST API."
14
14
  spec.description = "Cloudflair aims to provide easy access to CloudFlare's public API."
@@ -22,15 +22,16 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = %w[lib]
24
24
 
25
- spec.add_runtime_dependency 'faraday', '>= 0.10.0'
26
- spec.add_runtime_dependency 'faraday_middleware'
27
25
  spec.add_runtime_dependency 'dry-configurable', '~> 0.1'
26
+ spec.add_runtime_dependency 'faraday', '>= 0.10.0'
28
27
  spec.add_runtime_dependency 'faraday-detailed_logger'
28
+ spec.add_runtime_dependency 'faraday_middleware'
29
29
 
30
30
  spec.add_development_dependency 'bundler', '~> 2.0.0'
31
+ spec.add_development_dependency 'dotenv', '~> 2.1'
31
32
  spec.add_development_dependency 'rake', '~> 12.0'
32
33
  spec.add_development_dependency 'rspec', '~> 3.0'
33
- spec.add_development_dependency 'dotenv', '~> 2.1'
34
34
  spec.add_development_dependency 'rubocop', '~> 0.48'
35
+ spec.add_development_dependency 'rubocop-performance'
35
36
  spec.add_development_dependency 'rubocop-rspec', '~> 1.15'
36
37
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/api'
2
4
  require 'cloudflair/version'
3
5
  require 'dry-configurable'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/api/zone'
2
4
  require 'cloudflair/api/railguns'
3
5
  require 'cloudflair/communication'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/api/zone/analytics'
2
4
  require 'cloudflair/api/zone/available_plan'
3
5
  require 'cloudflair/api/zone/available_rate_plan'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -6,6 +8,7 @@ module Cloudflair
6
8
 
7
9
  attr_reader :zone_id, :record_id
8
10
  deletable true
11
+ patchable_fields :content
9
12
  path 'zones/:zone_id/dns_records/:record_id'
10
13
 
11
14
  def initialize(zone_id, record_id)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/communication'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/api/zone/settings/advanced_ddos'
2
4
  require 'cloudflair/api/zone/settings/always_online'
3
5
  require 'cloudflair/api/zone/settings/browser_cache_ttl'
@@ -38,36 +40,36 @@ module Cloudflair
38
40
  end
39
41
 
40
42
  {
41
- advanced_ddos: Cloudflair::AdvancedDdos,
42
- always_online: Cloudflair::AlwaysOnline,
43
- browser_cache_ttl: Cloudflair::BrowserCacheTtl,
44
- browser_check: Cloudflair::BrowserCheck,
45
- cache_level: Cloudflair::CacheLevel,
46
- challenge_ttl: Cloudflair::ChallengeTtl,
47
- development_mode: Cloudflair::DevelopmentMode,
48
- email_obfuscation: Cloudflair::EmailObfuscation,
49
- hotlink_protection: Cloudflair::HotlinkProtection,
50
- ip_geolocation: Cloudflair::IpGeolocation,
51
- ipv6: Cloudflair::Ipv6,
52
- minify: Cloudflair::Minify,
53
- mirage: Cloudflair::Mirage,
54
- mobile_redirect: Cloudflair::MobileRedirect,
43
+ advanced_ddos: Cloudflair::AdvancedDdos,
44
+ always_online: Cloudflair::AlwaysOnline,
45
+ browser_cache_ttl: Cloudflair::BrowserCacheTtl,
46
+ browser_check: Cloudflair::BrowserCheck,
47
+ cache_level: Cloudflair::CacheLevel,
48
+ challenge_ttl: Cloudflair::ChallengeTtl,
49
+ development_mode: Cloudflair::DevelopmentMode,
50
+ email_obfuscation: Cloudflair::EmailObfuscation,
51
+ hotlink_protection: Cloudflair::HotlinkProtection,
52
+ ip_geolocation: Cloudflair::IpGeolocation,
53
+ ipv6: Cloudflair::Ipv6,
54
+ minify: Cloudflair::Minify,
55
+ mirage: Cloudflair::Mirage,
56
+ mobile_redirect: Cloudflair::MobileRedirect,
55
57
  origin_error_page_pass_thru: Cloudflair::OriginErrorPagePassThru,
56
- polish: Cloudflair::Polish,
57
- prefetch_preload: Cloudflair::PrefetchPreload,
58
- response_buffering: Cloudflair::ResponseBuffering,
59
- rocket_loader: Cloudflair::RocketLoader,
60
- security_header: Cloudflair::SecurityHeader,
61
- security_level: Cloudflair::SecurityLevel,
62
- server_side_exclude: Cloudflair::ServerSideExclude,
58
+ polish: Cloudflair::Polish,
59
+ prefetch_preload: Cloudflair::PrefetchPreload,
60
+ response_buffering: Cloudflair::ResponseBuffering,
61
+ rocket_loader: Cloudflair::RocketLoader,
62
+ security_header: Cloudflair::SecurityHeader,
63
+ security_level: Cloudflair::SecurityLevel,
64
+ server_side_exclude: Cloudflair::ServerSideExclude,
63
65
  sort_query_string_for_cache: Cloudflair::SortQueryStringForCache,
64
- ssl: Cloudflair::Ssl,
65
- tls_client_auth: Cloudflair::TlsClientAuth,
66
- tls_1_2_only: Cloudflair::Tls12Only,
67
- tls_1_3: Cloudflair::Tls13,
68
- true_client_ip_header: Cloudflair::TrueClientIpHeader,
69
- waf: Cloudflair::Waf,
70
- websockets: Cloudflair::Websockets,
66
+ ssl: Cloudflair::Ssl,
67
+ tls_client_auth: Cloudflair::TlsClientAuth,
68
+ tls_1_2_only: Cloudflair::Tls12Only,
69
+ tls_1_3: Cloudflair::Tls13,
70
+ true_client_ip_header: Cloudflair::TrueClientIpHeader,
71
+ waf: Cloudflair::Waf,
72
+ websockets: Cloudflair::Websockets
71
73
  }.each do |method, klass|
72
74
  define_method method do
73
75
  klass.new @zone_id
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/entity'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/api/zone/available_plan'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/api/zone/custom_hostname'
2
4
 
3
5
  module Cloudflair
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/api/zone/dns_record'
2
4
 
3
5
  module Cloudflair
4
6
  class Zone
5
7
  def dns_records(filter = {})
6
8
  raw_records = response connection.get("#{path}/dns_records", filter)
7
-
8
9
  raw_records.map { |raw_record| build_dns_record(raw_record) }
9
10
  end
10
11
 
@@ -14,7 +15,6 @@ module Cloudflair
14
15
 
15
16
  def new_dns_record(record_data)
16
17
  raw_record = response connection.post("#{path}/dns_records", record_data)
17
-
18
18
  build_dns_record raw_record
19
19
  end
20
20
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/api/zone/railgun'
2
4
 
3
5
  module Cloudflair
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/error/cloudflare_error'
2
4
  require 'cloudflair/error/cloudflair_error'
3
5
  require 'cloudflair/connection'
@@ -35,8 +37,9 @@ module Cloudflair
35
37
  body = response.body
36
38
 
37
39
  unless body['success']
38
- fail Cloudflair::CloudflairError, "Unrecognized response format: '#{body}'" unless body['errors']
39
- fail Cloudflair::CloudflareError, body['errors']
40
+ raise Cloudflair::CloudflairError, "Unrecognized response format: '#{body}'" unless body['errors']
41
+
42
+ raise Cloudflair::CloudflareError, body['errors']
40
43
  end
41
44
 
42
45
  body['result']
@@ -44,32 +47,32 @@ module Cloudflair
44
47
 
45
48
  def raise_on_http_error(status)
46
49
  case status
47
- when 200..399 then
48
- when 400..499 then
50
+ when 200..399
51
+ when 400..499
49
52
  raise_on_http_client_error status
50
- when 500..599 then
51
- fail Cloudflair::CloudflairError, "#{status} Remote Error"
53
+ when 500..599
54
+ raise Cloudflair::CloudflairError, "#{status} Remote Error"
52
55
  else
53
- fail Cloudflair::CloudflairError, "#{status} Unknown Error Code"
56
+ raise Cloudflair::CloudflairError, "#{status} Unknown Error Code"
54
57
  end
55
58
  end
56
59
 
57
60
  def raise_on_http_client_error(status)
58
61
  case status
59
- when 400 then
60
- fail Cloudflair::CloudflairError, '400 Bad Request'
61
- when 401 then
62
- fail Cloudflair::CloudflairError, '401 Unauthorized'
63
- when 403 then
64
- fail Cloudflair::CloudflairError, '403 Forbidden'
65
- when 405 then
66
- fail Cloudflair::CloudflairError, '405 Method Not Allowed'
67
- when 415 then
68
- fail Cloudflair::CloudflairError, '415 Unsupported Media Type'
69
- when 429 then
70
- fail Cloudflair::CloudflairError, '429 Too Many Requests'
62
+ when 400
63
+ raise Cloudflair::CloudflairError, '400 Bad Request'
64
+ when 401
65
+ raise Cloudflair::CloudflairError, '401 Unauthorized'
66
+ when 403
67
+ raise Cloudflair::CloudflairError, '403 Forbidden'
68
+ when 405
69
+ raise Cloudflair::CloudflairError, '405 Method Not Allowed'
70
+ when 415
71
+ raise Cloudflair::CloudflairError, '415 Unsupported Media Type'
72
+ when 429
73
+ raise Cloudflair::CloudflairError, '429 Too Many Requests'
71
74
  else
72
- fail Cloudflair::CloudflairError, "#{status} Request Error"
75
+ raise Cloudflair::CloudflairError, "#{status} Request Error"
73
76
  end
74
77
  end
75
78
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'faraday'
2
4
  require 'faraday_middleware'
3
5
  require 'faraday/detailed_logger'
@@ -7,25 +9,32 @@ module Cloudflair
7
9
  class Connection
8
10
  def self.new
9
11
  config = Cloudflair.config
10
-
11
12
  new_faraday_from config
12
13
  end
13
14
 
14
- def self.headers
15
- headers = {}
15
+ def self.headers # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
16
16
  cloudflare_auth_config = Cloudflair.config.cloudflare.auth
17
- if !(cloudflare_auth_config.key.nil? || cloudflare_auth_config.email.nil?)
18
- headers['X-Auth-Key'] = cloudflare_auth_config.key
19
- headers['X-Auth-Email'] = cloudflare_auth_config.email
20
- elsif !cloudflare_auth_config.user_service_key.nil?
21
- headers['X-Auth-User-Service-Key'] = cloudflare_auth_config.user_service_key
22
- else
23
- raise CloudflairError, 'Neither email & key nor user_service_key have been defined.'
17
+
18
+ if !cloudflare_auth_config.key.nil? && !cloudflare_auth_config.email.nil?
19
+ return({
20
+ 'X-Auth-Key' => cloudflare_auth_config.key,
21
+ 'X-Auth-Email' => cloudflare_auth_config.email
22
+ })
24
23
  end
25
- headers
24
+
25
+ unless cloudflare_auth_config.user_service_key.nil?
26
+ return({
27
+ 'Authorization' => "Bearer #{cloudflare_auth_config.user_service_key}"
28
+ })
29
+ end
30
+
31
+ raise(
32
+ CloudflairError,
33
+ 'Neither email & key nor user_service_key have been defined.'
34
+ )
26
35
  end
27
36
 
28
- private_class_method def self.new_faraday_from(config)
37
+ private_class_method def self.new_faraday_from(config) # rubocop:disable Metrics/AbcSize
29
38
  Faraday.new(url: config.cloudflare.api_base_url, headers: headers) do |faraday|
30
39
  faraday.request :json
31
40
  faraday.response config.faraday.logger if config.faraday.logger
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cloudflair/communication'
2
4
 
3
5
  module Cloudflair
@@ -16,13 +18,14 @@ module Cloudflair
16
18
  def patchable_fields(*fields)
17
19
  return @patchable_fields if @patchable_fields
18
20
 
19
- if fields.nil?
20
- @patchable_fields = []
21
- elsif fields.is_a?(Array)
22
- @patchable_fields = fields.map(&:to_s)
23
- else
24
- @patchable_fields = [fields.to_s]
25
- end
21
+ @patchable_fields =
22
+ if fields.nil?
23
+ []
24
+ elsif fields.is_a?(Array)
25
+ fields.map(&:to_s)
26
+ else
27
+ [fields.to_s]
28
+ end
26
29
  end
27
30
 
28
31
  def deletable(deletable = false)
@@ -34,7 +37,7 @@ module Cloudflair
34
37
  def path(path = nil)
35
38
  return @path if @path
36
39
 
37
- fail ArgumentError, 'path is not defined' if path.nil?
40
+ raise ArgumentError, 'path is not defined' if path.nil?
38
41
 
39
42
  @path = path
40
43
  end
@@ -42,11 +45,12 @@ module Cloudflair
42
45
  def object_fields(*fields)
43
46
  return @object_fields if @object_fields
44
47
 
45
- if fields.nil? || fields.empty?
46
- @object_fields = []
47
- else
48
- @object_fields = fields.map(&:to_s)
49
- end
48
+ @object_fields =
49
+ if fields.nil? || fields.empty?
50
+ []
51
+ else
52
+ fields.map(&:to_s)
53
+ end
50
54
  end
51
55
 
52
56
  # allowed values:
@@ -69,17 +73,17 @@ module Cloudflair
69
73
  end
70
74
 
71
75
  def turn_all_items_into_a_single_hash(fields_to_class_map)
72
- fields_map = {}
73
- fields_to_class_map.each do |field_definition|
74
- if field_definition.is_a?(Hash)
75
- fields_to_class_map[0].each do |field, klass_or_proc|
76
- fields_map[field.to_s] = klass_or_proc
76
+ {}.tap do |fields_map|
77
+ fields_to_class_map.each do |field_definition|
78
+ if field_definition.is_a?(Hash)
79
+ fields_to_class_map[0].each do |field, klass_or_proc|
80
+ fields_map[field.to_s] = klass_or_proc
81
+ end
82
+ else
83
+ fields_map[field_definition.to_s] = nil
77
84
  end
78
- else
79
- fields_map[field_definition.to_s] = nil
80
85
  end
81
86
  end
82
- fields_map
83
87
  end
84
88
  end
85
89
 
@@ -102,7 +106,7 @@ module Cloudflair
102
106
  end
103
107
 
104
108
  def delete
105
- fail Cloudflair::CloudflairError, "Can't delete unless deletable=true" unless deletable
109
+ raise Cloudflair::CloudflairError, "Can't delete unless deletable=true" unless deletable
106
110
  return self if @deleted
107
111
 
108
112
  @data = response connection.delete path
@@ -126,27 +130,23 @@ module Cloudflair
126
130
  def method_missing(name_as_symbol, *args, &block)
127
131
  name = normalize_accessor name_as_symbol
128
132
 
129
- return data if :_raw_data! == name_as_symbol
133
+ return data if name_as_symbol == :_raw_data!
130
134
 
131
135
  if name.end_with?('=')
132
136
  if patchable_fields.include?(name[0..-2])
133
137
  dirty_data[name[0..-2]] = args[0]
134
138
  return
135
- else
136
- super
137
139
  end
138
- end
139
140
 
140
- # allow access to the unmodified data using 'zone.always_string!' or 'zone._name!'
141
- if name.end_with?('!') && data.keys.include?(name[0..-2])
142
- return data[name[0..2]]
141
+ super
143
142
  end
144
143
 
144
+ # allow access to the unmodified data using 'zone.always_string!' or 'zone._name!'
145
+ return data[name[0..2]] if name.end_with?('!') && data.key?(name[0..-2])
145
146
  return objectify(name) if object_fields.include? name
146
- return arrayify(name, array_object_fields[name]) if array_object_fields.keys.include? name
147
-
148
- return dirty_data[name] if dirty_data.keys.include? name
149
- return data[name] if data.is_a?(Hash) && data.keys.include?(name)
147
+ return arrayify(name, array_object_fields[name]) if array_object_fields.key?(name)
148
+ return dirty_data[name] if dirty_data.key?(name)
149
+ return data[name] if data.is_a?(Hash) && data.key?(name)
150
150
 
151
151
  super
152
152
  end
@@ -154,16 +154,13 @@ module Cloudflair
154
154
  def respond_to_missing?(name_as_symbol, *args)
155
155
  name = normalize_accessor name_as_symbol
156
156
 
157
- return true if :_raw_data! == name_as_symbol
158
-
157
+ return true if name_as_symbol == :_raw_data!
159
158
  return true if name.end_with?('=') && patchable_fields.include?(name[0..-2])
160
- return true if name.end_with?('!') && data.keys.include?(name[0..-2])
161
-
159
+ return true if name.end_with?('!') && data.key?(name[0..-2])
162
160
  return true if object_fields.include? name
163
- return true if array_object_fields.keys.include? name
164
-
165
- return true if dirty_data.keys.include? name
166
- return true if data.is_a?(Hash) && data.keys.include?(name)
161
+ return true if array_object_fields.key?(name)
162
+ return true if dirty_data.key?(name)
163
+ return true if data.is_a?(Hash) && data.key?(name)
167
164
 
168
165
  super
169
166
  end
@@ -235,9 +232,11 @@ module Cloudflair
235
232
 
236
233
  def replace_path_variables_in(path)
237
234
  interpreted_path = path.clone
235
+
238
236
  path.scan(/:([a-zA-Z_][a-zA-Z0-9_]+[!?=]?)/) do |match, *|
239
- interpreted_path.gsub! ":#{match}", send(match).to_s
237
+ interpreted_path = interpreted_path.gsub ":#{match}", send(match).to_s
240
238
  end
239
+
241
240
  interpreted_path
242
241
  end
243
242
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Cloudflair
2
4
  class CloudflairError < StandardError
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Cloudflair
2
4
  class CloudflareError < StandardError
3
5
  attr_reader :cloudflare_errors
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Cloudflair
2
4
  end
metadata CHANGED
@@ -1,59 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudflair
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
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: 2019-05-22 00:00:00.000000000 Z
11
+ date: 2019-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: faraday
14
+ name: dry-configurable
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.10.0
19
+ version: '0.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.10.0
26
+ version: '0.1'
27
27
  - !ruby/object:Gem::Dependency
28
- name: faraday_middleware
28
+ name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.10.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 0.10.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: dry-configurable
42
+ name: faraday-detailed_logger
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0.1'
47
+ version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0.1'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: faraday-detailed_logger
56
+ name: faraday_middleware
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 2.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: dotenv
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.1'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rake
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -109,33 +123,33 @@ dependencies:
109
123
  - !ruby/object:Gem::Version
110
124
  version: '3.0'
111
125
  - !ruby/object:Gem::Dependency
112
- name: dotenv
126
+ name: rubocop
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '2.1'
131
+ version: '0.48'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '2.1'
138
+ version: '0.48'
125
139
  - !ruby/object:Gem::Dependency
126
- name: rubocop
140
+ name: rubocop-performance
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
- - - "~>"
143
+ - - ">="
130
144
  - !ruby/object:Gem::Version
131
- version: '0.48'
145
+ version: '0'
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - "~>"
150
+ - - ">="
137
151
  - !ruby/object:Gem::Version
138
- version: '0.48'
152
+ version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: rubocop-rspec
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -159,6 +173,8 @@ extra_rdoc_files: []
159
173
  files:
160
174
  - ".gitignore"
161
175
  - ".rspec"
176
+ - ".rubocop.yml"
177
+ - ".ruby-gemset"
162
178
  - ".ruby-version"
163
179
  - ".travis.yml"
164
180
  - Gemfile