class Kentico::Kontent::Delivery::Builders::UrlBuilder

Internal class which generates the URL required for Delivery REST API

Constants

MSG_LONG_QUERY
URL_MAX_LENGTH
URL_TEMPLATE_BASE
URL_TEMPLATE_ELEMENTS
URL_TEMPLATE_ITEM
URL_TEMPLATE_ITEMS
URL_TEMPLATE_ITEMS_FEED
URL_TEMPLATE_LANGUAGES
URL_TEMPLATE_PREVIEW
URL_TEMPLATE_TAXONOMIES
URL_TEMPLATE_TAXONOMY
URL_TEMPLATE_TYPE
URL_TEMPLATE_TYPES

Public Class Methods

provide_url(query) click to toggle source

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

# File lib/delivery/builders/url_builder.rb, line 31
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) click to toggle source

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

  • Args:

  • Raises:

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

# File lib/delivery/builders/url_builder.rb, line 49
def validate_url(url)
  raise UriFormatException, MSG_LONG_QUERY if url.length > URL_MAX_LENGTH
end

Private Class Methods

provide_base_url(query) click to toggle source

Returns the protocol and domain with project ID. Domain changes according to the query's use_preview attribute.

# File lib/delivery/builders/url_builder.rb, line 111
def provide_base_url(query)
  if query.use_preview
    format(URL_TEMPLATE_PREVIEW, query.project_id)
  else
    format(URL_TEMPLATE_BASE, query.project_id)
  end
end
provide_item(query) click to toggle source
# File lib/delivery/builders/url_builder.rb, line 79
def provide_item(query)
  if query.code_name.nil?
    URL_TEMPLATE_ITEMS
  else
    format(URL_TEMPLATE_ITEM, query.code_name)
  end
end
provide_path_part(query) click to toggle source

Returns relative path part of URL depending on query type.

# File lib/delivery/builders/url_builder.rb, line 62
def provide_path_part(query)
  case query.query_type
  when Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS
    provide_item query
  when Kentico::Kontent::Delivery::QUERY_TYPE_TYPES
    provide_type query
  when Kentico::Kontent::Delivery::QUERY_TYPE_TAXONOMIES
    provide_taxonomy query
  when Kentico::Kontent::Delivery::QUERY_TYPE_LANGUAGES
    URL_TEMPLATE_LANGUAGES
  when Kentico::Kontent::Delivery::QUERY_TYPE_ELEMENT
    format(URL_TEMPLATE_ELEMENTS, query.content_type, query.code_name)
  when Kentico::Kontent::Delivery::QUERY_TYPE_ITEMS_FEED
    URL_TEMPLATE_ITEMS_FEED
  end
end
provide_taxonomy(query) click to toggle source
# File lib/delivery/builders/url_builder.rb, line 87
def provide_taxonomy(query)
  if query.code_name.nil?
    URL_TEMPLATE_TAXONOMIES
  else
    format(URL_TEMPLATE_TAXONOMY, query.code_name)
  end
end
provide_type(query) click to toggle source
# File lib/delivery/builders/url_builder.rb, line 95
def provide_type(query)
  if query.code_name.nil?
    URL_TEMPLATE_TYPES
  else
    format(URL_TEMPLATE_TYPE, query.code_name)
  end
end