Skip to content

Commit

Permalink
Add support for the Webhook Endpoint resource
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Oct 17, 2018
1 parent 9bc6ae8 commit 94e40c5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/stripe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
require "stripe/transfer"
require "stripe/usage_record"
require "stripe/usage_record_summary"
require "stripe/webhook_endpoint"

# OAuth
require "stripe/oauth"
Expand Down
1 change: 1 addition & 0 deletions lib/stripe/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def self.object_classes # rubocop:disable Metrics/MethodLength
Transfer::OBJECT_NAME => Transfer,
UsageRecord::OBJECT_NAME => UsageRecord,
UsageRecordSummary::OBJECT_NAME => UsageRecordSummary,
WebhookEndpoint::OBJECT_NAME => WebhookEndpoint,
}
end

Expand Down
12 changes: 12 additions & 0 deletions lib/stripe/webhook_endpoint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Stripe
class WebhookEndpoint < APIResource
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Save
include Stripe::APIOperations::Delete
extend Stripe::APIOperations::List

OBJECT_NAME = "webhook_endpoint".freeze
end
end
42 changes: 42 additions & 0 deletions test/stripe/webhook_endpoint_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

require ::File.expand_path("../../test_helper", __FILE__)

module Stripe
class WebhookEndpointTest < Test::Unit::TestCase
should "be listable" do
webhook_endpoints = Stripe::WebhookEndpoint.list
assert_requested :get, "#{Stripe.api_base}/v1/webhook_endpoints"
assert webhook_endpoints.data.is_a?(Array)
assert webhook_endpoints.first.is_a?(Stripe::WebhookEndpoint)
end

should "be retrievable" do
webhook_endpoint = Stripe::WebhookEndpoint.retrieve("we_123")
assert_requested :get, "#{Stripe.api_base}/v1/webhook_endpoints/we_123"
assert webhook_endpoint.is_a?(Stripe::WebhookEndpoint)
end

should "be creatable" do
webhook_endpoint = Stripe::WebhookEndpoint.create(
enabled_events: ['*'],
url: 'https://stripe.com'
)
assert_requested :post, "#{Stripe.api_base}/v1/webhook_endpoints"
assert webhook_endpoint.is_a?(Stripe::WebhookEndpoint)
end

should "be saveable" do
webhook_endpoint = Stripe::WebhookEndpoint.retrieve("we_123")
webhook_endpoint.enabled_events = ['*']
webhook_endpoint.save
assert_requested :post, "#{Stripe.api_base}/v1/webhook_endpoints/#{webhook_endpoint.id}"
end

should "be updateable" do
webhook_endpoint = Stripe::WebhookEndpoint.update("we_123", enabled_events: ['*'])
assert_requested :post, "#{Stripe.api_base}/v1/webhook_endpoints/we_123"
assert webhook_endpoint.is_a?(Stripe::WebhookEndpoint)
end
end
end

0 comments on commit 94e40c5

Please sign in to comment.