diff --git a/lib/dnsimple/client/domains_email_forwards.rb b/lib/dnsimple/client/domains_email_forwards.rb index f7f2ebbf..67048594 100644 --- a/lib/dnsimple/client/domains_email_forwards.rb +++ b/lib/dnsimple/client/domains_email_forwards.rb @@ -24,6 +24,27 @@ def email_forwards(account_id, domain_id, options = {}) Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::EmailForward.new(r) }) end + # Lists ALL the email forwards for the domain. + # + # This method is similar to {#email_forwards}, but instead of returning the results of a specific page + # it iterates all the pages and returns the entire collection. + # + # Please use this method carefully, as fetching the entire collection will increase the number of requests + # you send to the API server and you may eventually risk to hit the throttle limit. + # + # @see https://developer.dnsimple.com/v2/domains/email-forwards/#list + # @see #email_forwards + # + # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard + # @param [#to_s] domain_id the domain id or domain name + # @param [Hash] options the filtering and sorting option + # @return [Dnsimple::CollectionResponse] + # + # @raise [Dnsimple::RequestError] + def all_email_forwards(account_id, domain_id, options = {}) + paginate(:email_forwards, account_id, domain_id, options) + end + # Creates an email forward for the domain. # # @see https://developer.dnsimple.com/v2/domains/email-forwards/#create diff --git a/spec/dnsimple/client/domains_email_forwards_spec.rb b/spec/dnsimple/client/domains_email_forwards_spec.rb index 3657b91d..35954c90 100644 --- a/spec/dnsimple/client/domains_email_forwards_spec.rb +++ b/spec/dnsimple/client/domains_email_forwards_spec.rb @@ -45,6 +45,37 @@ expect(result.id).to be_a(Fixnum) end end + + it "exposes the pagination information" do + response = subject.email_forwards(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 + + context "when the domain does not exist" do + it "raises NotFoundError" do + stub_request(:get, %r[/v2]) + .to_return(read_http_fixture("notfound-domain.http")) + + expect { + subject.email_forwards(account_id, domain_id) + }.to raise_error(Dnsimple::NotFoundError) + end + end + end + + describe "#all_email_forwards" do + let(:account_id) { 1010 } + let(:domain_id) { "example.com" } + + it "delegates to client.paginate" do + expect(subject).to receive(:paginate).with(:email_forwards, account_id, domain_id, { foo: "bar" }) + subject.all_email_forwards(account_id, domain_id, { foo: "bar" }) + end end describe "#create_email_forward" do