Skip to content

Commit a8d4e5b

Browse files
committed
Sockets added
1 parent b0ad7fd commit a8d4e5b

File tree

55 files changed

+6008
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+6008
-15
lines changed

CloudBoost.xcodeproj/project.pbxproj

+260-2
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Bucket
3+
type = "1"
4+
version = "2.0">
5+
<Breakpoints>
6+
<BreakpointProxy
7+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
8+
<BreakpointContent
9+
shouldBeEnabled = "Yes"
10+
ignoreCount = "0"
11+
continueAfterRunningActions = "No"
12+
filePath = "CloudBoost/CloudQuery.swift"
13+
timestampString = "482102370.255448"
14+
startingColumnNumber = "9223372036854775807"
15+
endingColumnNumber = "9223372036854775807"
16+
startingLineNumber = "459"
17+
endingLineNumber = "459"
18+
landmarkName = "paginate(_:_totalItemsInPage:callback:)"
19+
landmarkType = "5">
20+
</BreakpointContent>
21+
</BreakpointProxy>
22+
</Breakpoints>
23+
</Bucket>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0720"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "22FFC8BD1C97B9D50028EA61"
18+
BuildableName = "CloudBoost-Universal"
19+
BlueprintName = "CloudBoost-Universal"
20+
ReferencedContainer = "container:CloudBoost.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
<AdditionalOptions>
33+
</AdditionalOptions>
34+
</TestAction>
35+
<LaunchAction
36+
buildConfiguration = "Debug"
37+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
38+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
39+
launchStyle = "0"
40+
useCustomWorkingDirectory = "NO"
41+
ignoresPersistentStateOnLaunch = "NO"
42+
debugDocumentVersioning = "YES"
43+
debugServiceExtension = "internal"
44+
allowLocationSimulation = "YES">
45+
<MacroExpansion>
46+
<BuildableReference
47+
BuildableIdentifier = "primary"
48+
BlueprintIdentifier = "22FFC8BD1C97B9D50028EA61"
49+
BuildableName = "CloudBoost-Universal"
50+
BlueprintName = "CloudBoost-Universal"
51+
ReferencedContainer = "container:CloudBoost.xcodeproj">
52+
</BuildableReference>
53+
</MacroExpansion>
54+
<AdditionalOptions>
55+
</AdditionalOptions>
56+
</LaunchAction>
57+
<ProfileAction
58+
buildConfiguration = "Release"
59+
shouldUseLaunchSchemeArgsEnv = "YES"
60+
savedToolIdentifier = ""
61+
useCustomWorkingDirectory = "NO"
62+
debugDocumentVersioning = "YES">
63+
<MacroExpansion>
64+
<BuildableReference
65+
BuildableIdentifier = "primary"
66+
BlueprintIdentifier = "22FFC8BD1C97B9D50028EA61"
67+
BuildableName = "CloudBoost-Universal"
68+
BlueprintName = "CloudBoost-Universal"
69+
ReferencedContainer = "container:CloudBoost.xcodeproj">
70+
</BuildableReference>
71+
</MacroExpansion>
72+
</ProfileAction>
73+
<AnalyzeAction
74+
buildConfiguration = "Debug">
75+
</AnalyzeAction>
76+
<ArchiveAction
77+
buildConfiguration = "Release"
78+
revealArchiveInOrganizer = "YES">
79+
</ArchiveAction>
80+
</Scheme>

CloudBoost/CloudBoostUtilities.swift

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import Foundation
1010

11-
1211
public typealias callback = (status: Int, message: String) -> Void
1312

1413
//Types of errors beig thrown by CloudBoost SDK
@@ -37,6 +36,16 @@ public class CloudBoostResponse {
3736
}
3837
}
3938

39+
public class CloudBoostNotificationResponse {
40+
public var data: [AnyObject]?
41+
public var ack: SocketAckEmitter?
42+
43+
public func log() {
44+
print("Data: \(data)")
45+
print("Ack: \(ack)")
46+
}
47+
}
48+
4049
public class CloudBoostProgressResponse {
4150
public var progress: Double?
4251
public var complete = false
@@ -65,7 +74,7 @@ public enum CloudBoostDataType: String {
6574
case Object = "Object"
6675
case Id = "Id"
6776
case EncryptedText = "EncryptedText"
68-
case ACl = "ACL"
77+
case ACL = "ACL"
6978
}
7079

7180

CloudBoost/CloudCommunications.swift

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public class CloudCommunications: NSObject, NSURLSessionDelegate, NSURLSessionTa
7575
if(httpResponse.statusCode == 200){
7676
cloudBoostResponse.success = true
7777
} else {
78+
print("Error: \(error)")
7879
cloudBoostResponse.message = NSString(data: data!, encoding: NSUTF8StringEncoding) as? String
7980
}
8081
}

CloudBoost/CloudNotification.swift

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//
2+
// CloudNotification.swift
3+
// CloudBoost
4+
//
5+
// Created by Randhir Singh on 24/04/16.
6+
// Copyright © 2016 Randhir Singh. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public class CloudNotification {
12+
13+
/**
14+
*
15+
* Start listening to events
16+
*
17+
*
18+
* @param channelName channel to start listening on
19+
* @param callback a listener which is called when the event is triggered
20+
* @throws CloudBoostError
21+
*/
22+
public static func on(channelName: String, callback: (CloudBoostNotificationResponse)->Void) throws{
23+
if(CloudApp.getAppId() == nil){
24+
throw CloudBoostError.InvalidArgument
25+
}
26+
if(CloudApp.getAppKey() == nil){
27+
throw CloudBoostError.InvalidArgument
28+
}
29+
30+
CloudSocket.getSocket().connect()
31+
CloudSocket.getSocket().on(CloudApp.getAppId()! + channelName, callback: {
32+
data, ack in
33+
let resp = CloudBoostNotificationResponse()
34+
resp.data = data
35+
resp.ack = ack
36+
callback(resp)
37+
})
38+
CloudSocket.getSocket().emit("join-custom-channel", CloudApp.getAppId()! + channelName)
39+
}
40+
41+
/**
42+
*
43+
* Write data to a channel, any client subscribed to this channel will receive a notification
44+
*
45+
* @param channelName
46+
* @param data
47+
* @throws CloudBoostError
48+
*/
49+
public static func publish(channelName: String, data: AnyObject) throws{
50+
if(CloudApp.getAppId() == nil){
51+
throw CloudBoostError.InvalidArgument
52+
}
53+
if(CloudApp.getAppKey() == nil){
54+
throw CloudBoostError.InvalidArgument
55+
}
56+
// splitting into two strings
57+
let x = ["channel":CloudApp.getAppId()! + channelName, "data":data]
58+
let dat = try! NSJSONSerialization.dataWithJSONObject(x, options: NSJSONWritingOptions.init(rawValue: 0))
59+
let str = NSString(data: dat, encoding: NSUTF8StringEncoding) as! String
60+
CloudSocket.getSocket().emit("publish-custom-channel", str)
61+
}
62+
63+
/**
64+
* stop listening to events
65+
* @param channelName channel to stop listening from
66+
* @param callbackObject
67+
* @throws CloudBoostError
68+
*/
69+
public static func off(channelName: String, callback: ()->Void) throws{
70+
if(CloudApp.getAppId() == nil){
71+
throw CloudBoostError.InvalidArgument
72+
}
73+
if(CloudApp.getAppKey() == nil){
74+
throw CloudBoostError.InvalidArgument
75+
}
76+
77+
CloudSocket.getSocket().disconnect()
78+
CloudSocket.getSocket().emit("leave-custom-channel", CloudApp.getAppId()! + channelName)
79+
CloudSocket.getSocket().disconnect()
80+
CloudSocket.getSocket().off(CloudApp.getAppId()! + channelName)
81+
82+
}
83+
84+
85+
}

CloudBoost/CloudSearch.swift

+71-8
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,79 @@ public class CloudSearch {
1818
var size: Int?
1919
var sort = [AnyObject]()
2020

21+
var searchFilter: SearchFilter?
22+
var searchQuery: SearchQuery?
2123

22-
public init(tableName: String, searchObject: SearchQuery?, searchFilter: SearchFilter?){
24+
public init(tableName: String, searchQuery: SearchQuery?, searchFilter: SearchFilter?){
2325
self.collectionName = tableName
2426

25-
if searchObject != nil {
26-
self.bool["bool"] = searchObject?.bool
27+
if searchQuery != nil {
28+
self.bool["bool"] = searchQuery?.bool
2729
self.filtered["query"] = self.bool
2830
}else{
2931
self.filtered["query"] = [:]
3032
}
31-
3233
if searchFilter != nil {
3334
self.bool["bool"] = searchFilter?.bool
35+
self.filtered["filter"] = self.bool
36+
}else{
37+
self.filtered["filter"] = [:]
38+
}
39+
40+
self.from = 0
41+
self.size = 10
42+
43+
}
44+
45+
public init(tableName: String){
46+
self.collectionName = tableName
47+
48+
self.filtered["query"] = [:]
49+
self.filtered["filter"] = [:]
50+
51+
self.from = 0
52+
self.size = 10
53+
54+
}
55+
public init(tableName: String, searchQuery: SearchQuery?){
56+
self.collectionName = tableName
57+
58+
if searchQuery != nil {
59+
self.bool["bool"] = searchQuery?.bool
3460
self.filtered["query"] = self.bool
3561
}else{
3662
self.filtered["query"] = [:]
3763
}
64+
self.filtered["filter"] = [:]
3865

3966
self.from = 0
4067
self.size = 10
4168

4269
}
70+
public init(tableName: String, searchFilter: SearchFilter?){
71+
self.collectionName = tableName
72+
73+
self.filtered["query"] = [:]
74+
75+
if searchFilter != nil {
76+
self.bool["bool"] = searchFilter?.bool
77+
self.filtered["filter"] = self.bool
78+
}else{
79+
self.filtered["filter"] = [:]
80+
}
81+
82+
self.from = 0
83+
self.size = 10
84+
85+
}
86+
4387

44-
public init(tableName: [String], searchObject: SearchQuery?, searchFilter: SearchFilter?){
88+
89+
public init(tableName: [String], searchQuery: SearchQuery?, searchFilter: SearchFilter?){
4590
self.collectionArray = tableName
4691

47-
if searchObject != nil {
48-
self.bool["bool"] = searchObject?.bool
92+
if searchQuery != nil {
93+
self.bool["bool"] = searchQuery?.bool
4994
self.filtered["query"] = self.bool
5095
}else{
5196
self.filtered["query"] = [:]
@@ -62,6 +107,16 @@ public class CloudSearch {
62107
self.size = 10
63108

64109
}
110+
111+
func setSearchFilter(searchFilter: SearchFilter) {
112+
self.bool["bool"] = searchFilter.bool
113+
self.filtered["query"] = self.bool
114+
}
115+
116+
func setSearchQuery(searchQuery: SearchQuery){
117+
self.bool["bool"] = searchQuery.bool
118+
self.filtered["query"] = self.bool
119+
}
65120

66121

67122
// MARK: Setters and getter
@@ -97,6 +152,14 @@ public class CloudSearch {
97152
}
98153

99154
public func search(callback: (CloudBoostResponse)->Void) throws {
155+
156+
if let sf = self.searchFilter {
157+
self.setSearchFilter(sf)
158+
}
159+
if let sq = self.searchQuery {
160+
self.setSearchQuery(sq)
161+
}
162+
100163
var collectionString = ""
101164
if self.collectionArray.count > 0 {
102165
if collectionArray.count > 1 {
@@ -109,7 +172,7 @@ public class CloudSearch {
109172
}else{
110173
collectionString = self.collectionName!
111174
}
112-
175+
query["filtered"] = filtered
113176
let params = NSMutableDictionary()
114177
params["collectionName"] = collectionString
115178
params["query"] = query

CloudBoost/CloudSocket.swift

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// CloudSocket.swift
3+
// CloudBoost
4+
//
5+
// Created by Randhir Singh on 24/04/16.
6+
// Copyright © 2016 Randhir Singh. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public class CloudSocket {
12+
private static var socket: SocketIOClient?
13+
14+
public static func initialise(url: String){
15+
let socket = SocketIOClient(socketURL: NSURL(string: url)!, options: [.Log(true), .ForcePolling(true)])
16+
self.setSocket(socket)
17+
}
18+
19+
public static func getSocket() -> SocketIOClient {
20+
return CloudSocket.socket!
21+
}
22+
23+
public static func setSocket(socket: SocketIOClient){
24+
CloudSocket.socket = socket
25+
}
26+
27+
}

0 commit comments

Comments
 (0)