-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSugarRest.m
53 lines (37 loc) · 1.61 KB
/
SugarRest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// SugarRest.m
// UberMail
//
// Created by Amanda Sandberg on 4/24/13.
// Copyright (c) 2013 Andreas Sandberg. All rights reserved.
//
#import "SugarRest.h"
#import "AFHTTPClient.h"
@implementation SugarRest
static SugarRest *sharedInstance = nil;
-(id) init {
self = [super init];
if(self) {
[self setSessionIdForUser:@"temp" withPassword:@"pass"];
NSLog(@"Finishd initing");
}
return self;
}
+ (SugarRest *)sharedInstance {
if (sharedInstance == nil) {
sharedInstance = [[self alloc] init];
}
return sharedInstance;
}
-(void) setSessionIdForUser: (NSString * ) username withPassword: (NSString * ) pass {
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://50.112.254.200"]];
//Yes Sugarcrms REST API is this ugly..... payload is url and json encoded
[client getPath:@"service/v4/rest.php?method=login&input_type=JSON&response_type=JSON&rest_data=%7B%22user_auth%22%3A%7B%22user_name%22%3A%22admin%22%2C%22password%22%3A%22764aa20af226db531aa73b9f894b58f7%22%2C%22version%22%3A%221%22%7D%2C%22application_name%22%3A%22RestTest%22%2C%22name_value_list%22%3A%5B%5D%7D" parameters:nil success:^(AFHTTPRequestOperation *operation, id response) {
id payload = [NSJSONSerialization JSONObjectWithData:response options:NSJSONWritingPrettyPrinted error:nil];
NSLog(@"Payload %@", payload);
self->sessionId = [payload objectForKey:@"id"];
} failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSLog(@"NOT OK %@", error);
}];
}
@end