-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
520b32d
commit 69a667f
Showing
5 changed files
with
146 additions
and
50 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,36 @@ | ||
// | ||
// GithubClient.swift | ||
// jiraBar | ||
// | ||
// Created by Pavel Makhov on 2023-10-29. | ||
// | ||
|
||
import Foundation | ||
import Alamofire | ||
|
||
public class GithubClient { | ||
|
||
func getLatestRelease(completion:@escaping (((LatestRelease?) -> Void))) -> Void { | ||
let headers: HTTPHeaders = [ | ||
.contentType("application/json"), | ||
.accept("application/json") | ||
] | ||
AF.request("https://api.github.com/repos/menubar-apps/JiraBar/releases/latest", | ||
method: .get, | ||
encoding: JSONEncoding.default, | ||
headers: headers) | ||
.validate(statusCode: 200..<300) | ||
.responseDecodable(of: LatestRelease.self) { response in | ||
switch response.result { | ||
case .success(let latestRelease): | ||
completion(latestRelease) | ||
case .failure(let error): | ||
completion(nil) | ||
if let data = response.data { | ||
let json = String(data: data, encoding: String.Encoding.utf8) | ||
} | ||
sendNotification(body: error.localizedDescription) | ||
} | ||
} | ||
} | ||
} |
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,29 @@ | ||
// | ||
// GithubDtos.swift | ||
// jiraBar | ||
// | ||
// Created by Pavel Makhov on 2023-10-29. | ||
// | ||
|
||
import Foundation | ||
|
||
struct LatestRelease: Codable { | ||
|
||
var name: String | ||
var htmlUrl: String | ||
var assets: [Asset] | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case name | ||
case assets | ||
case htmlUrl = "html_url" | ||
} | ||
} | ||
|
||
struct Asset: Codable { | ||
var name: String | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case name | ||
} | ||
} |
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