use nightscout port number if available for missing cases
- use the server port number if available when pulling from /api/v1/entries endpoint - use the server port number if available to check connection at /api/v1/experiments/test - fixes JohanDegraeve/xdripswift#400
This commit is contained in:
parent
7eb822c1a1
commit
8f98f6d1c2
|
@ -9,6 +9,8 @@ extension Endpoint {
|
||||||
/// - parameters:
|
/// - parameters:
|
||||||
/// - hostAndScheme : hostname, eg http://www.mysite.com or https://www.mysite.com - must include the scheme - IF HOST DOESN'T START WITH A KNOWN SCHEME, THEN A FATAL ERROR WILL BE THROWN - known scheme's can be found in type EndPointScheme
|
/// - hostAndScheme : hostname, eg http://www.mysite.com or https://www.mysite.com - must include the scheme - IF HOST DOESN'T START WITH A KNOWN SCHEME, THEN A FATAL ERROR WILL BE THROWN - known scheme's can be found in type EndPointScheme
|
||||||
/// - count : maximum number of readings to get
|
/// - count : maximum number of readings to get
|
||||||
|
/// - token: the Nightscout token used for authentication (optional)
|
||||||
|
/// - port: Nightscout server port number (optional)
|
||||||
static func getEndpointForLatestNSEntries(hostAndScheme:String, count: Int, token: String?) -> Endpoint {
|
static func getEndpointForLatestNSEntries(hostAndScheme:String, count: Int, token: String?) -> Endpoint {
|
||||||
|
|
||||||
// split hostAndScheme in host and scheme
|
// split hostAndScheme in host and scheme
|
||||||
|
@ -30,10 +32,11 @@ extension Endpoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
return Endpoint(
|
return Endpoint(
|
||||||
host:host,
|
host: host,
|
||||||
scheme:scheme!,
|
scheme: scheme!,
|
||||||
path: "/api/v1/entries/sgv.json",
|
path: "/api/v1/entries/sgv.json",
|
||||||
queryItems: queryItems
|
queryItems: queryItems,
|
||||||
|
port: UserDefaults.standard.nightScoutPort
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,9 @@ struct Endpoint {
|
||||||
/// array of URLQueryItem
|
/// array of URLQueryItem
|
||||||
let queryItems: [URLQueryItem]
|
let queryItems: [URLQueryItem]
|
||||||
|
|
||||||
|
/// the Nightscout server port number
|
||||||
|
let port: Int
|
||||||
|
|
||||||
/// gets url
|
/// gets url
|
||||||
var url: URL? {
|
var url: URL? {
|
||||||
var components = URLComponents()
|
var components = URLComponents()
|
||||||
|
@ -25,6 +28,11 @@ struct Endpoint {
|
||||||
components.path = path
|
components.path = path
|
||||||
components.queryItems = queryItems
|
components.queryItems = queryItems
|
||||||
|
|
||||||
|
// add the port number component only if it exists (this avoids URLComponents adding a port number of 0 as port number is stored as non-optional integer in UserDefaults)
|
||||||
|
if port != 0 {
|
||||||
|
components.port = port
|
||||||
|
}
|
||||||
|
|
||||||
return components.url
|
return components.url
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,12 @@ class SettingsViewNightScoutSettingsViewModel {
|
||||||
private func testNightScoutCredentials() {
|
private func testNightScoutCredentials() {
|
||||||
|
|
||||||
// unwrap siteUrl and apiKey
|
// unwrap siteUrl and apiKey
|
||||||
guard let siteUrl = UserDefaults.standard.nightScoutUrl else {return}
|
guard var siteUrl = UserDefaults.standard.nightScoutUrl else {return}
|
||||||
|
|
||||||
|
// add port number if it exists
|
||||||
|
if UserDefaults.standard.nightScoutPort != 0 {
|
||||||
|
siteUrl += ":" + UserDefaults.standard.nightScoutPort.description
|
||||||
|
}
|
||||||
|
|
||||||
if let url = URL(string: siteUrl) {
|
if let url = URL(string: siteUrl) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue