mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-05-13 01:51:40 +08:00
28 lines
842 B
Swift
28 lines
842 B
Swift
//
|
|
// Samples.swift
|
|
// Freetime
|
|
//
|
|
// Created by Ryan Nystrom on 6/26/17.
|
|
// Copyright © 2017 Ryan Nystrom. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
func runningInSample() -> Bool {
|
|
return Bundle.main.object(forInfoDictionaryKey: "RUN_AS_SAMPLE") as? Bool ?? false
|
|
}
|
|
|
|
func sampleUserSession() -> GithubUserSession? {
|
|
guard runningInSample() else { return nil }
|
|
let authJSON = loadSample(path: "authorizations") as! [String: Any]
|
|
let auth = Authorization(json: authJSON)!
|
|
return GithubUserSession(authorization: auth, login: "rnystrom")
|
|
}
|
|
|
|
func loadSample(path: String) -> Any? {
|
|
guard runningInSample() else { return nil }
|
|
let url = Bundle.main.url(forResource: path, withExtension: "json")!
|
|
let data = try! Data(contentsOf: url)
|
|
return try! JSONSerialization.jsonObject(with: data, options: [])
|
|
}
|