Class: Kentico::Kontent::Delivery::Builders::UrlBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/delivery/builders/url_builder.rb

Overview

Internal class which generates the URL required for Delivery REST API

Constant Summary collapse

URL_TEMPLATE_BASE =
'https://deliver.kontent.ai/%s'.freeze
URL_TEMPLATE_PREVIEW =
'https://preview-deliver.kontent.ai/%s'.freeze
URL_TEMPLATE_ITEM =
'/items/%s'.freeze
URL_TEMPLATE_ITEMS =
'/items'.freeze
URL_TEMPLATE_TYPE =
'/types/%s'.freeze
URL_TEMPLATE_TYPES =
'/types'.freeze
URL_TEMPLATE_ELEMENTS =
'/types/%s/elements/%s'.freeze
URL_TEMPLATE_TAXONOMY =
'/taxonomies/%s'.freeze
URL_TEMPLATE_TAXONOMIES =
'/taxonomies'.freeze
URL_MAX_LENGTH =
65_519
MSG_LONG_QUERY =
'The request url is too long. Split your query into multiple calls.'.freeze

Class Method Summary collapse

Class Method Details

.provide_url(query) ⇒ Object

Returns the proper domain for the request along with the query string parameters configured by the DeliveryQuery.

  • Args:

    • query ( Kentico::Kontent::Delivery::DeliveryQuery )

  • Returns:

    • string The full URL for a Delivery request



29
30
31
32
33
34
35
36
37
38
# File 'lib/delivery/builders/url_builder.rb', line 29

def provide_url(query)
  url = provide_base_url(query)
  url += provide_path_part(query)

  if query.query_string.empty?
    url
  else
    url + query.query_string.to_s
  end
end

.validate_url(url) ⇒ Object

Checks whether the provided URL is too long and raises an error if so.

  • Args:

    • url (string) A full Delivery URL

  • Raises:

    • UriFormatException if the URL is 65,519 characters or more

Raises:

  • (UriFormatException)


47
48
49
# File 'lib/delivery/builders/url_builder.rb', line 47

def validate_url(url)
  raise UriFormatException, MSG_LONG_QUERY if url.length > URL_MAX_LENGTH
end