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

Returns a new instance of CreateWebhook.

Parameters:

  • client (#post_json) (defaults to: Container[:client])


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

Returns response data.

Parameters:

Returns:

  • (Hash)

    response data



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