Skip to content

Commit

Permalink
Merge pull request #6 from pdbogen/master
Browse files Browse the repository at this point in the history
variety of fixes
  • Loading branch information
jrmycanady committed Feb 16, 2018
2 parents aacb7d7 + e39e5cd commit c8a6719
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ This is a go client that allows easy access to the Nokia Health API (https://dev
**NOTICE** - Looking for users with data from various withings devices. Currently only testing against an account with a withings scale. The API documentation is very sketchy and testing against real data may find more issues.


## Oauth Notes
## OAuth Notes

The Nokia Health OAuth implemenation required some modifcations resulting in a fork of dghubble/oauth1. This project relies on the fork located at jrmycanady/oauth1.
The Nokia Health OAuth implemenation required some modifications resulting in a fork of dghubble/oauth1. This project relies on the fork located at jrmycanady/oauth1.

## Supported Resources (Currently all in the public API docs.)
* User Access Requests
* Retrieving user body measurements
* Retrieve activity measurments
* Retrieve activity measurements
* Retrieve workouts
* Retreive intraday activities - Apparently requires additional authorization wich I don't have yet so no testing.
* Retreive intraday activities - Apparently requires additional authorization which I don't have yet so no testing.
* Retrieve sleep measures - Limited testing so report any issues.
* Retrieve sleep summary - Limited testing so report any issues.
* Creating a notification
Expand All @@ -33,7 +33,7 @@ Once that is complete, you will need to request a token for the user. If you are

### User Authorization

Oauth1 has a multi step request process to generate a token for the end user. Details around this can be found [here](https://developer.health.nokia.com/api) as well as general searching. A short example is show below but for further information see the [godcos](https://godoc.org/github.com/jrmycanady/nokiahealth)
OAuth 1.0 has a multi step request process to generate a token for the end user. Details around this can be found [here](https://developer.health.nokia.com/api) as well as general searching. A short example is show below but for further information see the [godcos](https://godoc.org/github.com/jrmycanady/nokiahealth)

1. Generate end-user authorization url and provide it to the end user to click on. This URL is encoded in such a way that Nokia knows the user is requesting to give your develper account access to theirs.

Expand All @@ -47,15 +47,15 @@ if err != nil {

fmt.Println(ar.AuthorizationURL)
```
2. If you provided a callback URL nokia will then redirect them to that URL with queyr parameters set containing the verfier string and userid. Otherwise if it's empty the user will see it on screen and would need to copy and paste it into your app. Once you have those two bits of info, it's time to get the token.
2. If you provided a callback URL nokia will then redirect them to that URL with query parameters set containing the verifier string and userid. Otherwise if it's empty the user will see it on screen and would need to copy and paste it into your app. Once you have those two bits of info, it's time to get the token.
```go
u, err := ar.GenerateUser("<verifier>", <userid>)
if err != nil {
log.Fatal(err)
}
```
3. If all has gone well you now have a user object you may use to query. Methods off the user object include things like GetBodyMeasure()
4. Save the UseriD, AccessTokenStr and AccessSecretStr for later requets.
4. Save the UserID, AccessTokenStr and AccessSecretStr for later requests.

### User Requests

Expand All @@ -74,7 +74,7 @@ m, err := u.GetBodyMeasures(nil)


## Making Requests
Requests are performed from methods on the User. Each request accepts a specific query struct with the details for the request. For example:
Requests are performed from methods on the User. Each request accepts a specific query struct with the details for the request. For example:
```go
p := nokiahealth.BodyMeasuresQueryParams{}

Expand All @@ -84,8 +84,8 @@ p.StartDate = &t
m, err := u.GetBodyMeasures(&p)
```

In most cases the response will contain all the information you need. Some methods provide additional optional processing that can provide a more usable form to the data. GetBodyMeasures is one of these methods. It's recommended to read the [docs](https://godoc.org/github.com/jrmycanady/nokiahealth) for each method to see how best to use them.
In most cases the response will contain all the information you need. Some methods provide additional optional processing that can provide a more usable form to the data. GetBodyMeasures is one of these methods. It's recommended to read the [docs](https://godoc.org/github.com/jrmycanady/nokiahealth) for each method to see how best to use them.

```go
measures := m.ParseData()
```
```
16 changes: 8 additions & 8 deletions godoc.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Package nokiahealth is a client library for for working with the Nokia
// Health (Withings) API. It includes support for all resources listed on the public
// api documentation at https://developer.health.nokia.com/api/doc. This
// includes everything from user access token generation to retreiving
// body measurments and setting up notifications.
// includes everything from user access token generation to retrieving
// body measurements and setting up notifications.
//
// Due to limited access of Nokia Health devices, testing of each
// resource has been limited. If you have access to more data or run into
// any bugs/missing features, please place an issue on github at
// https://github.com/jrmycanady/nokiahealth. The API documentation has been
// found to be severly lacking or compeltely incorrect so oddities are
// found to be severly lacking or completely incorrect so oddities are
// expected to be found. Most are easily fixed as long as the raw request data
// can be provided.
//
Expand Down Expand Up @@ -41,9 +41,9 @@
// client := nokiahealth.NewClient("consumer_key","consumer_secret", "callback_url")
// The client can be used to handle user authorization as well as generate
// user structs from stores user authorization tokens. Details of that can be
// found in the authorization section. The following is an examle of creating
// found in the authorization section. The following is an example of creating
// a user from known tokens and secrets. All three parameters are required as
// the API doesn't rely on just the user_tokent to identify the user.
// the API doesn't rely on just the user_token to identify the user.
// user := client.GenerateUser("user_token", "user_secret", "user_id")
// With the user defined API calls can be made by utilizing on of the methods
// for the User struct. i.e.
Expand All @@ -54,7 +54,7 @@
// and how to use these parameters. https://developer.health.nokia.com/api/doc.
// Each param type is specific to the request type.
//
// Each method varies somewhat in the foramt it returns due to the inconsistencies
// Each method varies somewhat in the format it returns due to the inconsistencies
// in the Nokia Health API. This package does what it can to work around
// these inconsistencies but you should refer to the documentation for each
// method for more information. The one commonality is that the package does
Expand Down Expand Up @@ -100,10 +100,10 @@
// a different process or the original access request struct is not available.
// In such a case the generate user cannot be used which means you cannot
// obtain the secret. In those cases you can rebuild an access request token
// using the RebuildAccessReuqest() method of the client. This still requires
// using the RebuildAccessRequest() method of the client. This still requires
// storing the access request token and secret somewhere. Both of which are
// public fields on the AccessRequest struct.
// ar := client.RebuildAccessReuqest("token", "secret")
// ar := client.RebuildAccessRequest("token", "secret")
//
// Debug / Testing Client Options
//
Expand Down
2 changes: 1 addition & 1 deletion nokiahealth.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (u User) GetBodyMeasures(params *BodyMeasuresQueryParams) (BodyMeasuresResp
return bodyMeasureResponse, err
}

if params.ParseResponse {
if params != nil && params.ParseResponse {
bodyMeasureResponse.ParsedResponse = bodyMeasureResponse.ParseData()
}

Expand Down
8 changes: 4 additions & 4 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ type SleepSummaryData struct {
REMSleepDuration *int `json:"remsleepduration"`
WakeUpCount int `json:"wakeupcount"`
DurationToSleep int `json:"durationtosleep"`
DurationToWakeUp *int `json:"durationtowakeup`
DurationToWakeUp *int `json:"durationtowakeup"`
}

// SleepMeasuresResp represents the unmarshelled api response for sleep measures.
Expand Down Expand Up @@ -290,7 +290,7 @@ type ActivitiesMeasuresResp struct {
// body. As such they are all pointers. You may check SingleValue to determine
// if a single value was provided.
type ActivitiesMeasuresRespBody struct {
ParsedDate *time.Time `json:"parseddate`
ParsedDate *time.Time `json:"parseddate"`
Date *string `json:"date"`
Steps *float64 `json:"steps"`
Distance *float64 `json:"distance"`
Expand All @@ -308,7 +308,7 @@ type ActivitiesMeasuresRespBody struct {

// Activity represents an activity as recorded by Nokia Health.
type Activity struct {
ParsedDate *time.Time `json:"parseddate`
ParsedDate *time.Time `json:"parseddate"`
Date string `json:"date"`
Steps float64 `json:"steps"`
Distance float64 `json:"distance"`
Expand All @@ -334,7 +334,7 @@ type BodyMeasuresQueryParams struct {
MeasType *meastype.MeasType `json:"meastype"`
Category *int `json:"category"`
Limit *int `json:"limit"`
Offset *int `json:'offset"`
Offset *int `json:"offset"`
ParseResponse bool
}

Expand Down

0 comments on commit c8a6719

Please sign in to comment.