Class: Cloudflair::Zone

Inherits:
Object
  • Object
show all
Includes:
Entity
Defined in:
lib/cloudflair/api/zone.rb,
lib/cloudflair/api/zone__railguns.rb,
lib/cloudflair/api/zone__dns_records.rb,
lib/cloudflair/api/zone__available_plans.rb,
lib/cloudflair/api/zone__custom_hostnames.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Entity

#data=, #delete, included, #method_missing, #patch, #reload, #respond_to_missing?, #revert, #update

Methods included from Communication

#connection, #hash_to_object, #response

Constructor Details

#initialize(zone_id) ⇒ Zone

Returns a new instance of Zone.



26
27
28
# File 'lib/cloudflair/api/zone.rb', line 26

def initialize(zone_id)
  @zone_id = zone_id
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Cloudflair::Entity

Instance Attribute Details

#zone_idObject (readonly)

Returns the value of attribute zone_id.



19
20
21
# File 'lib/cloudflair/api/zone.rb', line 19

def zone_id
  @zone_id
end

Instance Method Details

#analyticsObject



42
43
44
# File 'lib/cloudflair/api/zone.rb', line 42

def analytics
  Cloudflair::Analytics.new zone_id
end

#available_plan(plan_id) ⇒ Object



17
18
19
# File 'lib/cloudflair/api/zone__available_plans.rb', line 17

def available_plan(plan_id)
  Cloudflair::AvailablePlan.new zone_id, plan_id
end

#available_plansObject



7
8
9
10
11
12
13
14
15
# File 'lib/cloudflair/api/zone__available_plans.rb', line 7

def available_plans
  raw_plans = response connection.get("#{path}/available_plans")

  raw_plans.map do |raw_plan|
    zone = available_plan raw_plan['id']
    zone.data = raw_plan
    zone
  end
end

#available_rate_plansObject



38
39
40
# File 'lib/cloudflair/api/zone.rb', line 38

def available_rate_plans
  Cloudflair::AvailableRatePlan.new zone_id
end

#custom_hostname(custom_hostname_id) ⇒ Object



13
14
15
# File 'lib/cloudflair/api/zone__custom_hostnames.rb', line 13

def custom_hostname(custom_hostname_id)
  Cloudflair::CustomHostname.new zone_id, custom_hostname_id
end

#custom_hostnames(filter = {}) ⇒ Object



7
8
9
10
11
# File 'lib/cloudflair/api/zone__custom_hostnames.rb', line 7

def custom_hostnames(filter = {})
  raw_hostnames = response connection.get("#{path}/custom_hostnames", filter)

  raw_hostnames.map { |raw_hostname| build_custom_hostname(raw_hostname) }
end

#dns_record(record_id) ⇒ Object



12
13
14
# File 'lib/cloudflair/api/zone__dns_records.rb', line 12

def dns_record(record_id)
  Cloudflair::DnsRecord.new zone_id, record_id
end

#dns_records(filter = {}) ⇒ Object



7
8
9
10
# File 'lib/cloudflair/api/zone__dns_records.rb', line 7

def dns_records(filter = {})
  raw_records = response connection.get("#{path}/dns_records", filter)
  raw_records.map { |raw_record| build_dns_record(raw_record) }
end

#new_custom_hostname(hostname_data) ⇒ Object



17
18
19
20
21
# File 'lib/cloudflair/api/zone__custom_hostnames.rb', line 17

def new_custom_hostname(hostname_data)
  raw_hostname = response connection.post("#{path}/custom_hostnames", hostname_data)

  build_custom_hostname raw_hostname
end

#new_dns_record(record_data) ⇒ Object



16
17
18
19
# File 'lib/cloudflair/api/zone__dns_records.rb', line 16

def new_dns_record(record_data)
  raw_record = response connection.post("#{path}/dns_records", record_data)
  build_dns_record raw_record
end

#purge_cacheObject



34
35
36
# File 'lib/cloudflair/api/zone.rb', line 34

def purge_cache
  Cloudflair::PurgeCache.new zone_id
end

#railgun(railgun_id) ⇒ Object



17
18
19
# File 'lib/cloudflair/api/zone__railguns.rb', line 17

def railgun(railgun_id)
  Cloudflair::Railgun.new zone_id, railgun_id
end

#railguns(filter = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/cloudflair/api/zone__railguns.rb', line 7

def railguns(filter = {})
  raw_railguns = response connection.get("#{path}/railguns", filter)

  raw_railguns.map do |raw_railgun|
    railgun = railgun raw_railgun['id']
    railgun.data = raw_railgun
    railgun
  end
end

#settingsObject



30
31
32
# File 'lib/cloudflair/api/zone.rb', line 30

def settings
  Cloudflair::Settings.new zone_id
end