Module: ShopifyApp::Utils
- Defined in:
- lib/shopify_app/utils.rb
Constant Summary collapse
- TRUSTED_SHOPIFY_DOMAINS =
[ "shopify.com", "myshopify.io", "myshopify.com", ].freeze
Class Method Summary collapse
Class Method Details
.sanitize_shop_domain(shop_domain) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/shopify_app/utils.rb', line 11 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?://|, "") trusted_domains = TRUSTED_SHOPIFY_DOMAINS.dup.push(myshopify_domain) u = URI("http://#{name}") regex = /^[a-z0-9][a-z0-9\-]*[a-z0-9]\.(#{trusted_domains.join("|")})$/ u.host if u.host&.match(regex) rescue URI::InvalidURIError nil end |
.shop_login_url(shop:, host:, return_to:) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/shopify_app/utils.rb', line 25 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 |