diff --git a/.gitignore b/.gitignore index 8f67fed..2298b58 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ # strava_flutter specific secret.dart todo.txt +# temp +starSegment.dart .DS_Store .dart_tool/ diff --git a/README.md b/README.md index 37d9753..b86de59 100644 --- a/README.md +++ b/README.md @@ -68,4 +68,4 @@ And Javier for https://javiercbk.github.io/json_to_dart/ License: -strava-flutter is provided under a MIT License. Copyright (c) 2019 Patrick FINKELSTEIN +strava-flutter is provided under a MIT License. Copyright (c) 2019 Patrick FINK diff --git a/example/lib/examples.dart b/example/lib/examples.dart index 0455010..395b25c 100644 --- a/example/lib/examples.dart +++ b/example/lib/examples.dart @@ -51,7 +51,7 @@ import 'package:strava_flutter/Models/summaryActivity.dart'; bool isAuthOk = false; - isAuthOk = await strava.OAuth(clientID, 'activity:write', secret, 'auto'); + isAuthOk = await strava.Oauth(clientId, 'activity:write', secret, 'auto'); print('---> Authentication result: $isAuthOk'); @@ -87,7 +87,7 @@ void example(String secret) async { secret); final prompt = 'auto'; - isAuthOk = await strava.OAuth(clientID, 'activity:write,profile:read_all', secret, prompt); + isAuthOk = await strava.Oauth(clientId, 'activity:write,profile:read_all', secret, prompt); if (isAuthOk) { diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index e86238e..ec488a7 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -12,7 +12,7 @@ import 'package:flutter_test/flutter_test.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. - await tester.pumpWidget(MyApp()); + // await tester.pumpWidget(MyApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); diff --git a/lib/API/Oauth.dart b/lib/API/Oauth.dart index 61fc4c7..6a7bd84 100644 --- a/lib/API/Oauth.dart +++ b/lib/API/Oauth.dart @@ -28,7 +28,7 @@ abstract class Auth { // Save also in globals to get direct access globals.token.accessToken = token; globals.token.scope = scope; - globals.token.expiresAt =expire; + globals.token.expiresAt = expire; globals.displayInfo('token saved!!!'); } @@ -44,10 +44,10 @@ abstract class Auth { localToken.expiresAt = prefs.getInt('expire'); localToken.scope = prefs.getString('scope'); - // load the data in globals - globals.token.accessToken =localToken.accessToken; - globals.token.expiresAt =localToken.expiresAt; - globals.token.scope =localToken.scope; + // load the data in globals + globals.token.accessToken = localToken.accessToken; + globals.token.expiresAt = localToken.expiresAt; + globals.token.scope = localToken.scope; } catch (error) { globals.displayInfo('Error getting the key'); localToken.accessToken = null; @@ -58,18 +58,20 @@ abstract class Auth { if (localToken.expiresAt != null) { var dateExpired = DateTime.fromMillisecondsSinceEpoch(localToken.expiresAt); - var _disp = dateExpired.day.toString() + '/' + - dateExpired.month.toString() + ' ' + - dateExpired.hour.toString() + 'hours'; - - globals.displayInfo('stored token ${localToken.accessToken} expires: $_disp '); + var _disp = dateExpired.day.toString() + + '/' + + dateExpired.month.toString() + + ' ' + + dateExpired.hour.toString() + + 'hours'; + + globals.displayInfo( + 'stored token ${localToken.accessToken} expires: $_disp '); } return (localToken); } - - // Get the code from Strava server Future getStravaCode( String clientID, String scope, String prompt) async { @@ -117,36 +119,35 @@ abstract class Auth { }); } - /// Do Strava Authentication. - /// + /// Do Strava Authentication. + /// /// Do not do/show the Strava login if a token has been stored previously /// and is not expired /// Do/show the Strava login if the scope has been changed since last storage of the token /// return true if no problem in authentication has been found - Future OAuth( + Future Oauth( String clientID, String scope, String secret, String prompt) async { print('Welcome to Oauth'); bool isAuthOk = false; bool isExpired = true; - final Token tokenStored = await getStoredToken(); final String _token = tokenStored.accessToken; - // Check if the token is not expired + // Check if the token is not expired if (_token != "null") { - globals.displayInfo('token has been stored before! ${tokenStored.accessToken}'); + globals.displayInfo( + 'token has been stored before! ${tokenStored.accessToken}'); isExpired = isTokenExpired(tokenStored); globals.displayInfo('isExpired $isExpired'); } - - // Check if the scope has changed + // Check if the scope has changed if ((tokenStored.scope != scope) || (_token == "null") || isExpired) { // Ask for a new authorization globals.displayInfo('Doing a new authorization'); - isAuthOk = await newAuthorization(clientID, secret, scope, prompt); + isAuthOk = await newAuthorization(clientID, secret, scope, prompt); } else { isAuthOk = true; } @@ -154,20 +155,19 @@ abstract class Auth { return isAuthOk; } - -Future newAuthorization( - String clientID, String secret, String scope, String prompt) async { - + Future newAuthorization( + String clientID, String secret, String scope, String prompt) async { bool returnValue = false; await getStravaCode(clientID, scope, prompt); - var stravaCode = await onCodeReceived.stream.first; + var stravaCode = await onCodeReceived.stream.first; if (stravaCode != null) { var answer = await getStravaToken(clientID, secret, stravaCode); - globals.displayInfo('answer ${answer.expiresAt} , ${answer.accessToken}'); + globals + .displayInfo('answer ${answer.expiresAt} , ${answer.accessToken}'); // Save the token information if (answer.accessToken != null && answer.expiresAt != null) { @@ -180,8 +180,6 @@ Future newAuthorization( return returnValue; } - - Future getStravaToken( String clientID, String secret, String code) async { Token _answer = Token(); @@ -230,14 +228,10 @@ Future newAuthorization( DateTime.fromMillisecondsSinceEpoch(token.expiresAt); return (_expiryDate.isBefore(DateTime.now())); } - Future deAuthorize() async { - String returnValue; - - var _token = await getStoredToken(); - var _header = globals.createHeader(); + var _header = globals.createHeader(); if (_header != null) { final reqDeAuthorize = "https://www.strava.com/oauth/deauthorize"; var rep = await http.post(reqDeAuthorize, headers: _header); diff --git a/lib/API/clubs.dart b/lib/API/clubs.dart index 355e046..7995acb 100644 --- a/lib/API/clubs.dart +++ b/lib/API/clubs.dart @@ -1,20 +1,15 @@ -// clubs.dart +// clubs.dart import 'package:http/http.dart' as http; import 'dart:convert'; import 'dart:async'; - import '../Models/summaryAthlete.dart'; import '../Models/summaryActivity.dart'; import '../Models/club.dart'; import 'globals.dart' as globals; - - abstract class Clubs { - - // Scope needed: // id of the club Future> getClubMembersById(String id) async { @@ -24,7 +19,6 @@ abstract class Clubs { var _header = globals.createHeader(); - if (_header != null) { final reqList = "https://www.strava.com/api/v3/clubs/" + id + @@ -55,8 +49,7 @@ abstract class Clubs { return returnListMembers; } - -Future getClubById(String id) async { + Future getClubById(String id) async { Club returnClub; var _header = globals.createHeader(); @@ -81,7 +74,6 @@ Future getClubById(String id) async { return returnClub; } - Future> getClubActivitiesById(String id) async { List returnSummary; @@ -117,5 +109,4 @@ Future getClubById(String id) async { } return returnSummary; } - } diff --git a/lib/API/constants.dart b/lib/API/constants.dart index 121085c..218f069 100644 --- a/lib/API/constants.dart +++ b/lib/API/constants.dart @@ -1,16 +1,8 @@ // Constants.dart - - - final tokenEndpoint = "https://www.strava.com/oauth/token"; final authorizationEndpoint = "https://www.strava.com/oauth/authorize"; -final clientID = '32212'; +final clientId = '32212'; final String redirectUrl = "http://localhost:8080"; - - - - - diff --git a/lib/API/globals.dart b/lib/API/globals.dart index c2bfb61..32afc4a 100644 --- a/lib/API/globals.dart +++ b/lib/API/globals.dart @@ -1,28 +1,26 @@ -// globals.dart +// globals.dart import 'package:flutter/foundation.dart'; import 'token.dart'; -bool isInDebug = true; // set to true to see debug message in API +bool isInDebug = true; // set to true to see debug message in API -Token token = Token(); // Where the token info is stored when executing APIs +Token token = Token(); // Where the token info is stored when executing APIs // To display debug info in Strava API void displayInfo(String message) { - if (isInDebug) { - var msgToDisplay = '--> Strava_flutter: ' + message; - debugPrint(msgToDisplay); - } - + if (isInDebug) { + var msgToDisplay = '--> Strava_flutter: ' + message; + debugPrint(msgToDisplay); } - +} Map createHeader() { - var _token = token; - if (_token != null) { - return {'Authorization': 'Bearer ${_token.accessToken}'}; - } else { - return {null: null}; - } - } \ No newline at end of file + var _token = token; + if (_token != null) { + return {'Authorization': 'Bearer ${_token.accessToken}'}; + } else { + return {null: null}; + } +} diff --git a/lib/API/strava.dart b/lib/API/strava.dart index ef5053b..f4f2f52 100644 --- a/lib/API/strava.dart +++ b/lib/API/strava.dart @@ -2,7 +2,6 @@ import 'package:http/http.dart' as http; import 'dart:convert'; import 'dart:async'; - import '../Models/fault.dart'; import '../Models/gear.dart'; import '../Models/detailedAthlete.dart'; @@ -16,7 +15,6 @@ import 'Oauth.dart'; import 'upload.dart'; import 'clubs.dart'; - /// Initialize the Strava API /// clientID: ID of your Strava app /// redirectURL: url that will be called after Strava authorize your app @@ -24,8 +22,8 @@ import 'clubs.dart'; /// scope: Strava scope check https://developers.strava.com/docs/oauth-updates/ class Strava with Upload, Auth, Clubs { String secret; - - Strava (bool isInDebug, String secretKey) { + + Strava(bool isInDebug, String secretKey) { globals.isInDebug = isInDebug; secret = secretKey; } @@ -33,19 +31,15 @@ class Strava with Upload, Auth, Clubs { // Strava( this.isInDebug, this.secret); // final bool isInDebug; // final String secret; - - -/// List of statuscode used by Fault -/// To get info to API caller -/// Should have a nicer to do it in Dart! -final statusOk = 0; -final statusInvalidToken = 1; -final statusUnknownError = 2; -final statusHeaderIsEmpty = 3; -final statusNotFound = 4; - - + /// List of statuscode used by Fault + /// To get info to API caller + /// Should have a nicer to do it in Dart! + final statusOk = 0; + final statusInvalidToken = 1; + final statusUnknownError = 2; + final statusHeaderIsEmpty = 3; + final statusNotFound = 4; /// getRunningRacebyId /// @@ -95,7 +89,6 @@ final statusNotFound = 4; if (rep.statusCode == 200) { // globals.displayInfo('List races info ${rep.body}'); final jsonResponse = json.decode(rep.body); - if (jsonResponse != null) { List _listRaces = List(); @@ -103,7 +96,8 @@ final statusNotFound = 4; jsonResponse.forEach((element) { var _race = RunningRace.fromJson(element); _race.fault = Fault(88, ''); - globals.displayInfo('${_race.name} , ${_race.startDateLocal} ${_race.id}'); + globals.displayInfo( + '${_race.name} , ${_race.startDateLocal} ${_race.id}'); _race.fault.statusCode = statusOk; _listRaces.add(_race); }); @@ -117,7 +111,6 @@ final statusNotFound = 4; } } - /// scope: activity:read Future getActivityById(String id) async { DetailedActivity returnActivity = DetailedActivity(); @@ -128,53 +121,51 @@ final statusNotFound = 4; if (_header != null) { final reqActivity = "https://www.strava.com/api/v3/activities/" + - id + '?include_all_efforts=true'; + id + + '?include_all_efforts=true'; var rep = await http.get(reqActivity, headers: _header); - switch (rep.statusCode) { - case 200: { - - globals.displayInfo(rep.statusCode.toString()); - globals.displayInfo('Activity info ${rep.body}'); - final jsonResponse = json.decode(rep.body); + switch (rep.statusCode) { + case 200: + { + globals.displayInfo(rep.statusCode.toString()); + globals.displayInfo('Activity info ${rep.body}'); + final jsonResponse = json.decode(rep.body); - + DetailedActivity _activity = + DetailedActivity.fromJson(jsonResponse); + _activity.fault = Fault(88, ''); + _activity.fault.statusCode = statusOk; + globals.displayInfo(_activity.name); - DetailedActivity _activity = DetailedActivity.fromJson(jsonResponse); - _activity.fault = Fault(88, ''); - _activity.fault.statusCode = statusOk; - globals.displayInfo(_activity.name); + returnActivity = _activity; + break; + } - returnActivity = _activity; - break; - } + case 404: + { + globals.displayInfo('Activity not found'); + returnActivity.fault.statusCode = statusNotFound; + } + break; - case 404: { - globals.displayInfo('Activity not found'); - returnActivity.fault.statusCode = statusNotFound; - } - break; - - default: { - returnActivity.fault.statusCode = statusUnknownError; + default: + { + returnActivity.fault.statusCode = statusUnknownError; - break; - } + break; + } - // add error 404 activity not found + // add error 404 activity not found + } + return returnActivity; } - return returnActivity; - } } - - - - /// Scope needed: any /// Give answer only if id is related to logged athlete - /// + /// Future getGearById(String id) async { Gear returnGear = Gear(); @@ -182,13 +173,13 @@ final statusNotFound = 4; var _header = globals.createHeader(); - if (_header != null) { final reqGear = 'https://www.strava.com/api/v3/gear/' + id; var rep = await http.get(reqGear, headers: _header); switch (rep.statusCode) { - case 200: { + case 200: + { globals.displayInfo(rep.statusCode.toString()); globals.displayInfo(' ${rep.body}'); final jsonResponse = json.decode(rep.body); @@ -198,18 +189,20 @@ final statusNotFound = 4; globals.displayInfo(_gear.description); _gear.fault.statusCode = statusOk; returnGear = _gear; - } - break; + } + break; - case 401: { + case 401: + { returnGear.fault.statusCode = statusInvalidToken; - } - break; + } + break; - default: { + default: + { returnGear.fault.statusCode = statusUnknownError; - } - break; + } + break; } } else { returnGear.fault.statusCode = statusHeaderIsEmpty; @@ -218,9 +211,9 @@ final statusNotFound = 4; return returnGear; } - /// + /// /// scope needed: profile:read_all scope - /// + /// /// return: see status value in strava class Future getLoggedInAthlete() async { DetailedAthlete returnAthlete = DetailedAthlete(); @@ -233,32 +226,36 @@ final statusNotFound = 4; var rep = await http.get(reqAthlete, headers: _header); switch (rep.statusCode) { - case 200: { + case 200: + { globals.displayInfo(rep.statusCode.toString()); globals.displayInfo('Athlete info ${rep.body}'); final jsonResponse = json.decode(rep.body); DetailedAthlete _athlete = DetailedAthlete.fromJson(jsonResponse); - globals.displayInfo(' athlete ${_athlete.firstname}, ${_athlete.lastname}'); + globals.displayInfo( + ' athlete ${_athlete.firstname}, ${_athlete.lastname}'); _athlete.fault = Fault(statusOk, 'getLoggedInAthlete done'); returnAthlete = _athlete; - } - break; + } + break; - case 401:{ + case 401: + { returnAthlete.fault = Fault(statusInvalidToken, 'invalid token'); globals.displayInfo( 'problem in getLoggedInAthlete request , ${returnAthlete.fault.statusCode} ${rep.body}'); - } - break; + } + break; - default: { + default: + { returnAthlete.fault = Fault(statusUnknownError, 'Unknown Error'); globals.displayInfo('problem in getLoggedInAthlete, unknown error'); - } - break; + } + break; } } @@ -277,7 +274,8 @@ final statusNotFound = 4; var rep = await http.get(reqAthlete, headers: _header); switch (rep.statusCode) { - case 200: { + case 200: + { globals.displayInfo(rep.statusCode.toString()); globals.displayInfo('Zone info ${rep.body}'); final jsonResponse = json.decode(rep.body); @@ -297,18 +295,20 @@ final statusNotFound = 4; } break; - case 401: { + case 401: + { // returnAthlete.errorCode = ErrorCode.tokenIsInvalid; print('problem in getLoggedInAthlete request , ${rep.body}'); - } - break; + } + break; - default:{ + default: + { // returnAthlete.errorCode = ErrorCode.unknownError; print('problem in getLoggedInAthlete, unknown error'); - } - break; + } + break; } } @@ -327,7 +327,8 @@ final statusNotFound = 4; var rep = await http.put(reqAthlete, headers: _header); switch (rep.statusCode) { - case 200:{ + case 200: + { globals.displayInfo(rep.statusCode.toString()); globals.displayInfo('Athlete info ${rep.body}'); final jsonResponse = json.decode(rep.body); @@ -337,23 +338,25 @@ final statusNotFound = 4; _athlete.fault.statusCode = statusOk; returnAthlete = _athlete; - } - break; + } + break; - case 401: { + case 401: + { returnAthlete.fault.statusCode = statusInvalidToken; globals.displayInfo( 'problem in updateLoggedInAthleteequest , ${returnAthlete.fault.statusCode} ${rep.body}'); - } - break; + } + break; - default: { + default: + { returnAthlete.fault.statusCode = statusUnknownError; globals.displayInfo( 'problem in updateLoggedInAthlete, unknown error ${rep.body}'); - } - break; + } + break; } } @@ -361,7 +364,7 @@ final statusNotFound = 4; } /// For the moment, only 1 page is handled - /// + /// Future getStats(int id) async { Stats returnStats; @@ -373,30 +376,33 @@ final statusNotFound = 4; "/stats?page=&per_page=;"; var rep = await http.get(reqStats, headers: _header); - switch (rep.statusCode) { - case 200: { - globals.displayInfo('stats info ${rep.body}'); - final jsonResponse = json.decode(rep.body); + switch (rep.statusCode) { + case 200: + { + globals.displayInfo('stats info ${rep.body}'); + final jsonResponse = json.decode(rep.body); - Stats _stats = Stats.fromJson(jsonResponse); - _stats.fault =Fault(88, ''); - _stats.fault.statusCode = statusOk; - returnStats = _stats; - } - break; - - // case 400: - - default: { - returnStats.fault.statusCode = statusUnknownError; - globals.displayInfo('problem in getStats request, {rep.statusCode}'); + Stats _stats = Stats.fromJson(jsonResponse); + _stats.fault = Fault(88, ''); + _stats.fault.statusCode = statusOk; + returnStats = _stats; + } + break; + + // case 400: + + default: + { + returnStats.fault.statusCode = statusUnknownError; + globals + .displayInfo('problem in getStats request, {rep.statusCode}'); + } + break; } - break; - } - return returnStats; + return returnStats; + } } -} void dispose() { onCodeReceived.close(); diff --git a/lib/API/token.dart b/lib/API/token.dart index 3a293ab..966692c 100644 --- a/lib/API/token.dart +++ b/lib/API/token.dart @@ -36,7 +36,6 @@ class Token { return model; } - // NOT used for the moment //------------------------- Future getStoredToken() async { @@ -57,6 +56,5 @@ class Token { localToken.scope = null; } return localToken; - } } diff --git a/lib/API/upload.dart b/lib/API/upload.dart index 72af74b..f2f69fb 100644 --- a/lib/API/upload.dart +++ b/lib/API/upload.dart @@ -4,31 +4,24 @@ import 'dart:async'; import 'dart:convert'; - import 'package:http/http.dart' as http; import '../Models/fault.dart'; import '../Models/uploadActivity.dart'; - - abstract class Upload { - Future uploadActivity(String name, String description, String fileUrl, String fileType, String accessToken) async { - - print('Starting to upload activity'); // To check if the activity has been uploaded successfully // No numeric error code for the moment given by Strava - final String ready = "Your activity is ready."; - final String deleted = "The created activity has been deleted."; - final String error = "There was an error processing your activity."; - final String processed = "Your activity is still being processed."; - final String notFound = 'Not Found'; + final String ready = "Your activity is ready."; + final String deleted = "The created activity has been deleted."; + final String error = "There was an error processing your activity."; + final String processed = "Your activity is still being processed."; + final String notFound = 'Not Found'; - final postUri = Uri.parse('https://www.strava.com/api/v3/uploads'); StreamController onUploadPending = StreamController(); @@ -75,43 +68,35 @@ abstract class Upload { onUploadPending.add(idUpload); }); - String reqCheckUpgrade = - 'https://www.strava.com/api/v3/uploads/'; + String reqCheckUpgrade = 'https://www.strava.com/api/v3/uploads/'; onUploadPending.stream.listen((id) async { - reqCheckUpgrade =reqCheckUpgrade + id.toString(); + reqCheckUpgrade = reqCheckUpgrade + id.toString(); var resp = await http.get(reqCheckUpgrade, headers: header); print('check status ${resp.reasonPhrase}'); - if (resp.reasonPhrase == ready) { print('---> Activity succesfully uploaded'); onUploadPending.close(); - } + } - if ((resp.reasonPhrase == notFound) || (resp.reasonPhrase - == error)) { + if ((resp.reasonPhrase == notFound) || (resp.reasonPhrase == error)) { print('---> Error while checking status upload'); onUploadPending.close(); - } + } if (resp.reasonPhrase == deleted) { print('---> Activity deleted'); onUploadPending.close(); } - - if (resp.reasonPhrase == processed ) { + + if (resp.reasonPhrase == processed) { print('---> try another time'); // wait 2 sec before checking again status Timer(Duration(seconds: 2), () => onUploadPending.add(id)); - } }); } return fault; } - - - - } diff --git a/lib/Models/club.dart b/lib/Models/club.dart index 4515b82..9f4f914 100644 --- a/lib/Models/club.dart +++ b/lib/Models/club.dart @@ -1,4 +1,4 @@ -// Club +// Club import 'fault.dart'; @@ -54,7 +54,8 @@ class Club { this.clubType, this.postCount, this.ownerId, - this.followingCount}): fault = Fault(88, ''); + this.followingCount}) + : fault = Fault(88, ''); Club.fromJson(Map json) { id = json['id']; @@ -112,4 +113,3 @@ class Club { return data; } } - diff --git a/lib/Models/detailedActivity.dart b/lib/Models/detailedActivity.dart index 1f6b3b0..52d32d3 100644 --- a/lib/Models/detailedActivity.dart +++ b/lib/Models/detailedActivity.dart @@ -1,9 +1,8 @@ -// Activity +// Activity import 'gear.dart'; import 'fault.dart'; - class DetailedActivity { Fault fault; int id; @@ -132,8 +131,8 @@ class DetailedActivity { this.deviceName, this.embedToken, this.segmentLeaderboardOptOut, - this.leaderboardOptOut}): fault = Fault(88, ''); - + this.leaderboardOptOut}) + : fault = Fault(88, ''); DetailedActivity.fromJson(Map json) { id = json['id']; @@ -371,7 +370,7 @@ class SegmentEfforts { Segment segment; int komRank; int prRank; - + List achievements; bool hidden; @@ -420,7 +419,7 @@ class SegmentEfforts { json['segment'] != null ? new Segment.fromJson(json['segment']) : null; komRank = json['kom_rank']; prRank = json['pr_rank']; - /**** + /**** if (json['achievements'] != null) { achievements = new List(); json['achievements'].forEach((v) { @@ -728,7 +727,6 @@ class Laps { } } - class Photos { Primary primary; bool usePrimaryPhoto; @@ -824,7 +822,4 @@ class HighlightedKudosers { data['show_name'] = this.showName; return data; } - - - } diff --git a/lib/Models/detailedAthlete.dart b/lib/Models/detailedAthlete.dart index 9748c26..6004cbd 100644 --- a/lib/Models/detailedAthlete.dart +++ b/lib/Models/detailedAthlete.dart @@ -37,7 +37,7 @@ class DetailedAthlete { List bikes; List shoes; - DetailedAthlete ( + DetailedAthlete( {Fault fault, this.id, this.username, @@ -66,9 +66,10 @@ class DetailedAthlete { this.ftp, this.weight, this.bikes, - this.shoes}): fault = Fault(99, ''); + this.shoes}) + : fault = Fault(99, ''); - DetailedAthlete .fromJson(Map json) { + DetailedAthlete.fromJson(Map json) { id = json['id']; username = json['username']; resourceState = json['resource_state']; @@ -103,7 +104,7 @@ class DetailedAthlete { ftp = json['ftp']; weight = json['weight']; if (json['bikes'] != null) { - bikes = List(); + bikes = List(); json['bikes'].forEach((v) { bikes.add(Bikes.fromJson(v)); }); diff --git a/lib/Models/fault.dart b/lib/Models/fault.dart index 0234922..5b1a783 100644 --- a/lib/Models/fault.dart +++ b/lib/Models/fault.dart @@ -3,4 +3,4 @@ class Fault { String message; Fault(this.statusCode, this.message); -} \ No newline at end of file +} diff --git a/lib/Models/gear.dart b/lib/Models/gear.dart index dc95eeb..8dec774 100644 --- a/lib/Models/gear.dart +++ b/lib/Models/gear.dart @@ -2,7 +2,6 @@ import 'fault.dart'; - class Gear { Fault fault; String id; @@ -23,7 +22,8 @@ class Gear { this.brandName, this.modelName, this.frameType, - this.description}): fault = Fault(88, ''); + this.description}) + : fault = Fault(88, ''); Gear.fromJson(Map json) { id = json['id']; diff --git a/lib/Models/runningRace.dart b/lib/Models/runningRace.dart index 0e0717e..e60484d 100644 --- a/lib/Models/runningRace.dart +++ b/lib/Models/runningRace.dart @@ -4,7 +4,7 @@ import 'fault.dart'; // It seems that routeIds is missing class RunningRace { - Fault fault; + Fault fault; String country; // List routeIds; int runningRaceType; @@ -19,8 +19,7 @@ class RunningRace { String url; RunningRace( - { - Fault fault, + {Fault fault, this.country, // this.routeIds, this.runningRaceType, @@ -32,7 +31,8 @@ class RunningRace { this.measurementPreference, this.id, this.state, - this.url}): fault = Fault(99, ''); + this.url}) + : fault = Fault(99, ''); RunningRace.fromJson(Map json) { country = json['country']; diff --git a/lib/Models/startSegment.dart b/lib/Models/startSegment.dart deleted file mode 100644 index b938ef7..0000000 --- a/lib/Models/startSegment.dart +++ /dev/null @@ -1,184 +0,0 @@ -class StarSegment { - int id; - int resourceState; - String name; - String activityType; - double distance; - double averageGrade; - double maximumGrade; - double elevationHigh; - double elevationLow; - List startLatlng; - List endLatlng; - double startLatitude; - double startLongitude; - double endLatitude; - double endLongitude; - int climbCategory; - String city; - String state; - String country; - bool private; - bool hazardous; - bool starred; - String createdAt; - String updatedAt; - double totalElevationGain; - // Map carte; - int effortCount; - int athleteCount; - int starCount; - AthleteSegmentStats athleteSegmentStats; - - StarSegment( - {this.id, - this.resourceState, - this.name, - this.activityType, - this.distance, - this.averageGrade, - this.maximumGrade, - this.elevationHigh, - this.elevationLow, - this.startLatlng, - this.endLatlng, - this.startLatitude, - this.startLongitude, - this.endLatitude, - this.endLongitude, - this.climbCategory, - this.city, - this.state, - this.country, - this.private, - this.hazardous, - this.starred, - this.createdAt, - this.updatedAt, - this.totalElevationGain, - // this.carte, - this.effortCount, - this.athleteCount, - this.starCount, - this.athleteSegmentStats}); - - StarSegment.fromJson(Map json) { - id = json['id']; - resourceState = json['resource_state']; - name = json['name']; - activityType = json['activity_type']; - distance = json['distance']; - averageGrade = json['average_grade']; - maximumGrade = json['maximum_grade']; - elevationHigh = json['elevation_high']; - elevationLow = json['elevation_low']; - startLatlng = json['start_latlng'].cast(); - endLatlng = json['end_latlng'].cast(); - startLatitude = json['start_latitude']; - startLongitude = json['start_longitude']; - endLatitude = json['end_latitude']; - endLongitude = json['end_longitude']; - climbCategory = json['climb_category']; - city = json['city']; - state = json['state']; - country = json['country']; - private = json['private']; - hazardous = json['hazardous']; - starred = json['starred']; - createdAt = json['created_at']; - updatedAt = json['updated_at']; - totalElevationGain = json['total_elevation_gain']; - // carte = json['map'] != null ? new Map.fromJson(json['map']) : null; - effortCount = json['effort_count']; - athleteCount = json['athlete_count']; - starCount = json['star_count']; - athleteSegmentStats = json['athlete_segment_stats'] != null - ? new AthleteSegmentStats.fromJson(json['athlete_segment_stats']) - : null; - } - - Map toJson() { - final Map data = new Map(); - data['id'] = this.id; - data['resource_state'] = this.resourceState; - data['name'] = this.name; - data['activity_type'] = this.activityType; - data['distance'] = this.distance; - data['average_grade'] = this.averageGrade; - data['maximum_grade'] = this.maximumGrade; - data['elevation_high'] = this.elevationHigh; - data['elevation_low'] = this.elevationLow; - data['start_latlng'] = this.startLatlng; - data['end_latlng'] = this.endLatlng; - data['start_latitude'] = this.startLatitude; - data['start_longitude'] = this.startLongitude; - data['end_latitude'] = this.endLatitude; - data['end_longitude'] = this.endLongitude; - data['climb_category'] = this.climbCategory; - data['city'] = this.city; - data['state'] = this.state; - data['country'] = this.country; - data['private'] = this.private; - data['hazardous'] = this.hazardous; - data['starred'] = this.starred; - data['created_at'] = this.createdAt; - data['updated_at'] = this.updatedAt; - data['total_elevation_gain'] = this.totalElevationGain; - if (this.map != null) { - data['map'] = this.map.toJson(); - } - data['effort_count'] = this.effortCount; - data['athlete_count'] = this.athleteCount; - data['star_count'] = this.starCount; - if (this.athleteSegmentStats != null) { - data['athlete_segment_stats'] = this.athleteSegmentStats.toJson(); - } - return data; - } -} - -/**** -class Map { - String id; - String polyline; - int resourceState; - - Map({this.id, this.polyline, this.resourceState}); - - Map.fromJson(Map json) { - id = json['id']; - polyline = json['polyline']; - resourceState = json['resource_state']; - } - - Map toJson() { - final Map data = new Map(); - data['id'] = this.id; - data['polyline'] = this.polyline; - data['resource_state'] = this.resourceState; - return data; - } -} -****/ - -class AthleteSegmentStats { - int prElapsedTime; - String prDate; - int effortCount; - - AthleteSegmentStats({this.prElapsedTime, this.prDate, this.effortCount}); - - AthleteSegmentStats.fromJson(Map json) { - prElapsedTime = json['pr_elapsed_time']; - prDate = json['pr_date']; - effortCount = json['effort_count']; - } - - Map toJson() { - final Map data = new Map(); - data['pr_elapsed_time'] = this.prElapsedTime; - data['pr_date'] = this.prDate; - data['effort_count'] = this.effortCount; - return data; - } -} diff --git a/lib/Models/stats.dart b/lib/Models/stats.dart index 801bcf5..6354c2f 100644 --- a/lib/Models/stats.dart +++ b/lib/Models/stats.dart @@ -28,24 +28,43 @@ class Stats { this.biggestClimbElevationGain, this.ytdRideTotals, this.allRideTotals, - this.ytdRunTotals}): fault = Fault(88, ''); + this.ytdRunTotals}) + : fault = Fault(88, ''); Stats.fromJson(Map json) { - recentRunTotals = json['recent_run_totals'] != null ? StatsTotals.fromJson(json['recent_run_totals']) : null; - allRunTotals = json['all_run_totals'] != null ? ActivityTotals.fromJson(json['all_run_totals']) : null; - recentSwimTotals = json['recent_swim_totals'] != null ? StatsTotals.fromJson(json['recent_swim_totals']) : null; + recentRunTotals = json['recent_run_totals'] != null + ? StatsTotals.fromJson(json['recent_run_totals']) + : null; + allRunTotals = json['all_run_totals'] != null + ? ActivityTotals.fromJson(json['all_run_totals']) + : null; + recentSwimTotals = json['recent_swim_totals'] != null + ? StatsTotals.fromJson(json['recent_swim_totals']) + : null; biggestRideDistance = json['biggest_ride_distance']; - ytdSwimTotals = json['ytd_swim_totals'] != null ? ActivityTotals.fromJson(json['ytd_swim_totals']) : null; + ytdSwimTotals = json['ytd_swim_totals'] != null + ? ActivityTotals.fromJson(json['ytd_swim_totals']) + : null; - allSwimTotals = json['all_swim_totals'] != null ? ActivityTotals.fromJson(json['all_swim_totals']) : null; - - recentRideTotals = json['recent_ride_totals'] != null ? StatsTotals.fromJson(json['recent_ride_totals']): null; + allSwimTotals = json['all_swim_totals'] != null + ? ActivityTotals.fromJson(json['all_swim_totals']) + : null; - biggestClimbElevationGain = json['biggest_climb_elevation_gain']; - ytdRideTotals = json['ytd_ride_totals'] != null ? ActivityTotals.fromJson(json['ytd_ride_totals']) : null; + recentRideTotals = json['recent_ride_totals'] != null + ? StatsTotals.fromJson(json['recent_ride_totals']) + : null; - allRideTotals = json['all_ride_totals'] != null ? ActivityTotals.fromJson(json['all_ride_totals']) : null; - ytdRunTotals = json['ytd_run_totals'] != null ? ActivityTotals.fromJson(json['ytd_run_totals']) : null; + biggestClimbElevationGain = json['biggest_climb_elevation_gain']; + ytdRideTotals = json['ytd_ride_totals'] != null + ? ActivityTotals.fromJson(json['ytd_ride_totals']) + : null; + + allRideTotals = json['all_ride_totals'] != null + ? ActivityTotals.fromJson(json['all_ride_totals']) + : null; + ytdRunTotals = json['ytd_run_totals'] != null + ? ActivityTotals.fromJson(json['ytd_run_totals']) + : null; } Map toJson() { @@ -93,7 +112,7 @@ class StatsTotals { } Map toJson() { - final Map data = Map(); + final Map data = Map(); data['distance'] = this.distance; data['achievement_count'] = this.achievementCount; data['count'] = this.count; @@ -104,9 +123,7 @@ class StatsTotals { } } - - - class ActivityTotals { +class ActivityTotals { int distance; int achievementCount; int count; @@ -141,4 +158,4 @@ class StatsTotals { data['moving_time'] = this.movingTime; return data; } -} \ No newline at end of file +} diff --git a/lib/Models/summaryActivity.dart b/lib/Models/summaryActivity.dart index ec37409..536fc88 100644 --- a/lib/Models/summaryActivity.dart +++ b/lib/Models/summaryActivity.dart @@ -2,7 +2,6 @@ import 'fault.dart'; - class SummaryActivity { Fault fault; int id; @@ -81,4 +80,3 @@ class Athlete { return data; } } - diff --git a/lib/Models/uploadActivity.dart b/lib/Models/uploadActivity.dart index adba631..1b1bade 100644 --- a/lib/Models/uploadActivity.dart +++ b/lib/Models/uploadActivity.dart @@ -29,7 +29,6 @@ class UploadActivity { } } - class ResponseUploadActivity { int id; String externalId; @@ -37,8 +36,8 @@ class ResponseUploadActivity { String status; int activityId; - - ResponseUploadActivity(this.id, this.externalId, this.error, this.status, this.activityId); + ResponseUploadActivity( + this.id, this.externalId, this.error, this.status, this.activityId); ResponseUploadActivity.fromJson(Map json) { id = json['id']; @@ -47,7 +46,4 @@ class ResponseUploadActivity { status = json['status']; activityId = json['activity_id']; } - - - } diff --git a/lib/Models/zone.dart b/lib/Models/zone.dart index 93d9972..d51058b 100644 --- a/lib/Models/zone.dart +++ b/lib/Models/zone.dart @@ -1,7 +1,6 @@ // zones import 'fault.dart'; - class Zone { Fault fault; List distributionBuckets; diff --git a/pubspec.yaml b/pubspec.yaml index 99efcdb..4ebfdfd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: strava_flutter -description: Flutter/Dart code to access Strava v3 API -version: 1.0.1+2 -author: Patrick FINKELSTEIN +description: Flutter/Dart code to access Strava v3 API including new authentication process (with expired date) +version: 1.0.2+3 +author: Patrick FINK homepage: https://github.com/BirdyF/strava_flutter environment: