Module: ShopifyApp::Utils

Defined in:
lib/shopify_app/utils.rb

Class Method Summary collapse

Class Method Details

.fetch_known_api_versionsObject



16
17
18
19
20
21
22
# File 'lib/shopify_app/utils.rb', line 16

def self.fetch_known_api_versions
  Rails.logger.info("[ShopifyAPI::ApiVersion] Fetching known Admin API Versions from Shopify...")
  ShopifyAPI::ApiVersion.fetch_known_versions
  Rails.logger.info("[ShopifyAPI::ApiVersion] Known API Versions: #{ShopifyAPI::ApiVersion.versions.keys}")
rescue ActiveResource::ConnectionError
  logger.error("[ShopifyAPI::ApiVersion] Unable to fetch api_versions from Shopify")
end

.sanitize_shop_domain(shop_domain) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/shopify_app/utils.rb', line 4

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

.shop_login_url(shop:, return_to:) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/shopify_app/utils.rb', line 24

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

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

  url.to_s
end