Class: Vonage::Verify2::TemplateFragments

Inherits:
Namespace
  • Object
show all
Defined in:
lib/vonage/verify2/template_fragments.rb

Defined Under Namespace

Classes: ListResponse

Constant Summary collapse

CHANNELS =
['sms', 'voice'].freeze

Instance Method Summary collapse

Instance Method Details

#create(template_id:, channel:, locale:, text:) ⇒ Response

Create a new template fragment.

Examples:

client.verify2.template_fragments.create(
                      template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
                      channel: 'sms',
                      locale: 'en-gb',
                      text: 'Your code is: ${code}'
                    )

Parameters:

  • :template_id. (required, String)

    The ID of the template for which to create the fragment

  • :channel. (required, String)

    The verification channel for which to create the fragment. Must be one of 'sms' or 'voice'

  • :locale. (required, String)

    The locale for which to create the fragment.

  • :text. (required, String)

    The text to be used in the template fragment. There are 4 reserved variables available to use as part of the text: $code, $brand, $time-limit and $time-limit-unit

Returns:

Raises:

  • (ArgumentError)

See Also:



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/vonage/verify2/template_fragments.rb', line 71

def create(template_id:, channel:, locale:, text:)
  raise ArgumentError, "Invalid 'channel' #{channel}. Must be one of #{CHANNELS.join(', ')}" unless CHANNELS.include?(channel)
  request(
    "/v2/verify/templates/#{template_id}/template_fragments",
    params: {
      channel: channel,
      locale: locale,
      text: text
    },
    type: Post)
end

#delete(template_id:, template_fragment_id:) ⇒ Response

Delete a template fragment.

Examples:

client.verify2.template_fragments.delete(
                      template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
                      template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19'
                    )

Parameters:

  • :template_id. (required, String)

    The ID of the template with which the fragment to be deleted is associated

  • :template_fragment_id. (required, String)

    The ID of the fragment to be deleted

Returns:

See Also:



121
122
123
# File 'lib/vonage/verify2/template_fragments.rb', line 121

def delete(template_id:, template_fragment_id:)
  request("/v2/verify/templates/#{template_id}/template_fragments/#{template_fragment_id}", type: Delete)
end

#info(template_id:, template_fragment_id:) ⇒ Response

Get details of a specific template fragment.

Examples:

template_fragment = client.verify2.template_fragments.info(
                      template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
                      template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19'
                    )

Parameters:

  • :template_id. (required, String)

    The ID of the template for which to retreive the fragment

  • :template_fragment_id. (required, String)

    The ID of the fragment to be retreived

Returns:

See Also:



45
46
47
# File 'lib/vonage/verify2/template_fragments.rb', line 45

def info(template_id:, template_fragment_id:)
  request("/v2/verify/templates/#{template_id}/template_fragments/#{template_fragment_id}")
end

#list(template_id:, **params) ⇒ ListResponse

Get a list of of template fragments for a specific template.

Examples:

template_fragment_list = client.verify2.template_fragments.list(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9')

Parameters:

  • :template_id. (required, String)

    The ID of the template for which to retreive the fragments

  • :page_size. (optional, Integer)

    The amount of template fragments to list per page

  • :page. (optional, Integer)

    The page number to retrieve

Returns:

See Also:



26
27
28
# File 'lib/vonage/verify2/template_fragments.rb', line 26

def list(template_id:, **params)
  request("/v2/verify/templates/#{template_id}/template_fragments", params: params, response_class: ListResponse)
end

#update(template_id:, template_fragment_id:, text:) ⇒ Response

Update an existing template fragment.

Examples:

client.verify2.template_fragments.update(
                      template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
                      template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19',
                      text: 'Your one-time code is: ${code}'
                    )

Parameters:

  • :template_id. (required, String)

    The ID of the template with which the fragment to be updated is associated

  • :template_fragment_id. (required, String)

    The ID of the fragment to be updated

  • :text. (required, String)

    The text to be used in the template fragment. There are 4 reserved variables available to use as part of the text: $code, $brand, $time-limit and $time-limit-unit

Returns:

See Also:



102
103
104
# File 'lib/vonage/verify2/template_fragments.rb', line 102

def update(template_id:, template_fragment_id:, text:)
  request("/v2/verify/templates/#{template_id}/template_fragments/#{template_fragment_id}", params: {text: text}, type: Patch)
end