Skip to content

Commit 8bcd994

Browse files
authored
Add support for Data Removal API (#147)
## What Adds support for the new [Data Removal API](https://postmarkapp.com/developer/api/data-removals-api). ## How Have some thoughts about the DRY-ness of these tests, but have gone for following local conventions for now!
1 parent addd182 commit 8bcd994

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

lib/postmark/account_api_client.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ def push_templates(attributes = {})
145145
batch
146146
end
147147

148-
end
148+
def get_data_removal_status(id)
149+
format_response(http_client.get("data-removals/#{id}"))
150+
end
149151

152+
def request_data_removal(attributes = {})
153+
data = serialize(HashHelper.to_postmark(attributes))
154+
format_response(http_client.post('data-removals', data))
155+
end
156+
end
150157
end

spec/integration/account_api_client_spec.rb

+16
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,20 @@
105105
# delete
106106
expect { subject.delete_server(new_server[:id]) }.not_to raise_error
107107
end
108+
109+
it 'manages data removals' do
110+
# create
111+
data_removal_status = subject.request_data_removal(
112+
'requested_by' => 'sender@postmarkapp.com',
113+
'requested_for' => 'test@example.com',
114+
'notify_when_completed' => false
115+
)
116+
117+
expect(data_removal_status[:status]).to eq('Pending')
118+
119+
# get
120+
fetched_data_removal_status = subject.get_data_removal_status(data_removal_status[:id])
121+
122+
expect(fetched_data_removal_status[:id]).to eq(data_removal_status[:id])
123+
end
108124
end

spec/unit/postmark/account_api_client_spec.rb

+41
Original file line numberDiff line numberDiff line change
@@ -728,5 +728,46 @@
728728
end
729729
end
730730

731+
describe '#get_data_removal_status' do
732+
let(:response) {
733+
{
734+
"ID" => 42,
735+
"Status" => "Done"
736+
}
737+
}
738+
739+
it 'performs a GET request to /data-removals/:id endpoint' do
740+
allow(subject.http_client).to receive(:get).
741+
with('data-removals/42').and_return(response)
742+
subject.get_data_removal_status(42)
743+
end
744+
745+
it 'formats the keys of returned response' do
746+
allow(subject.http_client).to receive(:get).and_return(response)
747+
keys = subject.get_data_removal_status(42).keys
748+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
749+
end
750+
end
751+
752+
describe '#request_data_removal' do
753+
let(:response) {
754+
{
755+
"ID" => 42,
756+
"Status" => "Done"
757+
}
758+
}
759+
760+
it 'performs a POST request to /data-removals endpoint' do
761+
allow(subject.http_client).to receive(:post).
762+
with('data-removals', an_instance_of(String)).and_return(response)
763+
subject.request_data_removal(:foo => 'bar')
764+
end
765+
766+
it 'formats the keys of returned response' do
767+
allow(subject.http_client).to receive(:post).and_return(response)
768+
keys = subject.request_data_removal(:foo => 'bar').keys
769+
expect(keys.all? { |k| k.is_a?(Symbol) }).to be true
770+
end
771+
end
731772
end
732773
end

0 commit comments

Comments
 (0)