class ShopifyAPI::Webhooks::Registrations::Http

Public Instance Methods

build_check_query() click to toggle source
# File lib/shopify_api/webhooks/registrations/http.rb, line 32
        def build_check_query
          <<~QUERY
            {
              webhookSubscriptions(first: 1, topics: #{@topic}) {
                edges {
                  node {
                    id
                    endpoint {
                      __typename
                      ... on WebhookHttpEndpoint {
                        callbackUrl
                      }
                    }
                  }
                }
              }
            }
          QUERY
        end
callback_address() click to toggle source
# File lib/shopify_api/webhooks/registrations/http.rb, line 11
def callback_address
  if @path.match?(%r{^https?://})
    @path
  elsif @path.match?(/^#{Context.host_name}/)
    "#{Context.host_scheme}://#{@path}"
  else
    "#{Context.host}/#{@path}"
  end
end
mutation_name(webhook_id) click to toggle source
# File lib/shopify_api/webhooks/registrations/http.rb, line 27
def mutation_name(webhook_id)
  webhook_id ? "webhookSubscriptionUpdate" : "webhookSubscriptionCreate"
end
parse_check_result(body) click to toggle source
# File lib/shopify_api/webhooks/registrations/http.rb, line 53
def parse_check_result(body)
  edges = body.dig("data", "webhookSubscriptions", "edges") || {}
  webhook_id = nil
  current_address = nil
  unless edges.empty?
    node = edges[0]["node"]
    webhook_id = node["id"].to_s
    current_address =
      if node.key?("endpoint")
        node["endpoint"]["callbackUrl"].to_s
      else
        node["callbackUrl"].to_s
      end
  end
  { webhook_id: webhook_id, current_address: current_address }
end
subscription_args() click to toggle source
# File lib/shopify_api/webhooks/registrations/http.rb, line 22
def subscription_args
  { callbackUrl: callback_address, includeFields: fields, metafieldNamespaces: metafield_namespaces }.compact
end