Skip to content

Commit

Permalink
Merge pull request #129 from next-tms/brody/add-carrier-tracking-url-…
Browse files Browse the repository at this point in the history
…template

Add `Carrier#tracking_url_template`
  • Loading branch information
brodyhoskins committed Feb 2, 2024
2 parents ca03d51 + b49ba17 commit 0357e24
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/freight_kit/carrier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,32 @@ def pickup_number_is_tracking_number?
false
end

# The template URL for tracking publicly. A template URL is a URL containing the token "%s" that can be replaced
# to generate a valid URL.
#
# For example, `tracking_url_template(:tracking_number)` might return:
# "https://example.com/tracking/pro/%s"
#
# This method is designed to provide a template URL for a specific tracking-related key, allowing applications to
# generate valid tracking URLs without involving FreightKit each time. The `key` parameter specifies the type of
# tracking information, and it must be one of the following symbols:
#
# - `:bol_number`: Bill of Lading number
# - `:order_number`: Order number
# - `:pickup_number`: Pickup number
# - `:po_number`: Purchase order number
# - `:tracking_number`: tracking number ("PRO number")
#
# @param [Symbol] key The symbol representing the type of tracking information for which the template URL is
# needed.
# @raise [ArgumentError] Raised if the provided key is not one of the specified tracking-related symbols.
# @return [String, nil] The template URL or nil if no template is available for the given key.
def tracking_url_template(key)
keys = %i[bol_number order_number pickup_number po_number tracking_number]

raise ArgumentError, "key must be one of: #{keys.join(", ")}" if keys.exclude?(key)
end

# Returns the keywords passed to `#initialize` that cannot be blank.
# @return [Array<Symbol>]
def requirements
Expand Down

0 comments on commit 0357e24

Please sign in to comment.