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.



24
25
26
# File 'lib/cloudflair/api/zone.rb', line 24

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.



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

def zone_id
  @zone_id
end

Instance Method Details

#analyticsObject



40
41
42
# File 'lib/cloudflair/api/zone.rb', line 40

def analytics
  Cloudflair::Analytics.new zone_id
end

#available_plan(plan_id) ⇒ Object



15
16
17
# File 'lib/cloudflair/api/zone__available_plans.rb', line 15

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

#available_plansObject



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

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



36
37
38
# File 'lib/cloudflair/api/zone.rb', line 36

def available_rate_plans
  Cloudflair::AvailableRatePlan.new zone_id
end

#custom_hostname(custom_hostname_id) ⇒ Object



11
12
13
# File 'lib/cloudflair/api/zone__custom_hostnames.rb', line 11

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

#custom_hostnames(filter = {}) ⇒ Object



5
6
7
8
9
# File 'lib/cloudflair/api/zone__custom_hostnames.rb', line 5

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



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

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

#dns_records(filter = {}) ⇒ Object



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

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



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

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



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

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

  build_dns_record raw_record
end

#purge_cacheObject



32
33
34
# File 'lib/cloudflair/api/zone.rb', line 32

def purge_cache
  Cloudflair::PurgeCache.new zone_id
end

#railgun(railgun_id) ⇒ Object



15
16
17
# File 'lib/cloudflair/api/zone__railguns.rb', line 15

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

#railguns(filter = {}) ⇒ Object



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

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



28
29
30
# File 'lib/cloudflair/api/zone.rb', line 28

def settings
  Cloudflair::Settings.new zone_id
end