cloudflair 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cloudflair/api/zone/available_plan.rb +16 -0
  3. data/lib/cloudflair/api/zone/available_rate_plan.rb +15 -0
  4. data/lib/cloudflair/api/zone/settings/advanced_ddos.rb +15 -0
  5. data/lib/cloudflair/api/zone/settings/always_online.rb +16 -0
  6. data/lib/cloudflair/api/zone/settings/browser_cache_ttl.rb +16 -0
  7. data/lib/cloudflair/api/zone/settings/browser_check.rb +16 -0
  8. data/lib/cloudflair/api/zone/settings/cache_level.rb +16 -0
  9. data/lib/cloudflair/api/zone/settings/challenge_ttl.rb +16 -0
  10. data/lib/cloudflair/api/zone/settings/development_mode.rb +5 -1
  11. data/lib/cloudflair/api/zone/settings/email_obfuscation.rb +16 -0
  12. data/lib/cloudflair/api/zone/settings/hotlink_protection.rb +16 -0
  13. data/lib/cloudflair/api/zone/settings/ip_geolocation.rb +16 -0
  14. data/lib/cloudflair/api/zone/settings/ipv6.rb +16 -0
  15. data/lib/cloudflair/api/zone/settings/minify.rb +16 -0
  16. data/lib/cloudflair/api/zone/settings/mirage.rb +16 -0
  17. data/lib/cloudflair/api/zone/settings/mobile_redirect.rb +16 -0
  18. data/lib/cloudflair/api/zone/settings/origin_error_page_pass_thru.rb +19 -0
  19. data/lib/cloudflair/api/zone/settings/polish.rb +16 -0
  20. data/lib/cloudflair/api/zone/settings/prefetch_preload.rb +20 -0
  21. data/lib/cloudflair/api/zone/settings/response_buffering.rb +20 -0
  22. data/lib/cloudflair/api/zone/settings/rocket_loader.rb +16 -0
  23. data/lib/cloudflair/api/zone/settings/security_header.rb +16 -0
  24. data/lib/cloudflair/api/zone/settings/security_level.rb +16 -0
  25. data/lib/cloudflair/api/zone/settings/server_side_exclude.rb +16 -0
  26. data/lib/cloudflair/api/zone/settings/sort_query_string_for_cache.rb +19 -0
  27. data/lib/cloudflair/api/zone/settings/ssl.rb +16 -0
  28. data/lib/cloudflair/api/zone/settings/tls_1_2_only.rb +20 -0
  29. data/lib/cloudflair/api/zone/settings/tls_1_3.rb +20 -0
  30. data/lib/cloudflair/api/zone/settings/tls_client_auth.rb +16 -0
  31. data/lib/cloudflair/api/zone/settings/true_client_ip_header.rb +19 -0
  32. data/lib/cloudflair/api/zone/settings/waf.rb +16 -0
  33. data/lib/cloudflair/api/zone/settings/websockets.rb +16 -0
  34. data/lib/cloudflair/api/zone/settings.rb +63 -2
  35. data/lib/cloudflair/api/zone.rb +20 -3
  36. data/lib/cloudflair/api.rb +4 -4
  37. data/lib/cloudflair/entity.rb +99 -12
  38. data/lib/cloudflair/version.rb +1 -1
  39. metadata +33 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0026c99261c0b4e103318525b4ae84d4a355ee3
4
- data.tar.gz: ea221bddb6dad9ff7d3a34c6e9c7c4d5950d9c8c
3
+ metadata.gz: 56fd1197bf91ccbbbc25632cc55246356689b74f
4
+ data.tar.gz: 77fc8bb524ef60c7a64e089799a3b32ed17b49b7
5
5
  SHA512:
6
- metadata.gz: c00fb8e18dcd6fb0ffd246782a4cd814d7d0bf09a1c67a12deceab171b5c0b9ad0948b31d2371e5bc9440d8e8f19eed8558fc2370d9f99cb1404346ba0765894
7
- data.tar.gz: 887e4a0fd254b061c1777c73d505a4a0588e8b86c2e623a70a9bcbc5b5c3b6e5f9c6bf60b90aafc735633bb7641a87b826db9c4777a6d68918864fa31968b8dc
6
+ metadata.gz: cdf21b581458669d7c5a41df55ca8e9cd4f6547564e691af98afec05f86b45f9b77eff79b1fd5995679eba1946022a9ebba31a66a509dc52b3f6a0f4e28e94c3
7
+ data.tar.gz: e55e62b873549576a13b085afd5fbd0bb3fbf53f6e12091d009929d47e03bb00f16958a8ab72db69073cef116839956830b4c1a6de5ed9f8f91e960112fa8b03
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class AvailablePlan
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id, :plan_id
8
+
9
+ path 'zones/:zone_id/available_plans/:plan_id'
10
+
11
+ def initialize(zone_id, plan_id)
12
+ @zone_id = zone_id
13
+ @plan_id = plan_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class AvailableRatePlan
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+ array_object_fields :components
9
+ path 'zones/:zone_id/available_rate_plans'
10
+
11
+ def initialize(zone_id)
12
+ @zone_id = zone_id
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class AdvancedDdos
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ path 'zones/:zone_id/settings/advanced_ddos'
10
+
11
+ def initialize(zone_id)
12
+ @zone_id = zone_id
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class AlwaysOnline
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/always_online'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class BrowserCacheTtl
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/browser_cache_ttl'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class BrowserCheck
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/browser_check'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class CacheLevel
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/cache_level'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class ChallengeTtl
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/challenge_ttl'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -4,7 +4,7 @@ module Cloudflair
4
4
  class DevelopmentMode
5
5
  include Cloudflair::Entity
6
6
 
7
- attr_accessor :zone_id
7
+ attr_reader :zone_id
8
8
 
9
9
  patchable_fields :value
10
10
  path 'zones/:zone_id/settings/development_mode'
@@ -12,5 +12,9 @@ module Cloudflair
12
12
  def initialize(zone_id)
13
13
  @zone_id = zone_id
14
14
  end
15
+
16
+ def time_remaining
17
+ data.fetch('time_remaining', 0)
18
+ end
15
19
  end
16
20
  end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class EmailObfuscation
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/email_obfuscation'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class HotlinkProtection
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/hotlink_protection'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class IpGeolocation
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/ip_geolocation'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class Ipv6
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/ipv6'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class Minify
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/minify'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class Mirage
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/mirage'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class MobileRedirect
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/mobile_redirect'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class OriginErrorPagePassThru
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ path 'zones/:zone_id/settings/origin_error_page_pass_thru'
10
+
11
+ def initialize(zone_id)
12
+ @zone_id = zone_id
13
+ end
14
+
15
+ def value
16
+ _raw_data!
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class Polish
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/polish'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class PrefetchPreload
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/prefetch_preload'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+
16
+ def value
17
+ _raw_data!
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class ResponseBuffering
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/response_buffering'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+
16
+ def value
17
+ _raw_data!
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class RocketLoader
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/rocket_loader'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class SecurityHeader
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/security_header'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class SecurityLevel
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/security_level'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class ServerSideExclude
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/server_side_exclude'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class SortQueryStringForCache
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ path 'zones/:zone_id/settings/sort_query_string_for_cache'
10
+
11
+ def initialize(zone_id)
12
+ @zone_id = zone_id
13
+ end
14
+
15
+ def value
16
+ _raw_data!
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class Ssl
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/ssl'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class Tls12Only
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/tls_1_2_only'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+
16
+ def value
17
+ _raw_data!
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class Tls13
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/tls_1_3'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+
16
+ def value
17
+ _raw_data!
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class TlsClientAuth
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/tls_client_auth'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class TrueClientIpHeader
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+ patchable_fields :value
9
+ path 'zones/:zone_id/settings/true_client_ip_header'
10
+
11
+ def initialize(zone_id)
12
+ @zone_id = zone_id
13
+ end
14
+
15
+ def value
16
+ _raw_data!
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class Waf
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/waf'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'cloudflair/entity'
2
+
3
+ module Cloudflair
4
+ class Websockets
5
+ include Cloudflair::Entity
6
+
7
+ attr_reader :zone_id
8
+
9
+ patchable_fields :value
10
+ path 'zones/:zone_id/settings/websockets'
11
+
12
+ def initialize(zone_id)
13
+ @zone_id = zone_id
14
+ end
15
+ end
16
+ end
@@ -1,4 +1,33 @@
1
+ require 'cloudflair/api/zone/settings/advanced_ddos'
2
+ require 'cloudflair/api/zone/settings/always_online'
3
+ require 'cloudflair/api/zone/settings/browser_cache_ttl'
4
+ require 'cloudflair/api/zone/settings/browser_check'
5
+ require 'cloudflair/api/zone/settings/cache_level'
6
+ require 'cloudflair/api/zone/settings/challenge_ttl'
1
7
  require 'cloudflair/api/zone/settings/development_mode'
8
+ require 'cloudflair/api/zone/settings/email_obfuscation'
9
+ require 'cloudflair/api/zone/settings/hotlink_protection'
10
+ require 'cloudflair/api/zone/settings/ip_geolocation'
11
+ require 'cloudflair/api/zone/settings/ipv6'
12
+ require 'cloudflair/api/zone/settings/minify'
13
+ require 'cloudflair/api/zone/settings/mirage'
14
+ require 'cloudflair/api/zone/settings/mobile_redirect'
15
+ require 'cloudflair/api/zone/settings/origin_error_page_pass_thru'
16
+ require 'cloudflair/api/zone/settings/polish'
17
+ require 'cloudflair/api/zone/settings/prefetch_preload'
18
+ require 'cloudflair/api/zone/settings/response_buffering'
19
+ require 'cloudflair/api/zone/settings/rocket_loader'
20
+ require 'cloudflair/api/zone/settings/security_header'
21
+ require 'cloudflair/api/zone/settings/security_level'
22
+ require 'cloudflair/api/zone/settings/server_side_exclude'
23
+ require 'cloudflair/api/zone/settings/sort_query_string_for_cache'
24
+ require 'cloudflair/api/zone/settings/ssl'
25
+ require 'cloudflair/api/zone/settings/tls_client_auth'
26
+ require 'cloudflair/api/zone/settings/tls_1_2_only'
27
+ require 'cloudflair/api/zone/settings/tls_1_3'
28
+ require 'cloudflair/api/zone/settings/true_client_ip_header'
29
+ require 'cloudflair/api/zone/settings/waf'
30
+ require 'cloudflair/api/zone/settings/websockets'
2
31
 
3
32
  module Cloudflair
4
33
  class Settings
@@ -8,8 +37,40 @@ module Cloudflair
8
37
  @zone_id = zone_id
9
38
  end
10
39
 
11
- def development_mode
12
- Cloudflair::DevelopmentMode.new @zone_id
40
+ { advanced_ddos: Cloudflair::AdvancedDdos,
41
+ always_online: Cloudflair::AlwaysOnline,
42
+ browser_cache_ttl: Cloudflair::BrowserCacheTtl,
43
+ browser_check: Cloudflair::BrowserCheck,
44
+ cache_level: Cloudflair::CacheLevel,
45
+ challenge_ttl: Cloudflair::ChallengeTtl,
46
+ development_mode: Cloudflair::DevelopmentMode,
47
+ email_obfuscation: Cloudflair::EmailObfuscation,
48
+ hotlink_protection: Cloudflair::HotlinkProtection,
49
+ ip_geolocation: Cloudflair::IpGeolocation,
50
+ ipv6: Cloudflair::Ipv6,
51
+ minify: Cloudflair::Minify,
52
+ mirage: Cloudflair::Mirage,
53
+ mobile_redirect: Cloudflair::MobileRedirect,
54
+ origin_error_page_pass_thru: Cloudflair::OriginErrorPagePassThru,
55
+ polish: Cloudflair::Polish,
56
+ prefetch_preload: Cloudflair::PrefetchPreload,
57
+ response_buffering: Cloudflair::ResponseBuffering,
58
+ rocket_loader: Cloudflair::RocketLoader,
59
+ security_header: Cloudflair::SecurityHeader,
60
+ security_level: Cloudflair::SecurityLevel,
61
+ server_side_exclude: Cloudflair::ServerSideExclude,
62
+ sort_query_string_for_cache: Cloudflair::SortQueryStringForCache,
63
+ ssl: Cloudflair::Ssl,
64
+ tls_client_auth: Cloudflair::TlsClientAuth,
65
+ tls_1_2_only: Cloudflair::Tls12Only,
66
+ tls_1_3: Cloudflair::Tls13,
67
+ true_client_ip_header: Cloudflair::TrueClientIpHeader,
68
+ waf: Cloudflair::Waf,
69
+ websockets: Cloudflair::Websockets,
70
+ }.each do |method, klass|
71
+ define_method method do
72
+ klass.new @zone_id
73
+ end
13
74
  end
14
75
  end
15
76
  end
@@ -1,5 +1,7 @@
1
- require 'cloudflair/api/zone/settings'
1
+ require 'cloudflair/api/zone/available_plan'
2
+ require 'cloudflair/api/zone/available_rate_plan'
2
3
  require 'cloudflair/api/zone/purge_cache'
4
+ require 'cloudflair/api/zone/settings'
3
5
  require 'cloudflair/entity'
4
6
 
5
7
  module Cloudflair
@@ -9,6 +11,7 @@ module Cloudflair
9
11
  attr_reader :zone_id
10
12
 
11
13
  patchable_fields :paused, :vanity_name_servers, :plan
14
+ object_fields :plan, :plan_pending, :owner
12
15
  deletable true
13
16
  path 'zones/:zone_id'
14
17
 
@@ -17,11 +20,25 @@ module Cloudflair
17
20
  end
18
21
 
19
22
  def settings
20
- @settings ||= Cloudflair::Settings.new zone_id
23
+ Cloudflair::Settings.new zone_id
21
24
  end
22
25
 
23
26
  def purge_cache
24
- @purge_cache ||= Cloudflair::PurgeCache.new zone_id
27
+ Cloudflair::PurgeCache.new zone_id
28
+ end
29
+
30
+ def available_rate_plans
31
+ Cloudflair::AvailableRatePlan.new zone_id
32
+ end
33
+
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
25
42
  end
26
43
  end
27
44
  end
@@ -9,11 +9,11 @@ module Cloudflair
9
9
  end
10
10
 
11
11
  def self.zones(filter = {})
12
- json_hashes = response connection.get('zones', filter)
12
+ raw_zones = response connection.get('zones', filter)
13
13
 
14
- json_hashes.map do |json|
15
- zone = Zone.new(json['id'])
16
- zone.data = json
14
+ raw_zones.map do |raw_zone|
15
+ zone = Zone.new(raw_zone['id'])
16
+ zone.data = raw_zone
17
17
  zone
18
18
  end
19
19
  end
@@ -9,6 +9,12 @@ module Cloudflair
9
9
  end
10
10
 
11
11
  module ClassMethods
12
+ def self.extended(other_klass)
13
+ @other_klass = other_klass
14
+ end
15
+
16
+ attr_accessor :fields_wrapper_class
17
+
12
18
  def patchable_fields(*fields)
13
19
  return @patchable_fields if @patchable_fields
14
20
 
@@ -34,10 +40,48 @@ module Cloudflair
34
40
 
35
41
  @path = path
36
42
  end
43
+
44
+ def object_fields(*fields)
45
+ return @object_fields if @object_fields
46
+
47
+ if fields.nil? || fields.empty?
48
+ @object_fields = []
49
+ else
50
+ @object_fields = fields.map(&:to_s)
51
+ end
52
+ end
53
+
54
+ # allowed values:
55
+ # <code>
56
+ # array_object_fields :field_a, :field_b, :field_c, 'fieldname_as_string'
57
+ # # next is ame as previous
58
+ # array_object_fields field_a: nil, field_b: nil, field_c: nil, 'fieldname_as_string': nil
59
+ # # next defines the types of the objects
60
+ # array_object_fields field_a: Klass, field_b: proc { |data| Klass.new data }, field_c: nil, 'fieldname_as_string'
61
+ # </code>
62
+ def array_object_fields(*fields_to_class_map)
63
+ return @array_object_fields if @array_object_fields
64
+
65
+ if fields_to_class_map.nil? || fields_to_class_map.empty?
66
+ @array_object_fields = {}
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
76
+ end
77
+ end
78
+ @array_object_fields = fields_map
79
+ end
80
+ end
37
81
  end
38
82
 
39
83
  def revert
40
- dirty.clear
84
+ dirty_data.clear
41
85
  end
42
86
 
43
87
  def reload
@@ -47,9 +91,9 @@ module Cloudflair
47
91
  end
48
92
 
49
93
  def patch
50
- return self if dirty.empty?
94
+ return self if dirty_data.empty?
51
95
 
52
- @data = response connection.patch path, dirty
96
+ @data = response connection.patch path, dirty_data
53
97
  revert
54
98
  self
55
99
  end
@@ -72,29 +116,34 @@ module Cloudflair
72
116
  checked_updated_fields[s_key] = values if patchable_fields.include? s_key
73
117
  end
74
118
 
75
- dirty.merge! checked_updated_fields
119
+ dirty_data.merge! checked_updated_fields
76
120
  patch
77
121
  end
78
122
 
79
123
  def method_missing(name_as_symbol, *args, &block)
80
124
  name = normalize_accessor name_as_symbol
81
125
 
126
+ return data if :_raw_data! == name_as_symbol
127
+
82
128
  if name.end_with?('=')
83
129
  if patchable_fields.include?(name[0..-2])
84
- dirty[name[0..-2]] = args[0]
130
+ dirty_data[name[0..-2]] = args[0]
85
131
  return
86
132
  else
87
133
  super
88
134
  end
89
135
  end
90
136
 
91
- # allow access to the original data using 'zone.always_string!' or 'zone._name!'
137
+ # allow access to the unmodified data using 'zone.always_string!' or 'zone._name!'
92
138
  if name.end_with?('!') && data.keys.include?(name[0..-2])
93
139
  return data[name[0..2]]
94
140
  end
95
141
 
96
- return dirty[name] if dirty.keys.include? name
97
- return data[name] if data.keys.include? name
142
+ return objectify(name) if object_fields.include? name
143
+ return arrayify(name, array_object_fields[name]) if array_object_fields.keys.include? name
144
+
145
+ return dirty_data[name] if dirty_data.keys.include? name
146
+ return data[name] if data.is_a?(Hash) && data.keys.include?(name)
98
147
 
99
148
  super
100
149
  end
@@ -102,11 +151,16 @@ module Cloudflair
102
151
  def respond_to_missing?(name_as_symbol, *args)
103
152
  name = normalize_accessor name_as_symbol
104
153
 
154
+ return true if :_raw_data! == name_as_symbol
155
+
105
156
  return true if name.end_with?('=') && patchable_fields.include?(name[0..-2])
106
157
  return true if name.end_with?('!') && data.keys.include?(name[0..-2])
107
158
 
108
- return true if dirty.keys.include? name
109
- return true if data.keys.include? name
159
+ return true if object_fields.include? name
160
+ return true if array_object_fields.keys.include? name
161
+
162
+ return true if dirty_data.keys.include? name
163
+ return true if data.is_a?(Hash) && data.keys.include?(name)
110
164
 
111
165
  super
112
166
  end
@@ -146,6 +200,39 @@ module Cloudflair
146
200
  self.class.deletable
147
201
  end
148
202
 
203
+ def object_fields
204
+ self.class.object_fields
205
+ end
206
+
207
+ def array_object_fields
208
+ self.class.array_object_fields
209
+ end
210
+
211
+ def objectify(name)
212
+ hash_to_object data[name]
213
+ end
214
+
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)
225
+ data[name].map do |data|
226
+ if klass_or_proc.nil?
227
+ hash_to_object data
228
+ elsif klass_or_proc.is_a? Proc
229
+ klass_or_proc.call data
230
+ else
231
+ klass_or_proc.new data
232
+ end
233
+ end
234
+ end
235
+
149
236
  def path
150
237
  return @path if @path
151
238
 
@@ -160,8 +247,8 @@ module Cloudflair
160
247
  interpreted_path
161
248
  end
162
249
 
163
- def dirty
164
- @dirty ||= {}
250
+ def dirty_data
251
+ @dirty_data ||= {}
165
252
  end
166
253
  end
167
254
  end
@@ -1,3 +1,3 @@
1
1
  module Cloudflair
2
- VERSION = '0.0.6'.freeze
2
+ VERSION = '0.0.7'.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.6
4
+ version: 0.0.7
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-21 00:00:00.000000000 Z
11
+ date: 2016-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -129,9 +129,40 @@ files:
129
129
  - lib/cloudflair.rb
130
130
  - lib/cloudflair/api.rb
131
131
  - lib/cloudflair/api/zone.rb
132
+ - lib/cloudflair/api/zone/available_plan.rb
133
+ - lib/cloudflair/api/zone/available_rate_plan.rb
132
134
  - lib/cloudflair/api/zone/purge_cache.rb
133
135
  - lib/cloudflair/api/zone/settings.rb
136
+ - lib/cloudflair/api/zone/settings/advanced_ddos.rb
137
+ - lib/cloudflair/api/zone/settings/always_online.rb
138
+ - lib/cloudflair/api/zone/settings/browser_cache_ttl.rb
139
+ - lib/cloudflair/api/zone/settings/browser_check.rb
140
+ - lib/cloudflair/api/zone/settings/cache_level.rb
141
+ - lib/cloudflair/api/zone/settings/challenge_ttl.rb
134
142
  - lib/cloudflair/api/zone/settings/development_mode.rb
143
+ - lib/cloudflair/api/zone/settings/email_obfuscation.rb
144
+ - lib/cloudflair/api/zone/settings/hotlink_protection.rb
145
+ - lib/cloudflair/api/zone/settings/ip_geolocation.rb
146
+ - lib/cloudflair/api/zone/settings/ipv6.rb
147
+ - lib/cloudflair/api/zone/settings/minify.rb
148
+ - lib/cloudflair/api/zone/settings/mirage.rb
149
+ - lib/cloudflair/api/zone/settings/mobile_redirect.rb
150
+ - lib/cloudflair/api/zone/settings/origin_error_page_pass_thru.rb
151
+ - lib/cloudflair/api/zone/settings/polish.rb
152
+ - lib/cloudflair/api/zone/settings/prefetch_preload.rb
153
+ - lib/cloudflair/api/zone/settings/response_buffering.rb
154
+ - lib/cloudflair/api/zone/settings/rocket_loader.rb
155
+ - lib/cloudflair/api/zone/settings/security_header.rb
156
+ - lib/cloudflair/api/zone/settings/security_level.rb
157
+ - lib/cloudflair/api/zone/settings/server_side_exclude.rb
158
+ - lib/cloudflair/api/zone/settings/sort_query_string_for_cache.rb
159
+ - lib/cloudflair/api/zone/settings/ssl.rb
160
+ - lib/cloudflair/api/zone/settings/tls_1_2_only.rb
161
+ - lib/cloudflair/api/zone/settings/tls_1_3.rb
162
+ - lib/cloudflair/api/zone/settings/tls_client_auth.rb
163
+ - lib/cloudflair/api/zone/settings/true_client_ip_header.rb
164
+ - lib/cloudflair/api/zone/settings/waf.rb
165
+ - lib/cloudflair/api/zone/settings/websockets.rb
135
166
  - lib/cloudflair/communication.rb
136
167
  - lib/cloudflair/connection.rb
137
168
  - lib/cloudflair/entity.rb