-
Notifications
You must be signed in to change notification settings - Fork 41
Add support for batch change zone records endpoint #477
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ca244b6
WIP
lokst 851c665
fix serialization
lokst c254c4d
Merge branch 'main' of github.com:dnsimple/dnsimple-python into batch…
lokst 725a6ea
Add unit tests
lokst 3ddbbe1
Add new line
lokst fb5e6fa
simplify
lokst dd822bd
reuse ZoneRecordInput struct, and add documentation
lokst 3f048c1
Remove unneeded tests
lokst 8f75727
clean up
lokst 0dc90eb
Clean up comments
lokst 8e97c25
Restore BatchChangeZoneRecordsCreateInput for consistency, but as an …
lokst bd9fd2e
Update tests/struct/batch_change_zone_records_test.py
lokst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import json | ||
from dataclasses import dataclass | ||
|
||
import omitempty | ||
|
||
from dnsimple.struct import Struct | ||
from dnsimple.struct.zone_record import ZoneRecord, ZoneRecordInput | ||
|
||
BatchChangeZoneRecordsCreateInput = ZoneRecordInput | ||
|
||
|
||
@dataclass | ||
class BatchChangeZoneRecordsUpdateInput(dict): | ||
"""Represents a zone record update input for a batch operation""" | ||
|
||
def __init__(self, id, name=None, content=None, ttl=None, priority=None, regions=None): | ||
dict.__init__(self, id=id, name=name, content=content, ttl=ttl, priority=priority, regions=regions) | ||
|
||
def to_json(self): | ||
omitted = omitempty(self) | ||
|
||
if self['name'] == '': | ||
omitted['name'] = '' | ||
|
||
return json.dumps(omitted) | ||
|
||
|
||
@dataclass | ||
class BatchChangeZoneRecordsDeleteInput(dict): | ||
"""Represents a zone record deletion input for a batch operation""" | ||
|
||
def __init__(self, id): | ||
dict.__init__(self, id=id) | ||
|
||
|
||
@dataclass | ||
class BatchChangeZoneRecordsInput(dict): | ||
"""Represents the data to send to the DNSimple API to make a batch change on the records of a zone | ||
|
||
All parameters are optional - you can perform creates only, updates only, deletes only, | ||
or any combination of the three operations. | ||
|
||
:param creates: List[BatchChangeZoneRecordsCreateInput] - Records to create (optional) | ||
:param updates: List[BatchChangeZoneRecordsUpdateInput] - Records to update (optional) | ||
:param deletes: List[BatchChangeZoneRecordsDeleteInput] - Records to delete (optional) | ||
""" | ||
|
||
def __init__(self, creates=None, updates=None, deletes=None): | ||
data = {} | ||
if creates is not None: | ||
data['creates'] = creates | ||
if updates is not None: | ||
data['updates'] = updates | ||
if deletes is not None: | ||
data['deletes'] = deletes | ||
dict.__init__(self, **data) | ||
|
||
def to_json(self): | ||
result = {} | ||
|
||
if 'creates' in self and self['creates'] is not None: | ||
result['creates'] = [json.loads(item.to_json()) for item in self['creates']] | ||
|
||
if 'updates' in self and self['updates'] is not None: | ||
result['updates'] = [json.loads(item.to_json()) for item in self['updates']] | ||
|
||
if 'deletes' in self and self['deletes'] is not None: | ||
result['deletes'] = [omitempty(item) for item in self['deletes']] | ||
|
||
return json.dumps(result) | ||
|
||
|
||
@dataclass | ||
class BatchChangeZoneRecordsDeleteResponse(Struct): | ||
"""Represents a deleted zone record in the batch change response""" | ||
id = None | ||
"""The record ID that was deleted""" | ||
|
||
def __init__(self, data): | ||
super().__init__(data) | ||
|
||
|
||
@dataclass | ||
class BatchChangeZoneRecordsResponse(Struct): | ||
"""Represents the response from batch changing zone records""" | ||
creates = None | ||
"""List of created zone records""" | ||
updates = None | ||
"""List of updated zone records""" | ||
deletes = None | ||
"""List of deleted zone record IDs""" | ||
|
||
def __init__(self, data): | ||
super().__init__(data) | ||
if 'creates' in data and data['creates'] is not None: | ||
self.creates = [ZoneRecord(item) for item in data['creates']] | ||
if 'updates' in data and data['updates'] is not None: | ||
self.updates = [ZoneRecord(item) for item in data['updates']] | ||
if 'deletes' in data and data['deletes'] is not None: | ||
self.deletes = [BatchChangeZoneRecordsDeleteResponse(item) for item in data['deletes']] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.