mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-04-26 22:35:48 +08:00
sample target bypasses auth
This commit is contained in:
@@ -36,24 +36,34 @@ extension GithubClient {
|
||||
parameters["before"] = GithubAPIDateFormatter().string(from: before)
|
||||
}
|
||||
|
||||
request(Request(
|
||||
path: "notifications",
|
||||
method: .get,
|
||||
parameters: parameters,
|
||||
headers: nil
|
||||
) { response in
|
||||
if let jsonArr = response.value as? [ [String: Any] ] {
|
||||
var notifications = [Notification]()
|
||||
for json in jsonArr {
|
||||
if let notification = Notification(json: json) {
|
||||
notifications.append(notification)
|
||||
}
|
||||
typealias NotificationsPayload = [[String: Any]]
|
||||
|
||||
let success = { (jsonArr: NotificationsPayload) in
|
||||
var notifications = [Notification]()
|
||||
for json in jsonArr {
|
||||
if let notification = Notification(json: json) {
|
||||
notifications.append(notification)
|
||||
}
|
||||
completion(.success(notifications))
|
||||
} else {
|
||||
completion(.failed(response.error))
|
||||
}
|
||||
})
|
||||
completion(.success(notifications))
|
||||
}
|
||||
|
||||
if let sampleJSON = loadSample(path: "notifications") as? NotificationsPayload {
|
||||
success(sampleJSON)
|
||||
} else {
|
||||
request(Request(
|
||||
path: "notifications",
|
||||
method: .get,
|
||||
parameters: parameters,
|
||||
headers: nil
|
||||
) { response in
|
||||
if let jsonArr = response.value as? NotificationsPayload {
|
||||
success(jsonArr)
|
||||
} else {
|
||||
completion(.failed(response.error))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,11 +44,14 @@ final class GithubSessionManager: NSObject, ListDiffable {
|
||||
private let defaults = UserDefaults.standard
|
||||
|
||||
override init() {
|
||||
if let data = defaults.object(forKey: Keys.sessions) as? Data,
|
||||
if let sample = sampleUserSession() {
|
||||
_userSessions = [sample.collectionKey: sample]
|
||||
_focusedKey = sample.collectionKey
|
||||
} else if let data = defaults.object(forKey: Keys.sessions) as? Data,
|
||||
let sessions = NSKeyedUnarchiver.unarchiveObject(with: data) as? SessionCollection {
|
||||
_userSessions = sessions
|
||||
_focusedKey = defaults.object(forKey: Keys.focused) as? String
|
||||
}
|
||||
_focusedKey = defaults.object(forKey: Keys.focused) as? String
|
||||
super.init()
|
||||
}
|
||||
|
||||
|
||||
@@ -308,6 +308,10 @@
|
||||
296CD8171F013FBF001190B9 /* MMMarkdown.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 295F52D91EF1C0C7000B53CF /* MMMarkdown.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
296CD8261F01413B001190B9 /* issue.json in Resources */ = {isa = PBXBuildFile; fileRef = 296CD8241F014130001190B9 /* issue.json */; };
|
||||
296CD8271F01413B001190B9 /* notifications.json in Resources */ = {isa = PBXBuildFile; fileRef = 296CD8251F014130001190B9 /* notifications.json */; };
|
||||
296CD8291F0141A6001190B9 /* Samples.swift in Sources */ = {isa = PBXBuildFile; fileRef = 296CD8281F0141A6001190B9 /* Samples.swift */; };
|
||||
296CD82A1F0141A6001190B9 /* Samples.swift in Sources */ = {isa = PBXBuildFile; fileRef = 296CD8281F0141A6001190B9 /* Samples.swift */; };
|
||||
296CD82B1F0141A6001190B9 /* Samples.swift in Sources */ = {isa = PBXBuildFile; fileRef = 296CD8281F0141A6001190B9 /* Samples.swift */; };
|
||||
296CD82D1F0147CF001190B9 /* authorizations.json in Resources */ = {isa = PBXBuildFile; fileRef = 296CD82C1F01476D001190B9 /* authorizations.json */; };
|
||||
297AE84D1EC0D58A00B44A1F /* DateDisplayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 297AE84C1EC0D58A00B44A1F /* DateDisplayTests.swift */; };
|
||||
297AE8741EC0D5C200B44A1F /* GithubLogin.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 297AE8591EC0D5C100B44A1F /* GithubLogin.storyboard */; };
|
||||
297AE8751EC0D5C200B44A1F /* LoginRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 297AE85A1EC0D5C100B44A1F /* LoginRequest.swift */; };
|
||||
@@ -528,6 +532,8 @@
|
||||
296CD8211F0140E3001190B9 /* FreetimeSamples-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "FreetimeSamples-Info.plist"; sourceTree = "<group>"; };
|
||||
296CD8241F014130001190B9 /* issue.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = issue.json; sourceTree = "<group>"; };
|
||||
296CD8251F014130001190B9 /* notifications.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = notifications.json; sourceTree = "<group>"; };
|
||||
296CD8281F0141A6001190B9 /* Samples.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Samples.swift; sourceTree = "<group>"; };
|
||||
296CD82C1F01476D001190B9 /* authorizations.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = authorizations.json; sourceTree = "<group>"; };
|
||||
297AE8341EC0D58A00B44A1F /* Freetime.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Freetime.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
297AE8481EC0D58A00B44A1F /* FreetimeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FreetimeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
297AE84C1EC0D58A00B44A1F /* DateDisplayTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateDisplayTests.swift; sourceTree = "<group>"; };
|
||||
@@ -849,8 +855,10 @@
|
||||
296CD8231F014130001190B9 /* Sample */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
296CD82C1F01476D001190B9 /* authorizations.json */,
|
||||
296CD8241F014130001190B9 /* issue.json */,
|
||||
296CD8251F014130001190B9 /* notifications.json */,
|
||||
296CD8281F0141A6001190B9 /* Samples.swift */,
|
||||
);
|
||||
path = Sample;
|
||||
sourceTree = "<group>";
|
||||
@@ -1235,6 +1243,7 @@
|
||||
296CD8261F01413B001190B9 /* issue.json in Resources */,
|
||||
296CD8141F013FBF001190B9 /* Localizable.stringsdict in Resources */,
|
||||
296CD8151F013FBF001190B9 /* Main.storyboard in Resources */,
|
||||
296CD82D1F0147CF001190B9 /* authorizations.json in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -1516,6 +1525,7 @@
|
||||
296CD7C01F013FBF001190B9 /* IssueClosedModel.swift in Sources */,
|
||||
296CD7C11F013FBF001190B9 /* IssueCommentDetailCell.swift in Sources */,
|
||||
296CD7C21F013FBF001190B9 /* ButtonCell.swift in Sources */,
|
||||
296CD82B1F0141A6001190B9 /* Samples.swift in Sources */,
|
||||
296CD7C31F013FBF001190B9 /* IssueCommentModel.swift in Sources */,
|
||||
296CD7C41F013FBF001190B9 /* SegmentedControlModel.swift in Sources */,
|
||||
296CD7C51F013FBF001190B9 /* SegmentedControlSectionController.swift in Sources */,
|
||||
@@ -1651,6 +1661,7 @@
|
||||
295840651EE89F28007723C6 /* IssueClosedModel.swift in Sources */,
|
||||
292FCAF91EDFCC510026635E /* IssueCommentDetailCell.swift in Sources */,
|
||||
29316DB51ECC7DEB007CAE3F /* ButtonCell.swift in Sources */,
|
||||
296CD8291F0141A6001190B9 /* Samples.swift in Sources */,
|
||||
292FCAFE1EDFCC510026635E /* IssueCommentModel.swift in Sources */,
|
||||
298BA09A1EC947FC00B01946 /* SegmentedControlModel.swift in Sources */,
|
||||
298BA0981EC947F100B01946 /* SegmentedControlSectionController.swift in Sources */,
|
||||
@@ -1757,6 +1768,7 @@
|
||||
2958409E1EEA00E1007723C6 /* IssueLabelSummaryCell.swift in Sources */,
|
||||
29C2950E1EC7B43B00D46CD2 /* ListKitTestCase.swift in Sources */,
|
||||
29C167721ECA0D7C00439D62 /* UIView+BottomBorder.swift in Sources */,
|
||||
296CD82A1F0141A6001190B9 /* Samples.swift in Sources */,
|
||||
295840B71EEA00E1007723C6 /* ErrorMessages.swift in Sources */,
|
||||
295840921EEA00E1007723C6 /* IssueEvent.swift in Sources */,
|
||||
2958407B1EEA00E1007723C6 /* IssueCommentImageModel.swift in Sources */,
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>29</string>
|
||||
<string>44</string>
|
||||
<key>LSApplicationQueriesSchemes</key>
|
||||
<array>
|
||||
<string>org-appextension-feature-password-management</string>
|
||||
|
||||
27
Sample/Samples.swift
Normal file
27
Sample/Samples.swift
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Samples.swift
|
||||
// Freetime
|
||||
//
|
||||
// Created by Ryan Nystrom on 6/26/17.
|
||||
// Copyright © 2017 Ryan Nystrom. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
func runningInSample() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
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: [])
|
||||
}
|
||||
20
Sample/authorizations.json
Normal file
20
Sample/authorizations.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"app": {
|
||||
"client_id": "abcde12345fghij67890",
|
||||
"name": "my github app",
|
||||
"url": "http://my-github-app.com"
|
||||
},
|
||||
"created_at": "2011-09-06T17:26:27Z",
|
||||
"fingerprint": "",
|
||||
"hashed_token": "25f94a2a5c7fbaf499c665bc73d67c1c87e496da8985131633ee0a95819db2e8",
|
||||
"id": 1,
|
||||
"note": "optional note",
|
||||
"note_url": "http://optional/note/url",
|
||||
"scopes": [
|
||||
"public_repo"
|
||||
],
|
||||
"token": "abcdefgh12345678",
|
||||
"token_last_eight": "12345678",
|
||||
"updated_at": "2011-09-06T20:39:23Z",
|
||||
"url": "https://api.github.com/authorizations/1"
|
||||
}
|
||||
Reference in New Issue
Block a user