Class: Prestashopper::UriHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/prestashopper/uri_handler.rb

Overview

Handle URIs, converting from base Prestashop URL to API URIs

Constant Summary collapse

API_PATH =
'api/'

Class Method Summary collapse

Class Method Details

.api_uri(base_url) ⇒ String

Convert a base Prestashop URL to its API URI

Parameters:

  • base_url (String)

    a Prestashop base URL. Do not append “/api”, it is appended internally. E.g. use “my.prestashop.com/”, not “my.prestashop.com/api”. URIs without scheme (e.g. “my.prestashop.com”) are assumed to be http:// by default.

Returns:

  • (String)

    the URI of the API for this Prestashop instance



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/prestashopper/uri_handler.rb', line 14

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