This repository was archived by the owner on Sep 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathSBBObjectManager.h
124 lines (114 loc) · 5.66 KB
/
SBBObjectManager.h
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// SBBObjectManager.h
// BridgeSDK
//
// Created by Erin Mounts on 9/25/14.
//
// Copyright (c) 2014, Sage Bionetworks
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Sage Bionetworks nor the names of BridgeSDk's
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL SAGE BIONETWORKS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#import <Foundation/Foundation.h>
#import <BridgeSDK/SBBComponent.h>
/*!
This protocol defines the interface to the SBBObjectManager's non-constructor, non-initializer methods. The interface is
abstracted out for use in mock objects for testing, and to allow selecting among multiple implementations at runtime.
*/
@protocol SBBObjectManagerProtocol <NSObject>
/*!
* Create a client object from JSON obtained via the Bridge API.
*
* By default, the object will be an instance (or array) of class SBB<type>, where <type> is the Bridge API object type
* as indicated in its "type" field, and SBB<type> is an SBBBridgeObject subclass with properties matching the fields
* defined for <type> in the API documentation.
*
* You can override this by setting up a mapping between <type> and a custom class via the
* setupMappingForType:toClass:fieldToPropertyMappings: method. In that case API manager methods in this SDK will use
* the classes defined in these mappings to pass data back and forth between your app and the Bridge API in place of
* the built-in SBB<type> classes.
*
* @param json A JSON object from the Bridge API.
*
* @return A client object (built-in or custom) representing that Bridge API object.
*
* @see bridgeJSONFromObject:
* @see setupMappingForType:toClass:fieldToPropertyMappings:
*/
- (id)objectFromBridgeJSON:(id)json;
/*!
* Create a Bridge JSON object (or array) from a client object.
*
* If object is an instance of a built-in SBB<type> class, it will be converted into a JSON Bridge object of <type>.
*
* If object is an instance of a class mapped from a type via setupMappingForType:toClass:fieldToPropertyMappings:,
* it will be reverse-converted according to the defined mapping to a JSON Bridge object of the mapped-from type.
*
* If the object is an NSDate object, it will be converted to an ISO 8601 date string.
*
* If the object is a standard JSON object (NSArray, NSDictionary, NSString, NSNumber), it will just be returned as-is.
*
* Any other kind of object will be ignored and this method will return nil.
*
* @param object The client object to convert to JSON for the Bridge API.
*
* @return JSON representing that client object.
*
* @see objectFromBridgeJSON:
* @see setupMappingForType:toClass:fieldToPropertyMappings:
*/
- (id)bridgeJSONFromObject:(id)object;
/*!
* Set up an SDK-wide mapping between Bridge API objects of a specified type and a particular client class, with
* Bridge object field names mapped to class properties according to a given dictionary.
*
* By default, unless an explicit mapping has been set up for a given Bridge API object type, the mapping will be done
* to an internal class named SBB<type> with property names matching the field names defined for the Bridge API object type.
*
* @param type The Bridge API type being mapped.
* @param mapToClass The client class to which it is to be mapped.
* @param mappings Keys are Bridge API field names; values are the corresponding class property names. A nil value for this parameter will cause the SDK to use the Bridge API field names as the corresponding class property names.
*/
- (void)setupMappingForType:(NSString *)type toClass:(Class)mapToClass fieldToPropertyMappings:(NSDictionary *)mappings;
/*!
* Clear any previously set up SDK-wide mapping of Bridge API objects of the specified type.
*
* The implicit mapping will revert to an internal class named SBB<type> with property names matching the field names
* defined for the Bridge API object type.
*
* @param type The Bridge API type being un-mapped.
*/
- (void)clearMappingForType:(NSString *)type;
@end
/*!
* This class handles converting between Bridge API JSON objects and corresponding client objects. It is used internally
* by the various API managers for that purpose.
*/
@interface SBBObjectManager : NSObject<SBBComponent, SBBObjectManagerProtocol>
/*!
* Use this method to create an independent object manager instance for testing.
*
* @return A fresh SBBObjectManager instance.
*/
+ (instancetype)objectManager;
@end