@@ -826,6 +826,8 @@ def get_reports_snapshot(
826
826
* ,
827
827
date_from : int = None ,
828
828
date_to : int = None ,
829
+ limit : int = None ,
830
+ start : str = None ,
829
831
** kwargs ,
830
832
) -> DetailedResponse :
831
833
"""
@@ -842,6 +844,10 @@ def get_reports_snapshot(
842
844
billing report snapshot is requested.
843
845
:param int date_to: (optional) Timestamp in milliseconds for which billing
844
846
report snapshot is requested.
847
+ :param int limit: (optional) Number of usage records returned. The default
848
+ value is 30. Maximum value is 200.
849
+ :param str start: (optional) The offset from which the records must be
850
+ fetched. Offset information is included in the response.
845
851
:param dict headers: A `dict` containing the request headers
846
852
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
847
853
:rtype: DetailedResponse with `dict` result representing a `SnapshotList` object
@@ -864,6 +870,8 @@ def get_reports_snapshot(
864
870
'month' : month ,
865
871
'date_from' : date_from ,
866
872
'date_to' : date_to ,
873
+ '_limit' : limit ,
874
+ '_start' : start ,
867
875
}
868
876
869
877
if 'headers' in kwargs :
@@ -3151,26 +3159,32 @@ class SnapshotListNext:
3151
3159
Reference to the next page of the search query if any.
3152
3160
3153
3161
:attr str href: (optional)
3162
+ :attr str offset: (optional)
3154
3163
"""
3155
3164
3156
3165
def __init__ (
3157
3166
self ,
3158
3167
* ,
3159
3168
href : str = None ,
3169
+ offset : str = None ,
3160
3170
) -> None :
3161
3171
"""
3162
3172
Initialize a SnapshotListNext object.
3163
3173
3164
3174
:param str href: (optional)
3175
+ :param str offset: (optional)
3165
3176
"""
3166
3177
self .href = href
3178
+ self .offset = offset
3167
3179
3168
3180
@classmethod
3169
3181
def from_dict (cls , _dict : Dict ) -> 'SnapshotListNext' :
3170
3182
"""Initialize a SnapshotListNext object from a json dictionary."""
3171
3183
args = {}
3172
3184
if 'href' in _dict :
3173
3185
args ['href' ] = _dict .get ('href' )
3186
+ if 'offset' in _dict :
3187
+ args ['offset' ] = _dict .get ('offset' )
3174
3188
return cls (** args )
3175
3189
3176
3190
@classmethod
@@ -3183,6 +3197,8 @@ def to_dict(self) -> Dict:
3183
3197
_dict = {}
3184
3198
if hasattr (self , 'href' ) and self .href is not None :
3185
3199
_dict ['href' ] = self .href
3200
+ if hasattr (self , 'offset' ) and self .offset is not None :
3201
+ _dict ['offset' ] = self .offset
3186
3202
return _dict
3187
3203
3188
3204
def _to_dict (self ):
@@ -4696,3 +4712,88 @@ def get_all(self) -> List[dict]:
4696
4712
next_page = self .get_next ()
4697
4713
results .extend (next_page )
4698
4714
return results
4715
+
4716
+
4717
+ class GetReportsSnapshotPager :
4718
+ """
4719
+ GetReportsSnapshotPager can be used to simplify the use of the "get_reports_snapshot" method.
4720
+ """
4721
+
4722
+ def __init__ (
4723
+ self ,
4724
+ * ,
4725
+ client : UsageReportsV4 ,
4726
+ account_id : str ,
4727
+ month : str ,
4728
+ date_from : int = None ,
4729
+ date_to : int = None ,
4730
+ limit : int = None ,
4731
+ ) -> None :
4732
+ """
4733
+ Initialize a GetReportsSnapshotPager object.
4734
+ :param str account_id: Account ID for which the billing report snapshot is
4735
+ requested.
4736
+ :param str month: The month for which billing report snapshot is requested.
4737
+ Format is yyyy-mm.
4738
+ :param int date_from: (optional) Timestamp in milliseconds for which
4739
+ billing report snapshot is requested.
4740
+ :param int date_to: (optional) Timestamp in milliseconds for which billing
4741
+ report snapshot is requested.
4742
+ :param int limit: (optional) Number of usage records returned. The default
4743
+ value is 30. Maximum value is 200.
4744
+ """
4745
+ self ._has_next = True
4746
+ self ._client = client
4747
+ self ._page_context = {'next' : None }
4748
+ self ._account_id = account_id
4749
+ self ._month = month
4750
+ self ._date_from = date_from
4751
+ self ._date_to = date_to
4752
+ self ._limit = limit
4753
+
4754
+ def has_next (self ) -> bool :
4755
+ """
4756
+ Returns true if there are potentially more results to be retrieved.
4757
+ """
4758
+ return self ._has_next
4759
+
4760
+ def get_next (self ) -> List [dict ]:
4761
+ """
4762
+ Returns the next page of results.
4763
+ :return: A List[dict], where each element is a dict that represents an instance of SnapshotListSnapshotsItem.
4764
+ :rtype: List[dict]
4765
+ """
4766
+ if not self .has_next ():
4767
+ raise StopIteration (message = 'No more results available' )
4768
+
4769
+ result = self ._client .get_reports_snapshot (
4770
+ account_id = self ._account_id ,
4771
+ month = self ._month ,
4772
+ date_from = self ._date_from ,
4773
+ date_to = self ._date_to ,
4774
+ limit = self ._limit ,
4775
+ start = self ._page_context .get ('next' ),
4776
+ ).get_result ()
4777
+
4778
+ next = None
4779
+ next_page_link = result .get ('next' )
4780
+ if next_page_link is not None :
4781
+ next = get_query_param (next_page_link .get ('href' ), '_start' )
4782
+ self ._page_context ['next' ] = next
4783
+ if next is None :
4784
+ self ._has_next = False
4785
+
4786
+ return result .get ('snapshots' )
4787
+
4788
+ def get_all (self ) -> List [dict ]:
4789
+ """
4790
+ Returns all results by invoking get_next() repeatedly
4791
+ until all pages of results have been retrieved.
4792
+ :return: A List[dict], where each element is a dict that represents an instance of SnapshotListSnapshotsItem.
4793
+ :rtype: List[dict]
4794
+ """
4795
+ results = []
4796
+ while self .has_next ():
4797
+ next_page = self .get_next ()
4798
+ results .extend (next_page )
4799
+ return results
0 commit comments