Permalink
Browse files

Adding DELETE to BaseTransport. Also changed some method arg names.

  • Loading branch information...
1 parent 9d0f7c1 commit be23ffc0defe517862c20540d86e6978411303c5 @gtaylor committed Oct 30, 2012
Showing with 66 additions and 13 deletions.
  1. +6 −5 route53/connection.py
  2. +3 −1 route53/hosted_zone.py
  3. +57 −7 route53/transport.py
View
@@ -22,20 +22,21 @@ def __init__(self, aws_access_key_id, aws_secret_access_key):
self.aws_secret_access_key = aws_secret_access_key
self.transport = RequestsTransport(self)
- def _send_request(self, path, params, method):
+ def _send_request(self, path, data, method):
"""
Uses the HTTP transport to query the Route53 API. Runs the response
through lxml's parser, before we hand it off for further picking
apart by our call-specific parsers.
:param str path: The RESTful path to tack on to the :py:attr:`endpoint`.
- :param dict params: A dict of GET or POST params.
+ :param data: The params to send along with the request.
+ :type data: Either a dict or bytes, depending on the request type.
:param str method: One of 'GET', 'POST', or 'DELETE'.
:rtype: lxml.etree._Element
:returns: An lxml Element root.
"""
- response_body = self.transport.send_request(path, params, method)
+ response_body = self.transport.send_request(path, data, method)
root = etree.fromstring(response_body)
print(prettyprint_xml(root))
return root
@@ -122,7 +123,7 @@ def create_hosted_zone(self, name, caller_reference=None, comment=None):
root = self._send_request(
path='hostedzone',
- params=body,
+ data=body,
method='POST',
)
@@ -142,7 +143,7 @@ def get_hosted_zone_by_id(self, id):
root = self._send_request(
path='hostedzone/%s' % id,
- params={},
+ data={},
method='GET',
)
View
@@ -27,6 +27,8 @@ def __init__(self, connection, id, name, caller_reference,
self.caller_reference = caller_reference
self.resource_record_set_count = int(resource_record_set_count)
self.comment = comment
+
+ # Don't access this directly, we use it for lazy loading.
self._nameservers = []
@property
@@ -35,4 +37,4 @@ def nameservers(self):
return self._nameservers
def __str__(self):
- return '<HostedZone: %s>' % self.name
+ return '<HostedZone: %s -- %s>' % (self.name, self.id)
View
@@ -87,14 +87,15 @@ def get_request_headers(self):
'Host': 'route53.amazonaws.com',
}
- def send_request(self, path, params, method):
+ def send_request(self, path, data, method):
"""
All outbound requests go through this method. It defers to the
transport's various HTTP method-specific methods.
:param str path: The path to tack on to the endpoint URL for
the query.
- :param dict params: The params to send along with the request.
+ :param data: The params to send along with the request.
+ :type data: Either a dict or bytes, depending on the request type.
:param str method: One of 'GET', 'POST', or 'DELETE'.
:rtype: str
@@ -104,9 +105,11 @@ def send_request(self, path, params, method):
headers = self.get_request_headers()
if method == 'GET':
- return self._send_get_request(path, params, headers)
+ return self._send_get_request(path, data, headers)
elif method == 'POST':
- return self._send_post_request(path, params, headers)
+ return self._send_post_request(path, data, headers)
+ elif method == 'DELETE':
+ return self._send_post_request(path, headers)
else:
raise Route53Error("Invalid request method: %s" % method)
@@ -116,18 +119,42 @@ def _send_get_request(self, path, params, headers):
Sends the GET request to the Route53 endpoint.
+ :param str path: The path to tack on to the endpoint URL for
+ the query.
+ :param dict params: Key/value pairs to send.
+ :param dict headers: A dict of headers to send with the request.
:rtype: str
:returns: The body of the response.
"""
raise NotImplementedError
- def _send_post_request(self, path, params, headers):
+ def _send_post_request(self, path, data, headers):
"""
Transport sub-classes need to override this.
Sends the POST request to the Route53 endpoint.
+ :param str path: The path to tack on to the endpoint URL for
+ the query.
+ :param data: Either a dict, or bytes.
+ :type data: dict or bytes
+ :param dict headers: A dict of headers to send with the request.
+ :rtype: str
+ :returns: The body of the response.
+ """
+
+ raise NotImplementedError
+
+ def _send_delete_request(self, path, headers):
+ """
+ Transport sub-classes need to override this.
+
+ Sends the DELETE request to the Route53 endpoint.
+
+ :param str path: The path to tack on to the endpoint URL for
+ the query.
+ :param dict headers: A dict of headers to send with the request.
:rtype: str
:returns: The body of the response.
"""
@@ -147,20 +174,43 @@ def _send_get_request(self, path, params, headers):
"""
Sends the GET request to the Route53 endpoint.
+ :param str path: The path to tack on to the endpoint URL for
+ the query.
+ :param dict params: Key/value pairs to send.
+ :param dict headers: A dict of headers to send with the request.
:rtype: str
:returns: The body of the response.
"""
r = requests.get(self.endpoint + path, params=params, headers=headers)
return r.text
- def _send_post_request(self, path, params, headers):
+ def _send_post_request(self, path, data, headers):
"""
Sends the POST request to the Route53 endpoint.
+ :param str path: The path to tack on to the endpoint URL for
+ the query.
+ :param data: Either a dict, or bytes.
+ :type data: dict or bytes
+ :param dict headers: A dict of headers to send with the request.
+ :rtype: str
+ :returns: The body of the response.
+ """
+
+ r = requests.post(self.endpoint + path, data=data, headers=headers)
+ return r.text
+
+ def _send_delete_request(self, path, headers):
+ """
+ Sends the DELETE request to the Route53 endpoint.
+
+ :param str path: The path to tack on to the endpoint URL for
+ the query.
+ :param dict headers: A dict of headers to send with the request.
:rtype: str
:returns: The body of the response.
"""
- r = requests.post(self.endpoint + path, data=params, headers=headers)
+ r = requests.delete(self.endpoint + path, headers=headers)
return r.text

0 comments on commit be23ffc

Please sign in to comment.