Skip to content

Commit

Permalink
Add Myself Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Pageler committed Oct 11, 2018
1 parent 3bf0302 commit ca11d61
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output


.DS_Store
16 changes: 16 additions & 0 deletions Sources/JiraSwift/JiraClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Christoph Pageler on 17.11.17.
//


import Foundation
import Quack

Expand Down Expand Up @@ -146,6 +147,21 @@ public extension Jira {
model: ServerInfoResult.self,
completion: completion)
}

public func getMyself() -> Quack.Result<Myself> {
return respond(method: .get,
path: "/rest/api/2/myself",
headers: defaultHeader,
model: Myself.self)
}

public func getMyself(completion: @escaping (Quack.Result<Myself>) -> ()) {
return respondAsync(method: .get,
path: "/rest/api/2/myself",
headers: defaultHeader,
model: Myself.self,
completion: completion)
}

}

Expand Down
1 change: 1 addition & 0 deletions Sources/JiraSwift/JiraIssue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Christoph Pageler on 17.11.17.
//


import Foundation
import Quack

Expand Down
55 changes: 55 additions & 0 deletions Sources/JiraSwift/JiraMyself.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// JiraMyself.swift
// JiraSwift
//
// Created by Christoph Pageler on 11.10.18.
//


import Foundation
import Quack


public extension Jira {

public class Myself: Quack.Model {

public let accountId: String
public let key: String
public let name: String
public let emailAddress: String
public let displayName: String
public let active: Bool

public let avatarUrl16: String?
public let avatarUrl24: String?
public let avatarUrl32: String?
public let avatarUrl48: String?

public required init?(json: JSON) {
guard let accountId = json["accountId"].string,
let key = json["key"].string,
let name = json["name"].string,
let emailAddress = json["emailAddress"].string,
let displayName = json["displayName"].string,
let active = json["active"].bool
else {
return nil
}

self.accountId = accountId
self.key = key
self.name = name
self.emailAddress = emailAddress
self.displayName = displayName
self.active = active

self.avatarUrl16 = json["avatarUrls"]["16x16"].string
self.avatarUrl24 = json["avatarUrls"]["24x24"].string
self.avatarUrl32 = json["avatarUrls"]["32x32"].string
self.avatarUrl48 = json["avatarUrls"]["48x48"].string
}

}

}
19 changes: 19 additions & 0 deletions Tests/JiraSwiftTests/JiraSwiftSearchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,23 @@ class JiraSwiftSearchTests: XCTestCase {
waitForExpectations(timeout: 15, handler: nil)
}

func testMyself() {
let e = expectation(description: "myselfExpectation")
let jiraClient = Jira.Client(url: URL(string: "your_jira_url")!,
username: "your_username",
password: "your_password")
jiraClient.getMyself() { result in
switch result {
case .success(let result):
XCTAssertNotNil(result)
case .failure:
XCTFail()
}
e.fulfill()

}

waitForExpectations(timeout: 15, handler: nil)
}

}

0 comments on commit ca11d61

Please sign in to comment.