Skip to content

Commit

Permalink
See #7, #8, #10, #14. Method header stubs for foundation of SDK.
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavin001 committed Jul 17, 2014
1 parent d2eaaa8 commit 7da143d
Show file tree
Hide file tree
Showing 32 changed files with 1,542 additions and 3,749 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions Common/Nodes/SLUser.m → Common/Models/SLUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
//

#import "SLUser.h"
#import "SLValue.h"
#import "SLRelationship.h"
#import "SLAPIManager.h"

@implementation SLUser
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions Common/SLAPIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,13 @@ typedef NS_ENUM(NSUInteger, SLHTTPMethodType)
withPassword:(NSString *)thePassword
withOrganization:(NSString *)theOrganization;

/**
Create a JSON representation of the record, using the serialization strategy of the store's adapter.
serialize takes an optional hash as a parameter, currently supported options are:
includeId: true if the record's ID should be included in the JSON representation.
*/
- (NSDictionary *) serialize:(NSDictionary *)options;

@end
2 changes: 2 additions & 0 deletions Common/SLAPIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,6 @@ - (PMKPromise *) authenticateWithUserEmail:(NSString *)theEmail
}




@end
120 changes: 79 additions & 41 deletions Common/SLModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "SLNodeProtocol.h"
#import "CoreData+MagicalRecord.h"
#import "SLObject.h"
#import "SLValue.h"
#import "SLSerializer.h"
#import <PromiseKit.h>

/**
Expand All @@ -29,21 +29,19 @@
}
// Properties
/**
String s -> SLValue s
*/
@property (strong, nonatomic) NSDictionary *data DEPRECATED_ATTRIBUTE;
@property (nonatomic, retain) SLNid nid;
/**
A list of relationships to this node.
@deprecated Use Core Data relationships now.
*/
@property (strong, nonatomic) NSMutableArray *rels DEPRECATED_ATTRIBUTE;
@property (nonatomic, retain) NSNumber *syncState;
/**
*/
//@property (strong, nonatomic) SLNid nid;
@property (nonatomic, retain) SLNid nid;
@property (nonatomic, retain) NSNumber *syncState;
@property (nonatomic, retain) NSDate *dateCreated;
/**
*/
@property (nonatomic, retain) NSDate *dateUpdated;

/**
Expand All @@ -52,6 +50,8 @@
*/
@property (getter=isSaved, readonly) BOOL saved;



/**
Returns an object initialized.
Expand Down Expand Up @@ -85,49 +85,43 @@
@param nid
@return Initialized object.
@deprecated Use `MR_createEntity`.
@deprecated Use `setupData`.
*/
+ (instancetype) initWithId:(SLNid)nid DEPRECATED_ATTRIBUTE;

/**
@deprecated Use `setupData`.
*/
+ (instancetype) initWithId:(SLNid)nid inContext:(NSManagedObjectContext *)context;

/**
Return the node type name. This is used in the requests to the `SLAPIManager`.
Setup record with existing data.
Used when pushing records from the server into the store.
This should be defined by the subclass implementation of `SLNode`.
@private
*/
+ (NSString *) type;
+ (instancetype) setupData:(NSDictionary *)data;

/**
Return the node type name. This is used in the requests to the `SLAPIManager`.
Edit when subclassing.
```
+ (NSDictionary *) attributeMappings
{
NSMutableDictionary *attrMap = [NSMutableDictionary dictionaryWithDictionary:[[[self superclass] class] attributeMappings]];
[attrMap setValue:@"name" forKey:@"name"];
[attrMap setValue:@"location" forKey:@"location"];
return [NSDictionary dictionaryWithDictionary: attrMap];
}
```
This should be defined by the subclass implementation of `SLNode`.
*/
+ (NSDictionary *) attributeMappings DEPRECATED_ATTRIBUTE;
+ (NSString *) type;

/**
Attribute to Key mappings for the Model.
Edit when subclassing, if neccessary.
*/
- (NSString *) attributeForKey:(NSString *)key DEPRECATED_ATTRIBUTE;
- (NSString *) keyForAttribute:(NSString *)attribute;

/**
Key to Attribute mappings for the Model.
Relationship to Key mappings for the Model.
Edit when subclassing, if neccessary.
*/
- (NSString *) keyForAttribute:(NSString *)attribute;

- (NSString *) keyForRelationship:(NSString *)relationship;

/**
Returns an NSArray of pending Nodes.
Expand Down Expand Up @@ -266,15 +260,9 @@


/**
Persists the node to the database.
This done by iterating through {data} and compiling a list of node SLValues
that haven't been saved. From the set of unsaved properties a update request to
SLAPI may be formulated.
@deprecated Use `pushWithAPIManager:withCallback` instead.
Save the record and persist any changes to the record to an extenal source via the adapter.
*/
- (void) save DEPRECATED_ATTRIBUTE;
- (void) save;

/**
Persists the node to the database, with callback on completion.
Expand Down Expand Up @@ -331,10 +319,60 @@
*/
- (PMKPromise *) remove;

/**
Create a new record in the current store. The properties passed to this method are set on the newly created record.
*/
- (instancetype) createRecord:(NSDictionary *)properties;

/**
This method returns a record for a given type and id combination.
*/
- (PMKPromise *) findById:(SLNid)nid;

/**
This method delegates a query to the adapter. This is the one place where adapter-level semantics are exposed to the application.
Exposing queries this way seems preferable to creating an abstract query language for all server-side queries, and then require all adapters to implement them.
This method returns a promise, which is resolved with a RecordArray once the server returns.
*/
- (PMKPromise *) findQuery:(NSDictionary *)query;

/**
This method returns an array of all records adapter can find. It triggers the adapter's findAll method to give it an opportunity to populate the array with records of that type.
*/
- (PMKPromise *) findAll;

/**
*/
- (PMKPromise *) findMany:(NSArray *)ids;

/**
Update existing records in the store. Unlike push, update will merge the new data properties with the existing properties. This makes it safe to use with a subset of record attributes. This method expects normalized data.
update is useful if you app broadcasts partial updates to records.
*/
- (instancetype) updateRecord:(NSDictionary *)properties;

/**
If the model `isDirty` this function will discard any unsaved changes
*/
- (NSDictionary *) serialize;
- (instancetype) rollback;

/**
For symmetry, a record can be deleted via the store.
*/
- (instancetype) deleteRecord;

/**
Create a JSON representation of the record, using the serialization strategy of the store's adapter.
serialize takes an optional hash as a parameter, currently supported options are:
includeId: true if the record's ID should be included in the JSON representation.
*/
- (NSDictionary *) serialize:(NSDictionary *)options;


@end
Loading

0 comments on commit 7da143d

Please sign in to comment.