[−][src]Crate psn_api_rs
A simple PSN API wrapper.
It uses an async http client(actix-web-client in this case) to communicate wih the official PSN API.
Some basics:
The crate use a pair of uuid
and two_step
code to login in to PSN Network and get a pair of access_token
and refresh_token
in response.
The access_token
last about an hour before expire and it's needed to call most other PSN APIs(The PSN store API doesn't need any token to access though).
The refresh_token
last much longer and it's used to generate a new access_token after/before it is expired.
- Some thing to note: There is a rate limiter for the official PSN API so better not make lots of calls in short time. Therefore its' best to avoid using in multi threads also as a single thread could hit the limit easily on any given machine running this crate.
Example:
use futures::lazy; use tokio::runtime::current_thread::Runtime; use psn_api_rs::{PSNRequest, PSN, models::PSNUser}; fn main() { let refresh_token = String::from("your refresh token"); let uuid = String::from("your uuid"); let two_step = String::from("your two_step code"); let mut runtime = Runtime::new().unwrap(); // construct a PSN struct,add credentials and call auth to generate tokens. let mut psn: PSN = runtime.block_on(lazy(|| { PSN::new() .set_region("us".to_owned()) // <- set to a psn region server suit your case. you can leave it as default which is hk .set_lang("en".to_owned()) // <- set to a language you want the response to be. default is en .set_self_online_id(String::from("Your Login account PSN online_id")) // <- this is used to generate new message thread. // safe to leave unset if you don't need to send any PSN message. .add_refresh_token(refresh_token) // <- If refresh_token is provided then it's safe to ignore uuid and two_step arg and call .auth() directly. .add_uuid(uuid) // <- uuid and two_step are used only when refresh_token is not working or not provided. .add_two_step(two_step) .auth() })).unwrap_or_else(|e| panic!("{:?}", e)); println!( "Authentication Success! These are your token info from PSN network: \r\n{:#?} ", psn ); let user: PSNUser = runtime.block_on( psn.add_online_id("Hakoom".to_owned()).get_profile() // <- use the psn struct to call for user_profile. ).unwrap_or_else(|e| panic!("{:?}", e)); println!( "Example finished. Got user info : \r\n{:#?}", user ); // psn struct is dropped at this point so it's better to store your access_token and refresh_token here to make them reusable. }
Modules
models |
|
urls |
|
Structs
PSN |
Traits
EncodeUrl | serde_urlencoded can be used to make a |
MultiPart | |
PSNRequest | You can override |