Skip to content
This repository has been archived by the owner on Oct 27, 2018. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiksaligrama committed Aug 5, 2016
1 parent eff44d0 commit fc123c0
Show file tree
Hide file tree
Showing 27 changed files with 5,462 additions and 37 deletions.
40 changes: 40 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xcuserstate

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
Pods/

Documentation/
builtFramework/
iOSInjectionProject/
464 changes: 464 additions & 0 deletions AWSMobileHubHelper.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions AWSMobileHubHelper.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions AWSMobileHubHelper/AWSMobileHubHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// AWSMobileHubHelper.h
//
// Copyright 2016 Amazon.com, Inc. or its affiliates (Amazon). All Rights Reserved.
//
// Code generated by AWS Mobile Hub. Amazon gives unlimited permission to
// copy, distribute and modify it.
//

#import "AWSContentManager.h"
#import "AWSCloudLogic.h"
#import "AWSIdentityManager.h"
#import "AWSPushManager.h"
#import "AWSFacebookSignInProvider.h"
#import "AWSGoogleSignInProvider.h"
#import "AWSUserFileManager.h"
140 changes: 140 additions & 0 deletions AWSMobileHubHelper/CloudLogic/AWSCloudLogic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
//
// AWSCloudLogic.h
//
//
// Copyright 2016 Amazon.com, Inc. or its affiliates (Amazon). All Rights Reserved.
//
// Code generated by AWS Mobile Hub. Amazon gives unlimited permission to
// copy, distribute and modify it.
//

#import <AWSCore/AWSCore.h>

NS_ASSUME_NONNULL_BEGIN

/**
* Cloud logic helper singleton class that provides convenient interface to invoke
* AWS Lambda functions and handle the results asynchronously.
* Requires the AWSLambda framework of AWSiOSSDK.
*/
@interface AWSCloudLogic : NSObject

/**
Returns the default Cloud Logic singleton instance configured using the information provided in `Info.plist` file.
*Swift*
let cloudLogic = AWSCloudLogic.defaultCloudLogic()
*Objective-C*
AWSCloudLogic *cloudLogic = [AWSCloudLogic defaultCloudLogic];
*/
+ (instancetype)defaultCloudLogic;

/**
Creates a helper client for `AWSCloud` for specified configuration with mentioned key.
Use this method only if you require a helper client with specific configuration.
For example, set the configuration in `- application:didFinishLaunchingWithOptions:`
*Swift*
let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialProvider)
AWSCloudLogic.registercloudLogicWithConfiguration(configuration, forKey: "USWest2cloudLogic")
*Objective-C*
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
identityPoolId:@"YourIdentityPoolId"];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2
credentialsProvider:credentialsProvider];
[AWSCloudLogic registercloudLogicWithConfiguration:configuration
forKey:@"USWest2cloudLogic"];
Then call the following to get the helper client:
*Swift*
let cloudLogic = AWSCloudLogic(forKey: "USWest2cloudLogic")
*Objective-C*
AWSCloudLogic *cloudLogic = [AWSCloudLogic cloudLogicForKey:@"USWest2cloudLogic"];
@warning After calling this method, do not modify the configuration object. It may cause unspecified behaviors.
@param serviceConfiguration AWSServiceConfiguration object for the cloud logic.
@param key A string to identify the helper client.
*/
+ (void)registerCloudLogicWithConfiguration:(AWSServiceConfiguration *)serviceConfiguration
forKey:(NSString *)key;

/**
Retrieves the helper client associated with the key. You need to call `+ registercloudLogicWithConfiguration:` before invoking this method. If `+ registercloudLogicWithConfiguration:` has not been called in advance or the key does not exist, this method returns `nil`.
*Swift*
let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialProvider)
AWSCloudLogic.registercloudLogicWithConfiguration(configuration, forKey: "USWest2cloudLogic")
*Objective-C*
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
identityPoolId:@"YourIdentityPoolId"];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2
credentialsProvider:credentialsProvider];
[AWSCloudLogic registercloudLogicWithConfiguration:configuration
forKey:@"USWest2cloudLogic"];
Then call the following to get the helper client:
*Swift*
let CloudLogic = AWSCloudLogic.CloudLogic(forKey: "USWest2cloudLogic")
*Objective-C*
AWSCloudLogic *CloudLogic = [AWSCloudLogic CloudLogicForKey:@"USWest2cloudLogic"];
@param key A string to identify the helper client.
@return An instance of AWSCloudLogic for specified key.
*/
+ (instancetype)CloudLogicForKey:(NSString *)key NS_SWIFT_NAME(CloudLogic(forKey:));

/**
Removes the helper client associated with the key and release it.
*Swift*
AWSCloudLogic.removecloudLogicForKey("USWest2cloudLogic")
*Objective-C*
[AWSCloudLogic removecloudLogicForKey:@"USWest2cloudLogic"];
@warning Before calling this method, make sure no method is running on this client.
@param key A string to identify the helper client.
*/
+ (void)removeCloudLogicForKey:(NSString *)key;

/**
Invokes the specified AWS Lambda function and passes the results and possible error back to the application asynchronously.
@param name AWS Lambda function name, e.g., hello-world
@param parameters The object from which to generate JSON request data. Can be `nil`.
@param completionBlock handler for results from the function
*/
- (void)invokeFunction:(NSString *)name
withParameters:(nullable id)parameters
completionBlock:(void (^)(id result, NSError *error))completionBlock;

@end

NS_ASSUME_NONNULL_END
117 changes: 117 additions & 0 deletions AWSMobileHubHelper/CloudLogic/AWSCloudLogic.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
//
// AWSCloudLogic.m
//
// Copyright 2016 Amazon.com, Inc. or its affiliates (Amazon). All Rights Reserved.
//
// Code generated by AWS Mobile Hub. Amazon gives unlimited permission to
// copy, distribute and modify it.
//

#import <Foundation/Foundation.h>
#import "AWSCloudLogic.h"
#import <AWSLambda/AWSLambda.h>

@interface AWSCloudLogic ()

@property AWSLambdaInvoker *invoker;

@end

@interface AWSLambdaInvoker()

- (instancetype)initWithConfiguration:(AWSServiceConfiguration *)configuration;

@end

@implementation AWSCloudLogic

static NSString *const AWSInfoClougLogic = @"CloudLogic";
static AWSSynchronizedMutableDictionary *_serviceClients = nil;

+ (instancetype)defaultCloudLogic {
AWSServiceConfiguration *serviceConfiguration = nil;
AWSServiceInfo *serviceInfo = [[AWSInfo defaultAWSInfo] defaultServiceInfo:AWSInfoClougLogic];
if (serviceInfo) {
serviceConfiguration = [[AWSServiceConfiguration alloc] initWithRegion:serviceInfo.region
credentialsProvider:serviceInfo.cognitoCredentialsProvider];
}

if (!serviceConfiguration) {
serviceConfiguration = [AWSServiceManager defaultServiceManager].defaultServiceConfiguration;
}

static AWSCloudLogic *_defaultCloudLogic = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_defaultCloudLogic = [[AWSCloudLogic alloc] initWithConfiguration:serviceConfiguration
key:@"default"];
});

return _defaultCloudLogic;
}

- (instancetype)initWithConfiguration:(AWSServiceConfiguration *)configuration
key:(NSString *)key {
if (self = [super init]) {
_invoker = [[AWSLambdaInvoker alloc] initWithConfiguration:configuration];
}
return self;
}


+ (void)registerCloudLogicWithConfiguration:(AWSServiceConfiguration *)serviceConfiguration
forKey:(NSString *)key {
if ([key isEqualToString:AWSInfoDefault]) {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"The key used for registering this instance is a reserved key. Please use some other key to register the instance."
userInfo:nil];
}
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_serviceClients = [AWSSynchronizedMutableDictionary new];
});

[_serviceClients setObject:[[AWSCloudLogic alloc] initWithConfiguration:serviceConfiguration
key:key]
forKey:key];

}

+ (instancetype)CloudLogicForKey:(NSString *)key {
@synchronized(self) {
AWSCloudLogic *serviceClient = [_serviceClients objectForKey:key];
if (serviceClient) {
return serviceClient;
}

AWSServiceInfo *serviceInfo = [[AWSInfo defaultAWSInfo] serviceInfo:AWSInfoClougLogic
forKey:key];
if (serviceInfo) {
AWSServiceConfiguration *serviceConfiguration = [[AWSServiceConfiguration alloc] initWithRegion:serviceInfo.region
credentialsProvider:serviceInfo.cognitoCredentialsProvider];
[AWSCloudLogic registerCloudLogicWithConfiguration:serviceConfiguration
forKey:key];
}

return [_serviceClients objectForKey:key];
}
}

+ (void)removeCloudLogicForKey:(NSString *)key {
[_serviceClients removeObjectForKey:key];
}

- (void)invokeFunction:(NSString *)name
withParameters:(id)parameters
completionBlock:(void (^)(id result, NSError *error))completionBlock {
AWSLogDebug(@"invokeFunction: Function Name: %@", name);
[_invoker invokeFunction:name
JSONObject:parameters
completionHandler:^(id _Nullable response, NSError * _Nullable error) {
if (completionBlock) {
completionBlock(response, error);
}
}];
}

@end
Loading

0 comments on commit fc123c0

Please sign in to comment.