Struct hub_sdk::HubSDK [] [src]

pub struct HubSDK { /* fields omitted */ }

Interface handle for a HubSDK instance

Methods

impl HubSDK
[src]

[src]

Create a new instance of the Geeny Hub SDK. SDK will immediately begin operation

Example

extern crate hub_sdk;

use hub_sdk::{HubSDK, HubSDKConfig};

fn main() {
    let sdk_cfg = HubSDKConfig::default();

    // Begin running the SDK. The hub_sdk handle may be used to interact with
    // the sdk. This handle may be cloned and given to multiple consumers
    let hub_sdk = HubSDK::new(sdk_cfg);
}

[src]

Check whether a given token is still valid.

Example

use hub_sdk::{HubSDK, HubSDKConfig};
let sdk_cfg = HubSDKConfig::default();
let hub_sdk = HubSDK::new(sdk_cfg);

let (email, valid) = hub_sdk.check_token()
    .expect("Failed to access auth info");

println!("Username: {}, Valid Token: {}", email, valid);

[src]

Perform a login to the Geeny API, allowing further operations such as creating a Thing

NOTE

Currently the SDK performs a login using Basic Authentication. The SDK uses the Email and Password to log in and retrieve an access token. The SDK DOES NOT store the password. The SDK will attempt to refresh the access token periodically when running, however after a long period of not running (e.g., when the service is stopped, or the Hub has been powered down), a new login will need to be performed.

The HubSDK::check_token() method may be used to check whether a new login needs to be performed.

It is HIGHLY RECOMMENDED never to store the user's password, and instead prompt the user directly whenever a login is necessary.

Example

use hub_sdk::{HubSDK, HubSDKConfig};
let sdk_cfg = HubSDKConfig::default();
let hub_sdk = HubSDK::new(sdk_cfg);

hub_sdk.login("cool_username@email.com", "S3cure_P@ssw0rd")
    .expect("Failed to log in!");

[src]

Logout of the Geeny API. No further API operations will be possible until a Login occurs. All active devices will be immediately unpaired

Example

use hub_sdk::{HubSDK, HubSDKConfig};
let sdk_cfg = HubSDKConfig::default();
let hub_sdk = HubSDK::new(sdk_cfg);

hub_sdk.logout().expect("Failed to log out!");

[src]

Create a new thing on the Geeny cloud

Example

This example is not tested
extern crate uuid;
use uuid::Uuid;
use hub_sdk::{HubSDK, HubSDKConfig};
use hub_sdk::geeny_api::models::ThingRequest;
let sdk_cfg = HubSDKConfig::default();
let hub_sdk = HubSDK::new(sdk_cfg);

let new_thing = ThingRequest {
    name: "New Demo Thing".into(),
    serial_number: "ABC123456".into(),
    thing_type: Uuid::from("2CB7F29A-527B-11E7-B114-B2F933D5FE66"),
};

hub_sdk.create_thing(new_thing)
    .expect("Failed to create new thing!");

[src]

Delete a thing from the Geeny cloud. The thing must not be currently active, e.g., it must first be unpaired

Example

use hub_sdk::{HubSDK, HubSDKConfig};
let sdk_cfg = HubSDKConfig::default();
let hub_sdk = HubSDK::new(sdk_cfg);

hub_sdk.delete_thing_by_serial("ABC123456")
    .expect("Failed to delete thing!");

[src]

Unpair a thing that is managed by the SDK. Unpairing a thing not currently managed by the SDK will not cause an error

Example

use hub_sdk::{HubSDK, HubSDKConfig};
let sdk_cfg = HubSDKConfig::default();
let hub_sdk = HubSDK::new(sdk_cfg);

hub_sdk.unpair_thing_by_serial("ABC123456")
    .expect("Failed to unpair thing!");

[src]

Send messages to the Geeny cloud on behalf of a thing

Example

use hub_sdk::{HubSDK, HubSDKConfig};
use hub_sdk::services::PartialThingMessage;

let sdk_cfg = HubSDKConfig::default();
let hub_sdk = HubSDK::new(sdk_cfg);

let messages = vec!(
    PartialThingMessage {
        topic: "demo/send/path".into(),
        msg: "demonstration message".into(),
    },
    PartialThingMessage {
        topic: "demo/other/path".into(),
        msg: "second demonstration message".into(),
    },
);

hub_sdk.send_messages("ABC123456", &messages)
    .expect("Failed to send messages!");

[src]

Obtain any messages sent from the Geeny cloud to a given thing

Example

use hub_sdk::{HubSDK, HubSDKConfig};
let sdk_cfg = HubSDKConfig::default();
let hub_sdk = HubSDK::new(sdk_cfg);

let messages = hub_sdk.receive_messages("ABC123456")
    .expect("Failed to receive messsages!");

for msg in messages {
    println!("topic: >>{}<<, message: >>{}<<", msg.topic, msg.msg);
}

Trait Implementations

impl Clone for HubSDK
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for HubSDK

impl Sync for HubSDK