diff --git a/Common/NSString+SLStringHelpers.h b/Common/Categories/NSString+SLStringHelpers.h similarity index 100% rename from Common/NSString+SLStringHelpers.h rename to Common/Categories/NSString+SLStringHelpers.h diff --git a/Common/NSString+SLStringHelpers.m b/Common/Categories/NSString+SLStringHelpers.m similarity index 100% rename from Common/NSString+SLStringHelpers.m rename to Common/Categories/NSString+SLStringHelpers.m diff --git a/Common/Models/SLAttribute.h b/Common/Models/SLAttribute.h index 6fcfa01..4f206fd 100644 --- a/Common/Models/SLAttribute.h +++ b/Common/Models/SLAttribute.h @@ -16,5 +16,6 @@ @property (nonatomic, retain) id parameters; @property (nonatomic, retain) NSString * assetName; @property (nonatomic, retain) NSString * desc; +@property (nonatomic, retain) NSString * humanName; @end diff --git a/Common/Models/SLAttribute.m b/Common/Models/SLAttribute.m index 214fc42..dc1ff15 100644 --- a/Common/Models/SLAttribute.m +++ b/Common/Models/SLAttribute.m @@ -15,7 +15,7 @@ @implementation SLAttribute @dynamic parameters; @dynamic assetName; @dynamic desc; - +@dynamic humanName; + (NSString *) type { diff --git a/Common/SLModel.h b/Common/SLModel.h index 5fd4e83..4d4bafa 100644 --- a/Common/SLModel.h +++ b/Common/SLModel.h @@ -188,6 +188,7 @@ /** Create a new record in the current store. The properties passed to this method are set on the newly created record. */ ++ (instancetype) createRecord; + (instancetype) createRecord:(NSDictionary *)properties; /** diff --git a/Common/SLModel.m b/Common/SLModel.m index ab55f19..ba3a191 100644 --- a/Common/SLModel.m +++ b/Common/SLModel.m @@ -202,6 +202,11 @@ - (NSDictionary *) serializeData { return [NSDictionary dictionaryWithDictionary:theData]; } ++ (instancetype) createRecord +{ + return [self createRecord:@{}]; +} + + (instancetype) createRecord:(NSDictionary *)properties { return [[SLStore sharedStore] createRecord:[self class] withProperties:properties]; diff --git a/Common/SLSerializer.m b/Common/SLSerializer.m index d707cf5..99a5fce 100644 --- a/Common/SLSerializer.m +++ b/Common/SLSerializer.m @@ -240,7 +240,22 @@ - (NSDictionary *) serializeAttribute:(SLModel *)record withKey:(NSString *)key - (NSDictionary *) serializeBelongsTo:(SLModel *)record withKey:(NSString *)key withData:(NSDictionary *)data { - return data; + NSMutableDictionary *results = [NSMutableDictionary dictionaryWithDictionary:data]; + + Class modelClass = [record class]; + NSString *payloadKey = [modelClass keyForAttribute:key]; + // Get the record + SLModel *origVal = [record valueForKeyPath:key]; + // Check if there is a record in the relationship + if (origVal != nil) + { + // Serialize the ID + NSDictionary *val = [SLObjectIdTransform serialize:origVal.nid]; + // Save it + [results setObject:val forKey:payloadKey]; + } + // Return the current serialized form of this record + return [NSDictionary dictionaryWithDictionary:results]; } - (NSDictionary *) serializeHasMany:(SLModel *)record withKey:(NSString *)key withData:(NSDictionary *)data diff --git a/Common/Streamlyne.xcdatamodeld/Streamlyne.xcdatamodel/contents b/Common/Streamlyne.xcdatamodeld/Streamlyne.xcdatamodel/contents index d72fd7a..25ce401 100644 --- a/Common/Streamlyne.xcdatamodeld/Streamlyne.xcdatamodel/contents +++ b/Common/Streamlyne.xcdatamodeld/Streamlyne.xcdatamodel/contents @@ -12,7 +12,8 @@ - + + @@ -59,7 +60,7 @@ - + diff --git a/Streamlyne Cocoa SDK.xcodeproj/project.pbxproj b/Streamlyne Cocoa SDK.xcodeproj/project.pbxproj index 26fe28b..28ed16a 100644 --- a/Streamlyne Cocoa SDK.xcodeproj/project.pbxproj +++ b/Streamlyne Cocoa SDK.xcodeproj/project.pbxproj @@ -311,8 +311,8 @@ children = ( 7783AFF519744B25000CAB0A /* install.sh */, 7783AFF419744B19000CAB0A /* README.md */, - 77AD7DDF1842F6DC0053C02C /* Common */, 77B4EA361840960B00435B97 /* Guide */, + 77AD7DDF1842F6DC0053C02C /* Common */, 7720FC1C18369CA20092D39B /* Streamlyne-iOS-SDK */, 7720FC3018369CA20092D39B /* Streamlyne-iOS-SDKTests */, 77B4EA14184094D400435B97 /* Streamlyne-Mac-SDK */, @@ -401,7 +401,7 @@ 77A473BE1978710600748E1F /* NSString+SLStringHelpers.h */, 77A473BF1978710600748E1F /* NSString+SLStringHelpers.m */, ); - name = Categories; + path = Categories; sourceTree = ""; }; 77AD7DDF1842F6DC0053C02C /* Common */ = { diff --git a/Streamlyne Cocoa SDK.xcodeproj/xcshareddata/xcschemes/Streamlyne-Mac-SDK.xcscheme b/Streamlyne Cocoa SDK.xcodeproj/xcshareddata/xcschemes/Streamlyne-Mac-SDK.xcscheme new file mode 100644 index 0000000..bc4917c --- /dev/null +++ b/Streamlyne Cocoa SDK.xcodeproj/xcshareddata/xcschemes/Streamlyne-Mac-SDK.xcscheme @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Streamlyne-iOS-SDKTests/Streamlyne_iOS_SDKTests.m b/Streamlyne-iOS-SDKTests/Streamlyne_iOS_SDKTests.m index 91572ab..b4b2785 100644 --- a/Streamlyne-iOS-SDKTests/Streamlyne_iOS_SDKTests.m +++ b/Streamlyne-iOS-SDKTests/Streamlyne_iOS_SDKTests.m @@ -39,13 +39,12 @@ @implementation Streamlyne_iOS_SDKTests (XCTAssertTrue([a isEqualToString:b], format) ); // Login Credentials -//#define SLLoginEmail @"test@test.co" -//#define SLLoginPassword @"test" -//#define SLLoginOrganization @"test" - -#define SLLoginEmail @"glavin@streamlyne.co" -#define SLLoginPassword @"glavin" -#define SLLoginOrganization @"nevis" +#define SLLoginEmail @"test@test.co" +#define SLLoginPassword @"test" +#define SLLoginOrganization @"test" +//#define SLLoginEmail @"glavin@streamlyne.co" +//#define SLLoginPassword @"glavin" +//#define SLLoginOrganization @"nevis" // Put setup code here. This method is called before the invocation of each test method in the class. @@ -69,6 +68,10 @@ - (void)setUp withOrganization:SLLoginOrganization] .then(^(SLClient *client, SLUser *me) { EndBlock(); + }) + .catch(^(NSError *error) { + EndBlock(); + XCTFail(@"setUp failed to authenticate with error: %@",error); }); WaitUntilBlockCompletes(); @@ -105,7 +108,6 @@ - (void) testHMAC NSString *message = @"ILove2Test!tTest!t"; NSString *secret = @"Streamlyne"; NSString *hmac = @"1c2c34e017a17a6ae42c0dbdf6a3586f6735de3b"; - NSString *result = [SLAdapter hmac:message withSecret:secret]; XCTAssertStringEqual(result, hmac, @"HMACs should be the same."); } @@ -120,9 +122,12 @@ - (void) testAuthentication withPassword:SLLoginPassword withOrganization:SLLoginOrganization] .then(^() { + NSLog(@"TESTTT"); XCTAssertTrue(true, @"PARTY. IT WORKED."); + EndBlock(); }) .catch(^(NSError *error) { + EndBlock(); XCTFail(@"%@", error); }) .finally(^() { @@ -488,18 +493,18 @@ - (void) testFindQuery } -- (void) testCreateAttributeDatum +- (void) testCreateAttribute { StartBlock(); - // Create - SLAttributeDatum *attributeDatum = [SLAttributeDatum createRecord:@{ - @"value": @123.0 - }]; + SLAttribute *attribute = [SLAttribute createRecord]; + attribute.name = @"TESTATTR1"; + attribute.humanName = @"Test Attribute"; + // Save - [attributeDatum save] - .then(^(SLAttributeDatum *attributeDatum) { - NSLog(@"Datum: %@", attributeDatum); + [attribute save] + .then(^(SLAttribute *attribute) { + NSLog(@"Attribute: %@", attribute); EndBlock(); }) .catch(^(NSError *error){ @@ -507,10 +512,47 @@ - (void) testCreateAttributeDatum EndBlock(); XCTFail(@"%@", error); }); - - WaitUntilBlockCompletes(); - +} + +- (void) testCreateAttributeDatum +{ + StartBlock(); + // Create + SLAttributeDatum *attributeDatum = [SLAttributeDatum createRecord:@{ + @"value": @123.0 + }]; + [SLAttribute findAll] + .then(^(NSArray *attributes) { + if ([attributes count] > 0) + { + // Get the first Attribute + SLAttribute *attribute = [attributes objectAtIndex:0]; + // Associate the Attribute to the AttributeDatum + attributeDatum.attribute = attribute; + // Save + [attributeDatum save] + .then(^(SLAttributeDatum *attributeDatum) { + NSLog(@"Datum: %@", attributeDatum); + EndBlock(); + }) + .catch(^(NSError *error){ + NSLog(@"%@", error); + EndBlock(); + XCTFail(@"%@", error); + }); + } + else + { + EndBlock(); + XCTFail(@"No attributes found for this AttributeDatum to be associated to."); + } + }) + .catch(^(NSError *error) { + EndBlock(); + XCTFail(@"Could not get an attribute to associate the AttributeDatum to: %@", error); + }); + WaitUntilBlockCompletes(); }