本文整理汇总了Python中twilio.rest.resources.util.transform_params函数的典型用法代码示例。如果您正苦于以下问题:Python transform_params函数的具体用法?Python transform_params怎么用?Python transform_params使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了transform_params函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: purchase
def purchase(self, status_callback_url=None, **kwargs):
"""
Attempt to purchase the specified number. The only required parameters
are **either** phone_number or area_code
:returns: Returns a :class:`PhoneNumber` instance on success,
:data:`False` on failure
:raises: A :exc:`TypeError` if neither phone_number or area_code
is specified.
"""
kwargs["StatusCallback"] = kwargs.get("status_callback",
status_callback_url)
if 'phone_number' not in kwargs and 'area_code' not in kwargs:
raise TypeError("phone_number or area_code is required")
number_type = kwargs.pop('type', False)
uri = self.uri
if number_type:
uri = "%s/%s" % (self.uri, TYPES[number_type])
params = transform_params(kwargs)
resp, instance = self.request('POST', uri, data=params)
return self.load_instance(instance)
示例2: iter
def iter(self, **kwargs):
""" Return all instance resources using an iterator
This will fetch a page of resources from the API and yield them in
turn. When the page is exhausted, this will make a request to the API
to retrieve the next page. Hence you may notice a pattern - the library
will loop through 50 objects very quickly, but there will be a delay
retrieving the 51st as the library must make another request to the API
for resources.
Example usage:
.. code-block:: python
for message in client.messages:
print message.sid
"""
params = transform_params(kwargs)
while True:
resp, page = self.request("GET", self.uri, params=params)
if self.key not in page:
raise StopIteration()
for ir in page[self.key]:
yield self.load_instance(ir)
if not page.get('next_page_uri', ''):
raise StopIteration()
o = urlparse(page['next_page_uri'])
params.update(parse_qs(o.query))
示例3: update
def update(self, **kwargs):
"""
Update your Twilio Sandbox
"""
resp, entry = self.request("POST", self.uri,
body=transform_params(kwargs))
return self.create_instance(entry)
示例4: update_instance
def update_instance(self, sid, body):
"""
Update an InstanceResource via a POST
sid: string -- String identifier for the list resource
body: dictionary -- Dict of items to POST
"""
uri = "%s/%s" % (self.uri, sid)
resp, entry = self.request("POST", uri, data=transform_params(body))
return self.load_instance(entry)
示例5: create_instance
def create_instance(self, body):
"""
Create an InstanceResource via a POST to the List Resource
:param dict body: Dictionary of POST data
"""
resp, instance = self.request("POST", self.uri, data=transform_params(body))
if resp.status_code not in (200, 201):
raise TwilioRestException(resp.status_code, self.uri, "Resource not created")
return self.load_instance(instance)
示例6: list
def list(self, type="local", country="US", region=None, postal_code=None,
lata=None, rate_center=None, **kwargs):
"""
Search for phone numbers
"""
kwargs["in_region"] = kwargs.get("in_region", region)
kwargs["in_postal_code"] = kwargs.get("in_postal_code", postal_code)
kwargs["in_lata"] = kwargs.get("in_lata", lata)
kwargs["in_rate_center"] = kwargs.get("in_rate_center", rate_center)
params = transform_params(kwargs)
uri = "%s/%s/%s" % (self.uri, country, self.types[type])
resp, page = self.request("GET", uri, params=params)
return [self.load_instance(i) for i in page[self.key]]
示例7: list
def list(self, type=None, **kwargs):
"""
:param phone_number: Show phone numbers that match this pattern.
:param friendly_name: Show phone numbers with this friendly name
:param type: Filter numbers by type. Available types are
'local', 'mobile', or 'tollfree'
You can specify partial numbers and use '*' as a wildcard.
"""
uri = self.uri
if type:
uri = "%s/%s" % (self.uri, TYPES[type])
params = transform_params(kwargs)
resp, page = self.request("GET", uri, params=params)
return [self.load_instance(i) for i in page[self.key]]
示例8: iter
def iter(self, **kwargs):
"""
Return all instance resources using an iterator
"""
params = transform_params(kwargs)
while True:
resp, page = self.request("GET", self.uri, params=params)
if self.key not in page:
raise StopIteration()
for ir in page[self.key]:
yield self.load_instance(ir)
if not page.get('next_page_uri', ''):
raise StopIteration()
o = urlparse(page['next_page_uri'])
params.update(parse_qs(o.query))
示例9: get_instances
def get_instances(self, params):
"""
Query the list resource for a list of InstanceResources.
Raises a :exc:`~twilio.TwilioRestException` if requesting a page of
results that does not exist.
:param dict params: List of URL parameters to be included in request
:param int page: The page of results to retrieve (most recent at 0)
:param int page_size: The number of results to be returned.
:returns: -- the list of resources
"""
params = transform_params(params)
resp, page = self.request("GET", self.uri, params=params)
if self.key not in page:
raise TwilioException("Key %s not present in response" % self.key)
return [self.load_instance(ir) for ir in page[self.key]]