Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.6.0 Fix most features. #56

Merged
merged 33 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5d98de1
feat: Garmin signin with Oauth (initial version).
gooin Sep 27, 2023
55203db
feat: handling errors
gooin Sep 28, 2023
a18ff73
refactor: oauth1 & oauth2 exchange
gooin Sep 28, 2023
34425d5
feat: get user settings by api
gooin Sep 28, 2023
ebb3862
feat: http client common header
gooin Sep 28, 2023
30413da
feat: export, import token & auto refresh token
gooin Oct 1, 2023
964b89a
feat: Activity API
gooin Oct 1, 2023
85568eb
feat: upload and delete activity
gooin Oct 2, 2023
efc98ce
doc: update readme
gooin Oct 2, 2023
8757b9a
feat: get OAUTH_CONSUMER from url, not hard code
gooin Oct 2, 2023
439992f
feat: handle Account locked
gooin Oct 2, 2023
c1bfccb
feat: handle MFA (TODO)
gooin Oct 2, 2023
a292f2f
fix: missing ticket
gooin Oct 2, 2023
354895a
feat: v1.6.0
gooin Oct 2, 2023
ce1e4ff
feat: make GarminConnect.client public
gooin Oct 2, 2023
664660a
feat: exportToken
gooin Oct 2, 2023
09f30fc
v1.6.1-rc.1
gooin Oct 2, 2023
3a391c8
v1.6.1-rc.2
gooin Oct 2, 2023
22c1d61
fix: refreshOauth2Token fetch OAUTH_CONSUMER
gooin Oct 2, 2023
9560efa
chore: remove logs
gooin Oct 2, 2023
8cb3ed1
v1.6.1
gooin Oct 2, 2023
e82aa73
new bug at sign in step: Handle Phone number
gooin Oct 2, 2023
dd454dc
chore: remove unused codes
gooin Oct 2, 2023
1d224c2
fix: error handling
gooin Oct 3, 2023
e96a6b9
v1.6.2-rc.1
gooin Oct 3, 2023
68898c8
fix: doc
gooin Oct 3, 2023
d9f1379
feat: delete method
gooin Oct 3, 2023
901a70f
feat: workouts get add delete
gooin Oct 3, 2023
f6a8e18
feat: make old env happy
gooin Oct 9, 2023
fbfc156
v1.6.3
gooin Oct 9, 2023
d78bb98
fix: make old env happy
gooin Oct 9, 2023
5ecbe28
fix: make old evn happy
gooin Oct 9, 2023
8f17778
v1.6.5
gooin Oct 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 68 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# garmin-connect

## v1.6.0 refactor

TODO:

- [x] New HttpClient class
- [x] Login and get user token
- [x] Garmin URLs works with `garmin.cn` and `garmin.com`
- [x] Auto refresh Ouath2 token
- [x] Oauth1,Oauth2 token import and export.
- [x] Download Activity, countActivities, getActivities, getActivity, getUserProfile, getUserSettings
- [x] Upload Activity, delete Activity
- [ ] Implementation of other methods, such as Badge,Workout,Gear etc
- [ ] Handle MFA
- [x] Handle Account locked
- [ ] Unit test
- [ ] Listeners

If something is not working, please check [https://connect.garmin.com/status/](https://connect.garmin.com/status/) first.

Currently, most of previous features are working, but some of Rest API are not added, such as `Gear`,`Workout`,`Badge` etc. So if you need these features, please add a PR.

All of above work inspired by [https://github.com/matin/garth](https://github.com/matin/garth). Many thanks.

---

A powerful JavaScript library for connecting to Garmin Connect for sending and receiving health and workout data. It comes with some predefined methods to get and set different kinds of data for your Garmin account, but also have the possibility to make [custom requests](#custom-requests) `GET`, `POST` and `PUT` are currently supported. This makes it easy to implement whatever may be missing to suite your needs.

## Prerequisites
Expand All @@ -24,15 +49,54 @@ $ npm install garmin-connect
```js
const { GarminConnect } = require('garmin-connect');
// Create a new Garmin Connect Client
const GCClient = new GarminConnect({"username": "my.email@example.com", "password": "MySecretPassword"});
const GCClient = new GarminConnect({
username: 'my.email@example.com',
password: 'MySecretPassword'
});
// Uses credentials from garmin.config.json or uses supplied params
await GCClient.login();
const userInfo = await GCClient.getUserInfo();
const userProfile = await GCClient.getUserProfile();
```

Now you can check `userInfo.emailAddress` to verify that your login was successful.
Now you can check `userProfile.userName` to verify that your login was successful.

## Reusing your session
## Reusing your session(since v1.6.0)

### Save token to file and reuse it.

```js
GCClient.saveTokenToFile('/path/to/save/tokens');
```

Result:

```bash
$ ls /path/to/save/tokens
oauth1_token.json oauth2_token.json
```

Reuse token:

```js
GCClient.loadTokenByFile('/path/to/save/tokens');
```

### Or just save your token to db or other storage.

```js
const oauth1 = GCClient.client.oauth1Token;
const oauth2 = GCClient.client.oauth2Token;
// save to db or other storage
...
```

Reuse token:

```js
GCClient.loadToken(oauth1, oauth2);
```

## Reusing your session(depreated)

This is an experimental feature and might not yet provide full stability.

Expand Down Expand Up @@ -360,4 +424,3 @@ For now, this library only supports the following:
- Get earned badges
- Get available badges
- Get details about one specific badge

27 changes: 21 additions & 6 deletions examples/example.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
const { GarminConnect } = require('garmin-connect');
const { GarminConnect } = require('../dist/index');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still be 'garmin-connect'


// Has to be run in an async function to be able to use the await keyword
const main = async () => {
// Create a new Garmin Connect Client
const GCClient = new GarminConnect();
const GCClient = new GarminConnect({
username: 'your-email',
password: 'your-password'
});

// TODO: Test China Domain
// China Domain
// const GCClient = new GarminConnect({
// username: 'your-email',
// password: 'your-password'
// }, 'garmin.cn');

// Uses credentials from garmin.config.json or uses supplied params
await GCClient.login('my.email@example.com', 'MySecretPassword');
await GCClient.login();

// // Get user info
// const info = await GCClient.getUserInfo();

// Get user info
const info = await GCClient.getUserInfo();
// Log info to make sure signin was successful
// console.log(info);
// // Get user settings
const settings = await GCClient.getUserSettings();

// Log info to make sure signin was successful
console.log(info);
console.log(settings);
};

// Run the code
Expand Down
Loading