Sha256: a2a9e48023c06dc9807acb8d3682fc755a83fe600309434c920c46e2bb9373f3

Contents?: true

Size: 860 Bytes

Versions: 7

Compression:

Stored size: 860 Bytes

Contents

# frozen_string_literal: true

module ShopifyApp
  module Utils
    def self.sanitize_shop_domain(shop_domain)
      myshopify_domain = ShopifyApp.configuration.myshopify_domain
      name = shop_domain.to_s.downcase.strip
      name += ".#{myshopify_domain}" if !name.include?(myshopify_domain.to_s) && !name.include?(".")
      name.sub!(%r|https?://|, "")

      u = URI("http://#{name}")
      u.host if u.host&.match(/^[a-z0-9][a-z0-9\-]*[a-z0-9]\.#{Regexp.escape(myshopify_domain)}$/)
    rescue URI::InvalidURIError
      nil
    end

    def self.shop_login_url(shop:, host:, return_to:)
      return ShopifyApp.configuration.login_url unless shop
      url = URI(ShopifyApp.configuration.login_url)

      url.query = URI.encode_www_form(
        shop: shop,
        host: host,
        return_to: return_to,
      )

      url.to_s
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
shopify_app-20.0.2 lib/shopify_app/utils.rb
shopify_app-20.0.1 lib/shopify_app/utils.rb
shopify_app-20.0.0 lib/shopify_app/utils.rb
shopify_app-19.1.0 lib/shopify_app/utils.rb
shopify_app-19.0.2 lib/shopify_app/utils.rb
shopify_app-19.0.1 lib/shopify_app/utils.rb
shopify_app-19.0.0 lib/shopify_app/utils.rb