Class: Rerout::UpdateLinkInput

Inherits:
Object
  • Object
show all
Defined in:
lib/rerout/update_link_input.rb

Overview

Request body for ‘PATCH /v1/links/:code`. Every field is optional. To send `null` to the server (clear an existing value), pass `Rerout::CLEAR` to that keyword argument.

Examples:

Rerout::UpdateLinkInput.new(target_url: 'https://new.example.com')
Rerout::UpdateLinkInput.new(expires_at: Rerout::CLEAR)

Constant Summary collapse

FIELDS =
%i[
  target_url expires_at is_active seo_title seo_description
  seo_image_url seo_canonical_url seo_noindex
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(target_url: OMIT, expires_at: OMIT, is_active: OMIT, seo_title: OMIT, seo_description: OMIT, seo_image_url: OMIT, seo_canonical_url: OMIT, seo_noindex: OMIT) ⇒ UpdateLinkInput

Returns a new instance of UpdateLinkInput.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rerout/update_link_input.rb', line 42

def initialize(target_url: OMIT, expires_at: OMIT, is_active: OMIT,
               seo_title: OMIT, seo_description: OMIT, seo_image_url: OMIT,
               seo_canonical_url: OMIT, seo_noindex: OMIT)
  @values = {
    target_url: target_url,
    expires_at: expires_at,
    is_active: is_active,
    seo_title: seo_title,
    seo_description: seo_description,
    seo_image_url: seo_image_url,
    seo_canonical_url: seo_canonical_url,
    seo_noindex: seo_noindex
  }
  freeze
end

Instance Method Details

#empty?Boolean

Returns true when no field was set.

Returns:

  • (Boolean)

    true when no field was set.



72
73
74
# File 'lib/rerout/update_link_input.rb', line 72

def empty?
  to_h.empty?
end

#to_hObject

Serialize for the wire. Unset fields are omitted; ‘Rerout::CLEAR` becomes `null`.



60
61
62
63
64
65
66
67
68
69
# File 'lib/rerout/update_link_input.rb', line 60

def to_h
  out = {}
  FIELDS.each do |field|
    v = @values[field]
    next if v.equal?(OMIT)

    out[field.to_s] = v.equal?(CLEAR) ? nil : v
  end
  out
end

#value_for(field) ⇒ Object

Returns the raw value (sentinel or actual) for a field.

Returns:

  • (Object)

    the raw value (sentinel or actual) for a field.



77
78
79
# File 'lib/rerout/update_link_input.rb', line 77

def value_for(field)
  @values.fetch(field)
end