1- // examples to use strava_flutter
1+ // Examples to use strava_flutter
22import 'dart:async' ;
33import 'dart:io' ;
44import '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
7779void 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
0 commit comments