-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for submitting workouts via API
This adds support for FitoTrack to automatically upload workouts via HTTP POST. We had to add authentication via query parameter, since FitoTrack did not support Header or BasicAuth authentication. We also now have a README section that can be extended. Fixes #64 Signed-off-by: Jo Vandeginste <Jo.Vandeginste@kuleuven.be>
- Loading branch information
1 parent
2f9e16a
commit 10f5926
Showing
14 changed files
with
289 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package importers | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
func importFitotrack(headers http.Header, body io.ReadCloser) (*Content, error) { | ||
if t := headers.Get("FitoTrack-Type"); t != "workout-gpx" { | ||
return nil, fmt.Errorf("unsupported FitoTrack-Type: %s", t) | ||
} | ||
|
||
wt := headers.Get("FitoTrack-Workout-Type") | ||
wn := headers.Get("FitoTrack-Comment") | ||
|
||
defer body.Close() | ||
|
||
b, err := io.ReadAll(body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
g := &Content{ | ||
Content: b, | ||
Type: wt, | ||
Notes: wn, | ||
} | ||
|
||
return g, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package importers | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
var ErrUnsupportedProgram = errors.New("unsupported program") | ||
|
||
type Content struct { | ||
Content []byte | ||
Filename string | ||
Notes string | ||
Type string | ||
} | ||
|
||
func Import(program string, headers http.Header, body io.ReadCloser) (*Content, error) { | ||
if program == "fitotrack" { | ||
return importFitotrack(headers, body) | ||
} | ||
|
||
return nil, fmt.Errorf("%w: %s", ErrUnsupportedProgram, program) | ||
} |
Oops, something went wrong.