pub struct MailchimpApi { /* private fields */ }
Expand description
Mailchimp API
Permite el acceso al API de Mailchimp si conoces bien los diferentes endpoints. Para más información sobre los endpoints ir a la página de desarrollos mailchimp Developers Mailchimp
§Ejemplo
extern crate mailchimp;
use mailchimp::MailchimpApi;
let api = MailchimpApi::new("<API Key>");
println!("Api version: {}", api.version());
println!("Api domain: {}", api.domain());
Implementations§
Source§impl MailchimpApi
impl MailchimpApi
Sourcepub fn new<'a>(api_key: &'a str) -> Self
pub fn new<'a>(api_key: &'a str) -> Self
Crea la nueva instancia del API
Argumentos api_key: Mailchimp API KEY http_transport: Interfaz por donde se harían las peticiones Get y Post al servicio
Sourcepub fn post<'a, T, P>(
&self,
endpoint: &'a str,
payload: P,
) -> Result<T, MailchimpErrorType>where
T: DeserializeOwned,
P: Serialize,
pub fn post<'a, T, P>(
&self,
endpoint: &'a str,
payload: P,
) -> Result<T, MailchimpErrorType>where
T: DeserializeOwned,
P: Serialize,
Realiza una petición de tipo POST
extern crate mailchimp;
use std::collections::HashMap;
use mailchimp::MailchimpApi;
use mailchimp::types::AuthorizedAppsType;
fn main() {
let api = MailchimpApi::new("aac1e319006883125e18a89e529b5abb73de4c81-usX");
let data = api.post::<AuthorizedAppsType, HashMap<String, String>>("authorized-apps", HashMap::new());
match data {
Ok(resp) => {
for app in resp.apps.iter() {
println!("{:?}", app)
}
},
Err(e) => println!("Error Title: {:?} \n Error detail {:?}", e.title, e.detail)
}
}
#Argumentos
endpoint
: Cadena de texto con el endpoint de la API al que se requiere acceder, no debe comenzar por “/”
payload
: Dato a enviar al servidor
Sourcepub fn patch<'a, T, P>(
&self,
endpoint: &'a str,
payload: P,
) -> Result<T, MailchimpErrorType>where
T: DeserializeOwned,
P: Serialize,
pub fn patch<'a, T, P>(
&self,
endpoint: &'a str,
payload: P,
) -> Result<T, MailchimpErrorType>where
T: DeserializeOwned,
P: Serialize,
Función para actualizar los recursos en el servidor
#Argumentos
endpoint
: Cadena de texto con el endpoint de la API al que se requiere acceder, no debe comenzar por “/”
payload
: Dato a enviar al servidor
Sourcepub fn put<'a, T, P>(
&self,
endpoint: &'a str,
payload: P,
) -> Result<T, MailchimpErrorType>where
T: DeserializeOwned,
P: Serialize,
pub fn put<'a, T, P>(
&self,
endpoint: &'a str,
payload: P,
) -> Result<T, MailchimpErrorType>where
T: DeserializeOwned,
P: Serialize,
Función para actualizar los recursos en el servidor
#Argumentos
endpoint
: Cadena de texto con el endpoint de la API al que se requiere acceder, no debe comenzar por “/”
payload
: Dato a enviar al servidor
Sourcepub fn get<'a, T>(
&self,
endpoint: &'a str,
payload: HashMap<String, String>,
) -> Result<T, MailchimpErrorType>where
T: DeserializeOwned,
pub fn get<'a, T>(
&self,
endpoint: &'a str,
payload: HashMap<String, String>,
) -> Result<T, MailchimpErrorType>where
T: DeserializeOwned,
Realiza una petición de tipo GET
extern crate mailchimp;
use std::collections::HashMap;
use mailchimp::MailchimpApi;
use mailchimp::types::AuthorizedAppType;
fn main() {
let api = MailchimpApi::new("aac1e319006883125e18a89e529b5abb73de4c81-usX");
let mut params = HashMap::new();
params.insert("client_id".to_string(), "".to_string());
params.insert("client_secret".to_string(), "".to_string());
let data = api.get::<AuthorizedAppType>("authorized-apps", params);
match data {
Ok(resp) => {
println!("{:?}", resp)
},
Err(e) => println!("Error Title: {:?} \n Error detail {:?}", e.title, e.detail)
}
}
#Argumentos
endpoint
: Cadena de texto con el endpoint de la API al que se requiere acceder, no debe comenzar por “/”
payload
: Listado llave valor de los parametros o data
Sourcepub fn delete<'a, T>(
&self,
endpoint: &'a str,
payload: HashMap<String, String>,
) -> Result<T, MailchimpErrorType>where
T: DeserializeOwned,
pub fn delete<'a, T>(
&self,
endpoint: &'a str,
payload: HashMap<String, String>,
) -> Result<T, MailchimpErrorType>where
T: DeserializeOwned,
Realiza una petición de tipo GET
extern crate mailchimp;
use std::collections::HashMap;
use mailchimp::MailchimpApi;
use mailchimp::types::AuthorizedAppType;
fn main() {
let api = MailchimpApi::new("aac1e319006883125e18a89e529b5abb73de4c81-usX");
let mut params = HashMap::new();
params.insert("client_id".to_string(), "".to_string());
params.insert("client_secret".to_string(), "".to_string());
let data = api.get::<AuthorizedAppType>("authorized-apps", params);
match data {
Ok(resp) => {
println!("{:?}", resp)
},
Err(e) => println!("Error Title: {:?} \n Error detail {:?}", e.title, e.detail)
}
}
#Argumentos
endpoint
: Cadena de texto con el endpoint de la API al que se requiere acceder, no debe comenzar por “/”
payload
: Listado llave valor de los parametros o data
Sourcepub fn ping(&self) -> Result<Ping, MailchimpErrorType>
pub fn ping(&self) -> Result<Ping, MailchimpErrorType>
A health check for the API that won’t return any account-specific information.
Trait Implementations§
Source§impl Clone for MailchimpApi
impl Clone for MailchimpApi
Source§fn clone(&self) -> MailchimpApi
fn clone(&self) -> MailchimpApi
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more