Struct pb_async::Client [−][src]
pub struct Client { /* fields omitted */ }
PushBullet client
Methods
impl Client
[src]
impl Client
pub fn new(token: &str) -> Result<Self, StartupError>
[src]
pub fn new(token: &str) -> Result<Self, StartupError>
Create a new client with a given token.
Example usage:
let token = std::env::var("PB_TOKEN").expect("expected PB_TOKEN env var to exist"); let client = pb_async::Client::new(&token) .expect("expected client creation to succeed");
pub fn with_client(
token: &str,
client: Client<HttpsConnector<HttpConnector>>
) -> Result<Self, StartupError>
[src]
pub fn with_client(
token: &str,
client: Client<HttpsConnector<HttpConnector>>
) -> Result<Self, StartupError>
Create a new client with a given token and an existing hyper client.
pub fn get_user(
&self
) -> impl Future<Item = User, Error = RequestError>
[src]
pub fn get_user(
&self
) -> impl Future<Item = User, Error = RequestError>
Retrieves information of the logged in user.
Example usage:
extern crate futures; extern crate pb_async; extern crate tokio; use futures::Future; tokio::executor::spawn(client.get_user().and_then(|user_info| { println!("User email is {}", user_info.email); Ok(()) }).or_else(|error| { eprintln!("error: {}", error); Ok(()) }));
pub fn list_devices(
&self
) -> impl Future<Item = Vec<Device>, Error = RequestError>
[src]
pub fn list_devices(
&self
) -> impl Future<Item = Vec<Device>, Error = RequestError>
Retrieves a list of devices.
Example usage:
extern crate futures; extern crate pb_async; extern crate tokio; use futures::Future; tokio::executor::spawn(client.list_devices().and_then(|devices| { println!("Devices: {:#?}", devices); Ok(()) }).or_else(|error| { eprintln!("error: {}", error); Ok(()) }));
pub fn push(
&self,
target: PushTarget,
data: PushData
) -> impl Future<Item = (), Error = RequestError>
[src]
pub fn push(
&self,
target: PushTarget,
data: PushData
) -> impl Future<Item = (), Error = RequestError>
Pushes some data to a target.
Example usage:
extern crate futures; extern crate pb_async; extern crate tokio; use futures::Future; tokio::executor::spawn( client.push( pb_async::PushTarget::SelfUser {}, pb_async::PushData::Note { title: "", body: "Hello, user!", }, ).or_else(|error| { eprintln!("error: {}", error); Ok(()) }) );
pub fn upload_request(
&self,
file_name: &str,
file_type: &str,
upload_data: Body
) -> impl Future<Item = UploadRequestResponse, Error = RequestError>
[src]
pub fn upload_request(
&self,
file_name: &str,
file_type: &str,
upload_data: Body
) -> impl Future<Item = UploadRequestResponse, Error = RequestError>
Prepares a file for upload prior to pushing it via Client::push
.
This method handles file streaming correctly. If you use a streaming
hyper::Body
, it will be correctly wrapped and the resulting
connection won't need to keep the entire file in memory.
Example usage:
extern crate futures; extern crate pb_async; extern crate tokio; use futures::Future; tokio::executor::spawn( client .upload_request("hello.txt", "text/plain", "Hello, world!\n".into()) .and_then(move |file_data| { client.push( pb_async::PushTarget::SelfUser {}, pb_async::PushData::File { body: "", file_name: &file_data.file_name, file_type: &file_data.file_type, file_url: &file_data.file_url, }, ) }) .or_else(|error| { eprintln!("error pushing file: {}", error); Ok(()) }), );