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

Adding support for Strava #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This repository contains a shim server, a shim server UI, and shims for third-pa
* [Jawbone UP](https://jawbone.com/up/developer)
* [RunKeeper](http://developer.runkeeper.com/healthgraph) ([application management portal](http://runkeeper.com/partner))
* [Withings](http://oauth.withings.com/api)
* [Strava](http://strava.github.io/api/)

The above links point to the developer website of each API. You'll need to visit these websites to register your
application and obtain authentication credentials for each of the shims you want to enable.
Expand Down Expand Up @@ -238,6 +239,9 @@ The currently supported shims are
* [omh:step-count](http://www.openmhealth.org/developers/schemas/#step-count)
* sleep
* [omh:sleep-duration](http://www.openmhealth.org/developers/schemas/#sleep-duration)
* strava
* activity
* [omh:physical-activity](http://www.openmhealth.org/developers/schemas/#physical-activity)

You can learn more about these shims and endpoints on the Open mHealth [developer site](http://www.openmhealth.org/developers/getting-started/).

Expand Down
4 changes: 4 additions & 0 deletions shim-server-ui/app/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ body {
padding-left: 10px;
}

.connected-row .glyphicon-calendar {
padding-left: 0px;
}

.sublink {
margin-right: 30px;
margin-bottom: 10px;
Expand Down
204 changes: 103 additions & 101 deletions shim-server-ui/app/views/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,117 +79,119 @@ <h3 class="panel-title">
</h3>
</div>

<ul class="list-group">

<li ng-class="{'connected-row':record.auths.indexOf(shim.shimKey) > -1}"
class="list-group-item" ng-repeat="shim in shims">
<div ng-show="record.auths.indexOf(shim.shimKey) == -1">
<span>{{shim.label}}</span>
<button ng-click="initOAuthFlow(record,shim.shimKey)"
type="button"
class="btn btn-primary pull-right">Connect
</button>
<div class="clearfix"></div>
</div>

<div ng-show="record.auths.indexOf(shim.shimKey) > -1">
<div class="panel-body">
<ul class="list-group">

<div style="width: 100%" ng-click="openEndpoints($event,record,shim.shimKey)">
<li ng-class="{'connected-row':record.auths.indexOf(shim.shimKey) > -1}"
class="list-group-item" ng-repeat="shim in shims">
<div ng-show="record.auths.indexOf(shim.shimKey) == -1">
<span>{{shim.label}}</span>

<span class="label label-lg label-success glyphicon glyphicon-ok">&nbsp;</span>

<button ng-click="disconnect($event, record, shim.shimKey)"
<button ng-click="initOAuthFlow(record,shim.shimKey)"
type="button"
class="btn btn-danger pull-right">Disconnect
class="btn btn-primary pull-right">Connect
</button>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>

<!--
-- Shim Data Panel: Presents endpoints for shim, allows for date range
-- selectors and clicking on data for verification purposes.
-->
<ul id="shim-panel-{{getHtmlId(record.username)}}-{{shim.shimKey}}"
class="list-group" style="display: none;">

<li class="list-group-item" ng-repeat="endpoint in shim.endpoints">
<div class="panel-heading">
<form class="form-inline" role="form" novalidate>
<div class="form-group col-md-1"><span>{{endpoint}}</span></div>
<div class="clearfix"></div>
<div class="form-group col-md-4">
<div class="input-group">
<input id="fromDate-{{getHtmlId(record.username)}}-{{shim.shimKey}}-{{endpoint}}"
type="text"
class="form-control"
value="{{fromDate}}"
ui-date
/>
<span class="input-group-btn">
<button id="fromBtn" type="button"
class="btn btn-default"
ng-click="pickDate('from',record,shim.shimKey,endpoint)"><i
class="glyphicon glyphicon-calendar"></i>
</button>
</span>

<div ng-show="record.auths.indexOf(shim.shimKey) > -1">

<div style="width: 100%" ng-click="openEndpoints($event,record,shim.shimKey)">
<span>{{shim.label}}</span>

<span class="label label-lg label-success glyphicon glyphicon-ok">&nbsp;</span>

<button ng-click="disconnect($event, record, shim.shimKey)"
type="button"
class="btn btn-danger pull-right">Disconnect
</button>
</div>
<div class="clearfix"></div>

<!--
-- Shim Data Panel: Presents endpoints for shim, allows for date range
-- selectors and clicking on data for verification purposes.
-->
<ul id="shim-panel-{{getHtmlId(record.username)}}-{{shim.shimKey}}"
class="list-group" style="display: none;">

<li class="list-group-item" ng-repeat="endpoint in shim.endpoints">
<div class="panel-heading">
<form class="form-inline" role="form" novalidate>
<div class="form-group col-md-1"><span>{{endpoint}}</span></div>
<div class="clearfix"></div>
<div class="col-md-4">
<div class="input-group">
<input id="fromDate-{{getHtmlId(record.username)}}-{{shim.shimKey}}-{{endpoint}}"
type="text"
class="form-control"
value="{{fromDate}}"
ui-date
/>
<span class="input-group-btn">
<button id="fromBtn" type="button"
class="btn btn-default"
ng-click="pickDate('from',record,shim.shimKey,endpoint)"><i
class="glyphicon glyphicon-calendar"></i>
</button>
</span>
</div>
</div>
</div>

<div class="form-group col-md-4">
<div class="input-group">
<input id="toDate-{{getHtmlId(record.username)}}-{{shim.shimKey}}-{{endpoint}}"
type="text"
class="form-control"
value="{{toDate}}"
ui-date
/>
<span class="input-group-btn">
<button id="toBtn" type="button"
class="btn btn-default"
ng-click="pickDate('to',record,shim.shimKey,endpoint)"><i
class="glyphicon glyphicon-calendar"></i>
</button>
</span>

<div class="form-group col-md-4">
<div class="input-group">
<input id="toDate-{{getHtmlId(record.username)}}-{{shim.shimKey}}-{{endpoint}}"
type="text"
class="form-control"
value="{{toDate}}"
ui-date
/>
<span class="input-group-btn">
<button id="toBtn" type="button"
class="btn btn-default"
ng-click="pickDate('to',record,shim.shimKey,endpoint)"><i
class="glyphicon glyphicon-calendar"></i>
</button>
</span>
</div>
</div>
</div>

<div class="form-group col-md-3" style="text-align: left;">
<div class="input-group btn-group">
<button ng-click=
"getData(record, shim.shimKey, endpoint, false)"
type="button" style="font-size: 10px;"
class="btn btn-default">Raw
</button>
<button ng-click=
"getData(record, shim.shimKey, endpoint, true)"
type="button" style="font-size: 10px;"
class="btn btn-default">Normalized
</button>

<div class="form-group col-md-4" style="text-align: left;">
<div class="input-group btn-group">
<button ng-click=
"getData(record, shim.shimKey, endpoint, false)"
type="button" style="font-size: 10px;"
class="btn btn-default">Raw
</button>
<button ng-click=
"getData(record, shim.shimKey, endpoint, true)"
type="button" style="font-size: 10px;"
class="btn btn-default">Normalized
</button>
</div>
</div>
</div>
</form>
</div>
<br>
<!--
-- A textbox which displays the JSON results from the shim server.
-->
<div class="panel-body">
<div id="shim-error-{{getHtmlId(record.username)}}-{{shim.shimKey}}-{{endpoint}}"
class="error"></div>
<div id="shim-spinner-{{getHtmlId(record.username)}}-{{shim.shimKey}}-{{endpoint}}"
class="spinner">&nbsp;</div>
<textarea class="jsonResponseBox"
id="shim-results-{{getHtmlId(record.username)}}-{{shim.shimKey}}-{{endpoint}}"
></textarea>
</div>
</li>
</ul>
</form>
</div>
<br>
<!--
-- A textbox which displays the JSON results from the shim server.
-->
<div class="panel-body">
<div id="shim-error-{{getHtmlId(record.username)}}-{{shim.shimKey}}-{{endpoint}}"
class="error"></div>
<div id="shim-spinner-{{getHtmlId(record.username)}}-{{shim.shimKey}}-{{endpoint}}"
class="spinner">&nbsp;</div>
<textarea class="jsonResponseBox"
id="shim-results-{{getHtmlId(record.username)}}-{{shim.shimKey}}-{{endpoint}}"
></textarea>
</div>
</li>
</ul>

</div>
</div>

</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.openmhealth.shim.runkeeper.RunkeeperShim;
import org.openmhealth.shim.withings.WithingsConfig;
import org.openmhealth.shim.withings.WithingsShim;
import org.openmhealth.shim.strava.StravaConfig;
import org.openmhealth.shim.strava.StravaShim;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -71,6 +73,9 @@ public class ShimRegistryImpl implements ShimRegistry {
@Autowired
private WithingsConfig withingsConfig;

@Autowired
private StravaConfig stravaConfig;

private LinkedHashMap<String, Shim> registryMap;

public ShimRegistryImpl() {
Expand Down Expand Up @@ -112,6 +117,12 @@ public void init() {
new HealthvaultShim(
authParametersRepo, shimServerConfig, healthvaultConfig));
}

if (stravaConfig.getClientId() != null) {
registryMap.put(StravaShim.SHIM_KEY,
new StravaShim(
authParametersRepo, accessParametersRepo, shimServerConfig, stravaConfig));
}
}

@Override
Expand All @@ -135,7 +146,8 @@ public List<Shim> getAvailableShims() {
new RunkeeperShim(null, null, null, runkeeperConfig),
new WithingsShim(null, null, withingsConfig),
new HealthvaultShim(null, null, healthvaultConfig),
new FitbitShim(null, null, fitbitConfig)
new FitbitShim(null, null, fitbitConfig),
new StravaShim(null, null, null, stravaConfig)
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2014 Open mHealth
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openmhealth.shim.strava;

import org.openmhealth.shim.ApplicationAccessParameters;
import org.openmhealth.shim.ApplicationAccessParametersRepo;
import org.openmhealth.shim.ShimConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
* @author Pedro Sampaio
*/
@Component
@ConfigurationProperties(prefix = "openmhealth.shim.strava")
public class StravaConfig implements ShimConfig {

private String clientId;

private String clientSecret;

@Autowired
private ApplicationAccessParametersRepo applicationParametersRepo;

public String getClientId() {
ApplicationAccessParameters parameters =
applicationParametersRepo.findByShimKey(StravaShim.SHIM_KEY);
return parameters != null ? parameters.getClientId() : clientId;
}

public void setClientId(String clientId) {
this.clientId = clientId;
}

public String getClientSecret() {
ApplicationAccessParameters parameters =
applicationParametersRepo.findByShimKey(StravaShim.SHIM_KEY);
return parameters != null ? parameters.getClientSecret() : clientSecret;
}

public void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
}
}
Loading