Skip to content

Commit

Permalink
Added support for listPushes
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Aug 29, 2016
1 parent 77021c8 commit 274a351
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/dnsimple/client/clients.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,12 @@ class ContactsService < ClientService

require_relative 'domains'
require_relative 'domains_email_forwards'
require_relative 'domains_pushes'

class DomainsService < ClientService
include Client::Domains
include Client::DomainsEmailForwards
include Client::DomainsPushes
end


Expand Down
32 changes: 32 additions & 0 deletions lib/dnsimple/client/domains_pushes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Dnsimple
class Client
module DomainsPushes

# Lists the pushes for the domain.
#
# @see https://developer.dnsimple.com/v2/domains/pushes/#list
#
# @example List domain pushes in the first page
# client.domains.pushes(2020, "example.com")
#
# @example List domain pushes, provide a specific page
# client.domains.pushes(2020, "example.com", page: 2)
#
# @param [Fixnum] account_id the account ID
# @param [#to_s] domain_id The domain ID or domain name
# @param [Hash] options
# @option options [Integer] :page current page (pagination)
# @option options [Integer] :per_page number of entries to return (pagination)
# @return [Dnsimple::PaginatedResponse<Dnsimple::Struct::DomainPush>]
#
# @raise [Dnsimple::NotFoundError]
# @raise [Dnsimple::RequestError]
def pushes(account_id, domain_id, options = {})
response = client.get(Client.versioned("/%s/domains/%s/pushes" % [account_id, domain_id]), Options::ListOptions.new(options))

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

end
end
1 change: 1 addition & 0 deletions lib/dnsimple/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def initialize(attributes = {})
require_relative 'struct/certificate_bundle'
require_relative 'struct/domain'
require_relative 'struct/domain_check'
require_relative 'struct/domain_push'
require_relative 'struct/email_forward'
require_relative 'struct/extended_attribute'
require_relative 'struct/oauth_token'
Expand Down
28 changes: 28 additions & 0 deletions lib/dnsimple/struct/domain_push.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Dnsimple
module Struct

class DomainPush < Base
# @return [Fixnum] The domain push ID in DNSimple.
attr_accessor :id

# @return [Fixnum] The associated domain ID.
attr_accessor :domain_id

# @return [Fixnum] The associated contact ID.
attr_accessor :contact_id

# @return [Fixnum] The associated account ID.
attr_accessor :account_id

# @return [String] When the domain push was created in DNSimple.
attr_accessor :created_at

# @return [String] When the domain push was last updated in DNSimple.
attr_accessor :updated_at

# @return [String] When the domain push was accepted in DNSimple.
attr_accessor :accepted_at
end

end
end
59 changes: 59 additions & 0 deletions spec/dnsimple/client/domains_pushes_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require 'spec_helper'

describe Dnsimple::Client, ".domains" do

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

describe "#pushes" do
let(:account_id) { 2020 }
let(:domain_id) { "example.com" }

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

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

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

it "supports pagination" do
subject.pushes(account_id, domain_id, page: 2)

expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/pushes?page=2")
end

it "supports extra request options" do
subject.pushes(account_id, domain_id, query: { foo: "bar" })

expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/pushes?foo=bar")
end

it "returns a list of domain pushes" do
response = subject.pushes(account_id, domain_id)

expect(response).to be_a(Dnsimple::PaginatedResponse)
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::DomainPush)
expect(result.id).to be_a(Fixnum)
end
end

it "exposes the pagination information" do
response = subject.pushes(account_id, domain_id)

expect(response.respond_to?(:page)).to be_truthy
expect(response.page).to eq(1)
expect(response.per_page).to be_a(Fixnum)
expect(response.total_entries).to be_a(Fixnum)
expect(response.total_pages).to be_a(Fixnum)
end
end

end
21 changes: 21 additions & 0 deletions spec/fixtures.http/listPushes/success.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 11 Aug 2016 10:19:54 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
X-RateLimit-Limit: 2400
X-RateLimit-Remaining: 2393
X-RateLimit-Reset: 1470913058
ETag: W/"fd29a0a43fb53ae2e5186232361fa4b9"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 12611d3b-aee5-49e3-a8bf-bd7899b1e797
X-Runtime: 0.045678
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},{"id":2,"domain_id":101,"contact_id":null,"account_id":2020,"created_at":"2016-08-11T10:18:48.351Z","updated_at":"2016-08-11T10:18:48.351Z","accepted_at":null}],"pagination":{"current_page":1,"per_page":30,"total_entries":2,"total_pages":1}}

0 comments on commit 274a351

Please sign in to comment.