Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
committed
May 31, 2012
1 parent
679ba31
commit 9bcc3ff
Showing
6 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters