Class: ShopifyAPI::Webhooks::Registration
- Inherits:
-
Object
- Object
- ShopifyAPI::Webhooks::Registration
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/shopify_api/webhooks/registration.rb
Direct Known Subclasses
ShopifyAPI::Webhooks::Registrations::EventBridge, ShopifyAPI::Webhooks::Registrations::Http, ShopifyAPI::Webhooks::Registrations::PubSub
Constant Summary collapse
- FIELDS_DELIMITER =
","
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#metafield_namespaces ⇒ Object
readonly
Returns the value of attribute metafield_namespaces.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Instance Method Summary collapse
- #build_check_query ⇒ Object
- #build_register_query(webhook_id: nil) ⇒ Object
- #callback_address ⇒ Object
-
#initialize(topic:, path:, handler: nil, fields: nil, metafield_namespaces: nil, filter: nil) ⇒ Registration
constructor
A new instance of Registration.
- #mutation_name(webhook_id) ⇒ Object
- #parse_check_result(body) ⇒ Object
- #subscription_args ⇒ Object
Constructor Details
#initialize(topic:, path:, handler: nil, fields: nil, metafield_namespaces: nil, filter: nil) ⇒ Registration
Returns a new instance of Registration.
34 35 36 37 38 39 40 41 42 |
# File 'lib/shopify_api/webhooks/registration.rb', line 34 def initialize(topic:, path:, handler: nil, fields: nil, metafield_namespaces: nil, filter: nil) @topic = T.let(topic.gsub("/", "_").upcase, String) @path = path @handler = handler fields_array = fields.is_a?(String) ? fields.split(FIELDS_DELIMITER) : fields @fields = T.let(fields_array&.map(&:strip)&.compact, T.nilable(T::Array[String])) @metafield_namespaces = T.let(&.map(&:strip)&.compact, T.nilable(T::Array[String])) @filter = filter end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
20 21 22 |
# File 'lib/shopify_api/webhooks/registration.rb', line 20 def fields @fields end |
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
26 27 28 |
# File 'lib/shopify_api/webhooks/registration.rb', line 26 def filter @filter end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
17 18 19 |
# File 'lib/shopify_api/webhooks/registration.rb', line 17 def handler @handler end |
#metafield_namespaces ⇒ Object (readonly)
Returns the value of attribute metafield_namespaces.
23 24 25 |
# File 'lib/shopify_api/webhooks/registration.rb', line 23 def @metafield_namespaces end |
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
14 15 16 |
# File 'lib/shopify_api/webhooks/registration.rb', line 14 def topic @topic end |
Instance Method Details
#build_check_query ⇒ Object
54 |
# File 'lib/shopify_api/webhooks/registration.rb', line 54 def build_check_query; end |
#build_register_query(webhook_id: nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/shopify_api/webhooks/registration.rb', line 68 def build_register_query(webhook_id: nil) identifier = webhook_id ? "id: \"#{webhook_id}\"" : "topic: #{@topic}" subscription_args_string = subscription_args.map do |k, v| "#{k}: #{[:includeFields, :metafieldNamespaces].include?(k) ? v : %("#{v}")}" end.join(", ") <<~QUERY mutation webhookSubscription { #{mutation_name(webhook_id)}(#{identifier}, webhookSubscription: {#{subscription_args_string}}) { userErrors { field message } webhookSubscription { #{subscription_response_attributes.join("\n ")} } } } QUERY end |
#callback_address ⇒ Object
45 |
# File 'lib/shopify_api/webhooks/registration.rb', line 45 def callback_address; end |
#mutation_name(webhook_id) ⇒ Object
51 |
# File 'lib/shopify_api/webhooks/registration.rb', line 51 def mutation_name(webhook_id); end |
#parse_check_result(body) ⇒ Object
65 |
# File 'lib/shopify_api/webhooks/registration.rb', line 65 def parse_check_result(body); end |
#subscription_args ⇒ Object
48 |
# File 'lib/shopify_api/webhooks/registration.rb', line 48 def subscription_args; end |