This repository has been archived by the owner on Jan 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,152 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// AccountController.swift | ||
// HarvestKit | ||
// | ||
// Created by Matthew Cheetham on 16/01/2016. | ||
// Copyright © 2016 Matt Cheetham. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
#if os(iOS) | ||
import ThunderRequest | ||
#elseif os(tvOS) | ||
import ThunderRequestTV | ||
#elseif os (OSX) | ||
import ThunderRequestMac | ||
#endif | ||
|
||
/** | ||
Handles loading information about the currently authenticated user | ||
*/ | ||
public final class AccountController { | ||
|
||
/** | ||
The request controller used to load account information. This is shared with other controllers | ||
*/ | ||
let requestController: TSCRequestController | ||
|
||
internal init(requestController: TSCRequestController) { | ||
|
||
self.requestController = requestController | ||
|
||
} | ||
|
||
/** | ||
Retrieves a user and a company object for the currently authenticated user. | ||
|
||
- parameter completionHandler: The completion handler to call passing a company and user object if available. This may also be passed an error object where appropriate | ||
*/ | ||
public func getAccountInformation(completionHandler: (currentUser: User?, currentCompany: Company?, requestError: NSError?) -> ()) { | ||
|
||
requestController.get("account/who_am_i") { (response: TSCRequestResponse?, requestError: NSError?) -> Void in | ||
|
||
if let error = requestError { | ||
completionHandler(currentUser: nil, currentCompany: nil, requestError: error) | ||
return; | ||
} | ||
|
||
guard let responseDictionary = response?.dictionary as? [String: AnyObject] else { | ||
completionHandler(currentUser: nil, currentCompany: nil, requestError: nil) | ||
return; | ||
} | ||
|
||
var responseCompany: Company? | ||
var responseUser: User? | ||
|
||
if let companyDictionary = responseDictionary["company"] as? [String: AnyObject] { | ||
responseCompany = Company(dictionary: companyDictionary) | ||
} | ||
|
||
if let _ = responseDictionary["user"] as? [String: AnyObject] { | ||
responseUser = User(dictionary: responseDictionary) | ||
} | ||
|
||
completionHandler(currentUser: responseUser, currentCompany: responseCompany, requestError: nil) | ||
|
||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// | ||
// Company.swift | ||
// HarvestKit | ||
// | ||
// Created by Matthew Cheetham on 16/01/2016. | ||
// Copyright © 2016 Matt Cheetham. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/** | ||
A struct representation of a company. Typiclaly returned from the API when querying about the current authenticated user | ||
*/ | ||
public struct Company { | ||
|
||
/** | ||
Determines whether or not this company account is active | ||
*/ | ||
public var active: Bool? | ||
|
||
/** | ||
The plan this buisiness is on. Determines how much their monthly payments are | ||
*/ | ||
public var planType: String? | ||
|
||
/** | ||
Not documented in Harvest Documentation. Presumably the format that timers from this account should be displayed in. | ||
*/ | ||
public var timeFormat: String? | ||
|
||
/** | ||
The URL that users must go to to access this harvest account | ||
*/ | ||
public var baseURL: NSURL? | ||
|
||
/** | ||
The day that this company considers to be the beginning of the working week | ||
*/ | ||
public var weekStartDay: String? | ||
|
||
/** | ||
An dictionary of objects determining what modules this company has enabled. This can determine which controllers you can use as some methods will return 404 where that feature is not enabled in the modules. Admins can configure modules. | ||
*/ | ||
public var modules: [String: Bool]? | ||
|
||
/** | ||
The seperator that should be used for numbers over a thousand if any. Helps to localise figures where appropriate | ||
*/ | ||
public var thousandsSeperator: String? | ||
|
||
/** | ||
The color scheme that the company has applied to their account in the website. You may use this to theme your application if you wish. | ||
*/ | ||
public var colorScheme: String? | ||
|
||
/** | ||
The symbol that should be use to denote a decimal. Varies per company locale. | ||
*/ | ||
public var decimalSymbol: String? | ||
|
||
/** | ||
The name of the company | ||
*/ | ||
public var companyName: String? | ||
|
||
/** | ||
The time format used by the company. 12h or 24h for example. | ||
*/ | ||
public var clockFormat: String? | ||
|
||
internal init(dictionary: [String: AnyObject]) { | ||
|
||
active = dictionary["active"] as? Bool | ||
planType = dictionary["plan_type"] as? String | ||
timeFormat = dictionary["time_format"] as? String | ||
|
||
if let baseURLString = dictionary["base_uri"] as? String { | ||
baseURL = NSURL(string: baseURLString) | ||
} | ||
|
||
weekStartDay = dictionary["week_start_day"] as? String | ||
modules = dictionary["modules"] as? [String: Bool] | ||
thousandsSeperator = dictionary["thousands_separator"] as? String | ||
colorScheme = dictionary["color_scheme"] as? String | ||
decimalSymbol = dictionary["decimal_symbol"] as? String | ||
companyName = dictionary["name"] as? String | ||
clockFormat = dictionary["clock"] as? String | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// | ||
// Contact.swift | ||
// HarvestKit | ||
// | ||
// Created by Matthew Cheetham on 16/01/2016. | ||
// Copyright © 2016 Matt Cheetham. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/** | ||
A struct representation of a project in the harvest system. | ||
*/ | ||
public struct Contact { | ||
|
||
/** | ||
A unique identifier for the contact in the Harvest API | ||
*/ | ||
public var identifier: Int? | ||
|
||
/** | ||
A the unique identifier of the client that this contact is assosciated with | ||
*/ | ||
public var clientIdentifier: Int? | ||
|
||
/** | ||
The prefix for the name of the contact. Typically Mr, Mrs, Mx etc. | ||
*/ | ||
public var title: String? | ||
|
||
/** | ||
The first name of the contact | ||
*/ | ||
public var firstName: String? | ||
|
||
/** | ||
The last name of the contact | ||
*/ | ||
public var lastName: String? | ||
|
||
/** | ||
The email address that can be used to reach this contact | ||
*/ | ||
public var email: String? | ||
|
||
/** | ||
The phone number that can be used to reach this contact at the office. Stored as a string and may contain country codes, dashes, brackets etc. | ||
*/ | ||
public var officePhoneNumber: String? | ||
|
||
/** | ||
The phone number that can be used to reach this contact on a mobile. Stored as a string and may contain country codes, dashes, brackets etc. | ||
*/ | ||
public var mobilePhoneNumber: String? | ||
|
||
/** | ||
The number that can be used to communicate with this contact by fax. Stored as a string and may contain country codes, dashes, brackets etc. | ||
*/ | ||
public var faxNumber: String? | ||
|
||
/** | ||
The date that the contact was created | ||
*/ | ||
public var created: NSDate? | ||
|
||
/** | ||
The date that the contact was last modified | ||
*/ | ||
public var updated: NSDate? | ||
|
||
/** | ||
Standard initialiser | ||
*/ | ||
public init() {} | ||
|
||
internal init?(dictionary: [String: AnyObject]) { | ||
|
||
guard let contactDictionary = dictionary["contact"] as? [String: AnyObject] else { | ||
print("Dictionary was missing contact key") | ||
return nil | ||
} | ||
|
||
identifier = contactDictionary["id"] as? Int | ||
clientIdentifier = contactDictionary["client_id"] as? Int | ||
title = contactDictionary["title"] as? String | ||
firstName = contactDictionary["first_name"] as? String | ||
lastName = contactDictionary["last_name"] as? String | ||
email = contactDictionary["email"] as? String | ||
officePhoneNumber = contactDictionary["phone_office"] as? String | ||
mobilePhoneNumber = contactDictionary["phone_mobile"] as? String | ||
faxNumber = contactDictionary["fax"] as? String | ||
|
||
if let createdDateString = contactDictionary["created_at"] as? String { | ||
|
||
let dateFormatter = NSDateFormatter() | ||
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'" | ||
created = dateFormatter.dateFromString(createdDateString) | ||
|
||
} | ||
|
||
if let updatedDateString = contactDictionary["updated_at"] as? String { | ||
|
||
let dateFormatter = NSDateFormatter() | ||
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'" | ||
updated = dateFormatter.dateFromString(updatedDateString) | ||
|
||
} | ||
|
||
} | ||
} |
Oops, something went wrong.