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_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
.
-
Args:
-
Returns:
-
string
The full URL for aDelivery
request
-
# 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)
click to toggle source
Checks whether the provided URL is too long and raises an error if so.
-
Args:
-
url (
string
) A fullDelivery
URL
-
-
Raises:
-
UriFormatException
if the URL is 65,519 characters or more
-
# 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
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.
-
Args:
-
Returns:
-
string
The URL with the project ID
-
# File lib/delivery/builders/url_builder.rb, line 105 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 73 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.
-
Args:
-
Returns:
-
string
The URL path part (without protocol or domain)
-
# File lib/delivery/builders/url_builder.rb, line 60 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_ELEMENT format(URL_TEMPLATE_ELEMENTS, query.content_type, query.code_name) end end
provide_taxonomy(query)
click to toggle source
# File lib/delivery/builders/url_builder.rb, line 81 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 89 def provide_type(query) if query.code_name.nil? URL_TEMPLATE_TYPES else format(URL_TEMPLATE_TYPE, query.code_name) end end