Skip to content

Commit

Permalink
Added support for initiatePush
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Aug 29, 2016
1 parent b27f65c commit 5917d8e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/dnsimple/client/domains_pushes.rb
Expand Up @@ -2,6 +2,28 @@ module Dnsimple
class Client
module DomainsPushes

# Initiate a push for the domain.
#
# @see https://developer.dnsimple.com/v2/domains/pushes/#initiate
#
# @example Initiate a domain pushe for example.com:
# client.domains.initiate_push(1010, "example.com", new_account_email: "admin@target-account.test")
#
# @param [Fixnum] account_id the account ID
# @param [#to_s] domain_id The domain ID or domain name
# @param [Hash] attributes
# @option attributes [String] :new_account_email the target account email (mandatory)
# @param [Hash] options
# @return [Dnsimple::Response<Dnsimple::Struct::DomainPush>]
#
# @raise [Dnsimple::RequestError]
def initiate_push(account_id, domain_id, attributes, options = {})
Extra.validate_mandatory_attributes(attributes, [:new_account_email])
response = client.post(Client.versioned("/%s/domains/%s/pushes" % [account_id, domain_id]), attributes, options)

Dnsimple::Response.new(response, Struct::DomainPush.new(response["data"]))
end

# Lists the pushes for the domain.
#
# @see https://developer.dnsimple.com/v2/domains/pushes/#list
Expand All @@ -25,6 +47,7 @@ def pushes(account_id, options = {})

Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::DomainPush.new(r) })
end

end

end
Expand Down
29 changes: 29 additions & 0 deletions spec/dnsimple/client/domains_pushes_spec.rb
Expand Up @@ -4,6 +4,35 @@

subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").domains }

describe "#initiate_push" do
let(:account_id) { 1010 }
let(:domain_id) { "example.com" }

before do
stub_request(:post, %r{/v2/#{account_id}/domains/#{domain_id}/pushes$}).
to_return(read_http_fixture("initiatePush/success.http"))
end

let(:attributes) { { new_account_email: "admin@target-account.test" } }

it "builds the correct request" do
subject.initiate_push(account_id, domain_id, attributes)

expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/pushes").
with(body: attributes).
with(headers: { 'Accept' => 'application/json' })
end

it "returns the domain push" do
response = subject.initiate_push(account_id, domain_id, attributes)
expect(response).to be_a(Dnsimple::Response)

result = response.data
expect(result).to be_a(Dnsimple::Struct::DomainPush)
expect(result.id).to be_a(Fixnum)
end
end

describe "#pushes" do
let(:account_id) { 2020 }

Expand Down
21 changes: 21 additions & 0 deletions spec/fixtures.http/initiatePush/success.http
@@ -0,0 +1,21 @@
HTTP/1.1 201 Created
Server: nginx
Date: Thu, 11 Aug 2016 10:16:03 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
X-RateLimit-Limit: 2400
X-RateLimit-Remaining: 2395
X-RateLimit-Reset: 1470913058
ETag: W/"fbbdec6f757e014f6f0b2159090aed80"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 3c3f4bee-3e06-4998-8946-02d4fae26fa4
X-Runtime: 0.601397
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: DENY
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=31536000

{"data":{"id":1,"domain_id":100,"contact_id":null,"account_id":2020,"created_at":"2016-08-11T10:16:03.340Z","updated_at":"2016-08-11T10:16:03.340Z","accepted_at":null}}

0 comments on commit 5917d8e

Please sign in to comment.