Sha256: f54568aced51660c8f82f3f7a3c1e927ba5a7e62010f34936836bc2c67a8b8fe

Contents?: true

Size: 970 Bytes

Versions: 3

Compression:

Stored size: 970 Bytes

Contents

require 'uri'

module PrestaShop

  # Handle URIs, converting from base Prestashop URL to API URIs
  class UriHandler
    API_PATH = 'api/'

    # Convert a base Prestashop URL to its API URI
    # @param base_url [String] a Prestashop base URL. Do not append "/api", it is appended internally. E.g. use
    #   "http://my.prestashop.com/", not "http://my.prestashop.com/api". URIs without scheme (e.g. "my.prestashop.com")
    #   are assumed to be http:// by default.
    # @return [String] the URI of the API for this Prestashop instance
    def self.api_uri(base_url)
      # Base URL must end in '/' so that we can properly append other path fragments for the API paths
      base_url.strip!
      base_url += '/' unless base_url[-1] == '/'

      # Add http:// scheme if the scheme is missing from the base url
      base_url = 'http://' + base_url if URI.parse(base_url).scheme.nil?

      uri = URI.join base_url, API_PATH
      return uri.to_s
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
presta_shop-0.1.2 lib/presta_shop/uri_handler.rb
presta_shop-0.1.1 lib/presta_shop/uri_handler.rb
presta_shop-0.1.0 lib/presta_shop/uri_handler.rb