Class: GandiV5::Email::Slot

Inherits:
Object
  • Object
show all
Includes:
Data
Defined in:
lib/gandi_v5/email/slot.rb

Overview

A slot is attached to a domain and (optionally) contains a mailbox. There must be an available slot for a mailbox to be created.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Data

#from_gandi, included, #to_gandi, #to_h, #values_at

Constructor Details

#initialize(fqdn: nil, **members) ⇒ GandiV5::Email::Slot

Create a new GandiV5::Email::Slot

Parameters:

  • fqdn (String) (defaults to: nil)

    the fully qualified domain this slot belongs to.

  • members (Hash<Symbol => Object>)


45
46
47
48
# File 'lib/gandi_v5/email/slot.rb', line 45

def initialize(fqdn: nil, **members)
  super(**members)
  @fqdn = fqdn
end

Instance Attribute Details

#capacityInteger (readonly)

Returns slot capacity (in MB).

Returns:

  • (Integer)

    slot capacity (in MB).



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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/email/slot.rb', line 23

class Slot
  include GandiV5::Data

  attr_reader :fqdn

  members :id, :refundable, :refund_amount, :refund_currency
  member(
    :capacity,
    converter: GandiV5::Data::Converter.new(
      from_gandi: ->(value) { value * 1_024**2 }
    )
  )
  member :created_at, converter: GandiV5::Data::Converter::Time
  member :mailbox_type, converter: GandiV5::Data::Converter::Symbol
  member :status, converter: GandiV5::Data::Converter::Symbol

  alias slot_id id

  # Create a new GandiV5::Email::Slot
  # @param fqdn [String] the fully qualified domain this slot belongs to.
  # @param members [Hash<Symbol => Object>]
  # @return [GandiV5::Email::Slot]
  def initialize(fqdn: nil, **members)
    super(**members)
    @fqdn = fqdn
  end

  # Delete this slot if it is inactive and refundable.
  # When you delete a slot, the prepaid account that was used to purchase the slot
  # will be refunded for the remaining time that will not be used.
  # @see GandiV5::Email::Mailbox#delete
  # @see https://api.gandi.net/docs/email#delete-v5-email-slots-domain-slot_id
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error] if slot is active.
  # @raise [GandiV5::Error] if slot is not refundable.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    fail GandiV5::Error, 'slot can\'t be deleted whilst active' if active?
    fail GandiV5::Error, 'slot can\'t be deleted if it\'s not refundable' unless refundable

    _response, data = GandiV5.delete url
    data['message']
  end

  # Requery Gandi for this slot's information.
  # @see https://api.gandi.net/docs/email#get-v5-email-slots-domain-slot_id
  # @return [GandiV5::Email::Slot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def refresh
    _response, data = GandiV5.get url
    from_gandi data
  end

  # Creates a new slot. You must have slots available before you can create a mailbox.
  # If you have used the two free standard 3GB mailbox slots that are included with the domain,
  # but require more mailboxes on that domain, you must first purchase additional slots.
  # @see https://api.gandi.net/docs/email#post-v5-email-slots-domain
  # @param fqdn [String, #to_s] the fully qualified domain name to add the slot to.
  # @param type [:standard, :premium] Tyhe type of slot to add.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(fqdn, type = :standard)
    body = {
      mailbox_type: type
    }.to_json

    response, _data = GandiV5.post url(fqdn), body
    fetch fqdn, response.headers[:location].split('/').last
  end

  # Get information for a slot.
  # @see https://api.gandi.net/docs/email#get-v5-email-slots-domain-slot_id
  # @param fqdn [String, #to_s] the fully qualified domain name the slot is on.
  # @param id [String, #to_s] the ID of the slot to fetch.
  # @return [GandiV5::Email::Slot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(fqdn, id)
    _response, data = GandiV5.get url(fqdn, id)
    slot = from_gandi data
    slot.instance_eval { @fqdn = fqdn }
    slot
  end

  # List slots for a domain.
  # @see https://api.gandi.net/docs/email#
  # @param fqdn [String, #to_s] the fully qualified domain name to list slots for.
  # @return [Array<GandiV5::Email::Slot>]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.list(fqdn)
    _response, data = GandiV5.get url(fqdn)
    data.map { |item| from_gandi item }
        .each { |item| item.instance_eval { @fqdn = fqdn } }
  end

  # Check if the slot is active (in use)
  # @return [Boolean]
  def active?
    status.eql?(:active)
  end

  # Check if the slot is inactive (not in use)
  # @return [Boolean]
  def inactive?
    status.eql?(:inactive)
  end

  # Check if the slot's mailbox_type is :free
  # @return [Boolean]
  def free?
    mailbox_type.eql?(:free)
  end

  # Check if the slot's mailbox_type is :standard
  # @return [Boolean]
  def standard?
    mailbox_type.eql?(:standard)
  end

  # Check if the slot's mailbox_type is :premium
  # @return [Boolean]
  def premium?
    mailbox_type.eql?(:premium)
  end

  private

  def url
    "#{BASE}email/slots/#{CGI.escape fqdn}/#{id}"
  end

  def self.url(fqdn, id = nil)
    "#{BASE}email/slots/#{CGI.escape fqdn}" +
      (id ? "/#{id}" : '')
  end
  private_class_method :url
end

#created_atTime (readonly)

Returns:

  • (Time)


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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/email/slot.rb', line 23

class Slot
  include GandiV5::Data

  attr_reader :fqdn

  members :id, :refundable, :refund_amount, :refund_currency
  member(
    :capacity,
    converter: GandiV5::Data::Converter.new(
      from_gandi: ->(value) { value * 1_024**2 }
    )
  )
  member :created_at, converter: GandiV5::Data::Converter::Time
  member :mailbox_type, converter: GandiV5::Data::Converter::Symbol
  member :status, converter: GandiV5::Data::Converter::Symbol

  alias slot_id id

  # Create a new GandiV5::Email::Slot
  # @param fqdn [String] the fully qualified domain this slot belongs to.
  # @param members [Hash<Symbol => Object>]
  # @return [GandiV5::Email::Slot]
  def initialize(fqdn: nil, **members)
    super(**members)
    @fqdn = fqdn
  end

  # Delete this slot if it is inactive and refundable.
  # When you delete a slot, the prepaid account that was used to purchase the slot
  # will be refunded for the remaining time that will not be used.
  # @see GandiV5::Email::Mailbox#delete
  # @see https://api.gandi.net/docs/email#delete-v5-email-slots-domain-slot_id
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error] if slot is active.
  # @raise [GandiV5::Error] if slot is not refundable.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    fail GandiV5::Error, 'slot can\'t be deleted whilst active' if active?
    fail GandiV5::Error, 'slot can\'t be deleted if it\'s not refundable' unless refundable

    _response, data = GandiV5.delete url
    data['message']
  end

  # Requery Gandi for this slot's information.
  # @see https://api.gandi.net/docs/email#get-v5-email-slots-domain-slot_id
  # @return [GandiV5::Email::Slot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def refresh
    _response, data = GandiV5.get url
    from_gandi data
  end

  # Creates a new slot. You must have slots available before you can create a mailbox.
  # If you have used the two free standard 3GB mailbox slots that are included with the domain,
  # but require more mailboxes on that domain, you must first purchase additional slots.
  # @see https://api.gandi.net/docs/email#post-v5-email-slots-domain
  # @param fqdn [String, #to_s] the fully qualified domain name to add the slot to.
  # @param type [:standard, :premium] Tyhe type of slot to add.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(fqdn, type = :standard)
    body = {
      mailbox_type: type
    }.to_json

    response, _data = GandiV5.post url(fqdn), body
    fetch fqdn, response.headers[:location].split('/').last
  end

  # Get information for a slot.
  # @see https://api.gandi.net/docs/email#get-v5-email-slots-domain-slot_id
  # @param fqdn [String, #to_s] the fully qualified domain name the slot is on.
  # @param id [String, #to_s] the ID of the slot to fetch.
  # @return [GandiV5::Email::Slot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(fqdn, id)
    _response, data = GandiV5.get url(fqdn, id)
    slot = from_gandi data
    slot.instance_eval { @fqdn = fqdn }
    slot
  end

  # List slots for a domain.
  # @see https://api.gandi.net/docs/email#
  # @param fqdn [String, #to_s] the fully qualified domain name to list slots for.
  # @return [Array<GandiV5::Email::Slot>]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.list(fqdn)
    _response, data = GandiV5.get url(fqdn)
    data.map { |item| from_gandi item }
        .each { |item| item.instance_eval { @fqdn = fqdn } }
  end

  # Check if the slot is active (in use)
  # @return [Boolean]
  def active?
    status.eql?(:active)
  end

  # Check if the slot is inactive (not in use)
  # @return [Boolean]
  def inactive?
    status.eql?(:inactive)
  end

  # Check if the slot's mailbox_type is :free
  # @return [Boolean]
  def free?
    mailbox_type.eql?(:free)
  end

  # Check if the slot's mailbox_type is :standard
  # @return [Boolean]
  def standard?
    mailbox_type.eql?(:standard)
  end

  # Check if the slot's mailbox_type is :premium
  # @return [Boolean]
  def premium?
    mailbox_type.eql?(:premium)
  end

  private

  def url
    "#{BASE}email/slots/#{CGI.escape fqdn}/#{id}"
  end

  def self.url(fqdn, id = nil)
    "#{BASE}email/slots/#{CGI.escape fqdn}" +
      (id ? "/#{id}" : '')
  end
  private_class_method :url
end

#fqdnObject (readonly)

Returns the value of attribute fqdn.



26
27
28
# File 'lib/gandi_v5/email/slot.rb', line 26

def fqdn
  @fqdn
end

#idInteger (readonly) Also known as: slot_id

Returns:

  • (Integer)


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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/email/slot.rb', line 23

class Slot
  include GandiV5::Data

  attr_reader :fqdn

  members :id, :refundable, :refund_amount, :refund_currency
  member(
    :capacity,
    converter: GandiV5::Data::Converter.new(
      from_gandi: ->(value) { value * 1_024**2 }
    )
  )
  member :created_at, converter: GandiV5::Data::Converter::Time
  member :mailbox_type, converter: GandiV5::Data::Converter::Symbol
  member :status, converter: GandiV5::Data::Converter::Symbol

  alias slot_id id

  # Create a new GandiV5::Email::Slot
  # @param fqdn [String] the fully qualified domain this slot belongs to.
  # @param members [Hash<Symbol => Object>]
  # @return [GandiV5::Email::Slot]
  def initialize(fqdn: nil, **members)
    super(**members)
    @fqdn = fqdn
  end

  # Delete this slot if it is inactive and refundable.
  # When you delete a slot, the prepaid account that was used to purchase the slot
  # will be refunded for the remaining time that will not be used.
  # @see GandiV5::Email::Mailbox#delete
  # @see https://api.gandi.net/docs/email#delete-v5-email-slots-domain-slot_id
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error] if slot is active.
  # @raise [GandiV5::Error] if slot is not refundable.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    fail GandiV5::Error, 'slot can\'t be deleted whilst active' if active?
    fail GandiV5::Error, 'slot can\'t be deleted if it\'s not refundable' unless refundable

    _response, data = GandiV5.delete url
    data['message']
  end

  # Requery Gandi for this slot's information.
  # @see https://api.gandi.net/docs/email#get-v5-email-slots-domain-slot_id
  # @return [GandiV5::Email::Slot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def refresh
    _response, data = GandiV5.get url
    from_gandi data
  end

  # Creates a new slot. You must have slots available before you can create a mailbox.
  # If you have used the two free standard 3GB mailbox slots that are included with the domain,
  # but require more mailboxes on that domain, you must first purchase additional slots.
  # @see https://api.gandi.net/docs/email#post-v5-email-slots-domain
  # @param fqdn [String, #to_s] the fully qualified domain name to add the slot to.
  # @param type [:standard, :premium] Tyhe type of slot to add.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(fqdn, type = :standard)
    body = {
      mailbox_type: type
    }.to_json

    response, _data = GandiV5.post url(fqdn), body
    fetch fqdn, response.headers[:location].split('/').last
  end

  # Get information for a slot.
  # @see https://api.gandi.net/docs/email#get-v5-email-slots-domain-slot_id
  # @param fqdn [String, #to_s] the fully qualified domain name the slot is on.
  # @param id [String, #to_s] the ID of the slot to fetch.
  # @return [GandiV5::Email::Slot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(fqdn, id)
    _response, data = GandiV5.get url(fqdn, id)
    slot = from_gandi data
    slot.instance_eval { @fqdn = fqdn }
    slot
  end

  # List slots for a domain.
  # @see https://api.gandi.net/docs/email#
  # @param fqdn [String, #to_s] the fully qualified domain name to list slots for.
  # @return [Array<GandiV5::Email::Slot>]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.list(fqdn)
    _response, data = GandiV5.get url(fqdn)
    data.map { |item| from_gandi item }
        .each { |item| item.instance_eval { @fqdn = fqdn } }
  end

  # Check if the slot is active (in use)
  # @return [Boolean]
  def active?
    status.eql?(:active)
  end

  # Check if the slot is inactive (not in use)
  # @return [Boolean]
  def inactive?
    status.eql?(:inactive)
  end

  # Check if the slot's mailbox_type is :free
  # @return [Boolean]
  def free?
    mailbox_type.eql?(:free)
  end

  # Check if the slot's mailbox_type is :standard
  # @return [Boolean]
  def standard?
    mailbox_type.eql?(:standard)
  end

  # Check if the slot's mailbox_type is :premium
  # @return [Boolean]
  def premium?
    mailbox_type.eql?(:premium)
  end

  private

  def url
    "#{BASE}email/slots/#{CGI.escape fqdn}/#{id}"
  end

  def self.url(fqdn, id = nil)
    "#{BASE}email/slots/#{CGI.escape fqdn}" +
      (id ? "/#{id}" : '')
  end
  private_class_method :url
end

#mailbox_type:standard, :premium (readonly)

Returns:

  • (:standard, :premium)


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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/email/slot.rb', line 23

class Slot
  include GandiV5::Data

  attr_reader :fqdn

  members :id, :refundable, :refund_amount, :refund_currency
  member(
    :capacity,
    converter: GandiV5::Data::Converter.new(
      from_gandi: ->(value) { value * 1_024**2 }
    )
  )
  member :created_at, converter: GandiV5::Data::Converter::Time
  member :mailbox_type, converter: GandiV5::Data::Converter::Symbol
  member :status, converter: GandiV5::Data::Converter::Symbol

  alias slot_id id

  # Create a new GandiV5::Email::Slot
  # @param fqdn [String] the fully qualified domain this slot belongs to.
  # @param members [Hash<Symbol => Object>]
  # @return [GandiV5::Email::Slot]
  def initialize(fqdn: nil, **members)
    super(**members)
    @fqdn = fqdn
  end

  # Delete this slot if it is inactive and refundable.
  # When you delete a slot, the prepaid account that was used to purchase the slot
  # will be refunded for the remaining time that will not be used.
  # @see GandiV5::Email::Mailbox#delete
  # @see https://api.gandi.net/docs/email#delete-v5-email-slots-domain-slot_id
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error] if slot is active.
  # @raise [GandiV5::Error] if slot is not refundable.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    fail GandiV5::Error, 'slot can\'t be deleted whilst active' if active?
    fail GandiV5::Error, 'slot can\'t be deleted if it\'s not refundable' unless refundable

    _response, data = GandiV5.delete url
    data['message']
  end

  # Requery Gandi for this slot's information.
  # @see https://api.gandi.net/docs/email#get-v5-email-slots-domain-slot_id
  # @return [GandiV5::Email::Slot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def refresh
    _response, data = GandiV5.get url
    from_gandi data
  end

  # Creates a new slot. You must have slots available before you can create a mailbox.
  # If you have used the two free standard 3GB mailbox slots that are included with the domain,
  # but require more mailboxes on that domain, you must first purchase additional slots.
  # @see https://api.gandi.net/docs/email#post-v5-email-slots-domain
  # @param fqdn [String, #to_s] the fully qualified domain name to add the slot to.
  # @param type [:standard, :premium] Tyhe type of slot to add.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(fqdn, type = :standard)
    body = {
      mailbox_type: type
    }.to_json

    response, _data = GandiV5.post url(fqdn), body
    fetch fqdn, response.headers[:location].split('/').last
  end

  # Get information for a slot.
  # @see https://api.gandi.net/docs/email#get-v5-email-slots-domain-slot_id
  # @param fqdn [String, #to_s] the fully qualified domain name the slot is on.
  # @param id [String, #to_s] the ID of the slot to fetch.
  # @return [GandiV5::Email::Slot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(fqdn, id)
    _response, data = GandiV5.get url(fqdn, id)
    slot = from_gandi data
    slot.instance_eval { @fqdn = fqdn }
    slot
  end

  # List slots for a domain.
  # @see https://api.gandi.net/docs/email#
  # @param fqdn [String, #to_s] the fully qualified domain name to list slots for.
  # @return [Array<GandiV5::Email::Slot>]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.list(fqdn)
    _response, data = GandiV5.get url(fqdn)
    data.map { |item| from_gandi item }
        .each { |item| item.instance_eval { @fqdn = fqdn } }
  end

  # Check if the slot is active (in use)
  # @return [Boolean]
  def active?
    status.eql?(:active)
  end

  # Check if the slot is inactive (not in use)
  # @return [Boolean]
  def inactive?
    status.eql?(:inactive)
  end

  # Check if the slot's mailbox_type is :free
  # @return [Boolean]
  def free?
    mailbox_type.eql?(:free)
  end

  # Check if the slot's mailbox_type is :standard
  # @return [Boolean]
  def standard?
    mailbox_type.eql?(:standard)
  end

  # Check if the slot's mailbox_type is :premium
  # @return [Boolean]
  def premium?
    mailbox_type.eql?(:premium)
  end

  private

  def url
    "#{BASE}email/slots/#{CGI.escape fqdn}/#{id}"
  end

  def self.url(fqdn, id = nil)
    "#{BASE}email/slots/#{CGI.escape fqdn}" +
      (id ? "/#{id}" : '')
  end
  private_class_method :url
end

#refund_amountnil, Numeric (readonly)

Returns refunded amount if you delete this slot now.

Returns:

  • (nil, Numeric)

    refunded amount if you delete this slot now.



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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/email/slot.rb', line 23

class Slot
  include GandiV5::Data

  attr_reader :fqdn

  members :id, :refundable, :refund_amount, :refund_currency
  member(
    :capacity,
    converter: GandiV5::Data::Converter.new(
      from_gandi: ->(value) { value * 1_024**2 }
    )
  )
  member :created_at, converter: GandiV5::Data::Converter::Time
  member :mailbox_type, converter: GandiV5::Data::Converter::Symbol
  member :status, converter: GandiV5::Data::Converter::Symbol

  alias slot_id id

  # Create a new GandiV5::Email::Slot
  # @param fqdn [String] the fully qualified domain this slot belongs to.
  # @param members [Hash<Symbol => Object>]
  # @return [GandiV5::Email::Slot]
  def initialize(fqdn: nil, **members)
    super(**members)
    @fqdn = fqdn
  end

  # Delete this slot if it is inactive and refundable.
  # When you delete a slot, the prepaid account that was used to purchase the slot
  # will be refunded for the remaining time that will not be used.
  # @see GandiV5::Email::Mailbox#delete
  # @see https://api.gandi.net/docs/email#delete-v5-email-slots-domain-slot_id
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error] if slot is active.
  # @raise [GandiV5::Error] if slot is not refundable.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    fail GandiV5::Error, 'slot can\'t be deleted whilst active' if active?
    fail GandiV5::Error, 'slot can\'t be deleted if it\'s not refundable' unless refundable

    _response, data = GandiV5.delete url
    data['message']
  end

  # Requery Gandi for this slot's information.
  # @see https://api.gandi.net/docs/email#get-v5-email-slots-domain-slot_id
  # @return [GandiV5::Email::Slot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def refresh
    _response, data = GandiV5.get url
    from_gandi data
  end

  # Creates a new slot. You must have slots available before you can create a mailbox.
  # If you have used the two free standard 3GB mailbox slots that are included with the domain,
  # but require more mailboxes on that domain, you must first purchase additional slots.
  # @see https://api.gandi.net/docs/email#post-v5-email-slots-domain
  # @param fqdn [String, #to_s] the fully qualified domain name to add the slot to.
  # @param type [:standard, :premium] Tyhe type of slot to add.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(fqdn, type = :standard)
    body = {
      mailbox_type: type
    }.to_json

    response, _data = GandiV5.post url(fqdn), body
    fetch fqdn, response.headers[:location].split('/').last
  end

  # Get information for a slot.
  # @see https://api.gandi.net/docs/email#get-v5-email-slots-domain-slot_id
  # @param fqdn [String, #to_s] the fully qualified domain name the slot is on.
  # @param id [String, #to_s] the ID of the slot to fetch.
  # @return [GandiV5::Email::Slot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(fqdn, id)
    _response, data = GandiV5.get url(fqdn, id)
    slot = from_gandi data
    slot.instance_eval { @fqdn = fqdn }
    slot
  end

  # List slots for a domain.
  # @see https://api.gandi.net/docs/email#
  # @param fqdn [String, #to_s] the fully qualified domain name to list slots for.
  # @return [Array<GandiV5::Email::Slot>]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.list(fqdn)
    _response, data = GandiV5.get url(fqdn)
    data.map { |item| from_gandi item }
        .each { |item| item.instance_eval { @fqdn = fqdn } }
  end

  # Check if the slot is active (in use)
  # @return [Boolean]
  def active?
    status.eql?(:active)
  end

  # Check if the slot is inactive (not in use)
  # @return [Boolean]
  def inactive?
    status.eql?(:inactive)
  end

  # Check if the slot's mailbox_type is :free
  # @return [Boolean]
  def free?
    mailbox_type.eql?(:free)
  end

  # Check if the slot's mailbox_type is :standard
  # @return [Boolean]
  def standard?
    mailbox_type.eql?(:standard)
  end

  # Check if the slot's mailbox_type is :premium
  # @return [Boolean]
  def premium?
    mailbox_type.eql?(:premium)
  end

  private

  def url
    "#{BASE}email/slots/#{CGI.escape fqdn}/#{id}"
  end

  def self.url(fqdn, id = nil)
    "#{BASE}email/slots/#{CGI.escape fqdn}" +
      (id ? "/#{id}" : '')
  end
  private_class_method :url
end

#refund_currencynil, String (readonly)

Returns refund currency.

Returns:

  • (nil, String)

    refund currency.



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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/email/slot.rb', line 23

class Slot
  include GandiV5::Data

  attr_reader :fqdn

  members :id, :refundable, :refund_amount, :refund_currency
  member(
    :capacity,
    converter: GandiV5::Data::Converter.new(
      from_gandi: ->(value) { value * 1_024**2 }
    )
  )
  member :created_at, converter: GandiV5::Data::Converter::Time
  member :mailbox_type, converter: GandiV5::Data::Converter::Symbol
  member :status, converter: GandiV5::Data::Converter::Symbol

  alias slot_id id

  # Create a new GandiV5::Email::Slot
  # @param fqdn [String] the fully qualified domain this slot belongs to.
  # @param members [Hash<Symbol => Object>]
  # @return [GandiV5::Email::Slot]
  def initialize(fqdn: nil, **members)
    super(**members)
    @fqdn = fqdn
  end

  # Delete this slot if it is inactive and refundable.
  # When you delete a slot, the prepaid account that was used to purchase the slot
  # will be refunded for the remaining time that will not be used.
  # @see GandiV5::Email::Mailbox#delete
  # @see https://api.gandi.net/docs/email#delete-v5-email-slots-domain-slot_id
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error] if slot is active.
  # @raise [GandiV5::Error] if slot is not refundable.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    fail GandiV5::Error, 'slot can\'t be deleted whilst active' if active?
    fail GandiV5::Error, 'slot can\'t be deleted if it\'s not refundable' unless refundable

    _response, data = GandiV5.delete url
    data['message']
  end

  # Requery Gandi for this slot's information.
  # @see https://api.gandi.net/docs/email#get-v5-email-slots-domain-slot_id
  # @return [GandiV5::Email::Slot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def refresh
    _response, data = GandiV5.get url
    from_gandi data
  end

  # Creates a new slot. You must have slots available before you can create a mailbox.
  # If you have used the two free standard 3GB mailbox slots that are included with the domain,
  # but require more mailboxes on that domain, you must first purchase additional slots.
  # @see https://api.gandi.net/docs/email#post-v5-email-slots-domain
  # @param fqdn [String, #to_s] the fully qualified domain name to add the slot to.
  # @param type [:standard, :premium] Tyhe type of slot to add.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(fqdn, type = :standard)
    body = {
      mailbox_type: type
    }.to_json

    response, _data = GandiV5.post url(fqdn), body
    fetch fqdn, response.headers[:location].split('/').last
  end

  # Get information for a slot.
  # @see https://api.gandi.net/docs/email#get-v5-email-slots-domain-slot_id
  # @param fqdn [String, #to_s] the fully qualified domain name the slot is on.
  # @param id [String, #to_s] the ID of the slot to fetch.
  # @return [GandiV5::Email::Slot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(fqdn, id)
    _response, data = GandiV5.get url(fqdn, id)
    slot = from_gandi data
    slot.instance_eval { @fqdn = fqdn }
    slot
  end

  # List slots for a domain.
  # @see https://api.gandi.net/docs/email#
  # @param fqdn [String, #to_s] the fully qualified domain name to list slots for.
  # @return [Array<GandiV5::Email::Slot>]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.list(fqdn)
    _response, data = GandiV5.get url(fqdn)
    data.map { |item| from_gandi item }
        .each { |item| item.instance_eval { @fqdn = fqdn } }
  end

  # Check if the slot is active (in use)
  # @return [Boolean]
  def active?
    status.eql?(:active)
  end

  # Check if the slot is inactive (not in use)
  # @return [Boolean]
  def inactive?
    status.eql?(:inactive)
  end

  # Check if the slot's mailbox_type is :free
  # @return [Boolean]
  def free?
    mailbox_type.eql?(:free)
  end

  # Check if the slot's mailbox_type is :standard
  # @return [Boolean]
  def standard?
    mailbox_type.eql?(:standard)
  end

  # Check if the slot's mailbox_type is :premium
  # @return [Boolean]
  def premium?
    mailbox_type.eql?(:premium)
  end

  private

  def url
    "#{BASE}email/slots/#{CGI.escape fqdn}/#{id}"
  end

  def self.url(fqdn, id = nil)
    "#{BASE}email/slots/#{CGI.escape fqdn}" +
      (id ? "/#{id}" : '')
  end
  private_class_method :url
end

#refundableBoolean (readonly)

Returns:

  • (Boolean)


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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/email/slot.rb', line 23

class Slot
  include GandiV5::Data

  attr_reader :fqdn

  members :id, :refundable, :refund_amount, :refund_currency
  member(
    :capacity,
    converter: GandiV5::Data::Converter.new(
      from_gandi: ->(value) { value * 1_024**2 }
    )
  )
  member :created_at, converter: GandiV5::Data::Converter::Time
  member :mailbox_type, converter: GandiV5::Data::Converter::Symbol
  member :status, converter: GandiV5::Data::Converter::Symbol

  alias slot_id id

  # Create a new GandiV5::Email::Slot
  # @param fqdn [String] the fully qualified domain this slot belongs to.
  # @param members [Hash<Symbol => Object>]
  # @return [GandiV5::Email::Slot]
  def initialize(fqdn: nil, **members)
    super(**members)
    @fqdn = fqdn
  end

  # Delete this slot if it is inactive and refundable.
  # When you delete a slot, the prepaid account that was used to purchase the slot
  # will be refunded for the remaining time that will not be used.
  # @see GandiV5::Email::Mailbox#delete
  # @see https://api.gandi.net/docs/email#delete-v5-email-slots-domain-slot_id
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error] if slot is active.
  # @raise [GandiV5::Error] if slot is not refundable.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    fail GandiV5::Error, 'slot can\'t be deleted whilst active' if active?
    fail GandiV5::Error, 'slot can\'t be deleted if it\'s not refundable' unless refundable

    _response, data = GandiV5.delete url
    data['message']
  end

  # Requery Gandi for this slot's information.
  # @see https://api.gandi.net/docs/email#get-v5-email-slots-domain-slot_id
  # @return [GandiV5::Email::Slot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def refresh
    _response, data = GandiV5.get url
    from_gandi data
  end

  # Creates a new slot. You must have slots available before you can create a mailbox.
  # If you have used the two free standard 3GB mailbox slots that are included with the domain,
  # but require more mailboxes on that domain, you must first purchase additional slots.
  # @see https://api.gandi.net/docs/email#post-v5-email-slots-domain
  # @param fqdn [String, #to_s] the fully qualified domain name to add the slot to.
  # @param type [:standard, :premium] Tyhe type of slot to add.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(fqdn, type = :standard)
    body = {
      mailbox_type: type
    }.to_json

    response, _data = GandiV5.post url(fqdn), body
    fetch fqdn, response.headers[:location].split('/').last
  end

  # Get information for a slot.
  # @see https://api.gandi.net/docs/email#get-v5-email-slots-domain-slot_id
  # @param fqdn [String, #to_s] the fully qualified domain name the slot is on.
  # @param id [String, #to_s] the ID of the slot to fetch.
  # @return [GandiV5::Email::Slot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(fqdn, id)
    _response, data = GandiV5.get url(fqdn, id)
    slot = from_gandi data
    slot.instance_eval { @fqdn = fqdn }
    slot
  end

  # List slots for a domain.
  # @see https://api.gandi.net/docs/email#
  # @param fqdn [String, #to_s] the fully qualified domain name to list slots for.
  # @return [Array<GandiV5::Email::Slot>]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.list(fqdn)
    _response, data = GandiV5.get url(fqdn)
    data.map { |item| from_gandi item }
        .each { |item| item.instance_eval { @fqdn = fqdn } }
  end

  # Check if the slot is active (in use)
  # @return [Boolean]
  def active?
    status.eql?(:active)
  end

  # Check if the slot is inactive (not in use)
  # @return [Boolean]
  def inactive?
    status.eql?(:inactive)
  end

  # Check if the slot's mailbox_type is :free
  # @return [Boolean]
  def free?
    mailbox_type.eql?(:free)
  end

  # Check if the slot's mailbox_type is :standard
  # @return [Boolean]
  def standard?
    mailbox_type.eql?(:standard)
  end

  # Check if the slot's mailbox_type is :premium
  # @return [Boolean]
  def premium?
    mailbox_type.eql?(:premium)
  end

  private

  def url
    "#{BASE}email/slots/#{CGI.escape fqdn}/#{id}"
  end

  def self.url(fqdn, id = nil)
    "#{BASE}email/slots/#{CGI.escape fqdn}" +
      (id ? "/#{id}" : '')
  end
  private_class_method :url
end

#status:active, :inactive (readonly)

Returns:

  • (:active, :inactive)


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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/email/slot.rb', line 23

class Slot
  include GandiV5::Data

  attr_reader :fqdn

  members :id, :refundable, :refund_amount, :refund_currency
  member(
    :capacity,
    converter: GandiV5::Data::Converter.new(
      from_gandi: ->(value) { value * 1_024**2 }
    )
  )
  member :created_at, converter: GandiV5::Data::Converter::Time
  member :mailbox_type, converter: GandiV5::Data::Converter::Symbol
  member :status, converter: GandiV5::Data::Converter::Symbol

  alias slot_id id

  # Create a new GandiV5::Email::Slot
  # @param fqdn [String] the fully qualified domain this slot belongs to.
  # @param members [Hash<Symbol => Object>]
  # @return [GandiV5::Email::Slot]
  def initialize(fqdn: nil, **members)
    super(**members)
    @fqdn = fqdn
  end

  # Delete this slot if it is inactive and refundable.
  # When you delete a slot, the prepaid account that was used to purchase the slot
  # will be refunded for the remaining time that will not be used.
  # @see GandiV5::Email::Mailbox#delete
  # @see https://api.gandi.net/docs/email#delete-v5-email-slots-domain-slot_id
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error] if slot is active.
  # @raise [GandiV5::Error] if slot is not refundable.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    fail GandiV5::Error, 'slot can\'t be deleted whilst active' if active?
    fail GandiV5::Error, 'slot can\'t be deleted if it\'s not refundable' unless refundable

    _response, data = GandiV5.delete url
    data['message']
  end

  # Requery Gandi for this slot's information.
  # @see https://api.gandi.net/docs/email#get-v5-email-slots-domain-slot_id
  # @return [GandiV5::Email::Slot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def refresh
    _response, data = GandiV5.get url
    from_gandi data
  end

  # Creates a new slot. You must have slots available before you can create a mailbox.
  # If you have used the two free standard 3GB mailbox slots that are included with the domain,
  # but require more mailboxes on that domain, you must first purchase additional slots.
  # @see https://api.gandi.net/docs/email#post-v5-email-slots-domain
  # @param fqdn [String, #to_s] the fully qualified domain name to add the slot to.
  # @param type [:standard, :premium] Tyhe type of slot to add.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(fqdn, type = :standard)
    body = {
      mailbox_type: type
    }.to_json

    response, _data = GandiV5.post url(fqdn), body
    fetch fqdn, response.headers[:location].split('/').last
  end

  # Get information for a slot.
  # @see https://api.gandi.net/docs/email#get-v5-email-slots-domain-slot_id
  # @param fqdn [String, #to_s] the fully qualified domain name the slot is on.
  # @param id [String, #to_s] the ID of the slot to fetch.
  # @return [GandiV5::Email::Slot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(fqdn, id)
    _response, data = GandiV5.get url(fqdn, id)
    slot = from_gandi data
    slot.instance_eval { @fqdn = fqdn }
    slot
  end

  # List slots for a domain.
  # @see https://api.gandi.net/docs/email#
  # @param fqdn [String, #to_s] the fully qualified domain name to list slots for.
  # @return [Array<GandiV5::Email::Slot>]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.list(fqdn)
    _response, data = GandiV5.get url(fqdn)
    data.map { |item| from_gandi item }
        .each { |item| item.instance_eval { @fqdn = fqdn } }
  end

  # Check if the slot is active (in use)
  # @return [Boolean]
  def active?
    status.eql?(:active)
  end

  # Check if the slot is inactive (not in use)
  # @return [Boolean]
  def inactive?
    status.eql?(:inactive)
  end

  # Check if the slot's mailbox_type is :free
  # @return [Boolean]
  def free?
    mailbox_type.eql?(:free)
  end

  # Check if the slot's mailbox_type is :standard
  # @return [Boolean]
  def standard?
    mailbox_type.eql?(:standard)
  end

  # Check if the slot's mailbox_type is :premium
  # @return [Boolean]
  def premium?
    mailbox_type.eql?(:premium)
  end

  private

  def url
    "#{BASE}email/slots/#{CGI.escape fqdn}/#{id}"
  end

  def self.url(fqdn, id = nil)
    "#{BASE}email/slots/#{CGI.escape fqdn}" +
      (id ? "/#{id}" : '')
  end
  private_class_method :url
end

Class Method Details

.create(fqdn, type = :standard) ⇒ String

Creates a new slot. You must have slots available before you can create a mailbox. If you have used the two free standard 3GB mailbox slots that are included with the domain, but require more mailboxes on that domain, you must first purchase additional slots.

Parameters:

  • fqdn (String, #to_s)

    the fully qualified domain name to add the slot to.

  • type (:standard, :premium) (defaults to: :standard)

    Tyhe type of slot to add.

Returns:

  • (String)

    The confirmation message from Gandi.

Raises:

See Also:



84
85
86
87
88
89
90
91
# File 'lib/gandi_v5/email/slot.rb', line 84

def self.create(fqdn, type = :standard)
  body = {
    mailbox_type: type
  }.to_json

  response, _data = GandiV5.post url(fqdn), body
  fetch fqdn, response.headers[:location].split('/').last
end

.fetch(fqdn, id) ⇒ GandiV5::Email::Slot

Get information for a slot.

Parameters:

  • fqdn (String, #to_s)

    the fully qualified domain name the slot is on.

  • id (String, #to_s)

    the ID of the slot to fetch.

Returns:

Raises:

See Also:



99
100
101
102
103
104
# File 'lib/gandi_v5/email/slot.rb', line 99

def self.fetch(fqdn, id)
  _response, data = GandiV5.get url(fqdn, id)
  slot = from_gandi data
  slot.instance_eval { @fqdn = fqdn }
  slot
end

.list(fqdn) ⇒ Array<GandiV5::Email::Slot>

List slots for a domain.

Parameters:

  • fqdn (String, #to_s)

    the fully qualified domain name to list slots for.

Returns:

Raises:

See Also:



111
112
113
114
115
# File 'lib/gandi_v5/email/slot.rb', line 111

def self.list(fqdn)
  _response, data = GandiV5.get url(fqdn)
  data.map { |item| from_gandi item }
      .each { |item| item.instance_eval { @fqdn = fqdn } }
end

Instance Method Details

#active?Boolean

Check if the slot is active (in use)

Returns:

  • (Boolean)


119
120
121
# File 'lib/gandi_v5/email/slot.rb', line 119

def active?
  status.eql?(:active)
end

#deleteString

Delete this slot if it is inactive and refundable. When you delete a slot, the prepaid account that was used to purchase the slot will be refunded for the remaining time that will not be used.

Returns:

  • (String)

    The confirmation message from Gandi.

Raises:

See Also:



59
60
61
62
63
64
65
# File 'lib/gandi_v5/email/slot.rb', line 59

def delete
  fail GandiV5::Error, 'slot can\'t be deleted whilst active' if active?
  fail GandiV5::Error, 'slot can\'t be deleted if it\'s not refundable' unless refundable

  _response, data = GandiV5.delete url
  data['message']
end

#free?Boolean

Check if the slot’s mailbox_type is :free

Returns:

  • (Boolean)


131
132
133
# File 'lib/gandi_v5/email/slot.rb', line 131

def free?
  mailbox_type.eql?(:free)
end

#inactive?Boolean

Check if the slot is inactive (not in use)

Returns:

  • (Boolean)


125
126
127
# File 'lib/gandi_v5/email/slot.rb', line 125

def inactive?
  status.eql?(:inactive)
end

#premium?Boolean

Check if the slot’s mailbox_type is :premium

Returns:

  • (Boolean)


143
144
145
# File 'lib/gandi_v5/email/slot.rb', line 143

def premium?
  mailbox_type.eql?(:premium)
end

#refreshGandiV5::Email::Slot

Requery Gandi for this slot’s information.



71
72
73
74
# File 'lib/gandi_v5/email/slot.rb', line 71

def refresh
  _response, data = GandiV5.get url
  from_gandi data
end

#standard?Boolean

Check if the slot’s mailbox_type is :standard

Returns:

  • (Boolean)


137
138
139
# File 'lib/gandi_v5/email/slot.rb', line 137

def standard?
  mailbox_type.eql?(:standard)
end