Commit 244f955a authored by Mauro E. Bender's avatar Mauro E. Bender

WIP #10 - Add credentials

parent 716d034e
//
// Credentials.swift
// Pods
//
// Created by Mauro Bender on 25/8/16.
//
//
struct Credentials {
let grantType: String
let data: [ String: String ]
func serialize() -> [ String: String ] {
var data = self.data
data += [ "grant_type": grantType ]
return data
}
}
extension Credentials {
init( username: String, password: String, extra: [ String: String ]? = nil ) {
self.grantType = "password"
var data = [ "username": username, "password": password ]
if extra != nil { data += extra }
self.data = data
}
init( assertion: String, extra: [ String: String ]? = nil ) {
self.grantType = "assertion"
var data = [ "assertion": assertion ]
if extra != nil { data += extra }
self.data = data
}
public static func password( username: String, password: String, extra: [ String: String ]? = nil ) -> Credentials {
return Credentials( username: username, password: password, extra: extra )
}
public static func facebook( token: String, extra: [ String: String ]? = nil ) -> Credentials {
return Credentials( assertion: token, extra: extra )
}
}
......@@ -12,4 +12,12 @@ func += <K, V> (inout left: [K:V], right: [K:V]) {
for (k, v) in right {
left.updateValue(v, forKey: k)
}
}
func += <K, V> (inout left: [K:V], right: [K:V]?) {
guard right != nil else { return }
for (k, v) in right! {
left.updateValue(v, forKey: k)
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment