Skip to content

Commit

Permalink
Merge origin/master
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterWithers committed May 1, 2015
2 parents 892b398 + bdec284 commit ce44820
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 2 deletions.
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
495359281AE91A88009E870A /* VSTServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 495359271AE91A88009E870A /* VSTServer.swift */; };
4996A49A1AD7B4D0000437CF /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4996A4991AD7B4D0000437CF /* LoginViewController.swift */; };
4996A49C1AD7BA43000437CF /* ProgressViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4996A49B1AD7BA43000437CF /* ProgressViewController.swift */; };
4996A49E1AD7C9CE000437CF /* TempObjects.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4996A49D1AD7C9CE000437CF /* TempObjects.swift */; };
Expand Down Expand Up @@ -38,6 +39,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
495359271AE91A88009E870A /* VSTServer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VSTServer.swift; sourceTree = "<group>"; };
4996A4991AD7B4D0000437CF /* LoginViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginViewController.swift; sourceTree = "<group>"; };
4996A49B1AD7BA43000437CF /* ProgressViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProgressViewController.swift; sourceTree = "<group>"; };
4996A49D1AD7C9CE000437CF /* TempObjects.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TempObjects.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -79,6 +81,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
495359291AE91AA1009E870A /* Models */ = {
isa = PBXGroup;
children = (
495359271AE91A88009E870A /* VSTServer.swift */,
);
name = Models;
sourceTree = "<group>";
};
4996A4A11AD7E4B1000437CF /* Resources */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -110,6 +120,7 @@
children = (
4996A49F1AD7E480000437CF /* Constants.swift */,
49C653DF1ACEA49E00CA2803 /* ViewControllers */,
495359291AE91AA1009E870A /* Models */,
4996A49D1AD7C9CE000437CF /* TempObjects.swift */,
4996A4A21AD7F829000437CF /* PassControlBackAndForth.swift */,
4996A4A11AD7E4B1000437CF /* Resources */,
Expand Down Expand Up @@ -274,6 +285,7 @@
49CD8F0D1ACED40500DD3A5F /* DownloadViewController.swift in Sources */,
49C653B91ACE9CB400CA2803 /* AppDelegate.swift in Sources */,
49AEA1401ADFC291001A82A1 /* InfoViewController.swift in Sources */,
495359281AE91A88009E870A /* VSTServer.swift in Sources */,
4996A4A01AD7E480000437CF /* Constants.swift in Sources */,
49F1F5C61AD8097000457411 /* ResultViewController.swift in Sources */,
49AEA13E1ADFBEF5001A82A1 /* SettingsViewController.swift in Sources */,
Expand Down
Expand Up @@ -9,6 +9,6 @@
import Foundation

let kDevelopmentMode = true
let kSpeedUpDownload = kDevelopmentMode ? false : false
let kSpeedUpDownload = kDevelopmentMode ? true : false

let kWebserviceURL = kDevelopmentMode ? "http://localhost:8080" : ""
let kWebserviceURL = kDevelopmentMode ? "http://applejack.science.ru.nl:8080/" : ""
Expand Up @@ -62,6 +62,14 @@ class LoginViewController: UIViewController {
createAccountLink.text = "Create account"
self.view.addSubview(createAccountLink)

//Create the VSTServer object
var vstServer : VSTServer = VSTServer(url: kWebserviceURL)

vstServer.tryLoggingIn("wessel", password: "hunter2")

vstServer.getAllVowels()
vstServer.createNewUser("Wessel")

}

override func didReceiveMemoryWarning()
Expand Down
126 changes: 126 additions & 0 deletions mobile/Vowel Space Travel iOS/Vowel Space Travel iOS/VSTServer.swift
@@ -0,0 +1,126 @@
//
// VSTServer.swift
// Vowel Space Travel iOS
//
// Created by Wessel Stoop on 23/04/15.
// Copyright (c) 2015 Radboud University. All rights reserved.
//

import Foundation

enum LoginResult
{
case Successful
case UserDoesNotExist
case IncorrectPassword
}

class VSTServer : NSObject
{
var url : String

var userName : String?
var userLoggedInSuccesfully : Bool = false

var latestResponse : NSArray?

init(url: String)
{
self.url = url
}

func HTTPGetToJSON(urlExtension: String, completionHandler: ((NSDictionary?, NSError?) -> Void))
{
var jsonData : NSDictionary?

var request : NSURLRequest = NSURLRequest(URL: NSURL(string: self.url+urlExtension)!)

println(request.URL.standardizedURL)
println(request.HTTPBody)

NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!, responseData: NSData!,error:NSError!) -> Void in

if error == nil
{
jsonData = NSJSONSerialization.JSONObjectWithData(responseData,options: NSJSONReadingOptions.MutableContainers, error:nil) as NSDictionary?

completionHandler(jsonData,error);

}
else
{
println("Error: \(error.localizedDescription)")
}

})

}

func HTTPPostToJSON(urlExtension: String, completionHandler: ((NSDictionary?, NSError?) -> Void))
{
var jsonData : NSDictionary?

var request : NSMutableURLRequest = NSMutableURLRequest(URL: NSURL(string: self.url+urlExtension)!)

println(self.url+urlExtension)

var jsonString : String = "{ \"firstName\" : \"Wessel\", \"lastName\" : \"Stoop\" }"
request.HTTPBody = jsonString.dataUsingEncoding(NSUTF8StringEncoding,allowLossyConversion:true)
request.HTTPMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")

NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!, responseData: NSData!,error:NSError!) -> Void in

if error == nil
{
jsonData = NSJSONSerialization.JSONObjectWithData(responseData,options: NSJSONReadingOptions.MutableContainers, error:nil) as NSDictionary?

completionHandler(jsonData,error);

}
else
{
println("Error: \(error.localizedDescription)")
}

})

}

func tryLoggingIn(userName : String, password: String) -> LoginResult
{
self.userName = userName
self.userLoggedInSuccesfully = true

return LoginResult.Successful
}

func createNewUser(userName : String)
{
self.HTTPPostToJSON("players")
{
(jsonData,err) -> Void in
}
}

func getAllVowels()
{
assert(self.userLoggedInSuccesfully, "You have to be logged in to do this")

var urlExtensionToGetVowels : String = "vowels?page=0&size=30"
self.HTTPGetToJSON(urlExtensionToGetVowels)
{
(jsonData,err) -> Void in

var unpackagedJsonData : NSDictionary = jsonData!["_embedded"] as NSDictionary

for vowel in unpackagedJsonData["vowels"] as NSArray
{

println(vowel["ipa"]!)
}

}
}

}

0 comments on commit ce44820

Please sign in to comment.