Class: BeyondApi::WebhookSubscriptions

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

Instance Attribute Summary

Attributes inherited from Base

#session

Instance Method Summary collapse

Methods included from Utils

#file_content_type, #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
29
30
31
# File 'lib/beyond_api/resources/webhook_subscriptions.rb', line 24

def activate(webhook_subscription_id)
  path = "/webhook-subscriptions/#{webhook_subscription_id}/activate"

  response, status = BeyondApi::Request.post(@session,
                                             path)

  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)


49
50
51
52
53
# File 'lib/beyond_api/resources/webhook_subscriptions.rb', line 49

def all(params = {})
  path = "/webhook-subscriptions"

  handle_all_request(path, :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)


81
82
83
84
85
86
87
88
89
# File 'lib/beyond_api/resources/webhook_subscriptions.rb', line 81

def create(body)
  path = "/webhook-subscriptions"

  response, status = BeyondApi::Request.post(@session,
                                             path,
                                             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



104
105
106
107
108
109
110
111
# File 'lib/beyond_api/resources/webhook_subscriptions.rb', line 104

def deactivate(webhook_subscription_id)
  path = "/webhook-subscriptions/#{webhook_subscription_id}/deactivate"

  response, status = BeyondApi::Request.post(@session,
                                             path)

  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



126
127
128
129
130
131
132
133
# File 'lib/beyond_api/resources/webhook_subscriptions.rb', line 126

def delete(webhook_subscription_id)
  path = "/webhook-subscriptions/#{webhook_subscription_id}"

  response, status = BeyondApi::Request.delete(@session,
                                               path)

  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)


149
150
151
152
153
154
155
156
# File 'lib/beyond_api/resources/webhook_subscriptions.rb', line 149

def find(webhook_subscription_id)
  path = "/webhook-subscriptions/#{webhook_subscription_id}"

  response, status = BeyondApi::Request.get(@session,
                                            path)

  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



187
188
189
190
191
192
193
194
195
# File 'lib/beyond_api/resources/webhook_subscriptions.rb', line 187

def update(webhook_subscription_id, body)
  path = "/webhook-subscriptions/#{webhook_subscription_id}"

  response, status = BeyondApi::Request.put(@session,
                                            path,
                                            body)

  handle_response(response, status)
end