Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
Added support for Nightscout Access Tokens (#6)
Browse files Browse the repository at this point in the history
Did a basic test, looks like it should work, thanks to @jees1234!.

This Fixes #2
  • Loading branch information
jees1234 authored and dabear committed Aug 5, 2019
1 parent 920755d commit 9e7e6a1
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 172 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using FloatingGlucose.Classes.Extensions;
using FloatingGlucose.Classes.Extensions;
using ShareClientDotNet;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -136,6 +136,10 @@ public virtual void OnPluginSelected(FormGlucoseSettings form)
{
form.lblDataSourceLocation.Text = "Dexcom share server";
form.txtDataSourceLocation.Text = this.shareClient.CurrentDexcomServer;

form.lblUsername.Text = "User Name";
form.lblPassword.Enabled = true;
form.txtPassword.Enabled = true;
}

public virtual bool VerifyConfig(Properties.Settings settings)
Expand Down Expand Up @@ -179,4 +183,4 @@ public virtual async Task<IDataSourcePlugin> GetDataSourceDataAsync(NameValueCol
return this;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using FloatingGlucose.Classes.Extensions;
using FloatingGlucose.Classes.Extensions;
using FloatingGlucose.Classes.Utils;
using Newtonsoft.Json;
using System;
Expand All @@ -24,7 +24,7 @@ internal class NightscoutPebbleEndpoint : IDataSourcePlugin

public List<string> HandleFormatting() => null;

public virtual bool RequiresUserNameAndPassword => false;
public virtual bool RequiresUserNameAndPassword => true;
public virtual bool PluginDisabled => false;
public virtual bool RequiresBrowseButton => false;
public virtual string BrowseDialogFileFilter => "";
Expand Down Expand Up @@ -138,6 +138,9 @@ public double RawGlucose
public virtual void OnPluginSelected(FormGlucoseSettings form)
{
form.lblDataSourceLocation.Text = "Your Nightscout installation URL";
form.lblUsername.Text = "Access Token";
form.lblPassword.Enabled = false;
form.txtPassword.Enabled = false;

var source = form.txtDataSourceLocation.Text.ToLower();
//for this plugin, we handle only http:// and https://
Expand Down Expand Up @@ -187,4 +190,4 @@ public virtual async Task<IDataSourcePlugin> GetDataSourceDataAsync(NameValueCol
return this;
}
}
}
}
24 changes: 20 additions & 4 deletions FloatingGlucose/FloatingGlucose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,21 @@ private NameValueCollection datasourceLocation
// data points to calculate raw glucose diff
var count = Default.EnableRawGlucoseDisplay ? 2 : 1;
var units = Default.GlucoseUnits;
var urlstripped = Default.DataPathLocation.TrimEnd('/');
var url = Default.DataPathLocation.TrimEnd('/');
var username = Default.UserName;
if (username == "")
{
url += $"/pebble?count={count}&units={units}";
} else
{
// username not empty -> use as Accees Token
url += $"/pebble?count={count}&units={units}&token={username}";
}

return new NameValueCollection()
{
{ "raw", Default.DataPathLocation },
{ "location", $"{urlstripped}/pebble?count={count}&units={units}"}
{ "location", url}
};
}
}
Expand Down Expand Up @@ -740,7 +750,13 @@ private void reenableAlarmsToolStripMenuItem_Click(object sender, EventArgs e)

private void openNightscoutSiteToolStripMenuItem_Click(object sender, EventArgs e)
{
var url = Default.DataPathLocation;
var url = Default.DataPathLocation.TrimEnd('/');
var username = Default.UserName;
if (username != "")
{
// username not empty -> use as Access Token
url += $"/?token={username}";
}
if (Validators.IsUrl(url))
{
try
Expand All @@ -763,4 +779,4 @@ private void reloadToolStripMenuItem_Click(object sender, EventArgs e)
this.LoadGlucoseValue();
}
}
}
}
Loading

0 comments on commit 9e7e6a1

Please sign in to comment.