Skip to content

Commit dca12de

Browse files
author
Patrick FINKELSTEIN
committed
added error code using Fault class
1 parent d318544 commit dca12de

14 files changed

Lines changed: 427 additions & 353 deletions

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ https://developers.strava.com/docs/authentication/
88

99

1010

11-
API currently supported in addition to authentication process:
12-
work in progress
11+
API currently supported:
12+
13+
- authorize
14+
- token
15+
- deauthorize
16+
1317

1418
- getLoggedInAthlete
1519
- updateLoggedInAthlete (scope profile:write)
@@ -20,24 +24,27 @@ work in progress
2024
- getClubMembersById (no need to be member of the club)
2125
- getRunningRaces
2226
- getRunningRaceById
27+
- uploadActivity (including getUploadById)
2328

2429

2530

26-
How to use:
27-
28-
Please check examples.dart for the moment
29-
30-
https://github.com/BirdyF/strava_flutter/blob/master/example/lib/examples.dart
31-
3231

3332
How to use it
33+
3434
1 - Create a file secret.dart to put the secret shown on Strava settings related to your app
3535
https://www.strava.com/settings/api
3636

3737
2 - In constants.dart put your appID in clientID
3838

3939
3 - To see debug info in Strava API, set isInDebug to true in globals.dart
4040

41+
4 - Please check examples.dart for the moment
42+
43+
https://github.com/BirdyF/strava_flutter/blob/master/example/lib/examples.dart
44+
45+
46+
If you have any problem and need an API not yet implemented please post an new issue
47+
4148

4249
Tested on:
4350
- Android 4.4.2 , 4.4.23

example/README.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

example/lib/examples.dart

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// examples to use strava_flutter
1+
// Examples to use strava_flutter
22
import 'dart:async';
33
import 'dart:io';
44
import 'package:flutter/services.dart' show rootBundle;
@@ -45,14 +45,14 @@ import 'package:strava_flutter/Models/summaryActivity.dart';
4545

4646

4747
// Do authentication with the right scope
48-
final strava = Strava(
48+
final strava = Strava(true, // To get display info in API
4949
secret, 'auto');
5050

5151
bool isAuthOk = false;
5252

5353
isAuthOk = await strava.OAuth(clientID, "http://localhost:8080", 'activity:write', secret);
5454

55-
print('---> thats it!!, $isAuthOk');
55+
print('---> Authentication result: $isAuthOk');
5656

5757
Token tokenStored = await strava.getStoredToken();
5858

@@ -72,54 +72,89 @@ import 'package:strava_flutter/Models/summaryActivity.dart';
7272
}
7373

7474

75-
76-
75+
///
76+
/// Example of dart code to use Strava API
77+
///
78+
/// set isInDebug to true in strava init to see the debug info
7779
void example(String secret) async {
7880

7981
bool isAuthOk = false;
8082

81-
final strava = Strava(
83+
final strava = Strava(true,
8284
secret, 'auto');
8385

84-
isAuthOk = await strava.OAuth(clientID, "http://localhost:8080", 'activity:write', secret);
86+
isAuthOk = await strava.OAuth(clientID, "http://localhost:8080", 'profile:read_all', secret);
8587

8688
if (isAuthOk) {
8789

90+
// Type of expected answer:
91+
// {"id":25707617,"username":"patrick_ff","resource_state":3,"firstname":"Patrick","lastname":"FF",
92+
// "city":"Le Beausset","state":"Provence-Alpes-Côte d'Azur","country":"France","sex":null,"premium"
8893
DetailedAthlete _athlete = await strava.getLoggedInAthlete();
8994
if (_athlete.fault.statusCode != strava.statusOk) {
90-
9195
print('Error in getloggedInAthlete ${_athlete.fault.statusCode}');
9296
}
93-
9497

95-
List<RunningRace> listRunningRaces = await strava.getRunningRaces("2019");
98+
// Type of expected answer
99+
// {"biggest_ride_distance":156733.0,"biggest_climb_elevation_gain":null,"recent_ride_totals":{"count":2,"distance":111427.7001953125,
100+
// "moving_time":17726,"elapsed_time":23181,"elevation_gain":1354.5838375091553,"achievement_count":0},"recent_run_to
101+
Stats _stats = await strava.getStats(_athlete.id);
102+
if (_stats.fault.statusCode != strava.statusOk) {
103+
print('Error in getloggedInAthlete ${_stats.fault.statusCode}');
104+
}
105+
106+
// A long list of races per city
107+
// Starting by Walt Disney World Marathon
108+
List<RunningRace> listRunningRaces = await strava.getRunningRaces('2019');
109+
if ((listRunningRaces == null) || (listRunningRaces[0].fault.statusCode != strava.statusOk)) {
110+
print('Error in getRunningRaces: ${listRunningRaces[0].fault.statusCode}');
111+
}
96112

97113
// id corresponding to BMW Berlin Marathon 29th Sept 2019
98114
RunningRace race = await strava.getRunningRaceById('2724');
99115

100-
// Change of the loggedAthlete in profile
116+
// Change weight of the loggedAthlete in profile (in kg)
101117
DetailedAthlete athlete2 = await strava.updateLoggedInAthlete(84);
102118

103119

104-
Gear gear = await strava.getGearById("b4366285");
105-
// print('error code getGearById ${gear.errorCode}');
106-
107-
Stats stats = await strava.getStats(_athlete.id);
108-
109-
// List<Zone> list = await strava.getLoggedInAthleteZones();
120+
/// Gear should be owned by the loggedIn Athleted
121+
/// Type of expected answer:
122+
/// {"id":"b4366285","primary":true,"name":"Roubaix Specialized","resource_state":3,"distance":461692.0,
123+
/// "brand_name":"Specialized","model_name":"Roubaix Expert","frame_type":3,"description":"So comfortable!"}
124+
Gear _gear = await strava.getGearById("b4366285");
125+
if (_gear.fault.statusCode != strava.statusOk) {
126+
print('error code getGearById ${_gear.fault.statusCode}');
127+
}
110128

129+
// You have to join this club to do the test
111130
final clubStravaMarseille =
112-
'226910'; // You have to join this club to do the test
113-
131+
'226910';
132+
/// Answer expected:
133+
/// {"id":226910,"resource_state":3,"name":"STRAVA Marseille ",
134+
/// "profile_medium":"https://dgalywyr863hv.cloudfront.net/pictures/clubs/226910/5003423/3/medium.jpg","profile":"https://dgalywyr863hv.cloudfront.net/pictures/clubs/226910/5003423/3/larg
114135
Club club = await strava.getClubById(clubStravaMarseille);
115136

116-
// Test getActivityById
117-
DetailedActivity _activity = await strava.getActivityById('2131889191');
118-
137+
138+
/// List the member of Strava club
139+
/// Expected answer (should start like this):
140+
/// [{"resource_state":2,"firstname":"Adam","lastname":"Š.","membership":"member",
141+
/// "admin":false,"owner":false},{"resource_state":2,"firstname":"Alex","lastname":"M.","membership"
119142
List<SummaryAthlete> listMembers = await strava.getClubMembersById('1');
120143

144+
// List<Zone> list = await strava.getLoggedInAthleteZones();
145+
121146
List<SummaryActivity> listSumm =
122147
await strava.getClubActivitiesById(clubStravaMarseille);
148+
149+
150+
/// You have to put an id of one activity of the logged Athlete
151+
/// You can find the id of one activity looking at your web page
152+
/// https://www.strava.com/activities/2130215349
153+
DetailedActivity _activity = await strava.getActivityById('2130215349');
154+
if (_activity.fault.statusCode != strava.statusOk) {
155+
print('Error in getActivityById: ${_activity.fault.statusCode}');
156+
157+
}
123158
}
124159
}
125160

example/lib/main.dart

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import 'package:flutter/material.dart';
22

33

4-
import 'package:flutter/services.dart' show rootBundle;
5-
import 'package:path_provider/path_provider.dart';
6-
74
import 'examples.dart';
85

96
import 'secret.dart'; // Store Strava app secret
@@ -43,10 +40,6 @@ class _StravaFlutterPageState extends State<StravaFlutterPage> {
4340
final String redirectUrl = "http://localhost:8080";
4441
final String scope = 'profile:write';
4542

46-
final strava = Strava(
47-
secret, // Put your secret key in secret.dart file
48-
'auto', // Prompt strava login only when needed
49-
);
5043

5144
@override
5245
void initState() {
@@ -78,6 +71,11 @@ class _StravaFlutterPageState extends State<StravaFlutterPage> {
7871

7972
void deAuthorize() async {
8073
// need to get authorized before (valid token)
74+
final strava = Strava(
75+
true, // to get disply info in API
76+
secret, // Put your secret key in secret.dart file
77+
'auto', // Prompt strava login only when needed
78+
);
8179
await strava.deAuthorize();
8280
}
8381

@@ -102,22 +100,7 @@ class _StravaFlutterPageState extends State<StravaFlutterPage> {
102100
// Working
103101
// Image.asset('assets/test.JPG'),
104102

105-
Text('Push this button'),
106-
Text(
107-
'to revoke/DeAuthorize Strava user',
108-
),
109-
Text(''),
110-
RaisedButton(
111-
child: Text('DeAuthorize'),
112-
onPressed: deAuthorize,
113-
),
114-
Text('Push this button to start'),
115-
Text(
116-
'the Strava authentication',
117-
),
118-
Text(
119-
'using basic example',
120-
),
103+
121104
Text(''),
122105
Text('Authentication'),
123106
Text('with strava_flutter Api'),
@@ -126,11 +109,24 @@ class _StravaFlutterPageState extends State<StravaFlutterPage> {
126109
onPressed: exampleStrava,
127110
),
128111
Text(''),
112+
Text(''),
129113
Text('Upload with authentication'),
130114
RaisedButton(
131115
child: Text('upload'),
132116
onPressed: upload,
133117
),
118+
Text(' '),
119+
Text(''),
120+
Text(''),
121+
Text('Push this button'),
122+
Text(
123+
'to revoke/DeAuthorize Strava user',
124+
),
125+
126+
RaisedButton(
127+
child: Text('DeAuthorize'),
128+
onPressed: deAuthorize,
129+
),
134130
],
135131
),
136132
),

0 commit comments

Comments
 (0)