Class: ShopifyAPI::Webhooks::Registrations::Http
Constant Summary
ShopifyAPI::Webhooks::Registration::FIELDS_DELIMITER
Instance Attribute Summary
#fields, #filter, #handler, #metafield_namespaces, #topic
Instance Method Summary
collapse
#build_register_query, #initialize
Instance Method Details
#build_check_query ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/shopify_api/webhooks/registrations/http.rb', line 33
def build_check_query
<<~QUERY
{
webhookSubscriptions(first: 1, topics: #{@topic}) {
edges {
node {
id
includeFields
metafieldNamespaces
filter
endpoint {
__typename
... on WebhookHttpEndpoint {
callbackUrl
}
}
}
}
}
}
QUERY
end
|
#callback_address ⇒ Object
11
12
13
14
15
16
17
18
19
|
# 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) ⇒ Object
28
29
30
|
# File 'lib/shopify_api/webhooks/registrations/http.rb', line 28
def mutation_name(webhook_id)
webhook_id ? "webhookSubscriptionUpdate" : "webhookSubscriptionCreate"
end
|
#parse_check_result(body) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/shopify_api/webhooks/registrations/http.rb', line 65
def parse_check_result(body)
edges = body.dig("data", "webhookSubscriptions", "edges") || {}
webhook_id = nil
fields = []
metafield_namespaces = []
filter = 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
fields = node["includeFields"] || []
metafield_namespaces = node["metafieldNamespaces"] || []
filter = node["filter"].to_s
end
{ webhook_id: webhook_id, current_address: current_address, fields: fields,
metafield_namespaces: metafield_namespaces, filter: filter, }
end
|
#subscription_args ⇒ Object
22
23
24
25
|
# File 'lib/shopify_api/webhooks/registrations/http.rb', line 22
def subscription_args
{ callbackUrl: callback_address, includeFields: fields,
metafieldNamespaces: metafield_namespaces, filter: filter, }.compact
end
|