Class: BeyondApi::WebhookSubscriptions

Inherits:
Base
  • Object
show all
Includes:
Utils
Defined in:
lib/beyond_api/resources/webhook_subscriptions.rb

Overview

:category: Resources

Instance Attribute Summary

Attributes inherited from Base

#session

Instance Method Summary collapse

Methods included from Utils

#handle_all_request, #handle_error, #handle_response, #sanitize_key, #sanitize_response, #to_object_struct

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from BeyondApi::Base

Instance Method Details

#activate(webhook_subscription_id) ⇒ Object

A POST request is used to activate a webhook subscription.

$ curl 'https://api-shop.beyondshop.cloud/api/webhook-subscriptions/268a8629-55cd-4890-9013-936b9b5ea14c/activate' -i -X POST \
    -H 'Authorization: Bearer <Access token>'

Examples:

Ruby example request

session.webhook_subscriptions.activate("268a8629-55cd-4890-9013-936b9b5ea14c")

Parameters:

  • webhook_subscription_id (String)

    the webhook subscription UUID

Returns:

  • true

Scopes:

  • ordr:r, prod:r


24
25
26
27
28
# File 'lib/beyond_api/resources/webhook_subscriptions.rb', line 24

def activate(webhook_subscription_id)
  response, status = BeyondApi::Request.post(@session, "/webhook-subscriptions/#{webhook_subscription_id}/activate")

  handle_response(response, status, respond_with_true: true)
end

#all(params = {}) ⇒ OpenStruct

A GET request is used to list all of the webhook subscriptions in a paged way.

$ curl 'https://api-shop.beyondshop.cloud/api/webhook-subscriptions' -i -X GET \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

@webhook_subscriptions = session.webhook_subscriptions.all(size: 100, page: 0)

Parameters:

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :paginated (Boolean)
  • :size (Integer)

    the page size

  • :page (Integer)

    the page number

Returns:

  • (OpenStruct)

46
47
48
# File 'lib/beyond_api/resources/webhook_subscriptions.rb', line 46

def all(params = {})
  handle_all_request("/webhook-subscriptions", :webhook_subscriptions, params)
end

#create(body) ⇒ OpenStruct

A POST request is used to create a webhook subscription.

The scopes needed for the operation depend on the event types you register for. e.g. Order events require the scope orde:r.

$ curl 'https://api-shop.beyondshop.cloud/api/webhook-subscriptions' -i -X POST \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
    "callbackUri":"http://example.com/test",
    "eventTypes": ["order.created", "product.created"]
}'

Examples:

body = {
  "callback_uri" => "http://example.com/test",
  "event_types" => ["order.created", "product.created"]
}

@webhook_subscription = session.webhook_subscriptions.create(body)

Parameters:

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

76
77
78
79
80
# File 'lib/beyond_api/resources/webhook_subscriptions.rb', line 76

def create(body)
  response, status = BeyondApi::Request.post(@session, "/webhook-subscriptions", body)

  handle_response(response, status)
end

#deactivate(webhook_subscription_id) ⇒ Object

A POST request is used to deactivate a webhook subscription.

$ curl 'https://api-shop.beyondshop.cloud/api/webhook-subscriptions/a597cea4-b688-4164-8c56-b6568ea4d5aa/deactivate' -i -X POST \
    -H 'Authorization: Bearer <Access token>'

Examples:

session.webhook_subscriptions.deactivate("a597cea4-b688-4164-8c56-b6568ea4d5aa")

Parameters:

  • webhook_subscription_id (String)

    the webhook subscription UUID

Returns:

  • true


95
96
97
98
99
# File 'lib/beyond_api/resources/webhook_subscriptions.rb', line 95

def deactivate(webhook_subscription_id)
  response, status = BeyondApi::Request.post(@session, "/webhook-subscriptions/#{webhook_subscription_id}/deactivate")

  handle_response(response, status, respond_with_true: true)
end

#delete(webhook_subscription_id) ⇒ Object

A DELETE request is used to delete a webhook subscription.

$ curl 'https://api-shop.beyondshop.cloud/api/webhook-subscriptions/c6076a5a-a8ad-443f-b20b-8a1b268b069e' -i -X DELETE \
    -H 'Authorization: Bearer <Access token>'

Examples:

session.webhook_subscriptions.delete("c6076a5a-a8ad-443f-b20b-8a1b268b069e")

Parameters:

  • webhook_subscription_id (String)

    the webhook subscription UUID

Returns:

  • true


114
115
116
117
118
# File 'lib/beyond_api/resources/webhook_subscriptions.rb', line 114

def delete(webhook_subscription_id)
  response, status = BeyondApi::Request.delete(@session, "/webhook-subscriptions/#{webhook_subscription_id}")

  handle_response(response, status, respond_with_true: true)
end

#find(webhook_subscription_id) ⇒ OpenStruct

A GET request is used to retrieve the details of a webook subscription.

$ curl 'https://api-shop.beyondshop.cloud/api/webhook-subscriptions/3d44ec71-768c-4927-9069-a96a5153e87c' -i -X GET \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

@webhook_subscription = session.webhook_subscriptions.find("3d44ec71-768c-4927-9069-a96a5153e87c")

Parameters:

  • webhook_subscription_id (String)

    the webhook subscription UUID

Returns:

  • (OpenStruct)

134
135
136
137
138
# File 'lib/beyond_api/resources/webhook_subscriptions.rb', line 134

def find(webhook_subscription_id)
  response, status = BeyondApi::Request.get(@session, "/webhook-subscriptions/#{webhook_subscription_id}")

  handle_response(response, status)
end

#update(webhook_subscription_id, body) ⇒ OpenStruct

A PUT request is used to update a subscription.

The scopes needed for the operation depend on the event types you register for. e.g. Order events require the scope orde:r.

$ curl 'https://api-shop.beyondshop.cloud/api/webhook-subscriptions/6f3bc033-c2d1-4f44-80e3-1b668f6bd699' -i -X PUT \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
    "callbackUri":"http://example.com/test/updated",
    "eventTypes": ["product.updated"]
}'

Examples:

body = {
  "callback_uri" => "http://example.com/test/updated",
  "event_types" => ["product.updated"]
}

@webhook_subscription = session.webhook_subscriptions.update("6f3bc033-c2d1-4f44-80e3-1b668f6bd699", body)

Parameters:

  • webhook_subscription_id (String)

    the webhook subscription UUID

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • ordr:r, prod:r


169
170
171
172
173
# File 'lib/beyond_api/resources/webhook_subscriptions.rb', line 169

def update(webhook_subscription_id, body)
  response, status = BeyondApi::Request.put(@session, "/webhook-subscriptions/#{webhook_subscription_id}", body)

  handle_response(response, status)
end