Class: Lucid::Shopify::CreateWebhook

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

Instance Method Summary collapse

Constructor Details

#initialize(client: Container[:client]) ⇒ CreateWebhook



9
10
11
# File 'lib/lucid/shopify/create_webhook.rb', line 9

def initialize(client: Container[:client])
  @client = client
end

Instance Method Details

#call(credentials, webhook) ⇒ Hash



17
18
19
20
21
22
23
24
25
# File 'lib/lucid/shopify/create_webhook.rb', line 17

def call(credentials, webhook)
  data = {**webhook, address: Shopify.config.webhook_uri}

  @client.post_json(credentials, 'webhooks', webhook: data)
rescue Response::Error => e
  raise e unless e.response.error_message?([
    /has already been taken/,
  ])
end