From 6d983140454eef3bf6cc3865c8d995f53488fb01 Mon Sep 17 00:00:00 2001 From: Jacob von Eyben Date: Mon, 16 Dec 2013 21:30:09 +0100 Subject: [PATCH] Corrected example code --- Example/IOSLinkedInAPI-Example/.gitignore | 1 - .../IOSLinkedInAPI-Example-Info.plist | 70 +++++---- .../IOSLinkedInAPI-Example-Prefix.pch | 12 +- .../AppIcon.appiconset/Contents.json | 53 +++++++ .../LaunchImage.launchimage/Contents.json | 51 ++++++ .../IOSLinkedInAPI-Example/LIAAppDelegate.h | 5 +- .../IOSLinkedInAPI-Example/LIAAppDelegate.m | 47 +----- .../LIALinkedInExampleViewController.h | 26 +++ .../LIALinkedInExampleViewController.m | 90 +++++++++++ .../en.lproj/InfoPlist.strings | 1 + .../IOSLinkedInAPI-Example/main.m | 2 - .../IOSLinkedInAPI-ExampleTests-Info.plist | 22 +++ .../IOSLinkedInAPI_ExampleTests.m | 34 ++++ .../en.lproj/InfoPlist.strings | 2 + Example/IOSLinkedInAPI-Example/Podfile | 4 +- Example/IOSLinkedInAPI-Example/Podfile.lock | 27 ++++ IOSLinkedInAPI/LIALinkedInAuthorization.xib | 3 +- .../LIALinkedInAuthorizationViewController.m | 8 - IOSLinkedInAPI/LIALinkedInHttpClient.h | 2 + IOSLinkedInAPI/LIALinkedInHttpClient.m | 148 +++++++++--------- 20 files changed, 440 insertions(+), 168 deletions(-) create mode 100644 Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/Images.xcassets/LaunchImage.launchimage/Contents.json create mode 100644 Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/LIALinkedInExampleViewController.h create mode 100644 Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/LIALinkedInExampleViewController.m create mode 100644 Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-ExampleTests/IOSLinkedInAPI-ExampleTests-Info.plist create mode 100644 Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-ExampleTests/IOSLinkedInAPI_ExampleTests.m create mode 100644 Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-ExampleTests/en.lproj/InfoPlist.strings create mode 100644 Example/IOSLinkedInAPI-Example/Podfile.lock diff --git a/Example/IOSLinkedInAPI-Example/.gitignore b/Example/IOSLinkedInAPI-Example/.gitignore index b5cd541..bb1a5dd 100644 --- a/Example/IOSLinkedInAPI-Example/.gitignore +++ b/Example/IOSLinkedInAPI-Example/.gitignore @@ -1,3 +1,2 @@ Pods/ -Podfile.lock IOSLinkedInAPI-Example/LIALinkedInClientExampleCredentials.h diff --git a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example-Info.plist b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example-Info.plist index 9c48a92..32c703b 100644 --- a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example-Info.plist +++ b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example-Info.plist @@ -6,36 +6,42 @@ CFBundleIdentifier com.ancientprogramming.${PRODUCT_NAME:rfc1034identifier} - CFBundleDevelopmentRegion - en - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - ${PRODUCT_NAME} - CFBundlePackageType - APPL - CFBundleSignature - ???? - - CFBundleDisplayName - ${PRODUCT_NAME} - CFBundleVersion - 1.0 - CFBundleShortVersionString - 1.0 - LSRequiresIPhoneOS - - UIRequiredDeviceCapabilities - - armv7 - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - + CFBundleDevelopmentRegion + en + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + - \ No newline at end of file + diff --git a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example-Prefix.pch b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example-Prefix.pch index 6f5698c..743435c 100644 --- a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example-Prefix.pch +++ b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example-Prefix.pch @@ -1,16 +1,16 @@ // -// Prefix header for all source files of the 'IOSLinkedInAPI-Example' target in the 'IOSLinkedInAPI-Example' project +// Prefix header +// +// The contents of this file are implicitly included at the beginning of every source file. // #import -#ifndef __IPHONE_4_0 -#warning "This project uses features only available in iOS SDK 4.0 and later." +#ifndef __IPHONE_3_0 +#warning "This project uses features only available in iOS SDK 3.0 and later." #endif #ifdef __OBJC__ #import - #import - -#endif \ No newline at end of file +#endif diff --git a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/Images.xcassets/AppIcon.appiconset/Contents.json b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..91bf9c1 --- /dev/null +++ b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,53 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/Images.xcassets/LaunchImage.launchimage/Contents.json b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/Images.xcassets/LaunchImage.launchimage/Contents.json new file mode 100644 index 0000000..6f870a4 --- /dev/null +++ b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/Images.xcassets/LaunchImage.launchimage/Contents.json @@ -0,0 +1,51 @@ +{ + "images" : [ + { + "orientation" : "portrait", + "idiom" : "iphone", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "2x" + }, + { + "orientation" : "portrait", + "idiom" : "iphone", + "subtype" : "retina4", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "2x" + }, + { + "orientation" : "portrait", + "idiom" : "ipad", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "1x" + }, + { + "orientation" : "landscape", + "idiom" : "ipad", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "1x" + }, + { + "orientation" : "portrait", + "idiom" : "ipad", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "2x" + }, + { + "orientation" : "landscape", + "idiom" : "ipad", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/LIAAppDelegate.h b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/LIAAppDelegate.h index bb649fd..bbb958d 100644 --- a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/LIAAppDelegate.h +++ b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/LIAAppDelegate.h @@ -7,13 +7,14 @@ // #import +#import "LIALinkedInExampleViewController.h" + -@class LIAViewController; @interface LIAAppDelegate : UIResponder @property (strong, nonatomic) UIWindow *window; -@property (strong, nonatomic) LIAViewController *viewController; +@property (strong, nonatomic) LIALinkedInExampleViewController *viewController; @end \ No newline at end of file diff --git a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/LIAAppDelegate.m b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/LIAAppDelegate.m index 6542dcc..d282fae 100644 --- a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/LIAAppDelegate.m +++ b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/LIAAppDelegate.m @@ -8,50 +8,17 @@ #import "LIAAppDelegate.h" -#import "LIAViewController.h" - @implementation LIAAppDelegate -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions -{ - self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - // Override point for customization after application launch. - self.viewController = [[LIAViewController alloc] init]; - self.window.rootViewController = self.viewController; - [self.window makeKeyAndVisible]; - return YES; -} - -- (void)applicationWillResignActive:(UIApplication *)application -{ - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. - -} - -- (void)applicationDidEnterBackground:(UIApplication *)application -{ - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. - -} - -- (void)applicationWillEnterForeground:(UIApplication *)application -{ - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. - -} - -- (void)applicationDidBecomeActive:(UIApplication *)application -{ - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. - -} +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + // Override point for customization after application launch. -- (void)applicationWillTerminate:(UIApplication *)application -{ - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + self.viewController = [[LIALinkedInExampleViewController alloc] init]; + self.window.rootViewController = self.viewController; + [self.window makeKeyAndVisible]; + return YES; } @end \ No newline at end of file diff --git a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/LIALinkedInExampleViewController.h b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/LIALinkedInExampleViewController.h new file mode 100644 index 0000000..674f8d2 --- /dev/null +++ b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/LIALinkedInExampleViewController.h @@ -0,0 +1,26 @@ +// LIALinkedInApplication.h +// +// Copyright (c) 2013 Ancientprogramming +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +#import + + +@interface LIALinkedInExampleViewController : UIViewController +@end \ No newline at end of file diff --git a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/LIALinkedInExampleViewController.m b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/LIALinkedInExampleViewController.m new file mode 100644 index 0000000..a0d73bf --- /dev/null +++ b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/LIALinkedInExampleViewController.m @@ -0,0 +1,90 @@ +// LIALinkedInApplication.h +// +// Copyright (c) 2013 Ancientprogramming +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +#import "LIALinkedInExampleViewController.h" +#import "LIALinkedInApplication.h" +#import "LIALinkedInHttpClient.h" +#import "LIALinkedInClientExampleCredentials.h" + + +@implementation LIALinkedInExampleViewController { + UIButton *_requestLinkedInTokenButton; + LIALinkedInHttpClient *_client; + +} + +- (void)viewDidLoad { + [super viewDidLoad]; + _client = [self client]; + self.view.backgroundColor = [UIColor whiteColor]; + _requestLinkedInTokenButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; + [_requestLinkedInTokenButton setTitle:@"Request token" forState:UIControlStateNormal]; + _requestLinkedInTokenButton.frame = CGRectMake(0, 0, 200, 44); + _requestLinkedInTokenButton.center = self.view.center; + [self.view addSubview:_requestLinkedInTokenButton]; + [_requestLinkedInTokenButton addTarget:self action:@selector(didRequestAuthToken) forControlEvents:UIControlEventTouchUpInside]; +} + +- (void)viewWillLayoutSubviews { + [super viewWillLayoutSubviews]; + _requestLinkedInTokenButton.center = self.view.center; +} + + +- (void)didRequestAuthToken { + +// if ([_client validToken]) { +// [self requestMeWithToken:[_client accessToken]]; +// } else { + [_client getAuthorizationCode:^(NSString *code) { + [self.client getAccessToken:code success:^(NSDictionary *accessTokenData) { + NSString *accessToken = [accessTokenData objectForKey:@"access_token"]; + [self requestMeWithToken:accessToken]; + } failure:^(NSError *error) { + NSLog(@"Quering accessToken failed %@", error); + }]; + } cancel:^{ + NSLog(@"Authorization was cancelled by user"); + } failure:^(NSError *error) { + NSLog(@"Authorization failed %@", error); + }]; +// } +} + +- (void)requestMeWithToken:(NSString *)accessToken { + [self.client GET:[NSString stringWithFormat:@"https://api.linkedin.com/v1/people/~?oauth2_access_token=%@&format=json", accessToken] parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *result) { + NSLog(@"current user %@", result); + } failure:^(AFHTTPRequestOperation *operation, NSError *error) { + NSLog(@"failed to fetch current user %@", error); + }]; +} + +- (LIALinkedInHttpClient *)client { + LIALinkedInApplication *application = [LIALinkedInApplication applicationWithRedirectURL:@"http://www.ancientprogramming.com/liaexample" + clientId:LINKEDIN_CLIENT_ID + clientSecret:LINKEDIN_CLIENT_SECRET + state:@"DCEEFWF45453sdffef424" + grantedAccess:@[@"r_fullprofile", @"r_network"]]; + return [LIALinkedInHttpClient clientForApplication:application presentingViewController:nil]; +} + + +@end \ No newline at end of file diff --git a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/en.lproj/InfoPlist.strings b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/en.lproj/InfoPlist.strings index b92732c..477b28f 100644 --- a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/en.lproj/InfoPlist.strings +++ b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/en.lproj/InfoPlist.strings @@ -1 +1,2 @@ /* Localized versions of Info.plist keys */ + diff --git a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/main.m b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/main.m index 0600d0e..8ec6dce 100644 --- a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/main.m +++ b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-Example/main.m @@ -6,7 +6,6 @@ // Copyright (c) 2013 Ancientprogramming. All rights reserved. // -#import #import "LIAAppDelegate.h" @@ -15,5 +14,4 @@ int main(int argc, char *argv[]) @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([LIAAppDelegate class])); } - } \ No newline at end of file diff --git a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-ExampleTests/IOSLinkedInAPI-ExampleTests-Info.plist b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-ExampleTests/IOSLinkedInAPI-ExampleTests-Info.plist new file mode 100644 index 0000000..61fe3b3 --- /dev/null +++ b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-ExampleTests/IOSLinkedInAPI-ExampleTests-Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + com.eybenconsult.linkedin.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-ExampleTests/IOSLinkedInAPI_ExampleTests.m b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-ExampleTests/IOSLinkedInAPI_ExampleTests.m new file mode 100644 index 0000000..eb7c1c6 --- /dev/null +++ b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-ExampleTests/IOSLinkedInAPI_ExampleTests.m @@ -0,0 +1,34 @@ +// +// IOSLinkedInAPI_ExampleTests.m +// IOSLinkedInAPI-ExampleTests +// +// Created by Jacob von Eyben on 05/12/13. +// Copyright (c) 2013 Eyben Consult ApS. All rights reserved. +// + +#import + +@interface IOSLinkedInAPI_ExampleTests : XCTestCase + +@end + +@implementation IOSLinkedInAPI_ExampleTests + +- (void)setUp +{ + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown +{ + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testExample +{ + XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); +} + +@end diff --git a/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-ExampleTests/en.lproj/InfoPlist.strings b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-ExampleTests/en.lproj/InfoPlist.strings new file mode 100644 index 0000000..477b28f --- /dev/null +++ b/Example/IOSLinkedInAPI-Example/IOSLinkedInAPI-ExampleTests/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/Example/IOSLinkedInAPI-Example/Podfile b/Example/IOSLinkedInAPI-Example/Podfile index c8e05a7..c2cf3c6 100644 --- a/Example/IOSLinkedInAPI-Example/Podfile +++ b/Example/IOSLinkedInAPI-Example/Podfile @@ -1,2 +1,2 @@ -platform :ios, '5.0' -pod 'AFNetworking', '~> 1.2.1' +platform :ios, '6.0' +pod 'AFNetworking', '~> 2.0.3' diff --git a/Example/IOSLinkedInAPI-Example/Podfile.lock b/Example/IOSLinkedInAPI-Example/Podfile.lock new file mode 100644 index 0000000..1ab5926 --- /dev/null +++ b/Example/IOSLinkedInAPI-Example/Podfile.lock @@ -0,0 +1,27 @@ +PODS: + - AFNetworking (2.0.3): + - AFNetworking/NSURLConnection + - AFNetworking/NSURLSession + - AFNetworking/Reachability + - AFNetworking/Security + - AFNetworking/Serialization + - AFNetworking/UIKit + - AFNetworking/NSURLConnection (2.0.3): + - AFNetworking/Reachability + - AFNetworking/Security + - AFNetworking/Serialization + - AFNetworking/NSURLSession (2.0.3): + - AFNetworking/NSURLConnection + - AFNetworking/Reachability (2.0.3) + - AFNetworking/Security (2.0.3) + - AFNetworking/Serialization (2.0.3) + - AFNetworking/UIKit (2.0.3): + - AFNetworking/NSURLConnection + +DEPENDENCIES: + - AFNetworking (~> 2.0.3) + +SPEC CHECKSUMS: + AFNetworking: e499052cbf3d743e9bb727bb37adb9dc2547ba15 + +COCOAPODS: 0.27.1 diff --git a/IOSLinkedInAPI/LIALinkedInAuthorization.xib b/IOSLinkedInAPI/LIALinkedInAuthorization.xib index a7ba515..3d90ffa 100644 --- a/IOSLinkedInAPI/LIALinkedInAuthorization.xib +++ b/IOSLinkedInAPI/LIALinkedInAuthorization.xib @@ -1,7 +1,6 @@ - + - diff --git a/IOSLinkedInAPI/LIALinkedInAuthorizationViewController.m b/IOSLinkedInAPI/LIALinkedInAuthorizationViewController.m index 8f59d56..91516a0 100644 --- a/IOSLinkedInAPI/LIALinkedInAuthorizationViewController.m +++ b/IOSLinkedInAPI/LIALinkedInAuthorizationViewController.m @@ -45,14 +45,6 @@ @implementation LIALinkedInAuthorizationViewController BOOL handlingRedirectURL; -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { - self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; - if (self) { - // Custom initialization - } - return self; -} - - (id)initWithApplication:(LIALinkedInApplication *)application success:(LIAAuthorizationCodeSuccessCallback)success cancel:(LIAAuthorizationCodeCancelCallback)cancel failure:(LIAAuthorizationCodeFailureCallback)failure { self = [super init]; if (self) { diff --git a/IOSLinkedInAPI/LIALinkedInHttpClient.h b/IOSLinkedInAPI/LIALinkedInHttpClient.h index 1b1e71e..5c31dc1 100755 --- a/IOSLinkedInAPI/LIALinkedInHttpClient.h +++ b/IOSLinkedInAPI/LIALinkedInHttpClient.h @@ -32,6 +32,8 @@ - (BOOL)validToken; +- (NSString *)accessToken; + - (void)getAccessToken:(NSString *)authorizationCode success:(void (^)(NSDictionary *))success failure:(void (^)(NSError *))failure; - (void)getAuthorizationCode:(void (^)(NSString *))success cancel:(void (^)(void))cancel failure:(void (^)(NSError *))failure; diff --git a/IOSLinkedInAPI/LIALinkedInHttpClient.m b/IOSLinkedInAPI/LIALinkedInHttpClient.m index 8b36dfe..576c816 100755 --- a/IOSLinkedInAPI/LIALinkedInHttpClient.m +++ b/IOSLinkedInAPI/LIALinkedInHttpClient.m @@ -20,7 +20,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. #import "LIALinkedInHttpClient.h" -#import #import "LIALinkedInAuthorizationViewController.h" #import "NSString+LIAEncode.h" @@ -36,99 +35,102 @@ @interface LIALinkedInHttpClient () @implementation LIALinkedInHttpClient + (LIALinkedInHttpClient *)clientForApplication:(LIALinkedInApplication *)application { - return [self clientForApplication:application presentingViewController:nil]; + return [self clientForApplication:application presentingViewController:nil]; } + (LIALinkedInHttpClient *)clientForApplication:(LIALinkedInApplication *)application presentingViewController:viewController { - LIALinkedInHttpClient *client = [[self alloc] initWithBaseURL:[NSURL URLWithString:@"https://www.linkedin.com"]]; - client.application = application; - client.presentingViewController = viewController; - return client; + LIALinkedInHttpClient *client = [[self alloc] initWithBaseURL:[NSURL URLWithString:@"https://www.linkedin.com"]]; + client.application = application; + client.presentingViewController = viewController; + return client; } - (id)initWithBaseURL:(NSURL *)url { - self = [super initWithBaseURL:url]; - if (self) { - [self setResponseSerializer:[AFJSONResponseSerializer serializer]]; - } - return self; + self = [super initWithBaseURL:url]; + if (self) { + [self setResponseSerializer:[AFJSONResponseSerializer serializer]]; + } + return self; } -- (BOOL)validToken -{ - NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; - - if ([[NSDate date] timeIntervalSince1970] >= ([userDefaults doubleForKey:LINKEDIN_CREATION_KEY] + [userDefaults doubleForKey:LINKEDIN_EXPIRATION_KEY])) { - return NO; - } - else { - return YES; - } +- (BOOL)validToken { + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + + if ([[NSDate date] timeIntervalSince1970] >= ([userDefaults doubleForKey:LINKEDIN_CREATION_KEY] + [userDefaults doubleForKey:LINKEDIN_EXPIRATION_KEY])) { + return NO; + } + else { + return YES; + } +} + +- (NSString *)accessToken { + return [[NSUserDefaults standardUserDefaults] objectForKey:LINKEDIN_TOKEN_KEY]; } - (void)getAccessToken:(NSString *)authorizationCode success:(void (^)(NSDictionary *))success failure:(void (^)(NSError *))failure { - NSString *accessTokenUrl = @"/uas/oauth2/accessToken?grant_type=authorization_code&code=%@&redirect_uri=%@&client_id=%@&client_secret=%@"; - NSString *url = [NSString stringWithFormat:accessTokenUrl, authorizationCode, [self.application.redirectURL LIAEncode], self.application.clientId, self.application.clientSecret]; - - [self POST:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { - NSString *accessToken = [responseObject objectForKey:@"access_token"]; - NSTimeInterval expiration = [[responseObject objectForKey:@"expires_in"] doubleValue]; - - // store credentials - NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; - - [userDefaults setObject:accessToken forKey:LINKEDIN_TOKEN_KEY]; - [userDefaults setDouble:expiration forKey:LINKEDIN_EXPIRATION_KEY]; - [userDefaults setDouble:[[NSDate date] timeIntervalSince1970] forKey:LINKEDIN_CREATION_KEY]; - [userDefaults synchronize]; - - success(responseObject); - } failure:^(AFHTTPRequestOperation *operation, NSError *error) { - failure(error); - }]; - + NSString *accessTokenUrl = @"/uas/oauth2/accessToken?grant_type=authorization_code&code=%@&redirect_uri=%@&client_id=%@&client_secret=%@"; + NSString *url = [NSString stringWithFormat:accessTokenUrl, authorizationCode, [self.application.redirectURL LIAEncode], self.application.clientId, self.application.clientSecret]; + + [self POST:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { + NSString *accessToken = [responseObject objectForKey:@"access_token"]; + NSTimeInterval expiration = [[responseObject objectForKey:@"expires_in"] doubleValue]; + + // store credentials + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + + [userDefaults setObject:accessToken forKey:LINKEDIN_TOKEN_KEY]; + [userDefaults setDouble:expiration forKey:LINKEDIN_EXPIRATION_KEY]; + [userDefaults setDouble:[[NSDate date] timeIntervalSince1970] forKey:LINKEDIN_CREATION_KEY]; + [userDefaults synchronize]; + + success(responseObject); + } failure:^(AFHTTPRequestOperation *operation, NSError *error) { + failure(error); + }]; + } - (void)getAuthorizationCode:(void (^)(NSString *))success cancel:(void (^)(void))cancel failure:(void (^)(NSError *))failure { - LIALinkedInAuthorizationViewController *authorizationViewController = [[LIALinkedInAuthorizationViewController alloc] - initWithApplication: - self.application - success:^(NSString *code) { - [self hideAuthenticateView]; - if (success) { - success(code); - } - } - cancel:^{ - [self hideAuthenticateView]; - if (cancel) { - cancel(); - } - } failure:^(NSError *error) { - [self hideAuthenticateView]; - if (failure) { - failure(error); - } - }]; - [self showAuthorizationView:authorizationViewController]; + LIALinkedInAuthorizationViewController *authorizationViewController = [[LIALinkedInAuthorizationViewController alloc] + initWithApplication: + self.application + success:^(NSString *code) { + [self hideAuthenticateView]; + if (success) { + success(code); + } + } + cancel:^{ + [self hideAuthenticateView]; + if (cancel) { + cancel(); + } + } failure:^(NSError *error) { + [self hideAuthenticateView]; + if (failure) { + failure(error); + } + }]; + [self showAuthorizationView:authorizationViewController]; } - (void)showAuthorizationView:(LIALinkedInAuthorizationViewController *)authorizationViewController { - if (self.presentingViewController == nil) - self.presentingViewController = [[UIApplication sharedApplication] keyWindow].rootViewController; - - UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:authorizationViewController]; - - if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { - nc.modalPresentationStyle = UIModalPresentationFormSheet; - } - - [self.presentingViewController presentViewController:nc animated:YES completion:nil]; + if (self.presentingViewController == nil) + self.presentingViewController = [[UIApplication sharedApplication] keyWindow].rootViewController; + + UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:authorizationViewController]; + + if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { + nc.modalPresentationStyle = UIModalPresentationFormSheet; + } + + [self.presentingViewController presentViewController:nc animated:YES completion:nil]; } - (void)hideAuthenticateView { - [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; + [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; }