Skip to content
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

Merged
merged 16 commits into from
Jun 30, 2015
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion XcodeServerSDK/XcodeServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand All @@ -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?) -> ()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, you can also use filters for integrations, see /Applications/Xcode-beta.app/Contents/Developer/usr/share/xcs/xcsd/routes/routes_integration.js. Not that you have to add it now, just FYI, probably something to add at some point in the future 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 😆

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha yeah that makes sense. Let's split them first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@czechboy0 while working on #47 I've noticed thath your method: getBotIntegrations() use filters. Do you have any clue where I can find available keys for this :filter? query? While Charlesing around I've noticed only one:

  • last=

So I went to integrationFilterClass.js but guess what - can't find anything... 😕 Give me some hints as I want to include those to header docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See integrationSearchClass.js starting from line 124. Filters like from, last, number etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Down