1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
use chrono::Utc;
pub use raystack::{
is_tag_name, skyspark_tz_string_to_tz, BasicNumber, Coord, Date, DateTime, Error,
FromHaysonError, Grid, Hayson, HisReadRange, Marker, Na, NewSkySparkClientError, Number,
ParseJsonGridError, ParseRefError, ParseTagNameError, Ref, RemoveMarker, ScientificNumber,
Symbol, TagName, Time, Uri, ValueExt, Xstr,
};
use std::sync::Arc;
use tokio::runtime::Runtime;
use url::Url;
pub mod auth;
type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub struct SkySparkClient {
client: raystack::SkySparkClient,
rt: Arc<Runtime>,
}
impl SkySparkClient {
pub fn new(
project_api_url: Url,
username: &str,
password: &str,
) -> std::result::Result<Self, NewSkySparkClientError> {
let rt = Runtime::new().expect("could not create a new Tokio runtime");
Self::new_with_runtime(project_api_url, username, password, Arc::new(rt))
}
pub fn new_with_runtime(
project_api_url: Url,
username: &str,
password: &str,
rt: Arc<Runtime>,
) -> std::result::Result<Self, NewSkySparkClientError> {
let rclient = reqwest::Client::new();
let client = rt.block_on(raystack::SkySparkClient::new_with_client(
project_api_url,
username,
password,
rclient,
))?;
Ok(Self { client, rt })
}
pub fn project_name(&self) -> &str {
self.client.project_name()
}
pub fn project_api_url(&self) -> &Url {
self.client.project_api_url()
}
}
impl SkySparkClient {
pub fn about(&mut self) -> Result<Grid> {
self.rt.block_on(self.client.about())
}
pub fn formats(&mut self) -> Result<Grid> {
self.rt.block_on(self.client.formats())
}
pub fn his_read(&mut self, id: &Ref, range: &HisReadRange) -> Result<Grid> {
self.rt.block_on(self.client.his_read(id, range))
}
pub fn his_write_bool(&mut self, id: &Ref, his_data: &[(DateTime, bool)]) -> Result<Grid> {
self.rt.block_on(self.client.his_write_bool(id, his_data))
}
pub fn his_write_num(&mut self, id: &Ref, his_data: &[(DateTime, Number)]) -> Result<Grid> {
self.rt.block_on(self.client.his_write_num(id, his_data))
}
pub fn his_write_str(&mut self, id: &Ref, his_data: &[(DateTime, String)]) -> Result<Grid> {
self.rt.block_on(self.client.his_write_str(id, his_data))
}
pub fn utc_his_write_bool(
&mut self,
id: &Ref,
time_zone_name: &str,
his_data: &[(chrono::DateTime<Utc>, bool)],
) -> Result<Grid> {
self.rt
.block_on(self.client.utc_his_write_bool(id, time_zone_name, his_data))
}
pub fn utc_his_write_num(
&mut self,
id: &Ref,
time_zone_name: &str,
his_data: &[(chrono::DateTime<Utc>, Number)],
) -> Result<Grid> {
self.rt
.block_on(self.client.utc_his_write_num(id, time_zone_name, his_data))
}
pub fn utc_his_write_str(
&mut self,
id: &Ref,
time_zone_name: &str,
his_data: &[(chrono::DateTime<Utc>, String)],
) -> Result<Grid> {
self.rt
.block_on(self.client.utc_his_write_str(id, time_zone_name, his_data))
}
pub fn nav(&mut self, nav_id: Option<&Ref>) -> Result<Grid> {
self.rt.block_on(self.client.nav(nav_id))
}
pub fn ops(&mut self) -> Result<Grid> {
self.rt.block_on(self.client.ops())
}
pub fn read(&mut self, filter: &str, limit: Option<u64>) -> Result<Grid> {
self.rt.block_on(self.client.read(filter, limit))
}
pub fn read_by_ids(&mut self, ids: &[Ref]) -> Result<Grid> {
self.rt.block_on(self.client.read_by_ids(ids))
}
}
impl SkySparkClient {
pub fn eval(&mut self, axon_expr: &str) -> Result<Grid> {
self.rt.block_on(self.client.eval(axon_expr))
}
}