-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module Dnsimple | ||
class Client | ||
module Webhooks | ||
|
||
# Lists the webhooks in the account. | ||
# | ||
# @see https://developer.dnsimple.com/v2/webhooks/#list | ||
# @see #all_webhooks | ||
# | ||
# @example List all webhooks | ||
# client.webhooks.list(1010) | ||
# | ||
# @param [Fixnum] account_id the account ID | ||
# @param [Hash] options the filtering and sorting option | ||
# @return [Dnsimple::CollectionResponse<Dnsimple::Struct::Webhook>] | ||
# | ||
# @raise [Dnsimple::RequestError] | ||
def webhooks(account_id, options = {}) | ||
response = client.get(Client.versioned("/%s/webhooks" % [account_id]), options) | ||
|
||
Dnsimple::CollectionResponse.new(response, response["data"].map { |r| Struct::Webhook.new(r) }) | ||
end | ||
alias :list :webhooks | ||
alias :list_webhooks :webhooks | ||
|
||
# Lists ALL the webhooks in the account. | ||
# | ||
# This is equal to {#webhooks}. | ||
# We have implemented both methods to have a consistent design with other | ||
# resources that implements pagination. | ||
# | ||
# @see https://developer.dnsimple.com/v2/webhooks/#list | ||
# @see #webhooks | ||
# | ||
# @param [Fixnum] account_id the account ID | ||
# @param [Hash] options the filtering and sorting option | ||
# @return [Dnsimple::CollectionResponse<Dnsimple::Struct::Webhook>] | ||
# | ||
# @raise [Dnsimple::RequestError] | ||
def all_webhooks(account_id, options = {}) | ||
webhooks(account_id, options) | ||
end | ||
alias :all :all_webhooks | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Dnsimple | ||
module Struct | ||
|
||
class Webhook < Base | ||
# @return [Fixnum] The contact ID in DNSimple. | ||
attr_accessor :id | ||
|
||
# @return [String] The callback URL. | ||
attr_accessor :url | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'spec_helper' | ||
|
||
describe Dnsimple::Client, ".webhooks" do | ||
|
||
subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").webhooks } | ||
|
||
describe "#webhooks" do | ||
let(:account_id) { 1010 } | ||
|
||
before do | ||
stub_request(:get, %r[/v2/#{account_id}/webhooks]) | ||
.to_return(read_http_fixture("listWebhooks/success.http")) | ||
end | ||
|
||
it "builds the correct request" do | ||
subject.webhooks(account_id) | ||
|
||
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/webhooks") | ||
.with(headers: { 'Accept' => 'application/json' }) | ||
end | ||
|
||
it "supports extra request options" do | ||
subject.webhooks(account_id, query: { foo: "bar" }) | ||
|
||
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/webhooks?foo=bar") | ||
end | ||
|
||
it "returns the webhooks" do | ||
response = subject.webhooks(account_id) | ||
|
||
expect(response).to be_a(Dnsimple::CollectionResponse) | ||
expect(response.data).to be_a(Array) | ||
expect(response.data.size).to eq(2) | ||
|
||
response.data.each do |result| | ||
expect(result).to be_a(Dnsimple::Struct::Webhook) | ||
expect(result.id).to be_a(Fixnum) | ||
end | ||
end | ||
end | ||
|
||
describe "#all_webhooks" do | ||
let(:account_id) { 1010 } | ||
|
||
it "delegates to client.webhooks" do | ||
expect(subject).to receive(:webhooks).with(account_id, { foo: "bar" }) | ||
subject.all_webhooks(account_id, { foo: "bar" }) | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
HTTP/1.1 200 OK | ||
Server: nginx | ||
Date: Mon, 15 Feb 2016 17:06:21 GMT | ||
Content-Type: application/json; charset=utf-8 | ||
Transfer-Encoding: chunked | ||
Connection: keep-alive | ||
Status: 200 OK | ||
X-RateLimit-Limit: 4000 | ||
X-RateLimit-Remaining: 3991 | ||
X-RateLimit-Reset: 1455559348 | ||
ETag: W/"01f1ea26e8e06d8d969bf06678bf7d12" | ||
Cache-Control: max-age=0, private, must-revalidate | ||
X-Request-Id: bc611cd0-d1a9-48d0-b450-c9c86f0d0dcf | ||
X-Runtime: 0.104174 | ||
Strict-Transport-Security: max-age=31536000 | ||
|
||
{"data":[{"id":1,"url":"https://webhook.test"},{"id":2,"url":"https://another.test"}]} |