Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement registrar methods for Domain Prices API #230

Merged
merged 5 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This project uses [Semantic Versioning 2.0.0](http://semver.org/).

## main

- NEW: Added `registrar.get_domain_prices` to retrieve whether a domain is premium and the prices to register, transfer, and renew. (dnsimple/dnsimple-ruby#230)
- REMOVED: `domain.reset_domain_token` endpoint no longer exists and the client method is removed.
(dnsimple/dnsimple-ruby#231)

Expand Down
20 changes: 20 additions & 0 deletions lib/dnsimple/client/registrar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ def domain_premium_price(account_id, domain_name, options = {})
Dnsimple::Response.new(response, Struct::DomainPremiumPrice.new(response["data"]))
end

# Get prices for a domain.
# @see https://developer.dnsimple.com/v2/registrar/#getDomainPrices
#
# @example Check prices for example.com:
# client.registrar.get_domain_prices(1010, "example.com")
#
# @param [Integer] account_id the Account id
# @param [String] domain_name the domain name to find the prices
# @param [Hash] options
#
# @return [Struct::DomainPrice]
#
# @raise [RequestError] When the request fails.
def get_domain_prices(account_id, domain_name, options = {})
endpoint = Client.versioned("/%s/registrar/domains/%s/prices" % [account_id, domain_name])
response = client.get(endpoint, options)

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

# Registers a domain.
#
# @see https://developer.dnsimple.com/v2/registrar/#register
Expand Down
1 change: 1 addition & 0 deletions lib/dnsimple/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def initialize(attributes = {})
require_relative 'struct/domain'
require_relative 'struct/domain_check'
require_relative 'struct/domain_premium_price'
require_relative 'struct/domain_price'
require_relative 'struct/domain_push'
require_relative 'struct/domain_registration'
require_relative 'struct/domain_transfer'
Expand Down
24 changes: 24 additions & 0 deletions lib/dnsimple/struct/domain_price.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module Dnsimple
module Struct

class DomainPrice < Base
# @return [String] The domain name
attr_accessor :domain

# @return [Boolean] Whether the domain is premium.
attr_accessor :premium

# @return [Float] The price for registration
attr_accessor :registration_price

# @return [Float] The price for renewal
attr_accessor :renewal_price

# @return [Float] The price for transfer
attr_accessor :transfer_price
end

end
end
43 changes: 43 additions & 0 deletions spec/dnsimple/client/registrar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,49 @@
end
end

describe "#get_domain_prices" do
let(:account_id) { 1010 }

before do
stub_request(:get, %r{/v2/#{account_id}/registrar/domains/bingo.pizza/prices$})
.to_return(read_http_fixture("getDomainPrices/success.http"))
end

it "builds the correct request" do
subject.get_domain_prices(account_id, "bingo.pizza")

expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/registrar/domains/bingo.pizza/prices")
.with(headers: { "Accept" => "application/json" })
end

it "returns the prices" do
response = subject.get_domain_prices(account_id, "bingo.pizza")
expect(response).to be_a(Dnsimple::Response)

result = response.data

expect(result).to be_a(Dnsimple::Struct::DomainPrice)
expect(result.domain).to eq("bingo.pizza")
expect(result.premium).to be(true)
expect(result.registration_price).to eq(20.0)
expect(result.renewal_price).to eq(20.0)
expect(result.transfer_price).to eq(20.0)
end

context "when the TLD is not supported" do
before do
stub_request(:get, %r{/v2/#{account_id}/registrar/domains/bingo.pineapple/prices$})
.to_return(read_http_fixture("getDomainPrices/failure.http"))
end

it "raises error" do
expect {
subject.get_domain_prices(account_id, "bingo.pineapple")
}.to raise_error(Dnsimple::RequestError, "TLD .PINEAPPLE is not supported")
end
end
end

describe "#register_domain" do
let(:account_id) { 1010 }
let(:attributes) { { registrant_id: "10" } }
Expand Down
36 changes: 18 additions & 18 deletions spec/fixtures.http/getDomainPrices/failure.http
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
HTTP/1.1 400 Bad Request
Server: nginx
Date: Mon, 08 Mar 2021 14:35:58 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
X-RateLimit-Limit: 2400
X-RateLimit-Remaining: 2396
X-RateLimit-Reset: 1615217645
Cache-Control: no-cache
X-Request-Id: e414a674-63bb-4e54-b714-db5b516bb190
X-Runtime: 0.009579
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
Content-Security-Policy: frame-ancestors 'none'
HTTP/1.1 400 Bad Request
Server: nginx
Date: Mon, 08 Mar 2021 14:35:58 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
X-RateLimit-Limit: 2400
X-RateLimit-Remaining: 2396
X-RateLimit-Reset: 1615217645
Cache-Control: no-cache
X-Request-Id: e414a674-63bb-4e54-b714-db5b516bb190
X-Runtime: 0.009579
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
Content-Security-Policy: frame-ancestors 'none'

{"message":"TLD .PINEAPPLE is not supported"}
42 changes: 21 additions & 21 deletions spec/fixtures.http/getDomainPrices/success.http
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 08 Mar 2021 14:35:26 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
X-RateLimit-Limit: 2400
X-RateLimit-Remaining: 2397
X-RateLimit-Reset: 1615217645
ETag: W/"2104f27f2877f429295359cfc409f9f7"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: b0d9e000-58a6-4254-af43-8735d26e12d9
X-Runtime: 9.129301
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
Content-Security-Policy: frame-ancestors 'none'
Strict-Transport-Security: max-age=31536000
{"data":{"domain":"bingo.pizza","premium":true,"registration_price":20.0,"renewal_price":20.0,"transfer_price":20.0}}
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 08 Mar 2021 14:35:26 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
X-RateLimit-Limit: 2400
X-RateLimit-Remaining: 2397
X-RateLimit-Reset: 1615217645
ETag: W/"2104f27f2877f429295359cfc409f9f7"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: b0d9e000-58a6-4254-af43-8735d26e12d9
X-Runtime: 9.129301
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
Content-Security-Policy: frame-ancestors 'none'
Strict-Transport-Security: max-age=31536000

{"data":{"domain":"bingo.pizza","premium":true,"registration_price":20.0,"renewal_price":20.0,"transfer_price":20.0}}