1313# limitations under the License.
1414
1515"""Define API ManagedZones."""
16+
1617import six
1718
1819from google .cloud ._helpers import _rfc3339_to_datetime
1920from google .cloud .exceptions import NotFound
2021from google .cloud .dns .changes import Changes
2122from google .cloud .dns .resource_record_set import ResourceRecordSet
23+ from google .cloud .iterator import Iterator
2224
2325
2426class ManagedZone (object ):
@@ -330,29 +332,13 @@ def list_resource_record_sets(self, max_results=None, page_token=None,
330332 :param client: the client to use. If not passed, falls back to the
331333 ``client`` stored on the current zone.
332334
333- :rtype: tuple, (list, str)
334- :returns: list of
335- :class:`~.resource_record_set.ResourceRecordSet`,
336- plus a "next page token" string: if the token is not None,
337- indicates that more zones can be retrieved with another
338- call (pass that value as ``page_token``).
335+ :rtype: :class:`_ResourceRecordSetIterator`
336+ :returns: An iterator of
337+ :class:`~.resource_record_set.ResourceRecordSet` objects.
339338 """
340- params = {}
341-
342- if max_results is not None :
343- params ['maxResults' ] = max_results
344-
345- if page_token is not None :
346- params ['pageToken' ] = page_token
347-
348- path = '/projects/%s/managedZones/%s/rrsets' % (
349- self .project , self .name )
350- client = self ._require_client (client )
351- conn = client .connection
352- resp = conn .api_request (method = 'GET' , path = path , query_params = params )
353- zones = [ResourceRecordSet .from_api_repr (resource , self )
354- for resource in resp ['rrsets' ]]
355- return zones , resp .get ('nextPageToken' )
339+ return _ResourceRecordSetIterator (
340+ self , page_token = page_token ,
341+ max_results = max_results , client = client )
356342
357343 def list_changes (self , max_results = None , page_token = None , client = None ):
358344 """List change sets for this zone.
@@ -373,26 +359,98 @@ def list_changes(self, max_results=None, page_token=None, client=None):
373359 :param client: the client to use. If not passed, falls back to the
374360 ``client`` stored on the current zone.
375361
376- :rtype: tuple, (list, str)
377- :returns: list of
378- :class:`~.resource_record_set.ResourceRecordSet`,
379- plus a "next page token" string: if the token is not None,
380- indicates that more zones can be retrieved with another
381- call (pass that value as ``page_token``).
362+ :rtype: :class:`_ChangesIterator`
363+ :returns: An iterator of :class:`~.changes.Changes` objects.
382364 """
383- params = {}
365+ return _ChangesIterator (self , page_token = page_token ,
366+ max_results = max_results , client = client )
367+
368+
369+ class _ResourceRecordSetIterator (Iterator ):
370+ """An iterator listing all resource record sets.
371+
372+ :type zone: :class:`ManagedZone`
373+ :param zone: The managed zone from which to list resource record sets.
374+
375+ :type page_token: str
376+ :param page_token: (Optional) A token identifying a page in a result set.
384377
385- if max_results is not None :
386- params [ 'maxResults' ] = max_results
378+ :type max_results: int
379+ :param max_results: (Optional) The maximum number of results to fetch.
387380
388- if page_token is not None :
389- params ['pageToken' ] = page_token
381+ :type extra_params: dict or ``NoneType``
382+ :param extra_params: Extra query string parameters for the API call.
383+
384+ :type client: :class:`~google.cloud.dns.client.Client`
385+ :param client: (Optional) The client to use for making connections.
386+ Defaults to the zone's client.
387+ """
388+
389+ ITEMS_KEY = 'rrsets'
390+
391+ def __init__ (self , zone , page_token = None , max_results = None ,
392+ extra_params = None , client = None ):
393+ if client is None :
394+ client = zone ._client
395+ self .zone = zone
396+ path = '/projects/%s/managedZones/%s/rrsets' % (
397+ zone .project , zone .name )
398+ super (_ResourceRecordSetIterator , self ).__init__ (
399+ client = client , path = path , page_token = page_token ,
400+ max_results = max_results , extra_params = extra_params )
401+
402+ def _item_to_value (self , resource ):
403+ """Convert a JSON resource record set value to the native object.
404+
405+ :type resource: dict
406+ :param resource: An item to be converted to a resource record set.
390407
408+ :rtype: :class:`~.resource_record_set.ResourceRecordSet`
409+ :returns: The next resource record set in the page.
410+ """
411+ return ResourceRecordSet .from_api_repr (resource , self .zone )
412+
413+
414+ class _ChangesIterator (Iterator ):
415+ """An iterator listing all changes.
416+
417+ :type zone: :class:`ManagedZone`
418+ :param zone: The managed zone from which to list changes.
419+
420+ :type page_token: str
421+ :param page_token: (Optional) A token identifying a page in a result set.
422+
423+ :type max_results: int
424+ :param max_results: (Optional) The maximum number of results to fetch.
425+
426+ :type extra_params: dict or ``NoneType``
427+ :param extra_params: Extra query string parameters for the API call.
428+
429+ :type client: :class:`~google.cloud.dns.client.Client`
430+ :param client: (Optional) The client to use for making connections.
431+ Defaults to the zone's client.
432+ """
433+
434+ ITEMS_KEY = 'changes'
435+
436+ def __init__ (self , zone , page_token = None , max_results = None ,
437+ extra_params = None , client = None ):
438+ if client is None :
439+ client = zone ._client
440+ self .zone = zone
391441 path = '/projects/%s/managedZones/%s/changes' % (
392- self .project , self .name )
393- client = self ._require_client (client )
394- conn = client .connection
395- resp = conn .api_request (method = 'GET' , path = path , query_params = params )
396- zones = [Changes .from_api_repr (resource , self )
397- for resource in resp ['changes' ]]
398- return zones , resp .get ('nextPageToken' )
442+ zone .project , zone .name )
443+ super (_ChangesIterator , self ).__init__ (
444+ client = client , path = path , page_token = page_token ,
445+ max_results = max_results , extra_params = extra_params )
446+
447+ def _item_to_value (self , resource ):
448+ """Convert a JSON "changes" value to the native object.
449+
450+ :type resource: dict
451+ :param resource: An item to be converted to a "changes".
452+
453+ :rtype: :class:`.Changes`
454+ :returns: The next "changes" in the page.
455+ """
456+ return Changes .from_api_repr (resource , self .zone )
0 commit comments