Skip to content

Commit

Permalink
4.x-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebrowning committed Feb 23, 2016
1 parent 16e0f82 commit 7372659
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 513 deletions.
82 changes: 82 additions & 0 deletions DIOS.swift
@@ -0,0 +1,82 @@
//
// DIOS.swift
// Drupal Publisher
//
// Created by Kyle Browning on 1/25/16.
// Copyright © 2016 Kyle Browning. All rights reserved.
//

import UIKit
import Alamofire
import SwiftyJSON

class DIOS: NSObject {
static let sharedInstance = DIOS()

let DIOSURLKey = "diosurlkey"
let plistPath = NSBundle.mainBundle().pathForResource("dios", ofType: "plist")
let requestFormat = "?_format=json"
var headers = [
"Content-Type":"application/json",
"Accept":"application/json",
]
var URL : String?
var endpoint : String?
var basicUsername : String?
var basicPassword : String?
var signRequestsBasic : Bool?

override init() {
super.init()
self.signRequestsBasic = false
let dict = NSDictionary(contentsOfFile: plistPath!)
self.URL = dict!.objectForKey(self.DIOSURLKey) as? String

}
func setUserNameAndPassword(username:String?, password:String?) {
self.basicUsername = username
self.basicPassword = password
self.signRequestsBasic = true
}
func sendRequest(path:String?, method:Alamofire.Method, params:Dictionary<String, String>?, completionHandler:(success:Bool, response:NSDictionary!, error:NSError!) -> Void) {
let urlString = self.URL! + "/" + path! + self.requestFormat

if (self.signRequestsBasic == true) {

let plainString = self.basicUsername! + ":" + self.basicPassword!
let credentialData = plainString.dataUsingEncoding(NSUTF8StringEncoding)!
let base64String = credentialData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions([]))

headers["Authorization"] = "Basic \(base64String)"
}

Alamofire.request(method, urlString, parameters: params, encoding:.JSON, headers: headers).validate().responseJSON
{ response in switch response.result {
case .Success(let JSON):
let response = JSON as! NSDictionary
completionHandler(success: true, response: response, error: nil)
case .Failure(let error):
completionHandler(success: false, response: nil, error: error)
}
}

}
func logUserIn(username:String?, password:String?, completionHandler:(success:Bool, response:NSDictionary!, error:NSError!) -> Void) {
let body = [
"username": username! as String,
"password": password! as String,
]
// Fetch Request
Alamofire.request(.POST, self.URL! + "/" + self.endpoint! + "/user/login", headers: headers, parameters: body, encoding: .JSON)
.validate(statusCode: 200..<300)
.responseJSON { response in switch response.result {
case .Success(let JSON):
let response = JSON as! NSDictionary
completionHandler(success: true, response: response, error: nil)
case .Failure(let error):
completionHandler(success: false, response: nil, error: error)
}
}
}

}
31 changes: 0 additions & 31 deletions DIOSComment.h

This file was deleted.

50 changes: 0 additions & 50 deletions DIOSComment.m

This file was deleted.

33 changes: 0 additions & 33 deletions DIOSEntity.h

This file was deleted.

67 changes: 0 additions & 67 deletions DIOSEntity.m

This file was deleted.

31 changes: 0 additions & 31 deletions DIOSNode.h

This file was deleted.

40 changes: 0 additions & 40 deletions DIOSNode.m

This file was deleted.

35 changes: 0 additions & 35 deletions DIOSSession.h

This file was deleted.

0 comments on commit 7372659

Please sign in to comment.