Rust
Rust
MercadoLibre - Consultar mis datos personales
See more MercadoLibre Examples
Consultar mis datos personalesChilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
// First get our previously obtained OAuth2 access token.
let json_token = chilkat::JsonObject::new();
let _ = json_token.load_file("qa_data/tokens/mercadolibre.json").is_ok();
// Implements the following CURL command:
// curl - X GET https://api.mercadolibre.com/users/me?access_token=$ACCESS_TOKEN
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
let _ = http.set_url_var("access_token", &json_token.string_of("access_token").unwrap_or_default());
let sb_response_body = chilkat::StringBuilder::new();
if http.quick_get_sb("https://api.mercadolibre.com/users/me?access_token={$access_token}", &sb_response_body).is_err() {
println!("{}", http.last_error_text());
return;
}
let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load_sb(&sb_response_body);
j_resp.set_emit_compact(false);
println!("Response Body:");
println!("{}", j_resp.emit().unwrap_or_default());
let resp_status_code = http.last_status();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
println!("Response Header:");
println!("{}", http.last_header());
println!("Failed.");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "id": 202593498,
// "nickname": "TETE2870021",
// "registration_date": "2016-01-06T11: 31: 42.000-04: 00",
// "country_id": "AR",
// "address": {
// "state": "AR-C",
// "city": "Palermo"
// },
// "user_type": "normal",
// "tags": [
// "normal",
// "test_user",
// "user_info_verified"
// ],
// "logo": null,
// "points": 100,
// "site_id": "MLA",
// "permalink": "http://perfil.mercadolibre.com.ar/TETE2870021",
// "seller_reputation": {
// "level_id": null,
// "power_seller_status": null,
// "transactions": {
// "period": "historic",
// "total": 0,
// "completed": 0,
// "canceled": 0,
// "ratings": {
// "positive": 0,
// "negative": 0,
// "neutral": 0
// }
// }
// },
// "buyer_reputation": {
// "tags": [
// ]
// },
// "status": {
// "site_status": "active"
// }
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
let id = j_resp.int_of("id");
let nickname = j_resp.string_of("nickname").unwrap_or_default();
let registration_date = j_resp.string_of("registration_date").unwrap_or_default();
let country_id = j_resp.string_of("country_id").unwrap_or_default();
let address_state = j_resp.string_of("address.state").unwrap_or_default();
let address_city = j_resp.string_of("address.city").unwrap_or_default();
let user_type = j_resp.string_of("user_type").unwrap_or_default();
let logo = j_resp.string_of("logo").unwrap_or_default();
let points = j_resp.int_of("points");
let site_id = j_resp.string_of("site_id").unwrap_or_default();
let permalink = j_resp.string_of("permalink").unwrap_or_default();
let seller_reputation_level_id = j_resp.string_of("seller_reputation.level_id").unwrap_or_default();
let seller_reputation_power_seller_status = j_resp.string_of("seller_reputation.power_seller_status").unwrap_or_default();
let seller_reputation_transactions_period = j_resp.string_of("seller_reputation.transactions.period").unwrap_or_default();
let seller_reputation_transactions_total = j_resp.int_of("seller_reputation.transactions.total");
let seller_reputation_transactions_completed = j_resp.int_of("seller_reputation.transactions.completed");
let seller_reputation_transactions_canceled = j_resp.int_of("seller_reputation.transactions.canceled");
let seller_reputation_transactions_ratings_positive = j_resp.int_of("seller_reputation.transactions.ratings.positive");
let seller_reputation_transactions_ratings_negative = j_resp.int_of("seller_reputation.transactions.ratings.negative");
let seller_reputation_transactions_ratings_neutral = j_resp.int_of("seller_reputation.transactions.ratings.neutral");
let status_site_status = j_resp.string_of("status.site_status").unwrap_or_default();
let mut i = 0;
let mut count_i = j_resp.size_of_array("tags");
while i < count_i {
j_resp.set_i(i);
let _ = j_resp.string_of("tags[i]").unwrap_or_default();
i = i + 1;
}
i = 0;
count_i = j_resp.size_of_array("buyer_reputation.tags");
while i < count_i {
j_resp.set_i(i);
i = i + 1;
}