| ... | ... |
@@ -1,23 +1,23 @@ |
| 1 |
-/*STRAVA_API Workflow |
|
| 2 |
- |
|
| 3 |
-TODO CHANGE CLIENT_ID and password when publish the app |
|
| 4 |
- |
|
| 5 |
-OAuth2.0 strava / pebble |
|
| 6 |
- |
|
| 7 |
-1 - get activity:write authorization (once and for all) |
|
| 8 |
- GET https://www.strava.com/oauth/authorize?client_id=14883&response_type=code&redirect_uri=http://www.pebblebike.com/strava-se/authorize.php&scope=write |
|
| 9 |
- GET https://www.strava.com/oauth/authorize?client_id=94880&response_type=code&redirect_uri=http://strava.jonget.fr&scope=activity:write |
|
| 10 |
- monitor state, code and scope (as upload can be unchecked)! |
|
| 11 |
- code is short lived and one time usage |
|
| 12 |
-2 - get tokens in exchange of code (make it done by jonget.fr because of secret ? ) |
|
| 13 |
- POST https://www.strava.com/oauth/token?client_id=94880&client_secret=08dc170f0fe38f39dd327bea82a28db4400e6f00&code=db896b06f89804997a8088320fba755e6299c0d6&grant_type=authorization_code |
|
| 14 |
- refresh & access tokens + expiry of access token (6hours) retrieved |
|
| 15 |
- |
|
| 16 |
-3 - test if access token expired |
|
| 17 |
- |
|
| 18 |
-4a- if not, API call |
|
| 19 |
- GET https://www.strava.com/api/v3/athlete with "Authorization" header ="Bearer XXXXX" XXXXX=access token |
|
| 20 |
- |
|
| 21 |
-4b- if yes refresh access token with refresh token get in 2 (make it done by jonget.fr because of secret ? ) |
|
| 22 |
- POST https://www.strava.com/oauth/token?client_id=94880&client_secret=8a68d5b79f2fb3e00ad3eaa5025253990fbd6a58&refresh_token=c313d612768db4b12af2782372aa1d9349c265cb&grant_type=refresh_token |
|
| 23 |
-*/ |
|
| 1 |
+/*STRAVA_API Workflow |
|
| 2 |
+ |
|
| 3 |
+TODO CHANGE CLIENT_ID and password when publish the app |
|
| 4 |
+ |
|
| 5 |
+OAuth2.0 strava / pebble |
|
| 6 |
+ |
|
| 7 |
+1 - get activity:write authorization (once and for all) |
|
| 8 |
+ GET https://www.strava.com/oauth/authorize?client_id=14883&response_type=code&redirect_uri=http://www.pebblebike.com/strava-se/authorize.php&scope=write |
|
| 9 |
+ GET https://www.strava.com/oauth/authorize?client_id=94880&response_type=code&redirect_uri=http://strava.jonget.fr&scope=activity:write |
|
| 10 |
+ monitor state, code and scope (as upload can be unchecked)! |
|
| 11 |
+ code is short lived and one time usage |
|
| 12 |
+2 - get tokens in exchange of code (make it done by jonget.fr because of secret ? ) |
|
| 13 |
+ POST https://www.strava.com/oauth/token?client_id=94880&client_secret=08dc170f0fe38f39dd327bea82a28db4400e6f00&code=db896b06f89804997a8088320fba755e6299c0d6&grant_type=authorization_code |
|
| 14 |
+ refresh & access tokens + expiry of access token (6hours) retrieved |
|
| 15 |
+ |
|
| 16 |
+3 - test if access token expired |
|
| 17 |
+ |
|
| 18 |
+4a- if not, API call |
|
| 19 |
+ GET https://www.strava.com/api/v3/athlete with "Authorization" header ="Bearer XXXXX" XXXXX=access token |
|
| 20 |
+ |
|
| 21 |
+4b- if yes refresh access token with refresh token get in 2 (make it done by jonget.fr because of secret ? ) |
|
| 22 |
+ POST https://www.strava.com/oauth/token?client_id=94880&client_secret=8a68d5b79f2fb3e00ad3eaa5025253990fbd6a58&refresh_token=c313d612768db4b12af2782372aa1d9349c265cb&grant_type=refresh_token |
|
| 23 |
+*/ |
| ... | ... |
@@ -1,9 +1,12 @@ |
| 1 |
-/*STRAVA_API |
|
| 1 |
+/*STRAVA_API Workflow |
|
| 2 |
+ |
|
| 3 |
+TODO CHANGE CLIENT_ID and password when publish the app |
|
| 2 | 4 |
|
| 3 | 5 |
OAuth2.0 strava / pebble |
| 4 | 6 |
|
| 5 | 7 |
1 - get activity:write authorization (once and for all) |
| 6 |
- GET https://www.strava.com/oauth/authorize?client_id=94880&response_type=code&redirect_uri=http://strava.jonget.fr&approval_prompt=force&state=bike_companion&scope=activity:write |
|
| 8 |
+ GET https://www.strava.com/oauth/authorize?client_id=14883&response_type=code&redirect_uri=http://www.pebblebike.com/strava-se/authorize.php&scope=write |
|
| 9 |
+ GET https://www.strava.com/oauth/authorize?client_id=94880&response_type=code&redirect_uri=http://strava.jonget.fr&scope=activity:write |
|
| 7 | 10 |
monitor state, code and scope (as upload can be unchecked)! |
| 8 | 11 |
code is short lived and one time usage |
| 9 | 12 |
2 - get tokens in exchange of code (make it done by jonget.fr because of secret ? ) |
| ... | ... |
@@ -1,27 +1,13 @@ |
| 1 | 1 |
/*STRAVA_API |
| 2 | 2 |
|
| 3 |
-{
|
|
| 4 |
- "file": /path/to/file.txt, // {File} The uploaded file.
|
|
| 5 |
- "name": name_example, // {String} The desired name of the resulting activity.
|
|
| 6 |
- "description": description_example, // {String} The desired description of the resulting activity.
|
|
| 7 |
- "trainer": trainer_example, // {String} Whether the resulting activity should be marked as having been performed on a trainer.
|
|
| 8 |
- "commute": commute_example, // {String} Whether the resulting activity should be tagged as a commute.
|
|
| 9 |
- "dataType": dataType_example, // {String} The format of the uploaded file.
|
|
| 10 |
- "externalId": externalId_example // {String} The desired external identifier of the resulting activity.
|
|
| 11 |
-} |
|
| 12 |
- |
|
| 13 |
- |
|
| 14 |
-https://resmedglobal.atlassian.net/secure/CreateIssue.jspa?issuetype=2&pid=ISMS2 |
|
| 15 |
-https://resmedglobal.atlassian.net/secure/CreateIssue.jspa?issuetype=3&pid=ISMS2 |
|
| 16 |
- |
|
| 17 | 3 |
OAuth2.0 strava / pebble |
| 18 | 4 |
|
| 19 | 5 |
1 - get activity:write authorization (once and for all) |
| 20 | 6 |
GET https://www.strava.com/oauth/authorize?client_id=94880&response_type=code&redirect_uri=http://strava.jonget.fr&approval_prompt=force&state=bike_companion&scope=activity:write |
| 21 | 7 |
monitor state, code and scope (as upload can be unchecked)! |
| 22 | 8 |
code is short lived and one time usage |
| 23 |
-2 - get tokens in exchange of code |
|
| 24 |
- POST https://www.strava.com/oauth/token?client_id=94880&client_secret=08dc170f0fe38f39dd327bea82a28db4400e6f00&code=e0aeb60ea9f508d25974bb56ccb551be56b91470&grant_type=authorization_code |
|
| 9 |
+2 - get tokens in exchange of code (make it done by jonget.fr because of secret ? ) |
|
| 10 |
+ POST https://www.strava.com/oauth/token?client_id=94880&client_secret=08dc170f0fe38f39dd327bea82a28db4400e6f00&code=db896b06f89804997a8088320fba755e6299c0d6&grant_type=authorization_code |
|
| 25 | 11 |
refresh & access tokens + expiry of access token (6hours) retrieved |
| 26 | 12 |
|
| 27 | 13 |
3 - test if access token expired |
| ... | ... |
@@ -29,55 +15,6 @@ OAuth2.0 strava / pebble |
| 29 | 15 |
4a- if not, API call |
| 30 | 16 |
GET https://www.strava.com/api/v3/athlete with "Authorization" header ="Bearer XXXXX" XXXXX=access token |
| 31 | 17 |
|
| 32 |
-4b- if yes refresh access token with refresh token get in 2 |
|
| 18 |
+4b- if yes refresh access token with refresh token get in 2 (make it done by jonget.fr because of secret ? ) |
|
| 33 | 19 |
POST https://www.strava.com/oauth/token?client_id=94880&client_secret=8a68d5b79f2fb3e00ad3eaa5025253990fbd6a58&refresh_token=c313d612768db4b12af2782372aa1d9349c265cb&grant_type=refresh_token |
| 34 | 20 |
*/ |
| 35 |
- |
|
| 36 |
-gpxfile = b.getGpx(!0) // returned gpxfile is string |
|
| 37 |
-upload(gpxfile) |
|
| 38 |
- |
|
| 39 |
-function getGpx(t) {
|
|
| 40 |
- if (0 == points.length) return ""; |
|
| 41 |
- if (creator = "Ventoo SE", gpxfile = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creator="' + creator + '" version="1.1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd" xmlns:pb10="http://www.pebblebike.com/GPX/1/0/">\n', itemId = -1, trackNumber = 1, points.length > 0) {
|
|
| 42 |
- for (gpxfile += "<trk>\n<name>Track #1</name>\n<trkseg>\n", prevTime = -1, i = 0; i < points.length; i++) prevTime > 0 && points[i].t - prevTime > 43200 ? (trackNumber++, gpxfile += "</trkseg>\n</trk>\n<trk>\n<name>Track #" + trackNumber + "</name>\n<trkseg>\n") : prevTime > 0 && points[i].t - prevTime > 7200 && (gpxfile += "</trkseg>\n<trkseg>\n"), d = new Date(1e3 * points[i].t), ti = d.toISOString(), gpxfile += '<trkpt lat="' + points[i].la + '" lon="' + points[i].lo + '">\n <ele>' + points[i].a + "</ele><time>" + ti + "</time>\n", !t && points[i].h || (gpxfile += " <extensions>", t && (gpxfile += "<pb10:accuracy>" + points[i].ac + "</pb10:accuracy>"), points[i].h && (gpxfile += "<gpxtpx:TrackPointExtension>", gpxfile += "<gpxtpx:hr>" + points[i].h + "</gpxtpx:hr>", gpxfile += "</gpxtpx:TrackPointExtension>\n"), gpxfile += "</extensions>\n"), gpxfile += "</trkpt>\n", prevTime = points[i].t; |
|
| 43 |
- gpxfile += "</trkseg>\n</trk>\n" |
|
| 44 |
- } |
|
| 45 |
- return gpxfile += "</gpx>\n", gpxfile |
|
| 46 |
-} |
|
| 47 |
- |
|
| 48 |
-function upload(gpxfile) {
|
|
| 49 |
- params = {
|
|
| 50 |
- url: s, |
|
| 51 |
- method: "POST", |
|
| 52 |
- data: { description: "desc", data_type: "gpx" },
|
|
| 53 |
- files: { file: gpxfile },
|
|
| 54 |
- authorization: "Bearer " + c, |
|
| 55 |
- callback: function() {
|
|
| 56 |
- var z = ""; |
|
| 57 |
- if (r && console.log(e.status + " - " + e.txt), 201 == e.status) z = "Your activity has been created"; |
|
| 58 |
- else if (400 == e.status) z = "An error has occurred. If you've already uploaded the current activity, please delete it in Strava."; |
|
| 59 |
- else if (401 == e.status) z = "Error - Unauthorized. Please check your credentials in the settings.", o.setAccessToken("");
|
|
| 60 |
- else try { response_json = JSON.parse(e.txt), response_json.error ? (r && console.log("error:" + response_json.error), z = response_json.error, o.setAccessToken("")) : response_json.status && (r && console.log("status:" + response_json.status), z = response_json.status) } catch (z) { console.log("Error log, " + z) }
|
|
| 61 |
- z && Pebble.showSimpleNotificationOnPebble("Ventoo SE - Strava", z)
|
|
| 62 |
- } |
|
| 63 |
- } |
|
| 64 |
- //e[0] = params |
|
| 65 |
- var XHR = new XMLHttpRequest |
|
| 66 |
- console.log(e[0].url) |
|
| 67 |
- XHR.open(e[0].method, e[0].url, !0) |
|
| 68 |
- var r = Math.random().toString().substr(2); |
|
| 69 |
- XHR.setRequestHeader("content-type", "multipart/form-data; charset=utf-8; boundary=" + r)
|
|
| 70 |
- e[0].authorization && XHR.setRequestHeader("Authorization", e[0].authorization);
|
|
| 71 |
- for (var i in e[0].data) o += "--" + r + '\r\nContent-Disposition: form-data; name="' + i + '"\r\n\r\n' + e[0].data[i] + "\r\n"; |
|
| 72 |
- for (var i in e[0].files) o += "--" + r + '\r\nContent-Disposition: form-data; name="' + i + '" ; filename=test.gpx\r\n\r\n' + e[0].files[i] + "\r\n"; |
|
| 73 |
- o += "--" + r + "--\r\n" |
|
| 74 |
- |
|
| 75 |
- XHR.onreadystatechange = function() {
|
|
| 76 |
- try {
|
|
| 77 |
- 4 == XHR.readyState && (n.status = XHR.status, n.txt = XHR.responseText, n.xml = XHR.responseXML, e[0].callback && e[0].callback()) |
|
| 78 |
- } catch (t) {
|
|
| 79 |
- console.error("Error2 loading, ", t)
|
|
| 80 |
- } |
|
| 81 |
- } |
|
| 82 |
- XHR.send(o) |
|
| 83 |
-} |
|
| 84 | 21 |
\ No newline at end of file |
| ... | ... |
@@ -51,7 +51,7 @@ function upload(gpxfile) {
|
| 51 | 51 |
method: "POST", |
| 52 | 52 |
data: { description: "desc", data_type: "gpx" },
|
| 53 | 53 |
files: { file: gpxfile },
|
| 54 |
- authorization: "Bearer " + c |
|
| 54 |
+ authorization: "Bearer " + c, |
|
| 55 | 55 |
callback: function() {
|
| 56 | 56 |
var z = ""; |
| 57 | 57 |
if (r && console.log(e.status + " - " + e.txt), 201 == e.status) z = "Your activity has been created"; |
| ... | ... |
@@ -1,4 +1,4 @@ |
| 1 |
-STRAVA_API |
|
| 1 |
+/*STRAVA_API |
|
| 2 | 2 |
|
| 3 | 3 |
{
|
| 4 | 4 |
"file": /path/to/file.txt, // {File} The uploaded file.
|
| ... | ... |
@@ -30,4 +30,54 @@ OAuth2.0 strava / pebble |
| 30 | 30 |
GET https://www.strava.com/api/v3/athlete with "Authorization" header ="Bearer XXXXX" XXXXX=access token |
| 31 | 31 |
|
| 32 | 32 |
4b- if yes refresh access token with refresh token get in 2 |
| 33 |
- POST https://www.strava.com/oauth/token?client_id=94880&client_secret=08dc170f0fe38f39dd327bea82a28db4400e6f00&refresh_token=XXXXXXX&grant_type=refresh_token |
|
| 33 |
+ POST https://www.strava.com/oauth/token?client_id=94880&client_secret=8a68d5b79f2fb3e00ad3eaa5025253990fbd6a58&refresh_token=c313d612768db4b12af2782372aa1d9349c265cb&grant_type=refresh_token |
|
| 34 |
+*/ |
|
| 35 |
+ |
|
| 36 |
+gpxfile = b.getGpx(!0) // returned gpxfile is string |
|
| 37 |
+upload(gpxfile) |
|
| 38 |
+ |
|
| 39 |
+function getGpx(t) {
|
|
| 40 |
+ if (0 == points.length) return ""; |
|
| 41 |
+ if (creator = "Ventoo SE", gpxfile = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creator="' + creator + '" version="1.1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd" xmlns:pb10="http://www.pebblebike.com/GPX/1/0/">\n', itemId = -1, trackNumber = 1, points.length > 0) {
|
|
| 42 |
+ for (gpxfile += "<trk>\n<name>Track #1</name>\n<trkseg>\n", prevTime = -1, i = 0; i < points.length; i++) prevTime > 0 && points[i].t - prevTime > 43200 ? (trackNumber++, gpxfile += "</trkseg>\n</trk>\n<trk>\n<name>Track #" + trackNumber + "</name>\n<trkseg>\n") : prevTime > 0 && points[i].t - prevTime > 7200 && (gpxfile += "</trkseg>\n<trkseg>\n"), d = new Date(1e3 * points[i].t), ti = d.toISOString(), gpxfile += '<trkpt lat="' + points[i].la + '" lon="' + points[i].lo + '">\n <ele>' + points[i].a + "</ele><time>" + ti + "</time>\n", !t && points[i].h || (gpxfile += " <extensions>", t && (gpxfile += "<pb10:accuracy>" + points[i].ac + "</pb10:accuracy>"), points[i].h && (gpxfile += "<gpxtpx:TrackPointExtension>", gpxfile += "<gpxtpx:hr>" + points[i].h + "</gpxtpx:hr>", gpxfile += "</gpxtpx:TrackPointExtension>\n"), gpxfile += "</extensions>\n"), gpxfile += "</trkpt>\n", prevTime = points[i].t; |
|
| 43 |
+ gpxfile += "</trkseg>\n</trk>\n" |
|
| 44 |
+ } |
|
| 45 |
+ return gpxfile += "</gpx>\n", gpxfile |
|
| 46 |
+} |
|
| 47 |
+ |
|
| 48 |
+function upload(gpxfile) {
|
|
| 49 |
+ params = {
|
|
| 50 |
+ url: s, |
|
| 51 |
+ method: "POST", |
|
| 52 |
+ data: { description: "desc", data_type: "gpx" },
|
|
| 53 |
+ files: { file: gpxfile },
|
|
| 54 |
+ authorization: "Bearer " + c |
|
| 55 |
+ callback: function() {
|
|
| 56 |
+ var z = ""; |
|
| 57 |
+ if (r && console.log(e.status + " - " + e.txt), 201 == e.status) z = "Your activity has been created"; |
|
| 58 |
+ else if (400 == e.status) z = "An error has occurred. If you've already uploaded the current activity, please delete it in Strava."; |
|
| 59 |
+ else if (401 == e.status) z = "Error - Unauthorized. Please check your credentials in the settings.", o.setAccessToken("");
|
|
| 60 |
+ else try { response_json = JSON.parse(e.txt), response_json.error ? (r && console.log("error:" + response_json.error), z = response_json.error, o.setAccessToken("")) : response_json.status && (r && console.log("status:" + response_json.status), z = response_json.status) } catch (z) { console.log("Error log, " + z) }
|
|
| 61 |
+ z && Pebble.showSimpleNotificationOnPebble("Ventoo SE - Strava", z)
|
|
| 62 |
+ } |
|
| 63 |
+ } |
|
| 64 |
+ //e[0] = params |
|
| 65 |
+ var XHR = new XMLHttpRequest |
|
| 66 |
+ console.log(e[0].url) |
|
| 67 |
+ XHR.open(e[0].method, e[0].url, !0) |
|
| 68 |
+ var r = Math.random().toString().substr(2); |
|
| 69 |
+ XHR.setRequestHeader("content-type", "multipart/form-data; charset=utf-8; boundary=" + r)
|
|
| 70 |
+ e[0].authorization && XHR.setRequestHeader("Authorization", e[0].authorization);
|
|
| 71 |
+ for (var i in e[0].data) o += "--" + r + '\r\nContent-Disposition: form-data; name="' + i + '"\r\n\r\n' + e[0].data[i] + "\r\n"; |
|
| 72 |
+ for (var i in e[0].files) o += "--" + r + '\r\nContent-Disposition: form-data; name="' + i + '" ; filename=test.gpx\r\n\r\n' + e[0].files[i] + "\r\n"; |
|
| 73 |
+ o += "--" + r + "--\r\n" |
|
| 74 |
+ |
|
| 75 |
+ XHR.onreadystatechange = function() {
|
|
| 76 |
+ try {
|
|
| 77 |
+ 4 == XHR.readyState && (n.status = XHR.status, n.txt = XHR.responseText, n.xml = XHR.responseXML, e[0].callback && e[0].callback()) |
|
| 78 |
+ } catch (t) {
|
|
| 79 |
+ console.error("Error2 loading, ", t)
|
|
| 80 |
+ } |
|
| 81 |
+ } |
|
| 82 |
+ XHR.send(o) |
|
| 83 |
+} |
|
| 34 | 84 |
\ No newline at end of file |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,33 @@ |
| 1 |
+STRAVA_API |
|
| 2 |
+ |
|
| 3 |
+{
|
|
| 4 |
+ "file": /path/to/file.txt, // {File} The uploaded file.
|
|
| 5 |
+ "name": name_example, // {String} The desired name of the resulting activity.
|
|
| 6 |
+ "description": description_example, // {String} The desired description of the resulting activity.
|
|
| 7 |
+ "trainer": trainer_example, // {String} Whether the resulting activity should be marked as having been performed on a trainer.
|
|
| 8 |
+ "commute": commute_example, // {String} Whether the resulting activity should be tagged as a commute.
|
|
| 9 |
+ "dataType": dataType_example, // {String} The format of the uploaded file.
|
|
| 10 |
+ "externalId": externalId_example // {String} The desired external identifier of the resulting activity.
|
|
| 11 |
+} |
|
| 12 |
+ |
|
| 13 |
+ |
|
| 14 |
+https://resmedglobal.atlassian.net/secure/CreateIssue.jspa?issuetype=2&pid=ISMS2 |
|
| 15 |
+https://resmedglobal.atlassian.net/secure/CreateIssue.jspa?issuetype=3&pid=ISMS2 |
|
| 16 |
+ |
|
| 17 |
+OAuth2.0 strava / pebble |
|
| 18 |
+ |
|
| 19 |
+1 - get activity:write authorization (once and for all) |
|
| 20 |
+ GET https://www.strava.com/oauth/authorize?client_id=94880&response_type=code&redirect_uri=http://strava.jonget.fr&approval_prompt=force&state=bike_companion&scope=activity:write |
|
| 21 |
+ monitor state, code and scope (as upload can be unchecked)! |
|
| 22 |
+ code is short lived and one time usage |
|
| 23 |
+2 - get tokens in exchange of code |
|
| 24 |
+ POST https://www.strava.com/oauth/token?client_id=94880&client_secret=08dc170f0fe38f39dd327bea82a28db4400e6f00&code=e0aeb60ea9f508d25974bb56ccb551be56b91470&grant_type=authorization_code |
|
| 25 |
+ refresh & access tokens + expiry of access token (6hours) retrieved |
|
| 26 |
+ |
|
| 27 |
+3 - test if access token expired |
|
| 28 |
+ |
|
| 29 |
+4a- if not, API call |
|
| 30 |
+ GET https://www.strava.com/api/v3/athlete with "Authorization" header ="Bearer XXXXX" XXXXX=access token |
|
| 31 |
+ |
|
| 32 |
+4b- if yes refresh access token with refresh token get in 2 |
|
| 33 |
+ POST https://www.strava.com/oauth/token?client_id=94880&client_secret=08dc170f0fe38f39dd327bea82a28db4400e6f00&refresh_token=XXXXXXX&grant_type=refresh_token |