Skip to content

Commit

Permalink
Respond to tweak message
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-hofsteede committed May 8, 2014
1 parent b11869a commit 06ab609
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 1 deletion.
12 changes: 12 additions & 0 deletions HelloMixpanel/HelloMixpanel.xcodeproj/project.pbxproj
Expand Up @@ -22,6 +22,8 @@
05E98DE71918472100AFF3E1 /* MPObjectSelector.m in Sources */ = {isa = PBXBuildFile; fileRef = 05E98DE61918472100AFF3E1 /* MPObjectSelector.m */; };
05E98DF1191AE10000AFF3E1 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 05E98DF0191AE10000AFF3E1 /* MapKit.framework */; };
05E98DF3191AE27200AFF3E1 /* test_variant.json in Resources */ = {isa = PBXBuildFile; fileRef = 05E98DF2191AE27200AFF3E1 /* test_variant.json */; };
05E98DF6191B0A5C00AFF3E1 /* MPABTestDesignerTweakRequestMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 05E98DF5191B0A5C00AFF3E1 /* MPABTestDesignerTweakRequestMessage.m */; };
05E98DF9191B0B1400AFF3E1 /* MPABTestDesignerTweakResponseMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 05E98DF8191B0B1400AFF3E1 /* MPABTestDesignerTweakResponseMessage.m */; };
05F02D6318528F8C00527D93 /* MPNotificationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 05F02D6218528F8C00527D93 /* MPNotificationViewController.m */; };
05FF819E18452EA20073FBAC /* HomeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 05FF819D18452EA20073FBAC /* HomeViewController.m */; };
2802054017DEC234000D71F5 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2802053F17DEC234000D71F5 /* QuartzCore.framework */; };
Expand Down Expand Up @@ -122,6 +124,10 @@
05E98DE61918472100AFF3E1 /* MPObjectSelector.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPObjectSelector.m; sourceTree = "<group>"; };
05E98DF0191AE10000AFF3E1 /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; };
05E98DF2191AE27200AFF3E1 /* test_variant.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = test_variant.json; sourceTree = "<group>"; };
05E98DF4191B0A5C00AFF3E1 /* MPABTestDesignerTweakRequestMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPABTestDesignerTweakRequestMessage.h; sourceTree = "<group>"; };
05E98DF5191B0A5C00AFF3E1 /* MPABTestDesignerTweakRequestMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPABTestDesignerTweakRequestMessage.m; sourceTree = "<group>"; };
05E98DF7191B0B1400AFF3E1 /* MPABTestDesignerTweakResponseMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPABTestDesignerTweakResponseMessage.h; sourceTree = "<group>"; };
05E98DF8191B0B1400AFF3E1 /* MPABTestDesignerTweakResponseMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPABTestDesignerTweakResponseMessage.m; sourceTree = "<group>"; };
05F02D6118528F8C00527D93 /* MPNotificationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPNotificationViewController.h; sourceTree = "<group>"; };
05F02D6218528F8C00527D93 /* MPNotificationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPNotificationViewController.m; sourceTree = "<group>"; };
05FF819C18452EA20073FBAC /* HomeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HomeViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -511,6 +517,10 @@
C38D5F58D1809C6432B8B45B /* MPABTestDesignerChangeResponseMessage.h */,
C38D5C1843D5E8AE8715E3F4 /* MPABTestDesignerDeviceInfoRequestMessage.m */,
C38D5A46C299056A07676D14 /* MPABTestDesignerDeviceInfoRequestMessage.h */,
05E98DF4191B0A5C00AFF3E1 /* MPABTestDesignerTweakRequestMessage.h */,
05E98DF5191B0A5C00AFF3E1 /* MPABTestDesignerTweakRequestMessage.m */,
05E98DF7191B0B1400AFF3E1 /* MPABTestDesignerTweakResponseMessage.h */,
05E98DF8191B0B1400AFF3E1 /* MPABTestDesignerTweakResponseMessage.m */,
);
name = Messages;
sourceTree = "<group>";
Expand Down Expand Up @@ -723,6 +733,8 @@
A7B462DA191075DE00774977 /* MPObjectSerializerContext.m in Sources */,
A7B462D2191075DE00774977 /* MPCATransform3DToNSDictionaryValueTransformer.m in Sources */,
A7B462DE191075DE00774977 /* MPUIColorToNSStringValueTransformer.m in Sources */,
05E98DF6191B0A5C00AFF3E1 /* MPABTestDesignerTweakRequestMessage.m in Sources */,
05E98DF9191B0B1400AFF3E1 /* MPABTestDesignerTweakResponseMessage.m in Sources */,
86CC974E1811F82D0003EF50 /* MPNotification.m in Sources */,
A7B462D7191075DE00774977 /* MPCGSizeToNSDictionaryValueTransformer.m in Sources */,
A7B462D8191075DE00774977 /* MPClassDescription.m in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion HelloMixpanel/HelloMixpanel/HomeViewController.m
Expand Up @@ -13,7 +13,7 @@ - (void)viewDidLoad

self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"MPLogo.png"]];

FBTweakBind(self.view, alpha, @"Main Window", @"View", @"Alpha", 1.0f);
FBTweakBind(self.view, alpha, @"Main Window", @"View", @"Alpha", 1.0f, 0.0f, 1.0f);
}

@end
3 changes: 3 additions & 0 deletions Mixpanel/MPABTestDesignerConnection.m
Expand Up @@ -7,6 +7,8 @@
#import "MPABTestDesignerSnapshotRequestMessage.h"
#import "MPABTestDesignerChangeRequestMessage.h"
#import "MPABTestDesignerDeviceInfoRequestMessage.h"
#import "MPABTestDesignerTweakRequestMessage.h"


@interface MPABTestDesignerConnection () <MPWebSocketDelegate>
@end
Expand All @@ -28,6 +30,7 @@ - (id)initWithURL:(NSURL *)url
MPABTestDesignerSnapshotRequestMessageType : [MPABTestDesignerSnapshotRequestMessage class],
MPABTestDesignerChangeRequestMessageType : [MPABTestDesignerChangeRequestMessage class],
MPABTestDesignerDeviceInfoRequestMessageType : [MPABTestDesignerDeviceInfoRequestMessage class],
MPABTestDesignerTweakRequestMessageType : [MPABTestDesignerTweakRequestMessage class],
};

_session = [[NSMutableDictionary alloc] init];
Expand Down
15 changes: 15 additions & 0 deletions Mixpanel/MPABTestDesignerTweakRequestMessage.h
@@ -0,0 +1,15 @@
//
// MPABTestDesignerTweakRequestMessage.h
// HelloMixpanel
//
// Created by Alex Hofsteede on 7/5/14.
// Copyright (c) 2014 Mixpanel. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "MPAbstractABTestDesignerMessage.h"

extern NSString *const MPABTestDesignerTweakRequestMessageType;

@interface MPABTestDesignerTweakRequestMessage : MPAbstractABTestDesignerMessage
@end
56 changes: 56 additions & 0 deletions Mixpanel/MPABTestDesignerTweakRequestMessage.m
@@ -0,0 +1,56 @@
//
// MPABTestDesignerTweakRequestMessage.h
// HelloMixpanel
//
// Created by Alex Hofsteede on 7/5/14.
// Copyright (c) 2014 Mixpanel. All rights reserved.
//

#import "MPABTestDesignerTweakRequestMessage.h"
#import "MPABTestDesignerConnection.h"
#import "MPABTestDesignerTweakResponseMessage.h"

// Facebook Tweaks
#import "FBTweakStore.h"
#import "FBTweakCollection.h"
#import "FBTweakCategory.h"
#import "FBTweak.h"

NSString *const MPABTestDesignerTweakRequestMessageType = @"tweak_request";

@implementation MPABTestDesignerTweakRequestMessage

+ (instancetype)message
{
return [[self alloc] initWithType:@"tweak_request"];
}

- (NSOperation *)responseCommandWithConnection:(MPABTestDesignerConnection *)connection
{
__weak MPABTestDesignerConnection *weak_connection = connection;
NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
MPABTestDesignerConnection *conn = weak_connection;

dispatch_sync(dispatch_get_main_queue(), ^{
NSArray *tweaks = [self payload][@"tweaks"];
for (NSDictionary *tweak in tweaks) {
FBTweakStore *store = [FBTweakStore sharedInstance];
FBTweakCategory *category = [store tweakCategoryWithName:tweak[@"category"]];
FBTweakCollection *collection = [category tweakCollectionWithName:tweak[@"collection"]];
FBTweak *fbTweak = [collection tweakWithIdentifier:tweak[@"identifier"]];

NSLog(@"%@", tweak[@"value"]);
fbTweak.currentValue = tweak[@"value"];
}

});

MPABTestDesignerTweakResponseMessage *changeResponseMessage = [MPABTestDesignerTweakResponseMessage message];
changeResponseMessage.status = @"OK";
[conn sendMessage:changeResponseMessage];
}];

return operation;
}

@end
17 changes: 17 additions & 0 deletions Mixpanel/MPABTestDesignerTweakResponseMessage.h
@@ -0,0 +1,17 @@
//
// MPABTestDesignerTweakResponseMessage.h
// HelloMixpanel
//
// Created by Alex Hofsteede on 7/5/14.
// Copyright (c) 2014 Mixpanel. All rights reserved.
//

#import "MPAbstractABTestDesignerMessage.h"

@interface MPABTestDesignerTweakResponseMessage : MPAbstractABTestDesignerMessage

+ (instancetype)message;

@property (nonatomic, copy) NSString *status;

@end
28 changes: 28 additions & 0 deletions Mixpanel/MPABTestDesignerTweakResponseMessage.m
@@ -0,0 +1,28 @@
//
// MPABTestDesignerTweakResponseMessage.m
// HelloMixpanel
//
// Created by Alex Hofsteede on 7/5/14.
// Copyright (c) 2014 Mixpanel. All rights reserved.
//

#import "MPABTestDesignerTweakResponseMessage.h"

@implementation MPABTestDesignerTweakResponseMessage

+ (instancetype)message
{
return [[self alloc] initWithType:@"tweak_response"];
}

- (void)setStatus:(NSString *)status
{
[self setPayloadObject:status forKey:@"status"];
}

- (NSString *)status
{
return [self payloadObjectForKey:@"status"];
}

@end

0 comments on commit 06ab609

Please sign in to comment.