Class: Polar::Resources::Webhooks

Inherits:
Base
  • Object
show all
Defined in:
lib/polar/resources/webhooks.rb

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Polar::Resources::Base

Instance Method Details

#create_webhook_endpoint(attributes) ⇒ Hash

Create webhook endpoint

Parameters:

  • attributes (Hash)

    Webhook endpoint attributes

Options Hash (attributes):

  • :url (String)

    Webhook URL

  • :events (Array)

    List of events to subscribe to

  • :organization_id (String)

    Organization ID

Returns:

  • (Hash)

    Created webhook endpoint



24
25
26
27
# File 'lib/polar/resources/webhooks.rb', line 24

def create_webhook_endpoint(attributes)
  response = post('/webhooks/endpoints', attributes)
  response.body
end

#delete_webhook_endpoint(id) ⇒ Boolean

Delete webhook endpoint

Parameters:

  • id (String)

    Webhook endpoint ID

Returns:

  • (Boolean)

    Success status



49
50
51
52
# File 'lib/polar/resources/webhooks.rb', line 49

def delete_webhook_endpoint(id)
  delete("/webhooks/endpoints/#{id}")
  true
end

#get_webhook_endpoint(id) ⇒ Hash

Get webhook endpoint

Parameters:

  • id (String)

    Webhook endpoint ID

Returns:

  • (Hash)

    Webhook endpoint data



32
33
34
35
# File 'lib/polar/resources/webhooks.rb', line 32

def get_webhook_endpoint(id)
  response = get("/webhooks/endpoints/#{id}")
  response.body
end

#list_webhook_deliveries(params = {}) ⇒ PaginatedResponse

List webhook deliveries

Parameters:

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

    Query parameters

Options Hash (params):

  • :endpoint_id (String)

    Filter by endpoint ID

  • :page (Integer)

    Page number

  • :limit (Integer)

    Items per page

Returns:



68
69
70
# File 'lib/polar/resources/webhooks.rb', line 68

def list_webhook_deliveries(params = {})
  paginate('/webhooks/deliveries', params)
end

#list_webhook_endpoints(params = {}) ⇒ PaginatedResponse

List webhook endpoints

Parameters:

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

    Query parameters

Options Hash (params):

  • :organization_id (String)

    Filter by organization ID

  • :page (Integer)

    Page number

  • :limit (Integer)

    Items per page

Returns:



14
15
16
# File 'lib/polar/resources/webhooks.rb', line 14

def list_webhook_endpoints(params = {})
  paginate('/webhooks/endpoints', params)
end

#redeliver_webhook_event(delivery_id) ⇒ Hash

Redeliver webhook event

Parameters:

  • delivery_id (String)

    Webhook delivery ID

Returns:

  • (Hash)

    Redelivery result



75
76
77
78
# File 'lib/polar/resources/webhooks.rb', line 75

def redeliver_webhook_event(delivery_id)
  response = post("/webhooks/deliveries/#{delivery_id}/redeliver")
  response.body
end

#reset_webhook_endpoint_secret(id) ⇒ Hash

Reset webhook endpoint secret

Parameters:

  • id (String)

    Webhook endpoint ID

Returns:

  • (Hash)

    Updated webhook endpoint with new secret



57
58
59
60
# File 'lib/polar/resources/webhooks.rb', line 57

def reset_webhook_endpoint_secret(id)
  response = post("/webhooks/endpoints/#{id}/secret/reset")
  response.body
end

#update_webhook_endpoint(id, attributes) ⇒ Hash

Update webhook endpoint

Parameters:

  • id (String)

    Webhook endpoint ID

  • attributes (Hash)

    Updated attributes

Returns:

  • (Hash)

    Updated webhook endpoint



41
42
43
44
# File 'lib/polar/resources/webhooks.rb', line 41

def update_webhook_endpoint(id, attributes)
  response = patch("/webhooks/endpoints/#{id}", attributes)
  response.body
end