Skip to content

Commit f5631dc

Browse files
author
Patrick FINKELSTEIN
committed
Build 3 modifications to increase pub score
1 parent 4eb189f commit f5631dc

23 files changed

+239
-451
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# strava_flutter specific
22
secret.dart
33
todo.txt
4+
# temp
5+
starSegment.dart
46

57
.DS_Store
68
.dart_tool/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ And Javier for https://javiercbk.github.io/json_to_dart/
6868

6969

7070
License:
71-
strava-flutter is provided under a MIT License. Copyright (c) 2019 Patrick FINKELSTEIN
71+
strava-flutter is provided under a MIT License. Copyright (c) 2019 Patrick FINK

example/lib/examples.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import 'package:strava_flutter/Models/summaryActivity.dart';
5151

5252
bool isAuthOk = false;
5353

54-
isAuthOk = await strava.OAuth(clientID, 'activity:write', secret, 'auto');
54+
isAuthOk = await strava.Oauth(clientId, 'activity:write', secret, 'auto');
5555

5656
print('---> Authentication result: $isAuthOk');
5757

@@ -87,7 +87,7 @@ void example(String secret) async {
8787
secret);
8888
final prompt = 'auto';
8989

90-
isAuthOk = await strava.OAuth(clientID, 'activity:write,profile:read_all', secret, prompt);
90+
isAuthOk = await strava.Oauth(clientId, 'activity:write,profile:read_all', secret, prompt);
9191

9292
if (isAuthOk) {
9393

example/test/widget_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'package:flutter_test/flutter_test.dart';
1212
void main() {
1313
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
1414
// Build our app and trigger a frame.
15-
await tester.pumpWidget(MyApp());
15+
// await tester.pumpWidget(MyApp());
1616

1717
// Verify that our counter starts at 0.
1818
expect(find.text('0'), findsOneWidget);

lib/API/Oauth.dart

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ abstract class Auth {
2828
// Save also in globals to get direct access
2929
globals.token.accessToken = token;
3030
globals.token.scope = scope;
31-
globals.token.expiresAt =expire;
31+
globals.token.expiresAt = expire;
3232

3333
globals.displayInfo('token saved!!!');
3434
}
@@ -44,10 +44,10 @@ abstract class Auth {
4444
localToken.expiresAt = prefs.getInt('expire');
4545
localToken.scope = prefs.getString('scope');
4646

47-
// load the data in globals
48-
globals.token.accessToken =localToken.accessToken;
49-
globals.token.expiresAt =localToken.expiresAt;
50-
globals.token.scope =localToken.scope;
47+
// load the data in globals
48+
globals.token.accessToken = localToken.accessToken;
49+
globals.token.expiresAt = localToken.expiresAt;
50+
globals.token.scope = localToken.scope;
5151
} catch (error) {
5252
globals.displayInfo('Error getting the key');
5353
localToken.accessToken = null;
@@ -58,18 +58,20 @@ abstract class Auth {
5858
if (localToken.expiresAt != null) {
5959
var dateExpired =
6060
DateTime.fromMillisecondsSinceEpoch(localToken.expiresAt);
61-
var _disp = dateExpired.day.toString() + '/' +
62-
dateExpired.month.toString() + ' ' +
63-
dateExpired.hour.toString() + 'hours';
64-
65-
globals.displayInfo('stored token ${localToken.accessToken} expires: $_disp ');
61+
var _disp = dateExpired.day.toString() +
62+
'/' +
63+
dateExpired.month.toString() +
64+
' ' +
65+
dateExpired.hour.toString() +
66+
'hours';
67+
68+
globals.displayInfo(
69+
'stored token ${localToken.accessToken} expires: $_disp ');
6670
}
6771

6872
return (localToken);
6973
}
7074

71-
72-
7375
// Get the code from Strava server
7476
Future<void> getStravaCode(
7577
String clientID, String scope, String prompt) async {
@@ -117,57 +119,55 @@ abstract class Auth {
117119
});
118120
}
119121

120-
/// Do Strava Authentication.
121-
///
122+
/// Do Strava Authentication.
123+
///
122124
/// Do not do/show the Strava login if a token has been stored previously
123125
/// and is not expired
124126
/// Do/show the Strava login if the scope has been changed since last storage of the token
125127
/// return true if no problem in authentication has been found
126-
Future<bool> OAuth(
128+
Future<bool> Oauth(
127129
String clientID, String scope, String secret, String prompt) async {
128130
print('Welcome to Oauth');
129131
bool isAuthOk = false;
130132
bool isExpired = true;
131133

132-
133134
final Token tokenStored = await getStoredToken();
134135
final String _token = tokenStored.accessToken;
135136

136-
// Check if the token is not expired
137+
// Check if the token is not expired
137138
if (_token != "null") {
138-
globals.displayInfo('token has been stored before! ${tokenStored.accessToken}');
139+
globals.displayInfo(
140+
'token has been stored before! ${tokenStored.accessToken}');
139141

140142
isExpired = isTokenExpired(tokenStored);
141143
globals.displayInfo('isExpired $isExpired');
142144
}
143145

144-
145-
// Check if the scope has changed
146+
// Check if the scope has changed
146147
if ((tokenStored.scope != scope) || (_token == "null") || isExpired) {
147148
// Ask for a new authorization
148149
globals.displayInfo('Doing a new authorization');
149-
isAuthOk = await newAuthorization(clientID, secret, scope, prompt);
150+
isAuthOk = await newAuthorization(clientID, secret, scope, prompt);
150151
} else {
151152
isAuthOk = true;
152153
}
153154

154155
return isAuthOk;
155156
}
156157

157-
158-
Future<bool> newAuthorization(
159-
String clientID, String secret, String scope, String prompt) async {
160-
158+
Future<bool> newAuthorization(
159+
String clientID, String secret, String scope, String prompt) async {
161160
bool returnValue = false;
162161

163162
await getStravaCode(clientID, scope, prompt);
164163

165-
var stravaCode = await onCodeReceived.stream.first;
164+
var stravaCode = await onCodeReceived.stream.first;
166165

167166
if (stravaCode != null) {
168167
var answer = await getStravaToken(clientID, secret, stravaCode);
169168

170-
globals.displayInfo('answer ${answer.expiresAt} , ${answer.accessToken}');
169+
globals
170+
.displayInfo('answer ${answer.expiresAt} , ${answer.accessToken}');
171171

172172
// Save the token information
173173
if (answer.accessToken != null && answer.expiresAt != null) {
@@ -180,8 +180,6 @@ Future<bool> newAuthorization(
180180
return returnValue;
181181
}
182182

183-
184-
185183
Future<Token> getStravaToken(
186184
String clientID, String secret, String code) async {
187185
Token _answer = Token();
@@ -230,14 +228,10 @@ Future<bool> newAuthorization(
230228
DateTime.fromMillisecondsSinceEpoch(token.expiresAt);
231229
return (_expiryDate.isBefore(DateTime.now()));
232230
}
233-
234231

235232
Future<void> deAuthorize() async {
236-
String returnValue;
237-
238-
var _token = await getStoredToken();
239233

240-
var _header = globals.createHeader();
234+
var _header = globals.createHeader();
241235
if (_header != null) {
242236
final reqDeAuthorize = "https://www.strava.com/oauth/deauthorize";
243237
var rep = await http.post(reqDeAuthorize, headers: _header);

lib/API/clubs.dart

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
// clubs.dart
1+
// clubs.dart
22
import 'package:http/http.dart' as http;
33
import 'dart:convert';
44
import 'dart:async';
55

6-
76
import '../Models/summaryAthlete.dart';
87
import '../Models/summaryActivity.dart';
98
import '../Models/club.dart';
109

1110
import 'globals.dart' as globals;
1211

13-
14-
1512
abstract class Clubs {
16-
17-
1813
// Scope needed:
1914
// id of the club
2015
Future<List<SummaryAthlete>> getClubMembersById(String id) async {
@@ -24,7 +19,6 @@ abstract class Clubs {
2419

2520
var _header = globals.createHeader();
2621

27-
2822
if (_header != null) {
2923
final reqList = "https://www.strava.com/api/v3/clubs/" +
3024
id +
@@ -55,8 +49,7 @@ abstract class Clubs {
5549
return returnListMembers;
5650
}
5751

58-
59-
Future<Club> getClubById(String id) async {
52+
Future<Club> getClubById(String id) async {
6053
Club returnClub;
6154

6255
var _header = globals.createHeader();
@@ -81,7 +74,6 @@ Future<Club> getClubById(String id) async {
8174
return returnClub;
8275
}
8376

84-
8577
Future<List<SummaryActivity>> getClubActivitiesById(String id) async {
8678
List<SummaryActivity> returnSummary;
8779

@@ -117,5 +109,4 @@ Future<Club> getClubById(String id) async {
117109
}
118110
return returnSummary;
119111
}
120-
121112
}

lib/API/constants.dart

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
// Constants.dart
22

3-
4-
5-
63
final tokenEndpoint = "https://www.strava.com/oauth/token";
74
final authorizationEndpoint = "https://www.strava.com/oauth/authorize";
85

9-
final clientID = '32212';
6+
final clientId = '32212';
107

118
final String redirectUrl = "http://localhost:8080";
12-
13-
14-
15-
16-

lib/API/globals.dart

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
// globals.dart
1+
// globals.dart
22

33
import 'package:flutter/foundation.dart';
44

55
import 'token.dart';
66

7-
bool isInDebug = true; // set to true to see debug message in API
7+
bool isInDebug = true; // set to true to see debug message in API
88

9-
Token token = Token(); // Where the token info is stored when executing APIs
9+
Token token = Token(); // Where the token info is stored when executing APIs
1010

1111
// To display debug info in Strava API
1212
void displayInfo(String message) {
13-
if (isInDebug) {
14-
var msgToDisplay = '--> Strava_flutter: ' + message;
15-
debugPrint(msgToDisplay);
16-
}
17-
13+
if (isInDebug) {
14+
var msgToDisplay = '--> Strava_flutter: ' + message;
15+
debugPrint(msgToDisplay);
1816
}
19-
17+
}
2018

2119
Map<String, String> createHeader() {
22-
var _token = token;
23-
if (_token != null) {
24-
return {'Authorization': 'Bearer ${_token.accessToken}'};
25-
} else {
26-
return {null: null};
27-
}
28-
}
20+
var _token = token;
21+
if (_token != null) {
22+
return {'Authorization': 'Bearer ${_token.accessToken}'};
23+
} else {
24+
return {null: null};
25+
}
26+
}

0 commit comments

Comments
 (0)