Class: ShopifyClient::CreateWebhook

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify-client/create_webhook.rb

Instance Method Summary collapse

Instance Method Details

#call(client, webhook) ⇒ Integer

Returns ID.

Parameters:

  • client (Client)
  • webhook (Hash)

Options Hash (webhook):

  • :topic (String)
  • :fields (Array<String>)

Returns:

  • (Integer)

    ID



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/shopify-client/create_webhook.rb', line 11

def call(client, webhook)
  raise ConfigError, 'webhook_uri is not set' unless ShopifyClient.config.webhook_uri

  client.post('webhooks', webhook: webhook.merge(
    address: ShopifyClient.config.webhook_uri,
  )).data['webhook']['id']
rescue Response::Error => e
  raise e unless e.response.errors.message?([
    /has already been taken/,
  ])
end