reformat strings
This commit is contained in:
parent
1013a05b83
commit
b49ac43f08
1 changed files with 52 additions and 8 deletions
60
src/main.zig
60
src/main.zig
|
|
@ -55,7 +55,9 @@ fn authenticate(allocator: std.mem.Allocator, username: []const u8, password: []
|
||||||
var client = http.Client{ .allocator = allocator };
|
var client = http.Client{ .allocator = allocator };
|
||||||
defer client.deinit();
|
defer client.deinit();
|
||||||
|
|
||||||
const body = try std.fmt.allocPrint(allocator, "{{\"AuthFlow\":\"USER_PASSWORD_AUTH\",\"ClientId\":\"{s}\",\"AuthParameters\":{{\"USERNAME\":\"{s}\",\"PASSWORD\":\"{s}\"}}}}", .{ client_id, username, password });
|
const body = try std.fmt.allocPrint(allocator,
|
||||||
|
\\{{"AuthFlow":"USER_PASSWORD_AUTH","ClientId":"{s}","AuthParameters":{{"USERNAME":"{s}","PASSWORD":"{s}"}}}}
|
||||||
|
, .{ client_id, username, password });
|
||||||
defer allocator.free(body);
|
defer allocator.free(body);
|
||||||
|
|
||||||
const uri = try std.Uri.parse(cognito_url);
|
const uri = try std.Uri.parse(cognito_url);
|
||||||
|
|
@ -107,9 +109,32 @@ fn getDevices(allocator: std.mem.Allocator, id_token: []const u8, username: []co
|
||||||
var client = http.Client{ .allocator = allocator };
|
var client = http.Client{ .allocator = allocator };
|
||||||
defer client.deinit();
|
defer client.deinit();
|
||||||
|
|
||||||
const query = "query GetUserByEmail($email: String!) { getUserByEmail(email: $email) { items { id email devices { items { id thing_name device_name dsn model info { serial_id } } } } } }";
|
const query =
|
||||||
|
\\query GetUserByEmail($email: String!) {
|
||||||
|
\\ getUserByEmail(email: $email) {
|
||||||
|
\\ items {
|
||||||
|
\\ id
|
||||||
|
\\ email
|
||||||
|
\\ devices {
|
||||||
|
\\ items {
|
||||||
|
\\ id
|
||||||
|
\\ thing_name
|
||||||
|
\\ device_name
|
||||||
|
\\ dsn
|
||||||
|
\\ model
|
||||||
|
\\ info {
|
||||||
|
\\ serial_id
|
||||||
|
\\ }
|
||||||
|
\\ }
|
||||||
|
\\ }
|
||||||
|
\\ }
|
||||||
|
\\ }
|
||||||
|
\\}
|
||||||
|
;
|
||||||
|
|
||||||
const body = try std.fmt.allocPrint(allocator, "{{\"query\":\"{s}\",\"variables\":{{\"email\":\"{s}\"}}}}", .{ query, username });
|
const body = try std.fmt.allocPrint(allocator,
|
||||||
|
\\{{"query":"{s}","variables":{{"email":"{s}"}}}}
|
||||||
|
, .{ query, username });
|
||||||
defer allocator.free(body);
|
defer allocator.free(body);
|
||||||
|
|
||||||
const uri = try std.Uri.parse(appsync_url);
|
const uri = try std.Uri.parse(appsync_url);
|
||||||
|
|
@ -137,14 +162,20 @@ fn startRecirculation(allocator: std.mem.Allocator, id_token: []const u8, serial
|
||||||
var client = http.Client{ .allocator = allocator };
|
var client = http.Client{ .allocator = allocator };
|
||||||
defer client.deinit();
|
defer client.deinit();
|
||||||
|
|
||||||
const url = try std.fmt.allocPrint(allocator, "{s}/{s}/shadow", .{ shadow_api_url, serial_number });
|
const url = try std.fmt.allocPrint(allocator,
|
||||||
|
\\{s}/{s}/shadow
|
||||||
|
, .{ shadow_api_url, serial_number });
|
||||||
defer allocator.free(url);
|
defer allocator.free(url);
|
||||||
|
|
||||||
const body = try std.fmt.allocPrint(allocator, "{{\"recirculation_duration\":{d},\"set_recirculation_enabled\":true}}", .{duration_minutes});
|
const body = try std.fmt.allocPrint(allocator,
|
||||||
|
\\{{"recirculation_duration":{d},"set_recirculation_enabled":true}}
|
||||||
|
, .{duration_minutes});
|
||||||
defer allocator.free(body);
|
defer allocator.free(body);
|
||||||
|
|
||||||
const uri = try std.Uri.parse(url);
|
const uri = try std.Uri.parse(url);
|
||||||
const auth_header = try std.fmt.allocPrint(allocator, "Bearer {s}", .{id_token});
|
const auth_header = try std.fmt.allocPrint(allocator,
|
||||||
|
\\Bearer {s}
|
||||||
|
, .{id_token});
|
||||||
defer allocator.free(auth_header);
|
defer allocator.free(auth_header);
|
||||||
|
|
||||||
const result = try client.fetch(.{
|
const result = try client.fetch(.{
|
||||||
|
|
@ -165,9 +196,22 @@ fn getRecirculationStatus(allocator: std.mem.Allocator, id_token: []const u8, se
|
||||||
var client = http.Client{ .allocator = allocator };
|
var client = http.Client{ .allocator = allocator };
|
||||||
defer client.deinit();
|
defer client.deinit();
|
||||||
|
|
||||||
const query = "query GetDeviceShadow($heater_serial_number: ID!) { getDeviceShadow(heater_serial_number: $heater_serial_number) { heater_serial_number set_recirculation_enabled recirculation_enabled recirculation_duration set_domestic_temperature operation_enabled } }";
|
const query =
|
||||||
|
\\query GetDeviceShadow($heater_serial_number: ID!) {
|
||||||
|
\\ getDeviceShadow(heater_serial_number: $heater_serial_number) {
|
||||||
|
\\ heater_serial_number
|
||||||
|
\\ set_recirculation_enabled
|
||||||
|
\\ recirculation_enabled
|
||||||
|
\\ recirculation_duration
|
||||||
|
\\ set_domestic_temperature
|
||||||
|
\\ operation_enabled
|
||||||
|
\\ }
|
||||||
|
\\}
|
||||||
|
;
|
||||||
|
|
||||||
const body = try std.fmt.allocPrint(allocator, "{{\"query\":\"{s}\",\"variables\":{{\"heater_serial_number\":\"{s}\"}}}}", .{ query, serial_number });
|
const body = try std.fmt.allocPrint(allocator,
|
||||||
|
\\{{"query":"{s}","variables":{{"heater_serial_number":"{s}"}}}}
|
||||||
|
, .{ query, serial_number });
|
||||||
defer allocator.free(body);
|
defer allocator.free(body);
|
||||||
|
|
||||||
const uri = try std.Uri.parse(appsync_url);
|
const uri = try std.Uri.parse(appsync_url);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue