Class: PostForMe::Resources::Webhooks

Inherits:
Object
  • Object
show all
Defined in:
lib/post_for_me/resources/webhooks.rb,
sig/post_for_me/resources/webhooks.rbs

Overview

Webhooks enable you to subscribe to certain events. This involves Post for Me making a POST request to the URL of any webhooks you create. Only the events you subscribe to will be sent to your webhook URL.

Payload

When an event happens that your webhook is subscribed to, we will make a POST request with the following JSON body

    {
        "event_type": "",
        "data": {}
    }

The event_type will be the event that triggered the webhook POST, data will be the resulting entity from the event

Security

To verify the POST to your webhook URL is from us we will include a secret in the header "Post-For-Me-Webhook-Secret". When you create a webhook you will receive the secret in the response.

Retries

If your server fails to respond with a 2XX code, requests to it will be retried with exponential backoff around 8 times over the course of just over a day.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Webhooks

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Webhooks.

Parameters:



162
163
164
# File 'lib/post_for_me/resources/webhooks.rb', line 162

def initialize(client:)
  @client = client
end

Instance Method Details

#create(event_types:, url:, request_options: {}) ⇒ PostForMe::Models::Webhook

Create Webhook

Parameters:

Returns:

See Also:



48
49
50
51
52
53
54
55
56
57
# File 'lib/post_for_me/resources/webhooks.rb', line 48

def create(params)
  parsed, options = PostForMe::WebhookCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "v1/webhooks",
    body: parsed,
    model: PostForMe::Webhook,
    options: options
  )
end

#delete(id, request_options: {}) ⇒ PostForMe::Models::DeleteEntityResponse

Delete Webhook

Parameters:

Returns:

See Also:



150
151
152
153
154
155
156
157
# File 'lib/post_for_me/resources/webhooks.rb', line 150

def delete(id, params = {})
  @client.request(
    method: :delete,
    path: ["v1/webhooks/%1$s", id],
    model: PostForMe::DeleteEntityResponse,
    options: params[:request_options]
  )
end

#list(id: nil, event_type: nil, limit: nil, offset: nil, url: nil, request_options: {}) ⇒ PostForMe::Models::WebhookListResponse

Some parameter documentations has been truncated, see Models::WebhookListParams for more details.

Get a paginated result for webhooks based on the applied filters

Parameters:

  • id (Array<String>)

    Filter by id(s). Multiple values imply OR logic (e.g., ?id=wbh_xxxxxx&id=wbh_yyy

  • event_type (Array<String>)

    Filter by event type(s). Multiple values imply OR logic (e.g., ?event_type=socia

  • limit (Float)

    Number of items to return

  • offset (Float)

    Number of items to skip

  • url (Array<String>)

    Filter by url(s). Multiple values imply OR logic (e.g., ?url=https://example.com

  • request_options (PostForMe::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



127
128
129
130
131
132
133
134
135
136
137
# File 'lib/post_for_me/resources/webhooks.rb', line 127

def list(params = {})
  parsed, options = PostForMe::WebhookListParams.dump_request(params)
  query = PostForMe::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "v1/webhooks",
    query: query,
    model: PostForMe::Models::WebhookListResponse,
    options: options
  )
end

#retrieve(id, request_options: {}) ⇒ PostForMe::Models::Webhook

Get webhook by ID

Parameters:

Returns:

See Also:



70
71
72
73
74
75
76
77
# File 'lib/post_for_me/resources/webhooks.rb', line 70

def retrieve(id, params = {})
  @client.request(
    method: :get,
    path: ["v1/webhooks/%1$s", id],
    model: PostForMe::Webhook,
    options: params[:request_options]
  )
end

#update(id, event_types: nil, url: nil, request_options: {}) ⇒ PostForMe::Models::Webhook

Update Webhook

Parameters:

Returns:

See Also:



94
95
96
97
98
99
100
101
102
103
# File 'lib/post_for_me/resources/webhooks.rb', line 94

def update(id, params = {})
  parsed, options = PostForMe::WebhookUpdateParams.dump_request(params)
  @client.request(
    method: :patch,
    path: ["v1/webhooks/%1$s", id],
    body: parsed,
    model: PostForMe::Webhook,
    options: options
  )
end