@@ -130,6 +130,9 @@ This is the `AuthRequestBuilderProtocol` definition:
130
130
131
131
``` swift
132
132
public protocol AuthRequestBuilderProtocol {
133
+ func requestFor (socketID : String , channelName : String ) -> URLRequest?
134
+
135
+ // DEPRECATED
133
136
func requestFor (socketID : String , channel : PusherChannel) -> NSMutableURLRequest?
134
137
}
135
138
```
@@ -215,8 +218,8 @@ Authenticated channel example:
215
218
#### Swift
216
219
```swift
217
220
class AuthRequestBuilder: AuthRequestBuilderProtocol {
218
- func requestFor(socketID: String, channel: PusherChannel ) -> NSMutableURLRequest ? {
219
- let request = NSMutableURLRequest (url: URL(string: "http://localhost:9292/builder")!)
221
+ func requestFor(socketID: String, channelName: String ) -> URLRequest ? {
222
+ var request = URLRequest (url: URL(string: "http://localhost:9292/builder")!)
220
223
request.httpMethod = "POST"
221
224
request.httpBody = "socket_id=\(socketID)&channel_name=\(channel.name)".data(using: String.Encoding.utf8)
222
225
request.addValue("myToken", forHTTPHeaderField: "Authorization")
@@ -237,19 +240,24 @@ let pusher = Pusher(
237
240
``` objc
238
241
@interface AuthRequestBuilder : NSObject <AuthRequestBuilderProtocol>
239
242
240
- - (NSMutableURLRequest * )requestForSocketID:(NSString * )socketID channel:(PusherChannel * )channel ;
243
+ - (NSURLRequest * )requestForSocketID:(NSString * )socketID channelName:(NSString * )channelName ;
241
244
242
245
@end
243
246
244
247
@implementation AuthRequestBuilder
245
248
246
- - (NSMutableURLRequest* )requestForSocketID:(NSString * )socketID channel:(PusherChannel * )channel {
247
- NSMutableURLRequest * request = [[ NSMutableURLRequest alloc] initWithURL: [[ NSURL alloc] initWithString:@"http://localhost:9292/builder" ]] ;
248
- NSString * dataStr = [ NSString stringWithFormat: @"socket_id=%@&channel_name=%@", socketID, [ channel name]] ;
249
+ - (NSURLRequest * )requestForSocketID:(NSString * )socketID channelName:(NSString * )channelName {
250
+ NSURLRequest * request = [[ NSURLRequest alloc] initWithURL:[[ NSURL alloc] initWithString:@"http://localhost:9292/pusher/auth" ]] ;
251
+ NSMutableURLRequest * mutableRequest = [[ NSMutableURLRequest alloc] initWithURL: [[ NSURL alloc] initWithString:@"http://localhost:9292/pusher/auth" ]] ;
252
+
253
+ NSString * dataStr = [ NSString stringWithFormat: @"socket_id=%@&channel_name=%@", socketID, channelName] ;
249
254
NSData * data = [ dataStr dataUsingEncoding: NSUTF8StringEncoding ] ;
250
- request.HTTPBody = data;
251
- request.HTTPMethod = @"POST";
252
- [ request addValue:@"myToken" forHTTPHeaderField:@"Authorization"] ;
255
+ mutableRequest.HTTPBody = data;
256
+ mutableRequest.HTTPMethod = @"POST";
257
+ [ mutableRequest addValue:@"myToken" forHTTPHeaderField:@"Authorization"] ;
258
+
259
+ request = [ mutableRequest copy] ;
260
+
253
261
return request;
254
262
}
255
263
0 commit comments