pub struct SkySparkClient { /* private fields */ }Expand description
A client for interacting with a SkySpark server.
Implementations§
Source§impl SkySparkClient
impl SkySparkClient
Sourcepub fn new(
project_api_url: Url,
username: &str,
password: &str,
) -> Result<Self, NewSkySparkClientError>
pub fn new( project_api_url: Url, username: &str, password: &str, ) -> Result<Self, NewSkySparkClientError>
Create a new SkySparkClient.
§Example
use raystack_blocking::SkySparkClient;
use url::Url;
let url = Url::parse("https://skyspark.company.com/api/bigProject/").unwrap();
let mut client = SkySparkClient::new(url, "username", "p4ssw0rd").unwrap();Examples found in repository?
7fn main() -> Result<(), Box<dyn Error>> {
8 use raystack_blocking::{SkySparkClient, ValueExt};
9 use url::Url;
10
11 let url = Url::parse("https://www.example.com/api/projName/")?;
12
13 // If you are going to create many `SkySparkClient`s,
14 // reuse the same `reqwest::Client` in each `SkySparkClient`
15 // by using the `SkySparkClient::new_with_client` function instead.
16 let mut client = SkySparkClient::new(url, "username", "p4ssw0rd")?;
17
18 let sites_grid = client.eval("readAll(site)")?;
19
20 // Print the raw JSON:
21 println!("{}", sites_grid.to_json_string_pretty());
22
23 // Working with the Grid struct:
24 println!("All columns: {:?}", sites_grid.cols());
25 println!(
26 "first site id: {:?}",
27 sites_grid.rows()[0]["id"].as_hs_ref().unwrap()
28 );
29
30 Ok(())
31}Sourcepub fn new_with_runtime(
project_api_url: Url,
username: &str,
password: &str,
rt: Arc<Runtime>,
) -> Result<Self, NewSkySparkClientError>
pub fn new_with_runtime( project_api_url: Url, username: &str, password: &str, rt: Arc<Runtime>, ) -> Result<Self, NewSkySparkClientError>
Create a new SkySparkClient using an existing Tokio runtime.
Sourcepub fn project_name(&self) -> &str
pub fn project_name(&self) -> &str
Return the project name for this client.
Sourcepub fn project_api_url(&self) -> &Url
pub fn project_api_url(&self) -> &Url
Return the project API url being used by this client.
Source§impl SkySparkClient
impl SkySparkClient
Sourcepub fn about(&mut self) -> Result<Grid, Error>
pub fn about(&mut self) -> Result<Grid, Error>
Returns a grid containing basic server information.
Sourcepub fn filetypes(&mut self) -> Result<Grid, Error>
pub fn filetypes(&mut self) -> Result<Grid, Error>
Returns a grid describing what MIME types are available.
Sourcepub fn his_read(
&mut self,
id: &Ref,
range: &HisReadRange,
) -> Result<Grid, Error>
pub fn his_read( &mut self, id: &Ref, range: &HisReadRange, ) -> Result<Grid, Error>
Returns a grid of history data for a single point.
Sourcepub fn his_write_bool(
&mut self,
id: &Ref,
his_data: &[(DateTime, bool)],
) -> Result<Grid, Error>
pub fn his_write_bool( &mut self, id: &Ref, his_data: &[(DateTime, bool)], ) -> Result<Grid, Error>
Writes boolean values to a single point.
Sourcepub fn his_write_num(
&mut self,
id: &Ref,
his_data: &[(DateTime, Number)],
) -> Result<Grid, Error>
pub fn his_write_num( &mut self, id: &Ref, his_data: &[(DateTime, Number)], ) -> Result<Grid, Error>
Writes numeric values to a single point. unit must be a valid
Haystack unit literal, such as L/s or celsius.
Sourcepub fn his_write_str(
&mut self,
id: &Ref,
his_data: &[(DateTime, String)],
) -> Result<Grid, Error>
pub fn his_write_str( &mut self, id: &Ref, his_data: &[(DateTime, String)], ) -> Result<Grid, Error>
Writes string values to a single point.
Sourcepub fn utc_his_write_bool(
&mut self,
id: &Ref,
time_zone_name: &str,
his_data: &[(DateTime<Utc>, bool)],
) -> Result<Grid, Error>
pub fn utc_his_write_bool( &mut self, id: &Ref, time_zone_name: &str, his_data: &[(DateTime<Utc>, bool)], ) -> Result<Grid, Error>
Writes boolean values with UTC timestamps to a single point.
time_zone_name must be a valid SkySpark timezone name.
Sourcepub fn utc_his_write_num(
&mut self,
id: &Ref,
time_zone_name: &str,
his_data: &[(DateTime<Utc>, Number)],
) -> Result<Grid, Error>
pub fn utc_his_write_num( &mut self, id: &Ref, time_zone_name: &str, his_data: &[(DateTime<Utc>, Number)], ) -> Result<Grid, Error>
Writes numeric values with UTC timestamps to a single point.
unit must be a valid Haystack unit literal, such as L/s or
celsius.
time_zone_name must be a valid SkySpark timezone name.
Sourcepub fn utc_his_write_str(
&mut self,
id: &Ref,
time_zone_name: &str,
his_data: &[(DateTime<Utc>, String)],
) -> Result<Grid, Error>
pub fn utc_his_write_str( &mut self, id: &Ref, time_zone_name: &str, his_data: &[(DateTime<Utc>, String)], ) -> Result<Grid, Error>
Writes string values with UTC timestamps to a single point.
time_zone_name must be a valid SkySpark timezone name.
The Haystack nav operation.
Sourcepub fn ops(&mut self) -> Result<Grid, Error>
pub fn ops(&mut self) -> Result<Grid, Error>
Returns a grid containing the operations available on the server.
Source§impl SkySparkClient
impl SkySparkClient
Sourcepub fn eval(&mut self, axon_expr: &str) -> Result<Grid, Error>
pub fn eval(&mut self, axon_expr: &str) -> Result<Grid, Error>
Examples found in repository?
3fn main() -> Result<(), Box<dyn Error>> {
4 use raystack_blocking::{new_client, ValueExt};
5
6 let mut client = new_client("https://www.example.com/api/projName/", "username", "p4ssw0rd")?;
7
8 let sites_grid = client.eval("readAll(site)")?;
9
10 // Print the raw JSON:
11 println!("{}", sites_grid.to_json_string_pretty());
12
13 // Working with the Grid struct:
14 println!("All columns: {:?}", sites_grid.cols());
15 println!(
16 "first site id: {:?}",
17 sites_grid.rows()[0]["id"].as_hs_ref().unwrap()
18 );
19
20 Ok(())
21}More examples
7fn main() -> Result<(), Box<dyn Error>> {
8 use raystack_blocking::{SkySparkClient, ValueExt};
9 use url::Url;
10
11 let url = Url::parse("https://www.example.com/api/projName/")?;
12
13 // If you are going to create many `SkySparkClient`s,
14 // reuse the same `reqwest::Client` in each `SkySparkClient`
15 // by using the `SkySparkClient::new_with_client` function instead.
16 let mut client = SkySparkClient::new(url, "username", "p4ssw0rd")?;
17
18 let sites_grid = client.eval("readAll(site)")?;
19
20 // Print the raw JSON:
21 println!("{}", sites_grid.to_json_string_pretty());
22
23 // Working with the Grid struct:
24 println!("All columns: {:?}", sites_grid.cols());
25 println!(
26 "first site id: {:?}",
27 sites_grid.rows()[0]["id"].as_hs_ref().unwrap()
28 );
29
30 Ok(())
31}