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

Add Document.move_to_draft + Document.update #43

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions lib/panda_doc/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def get(path, data = {})
connection.get(normalized_path(path), **data)
end

def patch(path, data = {})
connection.patch(normalized_path(path), **data)
end

private

def normalized_path(path)
Expand Down
8 changes: 8 additions & 0 deletions lib/panda_doc/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def create(data)
respond(ApiClient.request(:post, "/documents", **data))
end

def update(uuid, **data)
respond(ApiClient.request(:patch, "/documents/#{uuid}", **data))
opti marked this conversation as resolved.
Show resolved Hide resolved
end

def send(uuid, **data)
respond(ApiClient.request(:post, "/documents/#{uuid}/send", **data))
end
Expand All @@ -20,6 +24,10 @@ def details(uuid)
respond(ApiClient.request(:get, "/documents/#{uuid}/details"))
end

def move_to_draft(uuid)
respond(ApiClient.request(:post, "/documents/#{uuid}/draft"))
end

def session(uuid, **data)
respond(
ApiClient.request(:post, "/documents/#{uuid}/session", **data),
Expand Down
1 change: 1 addition & 0 deletions lib/panda_doc/objects/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Document < Base

attribute? :tokens, Types::Array.of(Objects::Token)
attribute? :fields, Types::Array.of(Objects::Field)
attribute? :metadata, Types::Hash

alias_method :created_at, :date_created
alias_method :updated_at, :date_modified
Expand Down
46 changes: 46 additions & 0 deletions spec/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,50 @@
it_behaves_like "a document object interface"
end
end

describe ".move_to_draft" do
subject { described_class.move_to_draft("uuid") }

before do
allow(PandaDoc::ApiClient).to receive(:request)
.with(:post, "/documents/uuid/draft")
.and_return(response)
end

context "with failed response" do
let(:response) { failed_response }

it_behaves_like "a failure result"
end

context "with successful response" do
let(:response) { successful_response }
let(:body) { document_body }

it_behaves_like "a document object interface"
end
end

describe ".update" do
subject { described_class.update("uuid", metadata: { hello: "world" })}

before do
allow(PandaDoc::ApiClient).to receive(:request)
.with(:patch, "/documents/uuid", metadata: { hello: "world" })
.and_return(response)
end

context "with failed response" do
let(:response) { failed_response }

it_behaves_like "a failure result"
end

context "with successful response" do
let(:response) { successful_response }
let(:body) { document_body }

it_behaves_like "a document object interface"
end
andrewvy marked this conversation as resolved.
Show resolved Hide resolved
end
end