Skip to content

Commit ce4cd0a

Browse files
authored
Merge pull request #70 from TaskarCenterAtUW/feature-documentation
2 parents 2185b9c + 2cb5ba4 commit ce4cd0a

File tree

3 files changed

+57
-14
lines changed

3 files changed

+57
-14
lines changed

GoInfoGame/osmapi/OSMConfig.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@
66
//
77

88
import Foundation
9+
/// OSMConfig structure to handle the configuration
10+
///
911
public struct OSMConfig {
1012
public let baseUrl: String
11-
//https://waylyticsposm.westus2.cloudapp.azure.com/api/0.6/
12-
// For testing data upload
1313

14-
// Make all the URLs here.
14+
/// Production Openstreetmap server
15+
/// Links directly to OpenstreetMap server
1516
public static var production : OSMConfig {
1617
OSMConfig(baseUrl: "https://api.openstreetmap.org/api/0.6/")
1718
}
1819

20+
/// Internal test server
1921
public static var test: OSMConfig {
2022
OSMConfig(baseUrl: "https://waylyticsposm.westus2.cloudapp.azure.com/api/0.6/")
2123
}
22-
24+
/// Links to Dev server of OSM
2325
public static var testOSM : OSMConfig {
2426
OSMConfig(baseUrl: "\(url)api/0.6/")
2527
}

GoInfoGame/osmapi/OSMConnection.swift

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,31 @@
66
//
77

88
import Foundation
9+
10+
/**
11+
Base class that deals with all the interactions with OSM server
12+
*/
913
public class OSMConnection {
1014
// Creates a connection
1115
let baseUrl: String
1216
var currentChangesetId: Int? = 0
1317
let userCreds: OSMLogin
1418
// Lets see if we can start with some authentication or node
19+
20+
/// Initializer for OSMConnection
21+
/// - parameter config : The Server configuration (defaults to OSMConfig.testOSM)
22+
/// - parameter currentChangesetId: The overal changeset id for the user
23+
/// - parameter userCreds: User credentials for authenticated calls. Defaults to testOSM
1524
public init(config: OSMConfig = OSMConfig.testOSM, currentChangesetId: Int? = nil, userCreds: OSMLogin = OSMLogin.testOSM) {
1625
self.baseUrl = config.baseUrl
1726
self.currentChangesetId = currentChangesetId
1827
self.userCreds = userCreds
1928
}
20-
29+
/// Fetches a single node
30+
/// - parameter id : the `id` of the node
31+
/// - parameter completion: The completion handler that receives the node
2132
func getNode(id: String,_ completion: @escaping (Result<OSMNodeResponse, Error>)-> Void) {
33+
//TODO: Write error when node does not exist
2234
let urlString = self.baseUrl.appending("node/").appending(id).appending(".json")
2335
guard let url = URL(string: urlString) else {
2436
print("Invalid URL given")
@@ -27,8 +39,11 @@ public class OSMConnection {
2739
BaseNetworkManager.shared.addOrSetHeaders(header: "Authorization", value: "Basic \(self.userCreds.getHeaderData())")
2840
BaseNetworkManager.shared.fetchData(url: url, completion: completion) // Need to improve this one
2941
}
30-
42+
/// Fetches a single way
43+
/// - parameter id: the `id` of the way
44+
/// - parameter completion: The completion handler that receives the way
3145
func getWay(id: String,_ completion: @escaping (Result<OSMWayResponse, Error>)-> Void) {
46+
//TODO: Write errors when way does not exist
3247
let urlString = self.baseUrl.appending("way/").appending(id).appending(".json")
3348
guard let url = URL(string: urlString) else {
3449
print("Invalid URL given")
@@ -38,8 +53,10 @@ public class OSMConnection {
3853
BaseNetworkManager.shared.fetchData(url: url, completion: completion) // Need to improve this one
3954
}
4055

56+
/// Opens a changeset for the given user
57+
/// - parameter completion: Completion handler that receives the newly opened changesetId
4158
public func openChangeSet(_ completion: @escaping((Result<Int,Error>)->Void)) {
42-
// Have to open changeset
59+
//TODO: Write errors when not authenticated and if there is already an open changeset with same user
4360
let urlString = self.baseUrl.appending("changeset/create")
4461
guard let url = URL(string: urlString) else {
4562
print("Invalid URL given")
@@ -58,8 +75,11 @@ public class OSMConnection {
5875
completion(result)
5976
}
6077
}
61-
78+
/// Closes the changeset
79+
/// - parameter id: The changeset ID to be closed
80+
/// - parameter completion: The completion handler
6281
public func closeChangeSet(id: String,completion: @escaping((Result<Bool,Error>)->Void)) {
82+
//TODO: Write error codes if not able to close
6383
let urlString = self.baseUrl.appending("changeset/").appending(id).appending("/close")
6484
guard let url = URL(string: urlString) else {
6585
print("Invalid URL given")
@@ -109,9 +129,12 @@ public class OSMConnection {
109129
BaseNetworkManager.shared.fetchData(url: url, completion: completion)
110130
}
111131

112-
132+
/// Updates a single node
133+
/// - parameter node : An instance of `OSMNode`
134+
/// - parameter tags: A `[String:String]` dictionary containing new added tags
135+
/// - parameter completion : A handler that is called after the call is made
113136
public func updateNode(node: inout OSMNode, tags:[String:String], completion: @escaping((Result<Int,Error>)->Void)){
114-
// Have to do this.
137+
//TODO: Error handling when there is no active changeset, no node and not authorized
115138
let urlString = self.baseUrl.appending("node/").appending(String(node.id))
116139
guard let url = URL(string: urlString) else {
117140
print("Invalid URL given")
@@ -130,9 +153,12 @@ public class OSMConnection {
130153
BaseNetworkManager.shared.postData(url: url, method: "PUT",body: node ,completion: completion)
131154

132155
}
133-
156+
/// Updates a single way
157+
/// - parameter way: the current way element
158+
/// - parameter tags: `[String:String]` dictionary containing new tags
159+
/// - parameter completion: The completion handler after this is done
134160
public func updateWay(way: inout OSMWay, tags:[String:String], completion: @escaping((Result<Int,Error>)->Void)){
135-
// Have to do this.
161+
//TODO: Error handling when there is no active changeset, way not found and not authorized
136162
let urlString = self.baseUrl.appending("way/").appending(String(way.id))
137163
guard let url = URL(string: urlString) else {
138164
print("Invalid URL given")
@@ -148,15 +174,24 @@ public class OSMConnection {
148174
BaseNetworkManager.shared.postData(url: url, method: "PUT",body: way ,completion: completion)
149175

150176
}
177+
178+
/// Fetches the user details based on `id`
179+
/// - parameter id : Id of the user
180+
/// - parameter completion : Completion handler with user data response
151181
func getUserDetailsWithId(id: String,_ completion: @escaping (Result<OSMUserDataResponse, Error>)-> Void) {
182+
//TODO: Error for user id not found
152183
let urlString = self.baseUrl.appending("user/").appending(id).appending(".json")
153184
guard let url = URL(string: urlString) else {
154185
print("Invalid URL given")
155186
return
156187
}
157188
BaseNetworkManager.shared.fetchData(url: url, completion: completion)
158189
}
190+
191+
/// Fetches the current logged in user details
192+
/// - parameter completion : Completion handler
159193
public func getUserDetails(_ completion: @escaping (Result<OSMUserDataResponse, Error>)-> Void) {
194+
//TODO: Errors for unauthenticated call
160195
let urlString = self.baseUrl.appending("user/details.json")
161196
guard let url = URL(string: urlString) else {
162197
print("Invalid URL given")

GoInfoGame/osmapi/OSMLogin.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,32 @@
66
//
77

88
import Foundation
9+
/// Structure to store the user credentials
910
public struct OSMLogin {
11+
/// user name
1012
let username: String
13+
/// the password
1114
let password: String
1215

13-
// Header information needed
16+
/// Fetches the header information to be added
17+
/// - returns String
1418
func getHeaderData() -> String {
1519
let loginString = "\(username):\(password)"
1620
let loginData = loginString.data(using: String.Encoding.utf8)!
1721
let base64LoginString = loginData.base64EncodedString()
1822
return base64LoginString
1923
}
2024

25+
/// Production credentials
2126
public static var production : OSMLogin {
2227
OSMLogin(username: "[email protected]", password: "$$WentCityErwin")
2328
}
2429

30+
/// Test server credentials
2531
public static var test : OSMLogin {
2632
OSMLogin(username: "[email protected]", password: "a$hwa7hamA") // Need to change
2733
}
28-
34+
/// Dev server credentials
2935
public static var testOSM : OSMLogin {
3036
OSMLogin(username: "[email protected]", password: "d.Dgq6J6aBy.dCJ")
3137
}

0 commit comments

Comments
 (0)