Class: CloudflareClient::Zone::Subscription

Inherits:
Base show all
Defined in:
lib/cloudflare_client/zone/subscription.rb

Constant Summary collapse

VALID_FREQUENCIES =
%w[weekly monthly quarterly yearly].freeze
VALID_STATES =
%w[Trial Provisioned Paid AwaitingPayment Cancelled Failed Expired].freeze

Constants inherited from CloudflareClient::Zone

VALID_ZONE_STATUSES

Constants inherited from CloudflareClient

API_BASE, POSSIBLE_API_SETTINGS, VALID_BUNDLE_METHODS, VALID_DIRECTIONS, VALID_MATCHES, VERSION

Instance Attribute Summary

Attributes inherited from Base

#zone_id

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods inherited from CloudflareClient::Zone

#create_zone, #delete_zone, #edit_zone, #purge_zone_cache, #update_zone_settings, #zone, #zone_activation_check, #zone_setting, #zone_settings, #zones

Methods inherited from CloudflareClient

#initialize

Constructor Details

This class inherits a constructor from CloudflareClient::Zone::Base

Instance Method Details

#create(price:, currency:, id:, frequency:, component_values: nil, rate_plan: nil, zone: nil, state: nil) ⇒ Object

create a zone subscriptions FIXME: api talks about lots of read only constrains



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cloudflare_client/zone/subscription.rb', line 18

def create(price:, currency:, id:, frequency:, component_values: nil, rate_plan: nil, zone: nil, state: nil)
  basic_type_check(:price, price, Numeric)
  basic_type_check(:currency, currency, String)
  basic_type_check(:id, id, String)
  max_length_check(:id, id)
  valid_value_check(:frequency, frequency, VALID_FREQUENCIES)

  data = {price: price, currency: currency, id: id, frequency: frequency}

  unless component_values.nil?
    non_empty_array_check(:component_values, component_values)
    data[:component_values] = component_values
  end

  unless rate_plan.nil?
    non_empty_hash_check(:rate_plan, rate_plan)
    data[:rate_plan] = rate_plan
  end

  unless zone.nil?
    non_empty_hash_check(:zone, zone)
    data[:zone] = zone
  end

  unless state.nil?
    valid_value_check(:state, state, VALID_STATES)
    data[:state] = state
  end

  cf_post(path: "/zones/#{zone_id}/subscription", data: data)
end

#showObject

get a zone subscription FIXME: seems to throw a 404



11
12
13
# File 'lib/cloudflare_client/zone/subscription.rb', line 11

def show
  cf_get(path: "/zones/#{zone_id}/subscription")
end