-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add missing API calls: manage hosted repositories, get integrations #48
Changes from 9 commits
8e8180b
1cc90e9
fd4b501
2e39feb
1b88861
0838576
c588a2f
2e9825b
d022c9f
0aa2e8e
5ee13ee
ca9e64d
640bccd
a333b7a
7eb6418
7fbd319
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// Repository.swift | ||
// XcodeServerSDK | ||
// | ||
// Created by Mateusz Zając on 28.06.2015. | ||
// Copyright © 2015 Honza Dvorsky. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct Repository { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So far we have all the other types as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm... No particular reason but:
I can switch to Some more investigation and I think |
||
|
||
/** | ||
Enumeration describing HTTP access to the repository | ||
|
||
- None: No users are not allowed to read or write | ||
- LoggedIn: Logged in users are allowed to read and write | ||
*/ | ||
public enum HTTPAccessType: Int { | ||
|
||
case None = 0 | ||
case LoggedIn | ||
|
||
public func toString() -> String { | ||
switch self { | ||
case .None: | ||
return "No users are not allowed to read or write" | ||
case .LoggedIn: | ||
return "Logged in users are allowed to read and write" | ||
} | ||
} | ||
|
||
} | ||
|
||
/** | ||
Enumeration describing HTTPS access to the repository | ||
|
||
- SelectedReadWrite: Only selected users can read and/or write | ||
- LoggedInReadSelectedWrite: Only selected users can write but all logged in can read | ||
- LoggedInReadWrite: All logged in users can read and write | ||
*/ | ||
public enum SSHAccessType: Int { | ||
|
||
case SelectedReadWrite = 0 | ||
case LoggedInReadSelectedWrite | ||
case LoggedInReadWrite | ||
|
||
public func toString() -> String { | ||
switch self { | ||
case .SelectedReadWrite: | ||
return "Only selected users can read and/or write" | ||
case .LoggedInReadSelectedWrite: | ||
return "Only selected users can write but all logged in can read" | ||
case .LoggedInReadWrite: | ||
return "All logged in users can read and write" | ||
} | ||
} | ||
|
||
} | ||
|
||
public let name: String | ||
public let httpAccess: HTTPAccessType | ||
public let sshAccess: SSHAccessType | ||
public let writeAccessExternalIds: [String] | ||
public let readAccessExternalIds: [String] | ||
|
||
/** | ||
Designated initializer. | ||
|
||
- parameter name: Name of the repository. | ||
- parameter httpsAccess: HTTPS access type for the users. | ||
- parameter sshAccess: SSH access type for the users. | ||
- parameter writeAccessExternalIds: ID of users allowed to write to the repository. | ||
- parameter readAccessExternalIds: ID of users allowed to read from the repository. | ||
|
||
- returns: Initialized repository struct. | ||
*/ | ||
public init(name: String, httpAccess: HTTPAccessType, sshAccess: SSHAccessType, writeAccessExternalIds: [String], readAccessExternalIds: [String]) { | ||
self.name = name | ||
self.httpAccess = httpAccess | ||
self.sshAccess = sshAccess | ||
self.writeAccessExternalIds = writeAccessExternalIds | ||
self.readAccessExternalIds = readAccessExternalIds | ||
} | ||
|
||
/** | ||
Repository constructor from JSON object. | ||
|
||
- parameter json: JSON dictionary representing repository. | ||
|
||
- returns: Initialized repository struct. | ||
*/ | ||
public init(json: NSDictionary) { | ||
self.name = json.stringForKey("name") | ||
|
||
self.httpAccess = HTTPAccessType(rawValue: json.intForKey("httpAccessType"))! | ||
self.sshAccess = SSHAccessType(rawValue: json.intForKey("posixPermissions"))! | ||
|
||
self.writeAccessExternalIds = json.arrayForKey("writeAccessExternalIDs") | ||
self.readAccessExternalIds = json.arrayForKey("readAccessExternalIDs") | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -349,7 +349,7 @@ public extension XcodeServer { | |
} | ||
} | ||
|
||
public func getIntegrations(botId: String, query: [String: String], completion: (integrations: [Integration]?, error: NSError?) -> ()) { | ||
public func getBotIntegrations(botId: String, query: [String: String], completion: (integrations: [Integration]?, error: NSError?) -> ()) { | ||
|
||
let params = [ | ||
"bot": botId | ||
|
@@ -398,6 +398,38 @@ public extension XcodeServer { | |
} | ||
} | ||
|
||
/** | ||
XCS API call for retrievieng specified Integration. | ||
|
||
- parameter integrationId: ID of integration which is about to be retrieved. | ||
- parameter completion: | ||
- Optional retrieved integration. | ||
- Optional operation error. | ||
*/ | ||
public func getIntegration(integrationId: String, completion: (integration: Integration?, error: NSError?) -> ()) { | ||
|
||
let params = [ | ||
"integration": integrationId | ||
] | ||
|
||
self.sendRequestWithMethod(.GET, endpoint: .Integrations, params: params, query: nil, body: nil) { | ||
(response, body, error) -> () in | ||
|
||
guard error == nil else { | ||
completion(integration: nil, error: error) | ||
return | ||
} | ||
|
||
guard let integrationBody = body as? NSDictionary else { | ||
completion(integration: nil, error: Error.withInfo("Wrong body \(body)")) | ||
return | ||
} | ||
|
||
let integration = Integration(json: integrationBody) | ||
completion(integration: integration, error: nil) | ||
} | ||
} | ||
|
||
public func cancelIntegration(integrationId: String, completion: (success: Bool, error: NSError?) -> ()) { | ||
|
||
let params = [ | ||
|
@@ -415,6 +447,32 @@ public extension XcodeServer { | |
} | ||
} | ||
|
||
/** | ||
XCS API call for retrievieng all available integrations on server. | ||
|
||
- parameter integrations: Optional array of integrations. | ||
- parameter error: Optional error. | ||
*/ | ||
public func getIntegrations(completion: (integrations: [Integration]?, error: NSError?) -> ()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw, you can also use filters for integrations, see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WOW, this is pretty cool! I'll add it for sure but I guess after #47 is complete so I don't get lost 😆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haha yeah that makes sense. Let's split them first. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @czechboy0 while working on #47 I've noticed thath your method:
So I went to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you I hate JS... 😕 Can't find anything in this mess! Hope Swift will replace it soon 😆 |
||
|
||
self.sendRequestWithMethod(.GET, endpoint: .Integrations, params: nil, query: nil, body: nil) { | ||
(response, body, error) -> () in | ||
|
||
guard error == nil else { | ||
completion(integrations: nil, error: error) | ||
return | ||
} | ||
|
||
guard let integrationsBody = (body as? NSDictionary)?["results"] as? NSArray else { | ||
completion(integrations: nil, error: Error.withInfo("Wrong body \(body)")) | ||
return | ||
} | ||
|
||
let integrations: [Integration] = XcodeServerArray(integrationsBody) | ||
completion(integrations: integrations, error: nil) | ||
} | ||
} | ||
|
||
public func getDevices(completion: (devices: [Device]?, error: NSError?) -> ()) { | ||
|
||
self.sendRequestWithMethod(.GET, endpoint: .Devices, params: nil, query: nil, body: nil) { (response, body, error) -> () in | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// Repository.swift | ||
// XcodeServerSDK | ||
// | ||
// Created by Mateusz Zając on 28.06.2015. | ||
// Copyright © 2015 Honza Dvorsky. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
import XcodeServerSDK | ||
|
||
class RepositoryTests: XCTestCase { | ||
|
||
let json = [ | ||
"readAccessExternalIDs": [], | ||
"writeAccessExternalIDs": [ | ||
"FDF283F5-B9C3-4B43-9000-EF6A54934D4E", | ||
"ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050" | ||
], | ||
"name": "Test3", | ||
"posixPermissions": 1, | ||
"httpAccessType": 1 | ||
] | ||
|
||
// MARK: Initialization | ||
func testInit() { | ||
let repo = Repository(json: json) | ||
|
||
XCTAssertEqual(repo.name, "Test3") | ||
XCTAssertEqual(repo.httpAccess, Repository.HTTPAccessType.LoggedIn) | ||
XCTAssertEqual(repo.sshAccess, Repository.SSHAccessType.LoggedInReadSelectedWrite) | ||
XCTAssertEqual(repo.writeAccessExternalIds, [ "FDF283F5-B9C3-4B43-9000-EF6A54934D4E", "ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050" ]) | ||
XCTAssertEqual(repo.readAccessExternalIds, []) | ||
} | ||
|
||
func testManualInit() { | ||
let repo = Repository(name: "Test3", httpAccess: .LoggedIn, sshAccess: .LoggedInReadSelectedWrite, writeAccessExternalIds: [ "FDF283F5-B9C3-4B43-9000-EF6A54934D4E", "ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050" ], readAccessExternalIds: []) | ||
|
||
XCTAssertEqual(repo.name, "Test3") | ||
XCTAssertEqual(repo.httpAccess, Repository.HTTPAccessType.LoggedIn) | ||
XCTAssertEqual(repo.sshAccess, Repository.SSHAccessType.LoggedInReadSelectedWrite) | ||
XCTAssertEqual(repo.writeAccessExternalIds, [ "FDF283F5-B9C3-4B43-9000-EF6A54934D4E", "ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050" ]) | ||
XCTAssertEqual(repo.readAccessExternalIds, []) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome stuff, we need to have every class covered as well as this! 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know why it's duplicated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a strange thing... Probably because of some kind of bug. I'll handle this 😉