forked from kylebrowning/waterwheel.swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DIOSEntity.m
56 lines (50 loc) · 2.98 KB
/
DIOSEntity.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
54
55
56
//
// DIOSEntity.m
// dios
//
// Created by Kyle Browning on 9/4/14.
// Copyright (c) 2014 Kyle Browning. All rights reserved.
//
#import "DIOSEntity.h"
#import "DIOSSession.h"
@implementation DIOSEntity
+ (void) getEntityWithName:(NSString*)name andID:(NSString*)eid
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
NSString *path = [NSString stringWithFormat:@"%@/%@", name, eid];
[[DIOSSession sharedSession] sendRequestWithPath:path method:@"GET" params:nil success:success failure:failure];
}
+ (void) createEntityWithEntityName:(NSString*)name
type:(NSString*)type
andParams:(NSDictionary*)params
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
NSMutableDictionary *dict = [NSMutableDictionary new];
NSString *href = [NSString stringWithFormat:@"%@/rest/type/%@/%@", [[[DIOSSession sharedSession] baseURL] absoluteString], name, type];
NSDictionary *defaultDict = @{@"_links" : @{@"type" : @{@"href" : href}}};
[dict addEntriesFromDictionary:defaultDict];
[dict addEntriesFromDictionary:params];
NSString *path = [NSString stringWithFormat:@"entity/%@", name];
[[DIOSSession sharedSession] sendRequestWithPath:path method:@"POST" params:dict success:success failure:failure];
}
+ (void) deleteEntityWithEntityName:(NSString*)name andID:(NSString*)eid
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
NSString *path = [NSString stringWithFormat:@"%@/%@", name, eid];
[[DIOSSession sharedSession] sendRequestWithPath:path method:@"DELETE" params:nil success:success failure:failure];
}
+ (void) patchEntityWithEntityName:(NSString*)name
type:(NSString*)type
eid:(NSString*)eid
andParams:(NSDictionary*)params
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
NSMutableDictionary *dict = [NSMutableDictionary new];
NSString *href = [NSString stringWithFormat:@"%@/rest/type/%@/%@", [[[DIOSSession sharedSession] baseURL] absoluteString], name, type];
NSDictionary *defaultDict = @{@"_links" : @{@"type" : @{@"href" : href}}};
[dict addEntriesFromDictionary:defaultDict];
[dict addEntriesFromDictionary:params];
NSString *path = [NSString stringWithFormat:@"%@/%@", name, eid];
[[DIOSSession sharedSession] sendRequestWithPath:path method:@"PATCH" params:dict success:success failure:failure];
}
@end