From 5f444b6f0c2cb94475cf9349476125521d0e638e Mon Sep 17 00:00:00 2001 From: John Lannon Date: Fri, 18 Jul 2025 14:33:32 -0500 Subject: [PATCH 1/3] feature: add Document Section list and delete This adds API support for listing and deleting document sections --- README.md | 32 +++++++++++ lib/panda_doc/api_client.rb | 4 ++ lib/panda_doc/document_section.rb | 14 +++++ .../objects/document_sections_list.rb | 12 ++++ spec/document_section_spec.rb | 55 +++++++++++++++++++ 5 files changed, 117 insertions(+) create mode 100644 lib/panda_doc/objects/document_sections_list.rb diff --git a/README.md b/README.md index 61e5ff8..1718d69 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,38 @@ file = File.open("document.pdf", "w") do |f| end ``` +#### Listing document sections ([API](https://developers.pandadoc.com/reference#list-document-sections)) + +```ruby +sections = PandaDoc::DocumentSection.list("document_uuid") + +sections.results.each do |section| + puts section.uuid + puts section.name + puts section.status +end +``` + +#### Creating a document section ([API](https://developers.pandadoc.com/reference#create-document-section)) + +```ruby +section = PandaDoc::DocumentSection.create( + "document_uuid", + name: "Section Name", + file: file +) + +section.uuid # => "section_uuid" +section.name # => "Section Name" +section.status # => "uploaded" +``` + +#### Deleting a document section ([API](https://developers.pandadoc.com/reference#delete-document-section)) + +```ruby +PandaDoc::DocumentSection.delete("document_uuid", "section_uuid") +``` + #### Error handling If an error occurs during an API request it will be wrapped into a plain ruby diff --git a/lib/panda_doc/api_client.rb b/lib/panda_doc/api_client.rb index 5780ce2..ef476a2 100644 --- a/lib/panda_doc/api_client.rb +++ b/lib/panda_doc/api_client.rb @@ -54,6 +54,10 @@ def patch(path, data = {}) connection.patch(normalized_path(path), **data) end + def delete(path, data = {}) + connection.delete(normalized_path(path), **data) + end + private def normalized_path(path) diff --git a/lib/panda_doc/document_section.rb b/lib/panda_doc/document_section.rb index 46ad2ae..1c2fbff 100644 --- a/lib/panda_doc/document_section.rb +++ b/lib/panda_doc/document_section.rb @@ -4,6 +4,13 @@ module PandaDoc module DocumentSection extend self + def list(document_uuid, **options) + respond( + ApiClient.request(:get, "/documents/#{document_uuid}/sections", **options), + type: :document_sections_list + ) + end + def create(document_uuid, **data) respond( ApiClient.request(:post, "/documents/#{document_uuid}/sections/uploads", **data), @@ -11,6 +18,13 @@ def create(document_uuid, **data) ) end + def delete(document_uuid, section_uuid) + respond( + ApiClient.request(:delete, "/documents/#{document_uuid}/sections/#{section_uuid}"), + type: :empty + ) + end + private def respond(response, type: :document) diff --git a/lib/panda_doc/objects/document_sections_list.rb b/lib/panda_doc/objects/document_sections_list.rb new file mode 100644 index 0000000..3171fdf --- /dev/null +++ b/lib/panda_doc/objects/document_sections_list.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module PandaDoc + module Objects + # Represents a list of document sections + class DocumentSectionsList < Base + attribute :results, Types::Array.of(Objects::DocumentSection).default([].freeze) + + alias_method :document_sections, :results + end + end +end \ No newline at end of file diff --git a/spec/document_section_spec.rb b/spec/document_section_spec.rb index 03845e5..3c9926d 100644 --- a/spec/document_section_spec.rb +++ b/spec/document_section_spec.rb @@ -51,6 +51,35 @@ } end + describe ".list" do + subject { described_class.list(document_uuid) } + + before do + allow(PandaDoc::ApiClient).to receive(:request) + .with(:get, "/documents/#{document_uuid}/sections") + .and_return(response) + end + + context "with failed response" do + let(:response) { failed_response } + + it_behaves_like "a document section failure result" + end + + context "with successful response" do + let(:response) { successful_response } + let(:body) { { "results" => [document_body] } } + + it "returns an array of document sections" do + expect(subject.results).to all(be_a(PandaDoc::Objects::DocumentSection)) + end + + it "contains document sections" do + expect(subject.document_sections.first).to be_a(PandaDoc::Objects::DocumentSection) + end + end + end + describe ".create" do subject { described_class.create(document_uuid, name: "Foo") } @@ -73,4 +102,30 @@ it_behaves_like "a document section object interface" end end + + describe ".delete" do + let(:section_uuid) { "SECTION_UUID" } + subject { described_class.delete(document_uuid, section_uuid) } + + before do + allow(PandaDoc::ApiClient).to receive(:request) + .with(:delete, "/documents/#{document_uuid}/sections/#{section_uuid}") + .and_return(response) + end + + context "with failed response" do + let(:response) { failed_response } + + it_behaves_like "a document section failure result" + end + + context "with successful response" do + let(:response) { successful_response } + let(:body) { {} } + + it "returns a success result" do + expect(subject).to be_a(PandaDoc::SuccessResult) + end + end + end end From be3b9def8627777a8efcebcd82847fdb9948db77 Mon Sep 17 00:00:00 2001 From: John Lannon Date: Fri, 18 Jul 2025 14:36:01 -0500 Subject: [PATCH 2/3] fix: readme links --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1718d69..3d8fafe 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ file = File.open("document.pdf", "w") do |f| end ``` -#### Listing document sections ([API](https://developers.pandadoc.com/reference#list-document-sections)) +#### Listing document sections ([API](https://developers.pandadoc.com/reference/document-sections-info)) ```ruby sections = PandaDoc::DocumentSection.list("document_uuid") @@ -186,7 +186,7 @@ sections.results.each do |section| end ``` -#### Creating a document section ([API](https://developers.pandadoc.com/reference#create-document-section)) +#### Creating a document section ([API](https://developers.pandadoc.com/reference/create-document-section)) ```ruby section = PandaDoc::DocumentSection.create( @@ -200,7 +200,7 @@ section.name # => "Section Name" section.status # => "uploaded" ``` -#### Deleting a document section ([API](https://developers.pandadoc.com/reference#delete-document-section)) +#### Deleting a document section ([API](https://developers.pandadoc.com/reference/delete-section)) ```ruby PandaDoc::DocumentSection.delete("document_uuid", "section_uuid") From 7c93c1e13272338362efa5b708d99df565b59efd Mon Sep 17 00:00:00 2001 From: Igor Pstyga Date: Sat, 19 Jul 2025 23:23:19 -0700 Subject: [PATCH 3/3] Update lib/panda_doc/objects/document_sections_list.rb --- lib/panda_doc/objects/document_sections_list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/panda_doc/objects/document_sections_list.rb b/lib/panda_doc/objects/document_sections_list.rb index 3171fdf..abb2392 100644 --- a/lib/panda_doc/objects/document_sections_list.rb +++ b/lib/panda_doc/objects/document_sections_list.rb @@ -9,4 +9,4 @@ class DocumentSectionsList < Base alias_method :document_sections, :results end end -end \ No newline at end of file +end