Permalink
Browse files

[ios-sdk] Added FBContentLink class

Summary: Added FBContentLink class to assist with parsing of target_url fields.

Test Plan: Ran all unit tests

Reviewers: mmarucheck, ekoneil

Reviewed By: mmarucheck

CC: astewart, yariv

Differential Revision: 479905

Task ID: 1000858
  • Loading branch information...
Christopher Biettchert
Christopher Biettchert committed May 31, 2012
1 parent 679ba31 commit 9bcc3fff935e0b562e786e67d7ffd1801b69b580
View
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2012 Facebook
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#import <Foundation/Foundation.h>
+
+@interface FBContentLink : NSObject
+
+@property (readonly, copy) NSURL *targetURL;
+@property (readonly, copy) NSArray *actionTypes;
+@property (readonly, copy) NSString *source;
+@property (readonly, copy) NSArray *ref;
+@property (readonly, copy) NSDictionary *originalQueryParameters;
+
+- (id)initWithURL:(NSURL*)url;
+
+@end
View
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2012 Facebook
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#import "FBContentLink.h"
+#import "FBUtility.h"
+
+@implementation FBContentLink
+
+@synthesize targetURL = _targetURL;
+@synthesize actionTypes = _actionTypes;
+@synthesize source = _source;
+@synthesize ref =_ref;
+@synthesize originalQueryParameters = _originalQueryParameters;
+
+- (id)initWithURL:(NSURL*)url {
+ if (self = [super init]) {
+ NSString *query = [url fragment];
+ NSDictionary *params = [FBUtility dictionaryByParsingURLQueryPart:query];
+
+ _targetURL = [[NSURL alloc] initWithString:[params valueForKey:@"target_url"]];
+ _actionTypes = [[params valueForKey:@"fb_action_types"] componentsSeparatedByString:@","];
+ _source = [params valueForKey:@"fb_source"];
+ _ref = [[params valueForKey:@"fb_ref"] componentsSeparatedByString:@","];
+ _originalQueryParameters = params;
+ }
+ return self;
+}
+
+- (void)dealloc
+{
+ [_targetURL release];
+ [_actionTypes release];
+ [_source release];
+ [_ref release];
+ [_originalQueryParameters release];
+ [super dealloc];
+}
+
+@end
@@ -127,6 +127,9 @@
E2B99CF21549CD7F002AEA86 /* FBGraphObjectTableDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = E2B99CF01549CD7F002AEA86 /* FBGraphObjectTableDataSource.m */; };
E2B99CF51549E02A002AEA86 /* FBGraphObjectTableSelection.h in Headers */ = {isa = PBXBuildFile; fileRef = E2B99CF31549E02A002AEA86 /* FBGraphObjectTableSelection.h */; };
E2B99CF61549E02A002AEA86 /* FBGraphObjectTableSelection.m in Sources */ = {isa = PBXBuildFile; fileRef = E2B99CF41549E02A002AEA86 /* FBGraphObjectTableSelection.m */; };
+ E7BBCE2E15753C7400B6B8F6 /* FBContentLinkTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7BBCE2D15753C7400B6B8F6 /* FBContentLinkTests.m */; };
+ E7BBCE3115753C8E00B6B8F6 /* FBContentLink.h in Headers */ = {isa = PBXBuildFile; fileRef = E7BBCE2F15753C8E00B6B8F6 /* FBContentLink.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ E7BBCE3315753C8E00B6B8F6 /* FBContentLink.m in Sources */ = {isa = PBXBuildFile; fileRef = E7BBCE3015753C8E00B6B8F6 /* FBContentLink.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -245,6 +248,10 @@
E2B99CF01549CD7F002AEA86 /* FBGraphObjectTableDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBGraphObjectTableDataSource.m; sourceTree = "<group>"; };
E2B99CF31549E02A002AEA86 /* FBGraphObjectTableSelection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBGraphObjectTableSelection.h; sourceTree = "<group>"; };
E2B99CF41549E02A002AEA86 /* FBGraphObjectTableSelection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBGraphObjectTableSelection.m; sourceTree = "<group>"; };
+ E7BBCE2C15753C7400B6B8F6 /* FBContentLinkTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FBContentLinkTests.h; path = tests/FBContentLinkTests.h; sourceTree = "<group>"; };
+ E7BBCE2D15753C7400B6B8F6 /* FBContentLinkTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FBContentLinkTests.m; path = tests/FBContentLinkTests.m; sourceTree = "<group>"; };
+ E7BBCE2F15753C8E00B6B8F6 /* FBContentLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBContentLink.h; sourceTree = "<group>"; };
+ E7BBCE3015753C8E00B6B8F6 /* FBContentLink.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBContentLink.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -323,6 +330,8 @@
B9C6E1301525219600E46808 /* FBCacheIndex.h */,
B9C6E1311525219600E46808 /* FBCacheIndex.m */,
84E0CA051536198400778DA4 /* FBConnect.h */,
+ E7BBCE2F15753C8E00B6B8F6 /* FBContentLink.h */,
+ E7BBCE3015753C8E00B6B8F6 /* FBContentLink.m */,
84E0CA09153619D500778DA4 /* FBDataDiskCache.h */,
B9C6E1331525219600E46808 /* FBDataDiskCache.m */,
AEA93B0811D5293B000A4545 /* FBDialog.h */,
@@ -417,6 +426,8 @@
B9CBC54215254CBD0036AA71 /* FBCacheTests.m */,
E2325EEF155DAD0600E85A65 /* FBCommonRequestTests.h */,
E2325EF0155DAD0600E85A65 /* FBCommonRequestTests.m */,
+ E7BBCE2C15753C7400B6B8F6 /* FBContentLinkTests.h */,
+ E7BBCE2D15753C7400B6B8F6 /* FBContentLinkTests.m */,
84E374BD153CC1140043B59C /* FBGraphObjectTests.h */,
84E374BE153CC1140043B59C /* FBGraphObjectTests.m */,
858E424A1565F77400246151 /* FBOpenGraphActionTests.h */,
@@ -493,6 +504,7 @@
E2223AEB1554573900126FD2 /* FBPlacePickerViewController.h in Headers */,
85954B86155B452E00FABA9A /* FBGraphObjectPagingLoader.h in Headers */,
8525A5BA156F2049009F6F3F /* FBTestSession.h in Headers */,
+ E7BBCE3115753C8E00B6B8F6 /* FBContentLink.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -628,6 +640,8 @@
8525A5B0156EFCA1009F6F3F /* FBRequestConnectionTests.m in Sources */,
8525A5BC156F2049009F6F3F /* FBTestSession.m in Sources */,
85052AF9156F5E1200F8F9A5 /* FBTestSessionTests.m in Sources */,
+ E7BBCE2E15753C7400B6B8F6 /* FBContentLinkTests.m in Sources */,
+ E7BBCE3315753C8E00B6B8F6 /* FBContentLink.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -666,6 +680,7 @@
E2223AEC1554573900126FD2 /* FBPlacePickerViewController.m in Sources */,
85954B87155B452E00FABA9A /* FBGraphObjectPagingLoader.m in Sources */,
8525A5BB156F2049009F6F3F /* FBTestSession.m in Sources */,
+ E7BBCE3215753C8E00B6B8F6 /* FBContentLink.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2012 Facebook
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#import <SenTestingKit/SenTestingKit.h>
+
+@interface FBContentLinkTests : SenTestCase
+
+@end
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2012 Facebook
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#import "FBContentLinkTests.h"
+#import "FBContentLink.h"
+#import "FBTests.h"
+
+#if defined(FBIOSSDK_SKIP_CONTENT_LINK_TESTS)
+
+#pragma message ("warning: Skipping FBContentLinkTests")
+
+#else
+
+@implementation FBContentLinkTests
+
+- (void)testParseTargetURL
+{
+ NSURL *testURL = [[NSURL alloc] initWithString:@"fb123://authorize#expires_in=0&access_token=12345&target_url=http://target-url.com/?deeplink=1&fb_action_types=action1,action2&fb_source=source&fb_ref=ref1,ref2"];
+ NSArray *testActionType = [[NSArray alloc] initWithObjects:@"action1", @"action2", nil];
+ NSArray *testRef = [[NSArray alloc] initWithObjects:@"ref1", @"ref2", nil];
+ NSDictionary *testOriginalQueryParameters = [[NSDictionary alloc] initWithObjectsAndKeys:@"0", @"expires_in",
+ @"12345", @"access_token",
+ @"http://target-url.com/?deeplink=1", @"target_url",
+ @"action1,action2", @"fb_action_types",
+ @"source", @"fb_source",
+ @"ref1,ref2", @"fb_ref",
+ nil];
+
+ FBContentLink *contentLink = [[FBContentLink alloc] initWithURL:testURL];
+
+ STAssertEqualObjects([[NSURL alloc] initWithString:@"http://target-url.com/?deeplink=1"], contentLink.targetURL, @"Failed to correctly parse target_url");
+ STAssertTrue([contentLink.actionTypes isEqualToArray:testActionType], @"Failed to correctly parse fb_action_types");
+ STAssertEqualObjects(@"source", contentLink.source, @"Failed to correctly parse fb_source");
+ STAssertTrue([contentLink.ref isEqualToArray:testRef], @"Failed to correctly parse fb_ref");
+ STAssertTrue([contentLink.originalQueryParameters isEqualToDictionary:testOriginalQueryParameters], @"Incorrect originalQueryParameters");
+}
+
+@end
+
+#endif
View
@@ -29,6 +29,7 @@
//#define FBIOSSDK_SKIP_BATCH_REQUEST_TESTS
//#define FBIOSSDK_SKIP_REQUEST_CONNECTION_TESTS
//#define FBIOSSDK_SKIP_TEST_SESSION_TESTS
+//#define FBIOSSDK_SKIP_CONTENT_LINK_TESTS
// Base class for unit-tests that use test users; ensures that all test users
// created by a unit-test are deleted (by invalidating their session) during

0 comments on commit 9bcc3ff

Please sign in to comment.