-
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
4 changed files
with
97 additions
and
6 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,26 @@ | ||
module Dnsimple | ||
class Client | ||
module Registrar | ||
|
||
# Registers a domain. | ||
# | ||
# @see https://developer.dnsimple.com/v2/registrar/#register | ||
# | ||
# @param [Fixnum] account_id the account ID | ||
# @param [#to_s] domain_name The domain name to register. | ||
# @param [Hash] attributes | ||
# @param [Hash] options | ||
# @return [Struct::Domain] | ||
# | ||
# @raise [RequestError] When the request fails. | ||
def register(account_id, domain_name, attributes = {}, options = {}) | ||
Extra.validate_mandatory_attributes(attributes, [:registrant_id]) | ||
options = options.merge(attributes) | ||
response = client.post(Client.versioned("/%s/registrar/%s/registration" % [account_id, domain_name]), options) | ||
|
||
Dnsimple::Response.new(response, Struct::Domain.new(response["data"])) | ||
end | ||
|
||
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,36 @@ | ||
require 'spec_helper' | ||
|
||
describe Dnsimple::Client, ".registrar" do | ||
|
||
subject { described_class.new(api_endpoint: "https://api.dnsimple.test", access_token: "a1b2c3").registrar } | ||
|
||
|
||
describe "#register" do | ||
let(:account_id) { 1010 } | ||
|
||
before do | ||
stub_request(:post, %r[/v2/#{account_id}/registrar/.+/registration$]) | ||
.to_return(read_http_fixture("register/success.http")) | ||
end | ||
|
||
let(:attributes) { { registrant_id: "10" } } | ||
|
||
it "builds the correct request" do | ||
subject.register(account_id, domain_name = "example.com", attributes) | ||
|
||
expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/#{account_id}/registrar/#{domain_name}/registration") | ||
.with(body: attributes) | ||
.with(headers: { 'Accept' => 'application/json' }) | ||
end | ||
|
||
it "returns the domain" do | ||
response = subject.register(account_id, "example.com", attributes) | ||
expect(response).to be_a(Dnsimple::Response) | ||
|
||
result = response.data | ||
expect(result).to be_a(Dnsimple::Struct::Domain) | ||
expect(result.id).to be_a(Fixnum) | ||
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 201 Created | ||
Server: nginx | ||
Date: Sat, 16 Jan 2016 16:09:02 GMT | ||
Content-Type: application/json; charset=utf-8 | ||
Transfer-Encoding: chunked | ||
Connection: keep-alive | ||
Status: 201 Created | ||
X-RateLimit-Limit: 4000 | ||
X-RateLimit-Remaining: 3965 | ||
X-RateLimit-Reset: 1452960541 | ||
ETag: W/"e034ef9fb32487cf4dc034050ba846c5" | ||
Cache-Control: max-age=0, private, must-revalidate | ||
X-Request-Id: 8b378ee7-d8fa-4459-a1b0-a18bfd2354bb | ||
X-Runtime: 13.365767 | ||
Strict-Transport-Security: max-age=31536000 | ||
|
||
{"data":{"id":1,"account_id":1010,"registrant_id":2,"name":"example.weppos","unicode_name":"example.weppos","token":"cc8h1jP8bDLw5rXycL16k8BivcGiT6K9","state":"registered","auto_renew":false,"private_whois":false,"expires_on":"2017-01-16","created_at":"2016-01-16T16:08:50.649Z","updated_at":"2016-01-16T16:09:01.161Z"}} |