Skip to content

Commit

Permalink
Client API fix (WorldHealthOrganization#676)
Browse files Browse the repository at this point in the history
* Add client uuid generated on first use.

* First pass at client API for invoking WHO services.

* Switch to prod url.

* Encode JSON safely.
  • Loading branch information
patniemeyer committed Mar 30, 2020
1 parent 6f6a3ea commit 0caea46
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions client/flutter/lib/api/who_service.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'package:WHOFlutter/api/user_preferences.dart';
import 'package:http/http.dart' as http;
import 'dart:io';
Expand All @@ -11,7 +12,7 @@ class WhoService {
/// Put device token.
static Future<bool> putDeviceToken(String token) async {
Map<String, String> headers = await _getHeaders();
var postBody = '{"token": "$token"}';
var postBody = jsonEncode({"token": token});
var url = '$serviceUrl/putDeviceToken';
var response = await http.post(url, headers: headers, body: postBody);
if (response.statusCode != 200) {
Expand All @@ -23,7 +24,7 @@ class WhoService {
/// Put location
static Future<bool> putLocation({double latitude, double longitude}) async {
Map<String, String> headers = await _getHeaders();
var postBody = '{"latitude": "$latitude", "longitude": "$longitude"}';
var postBody = jsonEncode({"latitude": latitude, "longitude": longitude});
var url = '$serviceUrl/putLocation';
var response = await http.post(url, headers: headers, body: postBody);
if (response.statusCode != 200) {
Expand Down

0 comments on commit 0caea46

Please sign in to comment.