Skip to content
This repository has been archived by the owner on Jan 29, 2019. It is now read-only.

Commit

Permalink
Merge branch 'release/v1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
MattCheetham committed Mar 24, 2016
2 parents 9635c35 + 34fd9b2 commit ddcdc5c
Show file tree
Hide file tree
Showing 14 changed files with 1,152 additions and 310 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ before_install:
- brew install carthage
- carthage bootstrap --verbose
xcode_scheme: MyNewProjectTests
osx_image: xcode7.2
osx_image: xcode7.3
env:
global:
- LC_CTYPE=en_US.UTF-8
- LANG=en_US.UTF-8
- IOS_FRAMEWORK_SCHEME="HarvestKitiOS"
- TVOS_FRAMEWORK_SCHEME="HarvestKittvOS"
- OSX_FRAMEWORK_SCHEME="HarvestKitOSX"
- IOS_SDK=iphonesimulator9.2
- TVOS_SDK=appletvsimulator9.1
- IOS_SDK=iphonesimulator9.3
- TVOS_SDK=appletvsimulator9.2
- OSX_SDK=macosx10.11
matrix:
- DESTINATION="OS=9.0,name=iPhone 6S Plus" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=9.1,name=iPhone 6S" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=9.2,name=iPhone 6S" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=9.2,name=iPhone 6S Plus" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=9.0,name=Apple TV 1080p" SCHEME="$TVOS_FRAMEWORK_SCHEME" SDK="$TVOS_SDK" RUN_TESTS="NO" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=9.3,name=iPhone 6S Plus" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=9.2,name=Apple TV 1080p" SCHEME="$TVOS_FRAMEWORK_SCHEME" SDK="$TVOS_SDK" RUN_TESTS="NO" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="arch=x86_64" SCHEME="$OSX_FRAMEWORK_SCHEME" SDK="$OSX_SDK" RUN_TESTS="NO" BUILD_EXAMPLE="NO" POD_LINT="NO"
script:
- set -o pipefail
Expand Down
71 changes: 71 additions & 0 deletions HarvestKit-Shared/AccountController.swift
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)

}

}

}
91 changes: 91 additions & 0 deletions HarvestKit-Shared/Company.swift
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

}

}
110 changes: 110 additions & 0 deletions HarvestKit-Shared/Contact.swift
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)

}

}
}
Loading

0 comments on commit ddcdc5c

Please sign in to comment.