8/24/2023 0 Comments Rust mobile no verification![]() Then, an iterator is instantiated to iterate over the available usage records. First, a header indicating the information coming (“Twilio Account Usage”) is printed. However, if the body was retrieved, Serde JSON parses it into an AccountUsage struct: doing so makes the JSON body easier to work with programmatically.įollowing that, the get_total_usage_cost function is called to calculate the total cost of the retrieved usage records.Īt this point, there’s not all that much left, but to print out the retrieved and calculated information to the terminal. If it can’t do that, the code exits, printing the reason why the body could not be extracted to the terminal. Otherwise, the code next attempts to retrieve the response’s body as text. Next up, if the status code of the response was not HTTP 200 (OK), the code panics and exits, printing the error code to the terminal. As requests to Twilio’s API require the password to be supplied, auth_token is passed in as the Some variant of Option. Because of that, the password ( auth_token) needs to be supplied as an Option type. It uses Client’s basic_auth() function to authenticate the request, passing account_sid as the username and auth_token as the password.Īs the second parameter ( password) to basic_auth is an Option type, it allows for authentication both with and without a password. In addition, there are several other paths available these are:Īfter that, a new reqwest::blocking::Client object, client, is initialised and used to make a GET request to the URI defined in request_url. html, the information returned would instead be formatted as CSV or HTML respectively. The page size limits the maximum number of records returned to 20.Īs the URI ends with LastMonth.json, any results returned will be limited to those in the last month and returned in JSON format.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |