http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/ios/UGAPI/v2/UGConnection.h ---------------------------------------------------------------------- diff --git a/sdks/ios/UGAPI/v2/UGConnection.h b/sdks/ios/UGAPI/v2/UGConnection.h deleted file mode 100644 index d44c8e9..0000000 --- a/sdks/ios/UGAPI/v2/UGConnection.h +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -// -// UGConnection.h -// UGAPIApp -// -// Created by Tim Burks on 3/30/13. -// -// -#import <Foundation/Foundation.h> - -@class UGHTTPResult; - -@interface UGConnection : NSObject - -// These three properties tie a UGConnection to a specific application instance -@property (nonatomic, strong) NSString *server; -@property (nonatomic, strong) NSString *organization; -@property (nonatomic, strong) NSString *application; - -// As a convenience, a sharedConnection object is available, -// but any number of UGConnection objects may be created and separately configured. -+ (UGConnection *) sharedConnection; - -// Query helper: construct query dictionary from arguments -- (NSMutableDictionary *) queryWithString:(NSString *) queryString - limit:(int) limit - startUUID:(NSString *) startUUID - cursor:(NSString *) cursor - reversed:(BOOL) reversed; - -// Authentication helper: call this method with the result of a getAccessToken request. -- (BOOL) authenticateWithResult:(UGHTTPResult *) result; - -// Authentication helper: use this to confirm that a connection has a usable access token. -- (BOOL) isAuthenticated; - -// -// Usergrid API methods -// -// The following calls return NSMutableURLRequest objects that can be used to make Usergrid API calls. -// We recommend (but do not require) that they be made with instances of the UGHTTPClient class. -// -// The goal here is to directly expose the complete Usergrid API. -// -// This follows http://apigee.com/docs/usergrid/content/app-services-resources -// - -// Access tokens http://apigee.com/docs/usergrid/content/accesstoken - -- (NSMutableURLRequest *) getAccessTokenForAdminWithUsername:(NSString *) username - password:(NSString *) password; - -- (NSMutableURLRequest *) getAccessTokenForOrganizationWithClientID:(NSString *) clientID - clientSecret:(NSString *) clientSecret; - -- (NSMutableURLRequest *) getAccessTokenForApplicationWithUsername:(NSString *) username - password:(NSString *) password; - -- (NSMutableURLRequest *) getAccessTokenForApplicationWithClientID:(NSString *) clientID - clientSecret:(NSString *) clientSecret; - -// Admin users http://apigee.com/docs/usergrid/content/admin-user - -- (NSMutableURLRequest *) createAdminUserWithValues:(NSDictionary *) values; - -- (NSMutableURLRequest *) updateAdminUser:(NSString *) adminUserIdentifier - withValues:(NSDictionary *) values; - -- (NSMutableURLRequest *) getAdminUser:(NSString *) adminUserIdentifier; - -- (NSMutableURLRequest *) setPasswordForAdminUser:(NSString *) adminUserIdentifier - toValue:(NSString *) password; - -- (NSMutableURLRequest *) initiatePasswordResetForAdminUser; - -- (NSMutableURLRequest *) completePasswordResetForAdminUserWithValues:(NSDictionary *) values; - -- (NSMutableURLRequest *) activateAdminUser:(NSString *) adminUserIdentifier - withToken:(NSString *) token - sendingConfirmationEmail:(BOOL) sendingConfirmationEmail; - -- (NSMutableURLRequest *) reactivateAdminUser:(NSString *) adminUserIdentifier; - -- (NSMutableURLRequest *) getActivityFeedForAdminUser:(NSString *) adminUserIdentifier; - -// Client authorization http://apigee.com/docs/usergrid/content/client-authorization - -- (NSMutableURLRequest *) authorizeClient:(NSString *) clientIdentifier withResponseType:(NSString *) responseType; - -// Organizations and Applications http://apigee.com/docs/usergrid/content/organization - -- (NSMutableURLRequest *) createOrganizationWithValues:(NSDictionary *) values; - -- (NSMutableURLRequest *) getOrganization:(NSString *) organizationIdentifier; - -- (NSMutableURLRequest *) activateOrganization:(NSString *) organizationIdentifier - withToken:(NSString *) token - sendingConfirmationEmail:(BOOL) sendingConfirmationEmail; - -- (NSMutableURLRequest *) reactivateOrganization:(NSString *) organizationIdentifier; - -- (NSMutableURLRequest *) generateClientCredentialsForOrganization:(NSString *) organizationIdentifier; - -- (NSMutableURLRequest *) getClientCredentialsForOrganization:(NSString *) organizationIdentifier; - -- (NSMutableURLRequest *) getActivityFeedForOrganization:(NSString *) organizationIdentifier; - -- (NSMutableURLRequest *) createApplicationInOrganization:(NSString *) organizationIdentifier - withValues:(NSDictionary *) values; - -- (NSMutableURLRequest *) deleteApplication:(NSString *) applicationIdentifier - inOrganization:(NSString *) organizationIdentifier; - -- (NSMutableURLRequest *) generateClientCredentialsForApplication:(NSString *) applicationIdentifier - inOrganization:(NSString *) organizationIdentifier; - -- (NSMutableURLRequest *) getClientCredentialsForApplication:(NSString *) applicationIdentifier - inOrganization:(NSString *) organizationIdentifier; - -- (NSMutableURLRequest *) getApplicationsInOrganization:(NSString *) organizationIdentifier; - -- (NSMutableURLRequest *) addAdminUser:(NSString *) adminUserIdentifier - toOrganization:(NSString *) organizationIdentifier; - -- (NSMutableURLRequest *) getAdminUsersInOrganization:(NSString *) organizationIdentifier; - -- (NSMutableURLRequest *) removeAdminUser:(NSString *) adminUserIdentifier - fromOrganization:(NSString *) organizationIdentifier; - -- (NSMutableURLRequest *) getApplication:(NSString *) applicationIdentifier - inOrganization:(NSString *) organizationIdentifier; - -// Activity http://apigee.com/docs/usergrid/content/activity - -- (NSMutableURLRequest *) createActivityForUser:(NSString *) userIdentifier - withValues:(NSDictionary *) values; - -- (NSMutableURLRequest *) createActivityForGroup:(NSString *) groupIdentifier - withValues:(NSDictionary *) values; - -- (NSMutableURLRequest *) createActivityForFollowersOfUser:(NSString *) userIdentifier - inGroup:(NSString *) groupIdentifier - withValues:(NSDictionary *) values; - -- (NSMutableURLRequest *) getActivitiesForUser:(NSString *) userIdentifier; - -- (NSMutableURLRequest *) getActivitiesForGroup:(NSString *) groupIdentifier; - -- (NSMutableURLRequest *) getActivityFeedForUser:(NSString *) userIdentifier; - -- (NSMutableURLRequest *) getActivityFeedForGroup:(NSString *) groupIdentifier; - -// Assets - -- (NSMutableURLRequest *) getDataForAsset:(NSString *) assetIdentifier; - -- (NSMutableURLRequest *) postData:(NSData *) data - forAsset:(NSString *) assetIdentifier; - -// Collections (aka General-purpose endpoints) http://apigee.com/docs/usergrid/content/general-purpose-endpoints - -- (NSMutableURLRequest *) createEntityInCollection:(NSString *) collection - withValues:(NSDictionary *) values; - -- (NSMutableURLRequest *) getEntity:(NSString *) entityIdentifier - inCollection:(NSString *) collection; - -- (NSMutableURLRequest *) updateEntity:(NSString *) entityIdentifier - inCollection:(NSString *) collection - withValues:(NSDictionary *) values; - -- (NSMutableURLRequest *) deleteEntity:(NSString *) entityIdentifier - inCollection:(NSString *) collection; - -- (NSMutableURLRequest *) getEntitiesInCollection:(NSString *) collection - limit:(int) limit; - -- (NSMutableURLRequest *) getEntitiesInCollection:(NSString *) collection - usingQuery:(NSDictionary *) query; - -- (NSMutableURLRequest *) updateEntitiesInCollection:(NSString *) collection - usingQuery:(NSDictionary *) query - withValues:(NSDictionary *) values; - -- (NSMutableURLRequest *) deleteEntitiesInCollection:(NSString *) collection; - -- (NSMutableURLRequest *) deleteEntitiesInCollection:(NSString *) collection - usingQuery:(NSDictionary *) query; - - -// Devices http://apigee.com/docs/usergrid/content/device - -// there are no device-specific methods - -// Events and Counters http://apigee.com/docs/usergrid/content/events-and-counters - -- (NSMutableURLRequest *) createEventWithValues:(NSDictionary *) values; - -// Groups http://apigee.com/docs/usergrid/content/group - -- (NSMutableURLRequest *) createGroupWithValues:(NSDictionary *) values; - -- (NSMutableURLRequest *) addUser:(NSString *) userIdentifier - toGroup:(NSString *) groupIdentifier; - -- (NSMutableURLRequest *) getGroup:(NSString *) groupIdentifier; - -- (NSMutableURLRequest *) updateGroup:(NSString *) groupIdentifier - withValues:(NSDictionary *) values; - -- (NSMutableURLRequest *) deleteUser:(NSString *) userIdentifier - fromGroup:(NSString *) groupIdentifier; - -- (NSMutableURLRequest *) deleteGroup:(NSString *) groupIdentifier; - -- (NSMutableURLRequest *) getUsersInGroup:(NSString *) groupIdentifier; - -// Roles http://apigee.com/docs/usergrid/content/role - -- (NSMutableURLRequest *) createRoleWithValues:(NSDictionary *) values; - -- (NSMutableURLRequest *) getRoles; - -- (NSMutableURLRequest *) deleteRole:(NSString *) roleName; - -- (NSMutableURLRequest *) getPermissionsForRole:(NSString *) roleName; - -- (NSMutableURLRequest *) addPermissionsToRole:(NSString *) roleName - withValues:(NSDictionary *) values; - -- (NSMutableURLRequest *) deletePermissionsFromRole:(NSString *) roleName - usingPattern:(NSString *) pattern; - -- (NSMutableURLRequest *) addUser:(NSString *)userIdentifier - toRole:(NSString *)roleName; - -- (NSMutableURLRequest *) getUsersInRole:(NSString *) roleName; - -- (NSMutableURLRequest *) deleteUser:(NSString *) userIdentifier - fromRole:(NSString *) roleName; - -// Users http://apigee.com/docs/usergrid/content/user - -- (NSMutableURLRequest *) createUserWithValues:(NSDictionary *) values; - -- (NSMutableURLRequest *) setPasswordForUser:(NSString *) username - toPassword:(NSString *) newPassword - fromPassword:(NSString *) oldPassword; - -- (NSMutableURLRequest *) getUser:(NSString *) username; - -- (NSMutableURLRequest *) updateUser:(NSString *) username - withValues:(NSDictionary *) values; - -- (NSMutableURLRequest *) deleteUser:(NSString *) username; - -- (NSMutableURLRequest *) getUsersUsingQuery:(NSDictionary *) query; - -- (NSMutableURLRequest *) connectEntity:(NSString *) entity1 - inCollection:(NSString *) collection - toEntity:(NSString *) entity2 - throughRelationship:(NSString *) relationship; - -- (NSMutableURLRequest *) disconnectEntity:(NSString *) entity1 - inCollection:(NSString *) collection - fromEntity:(NSString *) entity2 - throughRelationship:(NSString *) relationship; - -- (NSMutableURLRequest *) getConnectionsToEntity:(NSString *) entity - inCollection:(NSString *) collection - throughRelationship:(NSString *) relationship - usingQuery:(NSDictionary *) query; - -@end
http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/ios/UGAPI/v2/UGConnection.m ---------------------------------------------------------------------- diff --git a/sdks/ios/UGAPI/v2/UGConnection.m b/sdks/ios/UGAPI/v2/UGConnection.m deleted file mode 100644 index 48840b3..0000000 --- a/sdks/ios/UGAPI/v2/UGConnection.m +++ /dev/null @@ -1,938 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -// -// UGConnection.m -// UGAPIApp -// -// Created by Tim Burks on 3/30/13. -// -// -#import "UGHTTPHelpers.h" -#import "UGHTTPResult.h" -#import "UGConnection.h" - -static NSString *boolean_representation(BOOL value) -{ - return (value ? @"true" : @"false"); -} - -@interface UGConnection () -@property (nonatomic, strong) NSString *token; -@property (nonatomic, strong) NSDate *tokenExpirationDate; -@end - -@implementation UGConnection - -+ (UGConnection *) sharedConnection -{ - static UGConnection *connection = nil; - if (!connection) { - connection = [[UGConnection alloc] init]; - } - return connection; -} - -- (id) init { - if (self = [super init]) { - self.server = @"http://api.usergrid.com"; - } - return self; -} - -- (UGConnection *) copy -{ - UGConnection *copy = [super copy]; - copy.server = self.server; - copy.organization = self.organization; - copy.application = self.application; - copy.token = self.token; - copy.tokenExpirationDate = self.tokenExpirationDate; - return copy; -} - -#pragma mark - Internal helpers - - -- (NSString *) root -{ - return [NSString stringWithFormat:@"%@/%@/%@", self.server, self.organization, self.application]; -} - -- (NSMutableURLRequest *) authorizedRequestWithMethod:(NSString *) method - path:(NSString *) path - body:(NSData *) body -{ - NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]]; - [request setHTTPMethod:method]; - if (body) { - [request setHTTPBody:body]; - } - if (self.token) { - [request setValue:[NSString stringWithFormat:@"Bearer %@", self.token] forHTTPHeaderField:@"Authorization"]; - } - return request; -} - -#pragma mark - External helpers - - -#pragma mark Queries - -- (NSMutableDictionary *) queryWithString:(NSString *) queryString - limit:(int) limit - startUUID:(NSString *) startUUID - cursor:(NSString *) cursor - reversed:(BOOL) reversed -{ - NSMutableDictionary *query = [NSMutableDictionary dictionary]; - if (queryString) { - query[@"ql"] = queryString; - } - if (limit > 0) { - query[@"limit"] = [NSNumber numberWithInt:limit]; - } - if (startUUID) { - query[@"start"] = startUUID; - } - if (cursor) { - query[@"cursor"] = cursor; - } - if (reversed) { - query[@"reversed"] = @"true"; - } - return query; -} - -#pragma mark Authentication - -- (BOOL) authenticateWithResult:(UGHTTPResult *) result -{ - id results = result.object; - self.token = results[@"access_token"]; - id expires = results[@"expires_in"]; - self.tokenExpirationDate = [NSDate dateWithTimeIntervalSinceNow:[expires intValue]]; - return [self isAuthenticated]; -} - -- (BOOL) isAuthenticated -{ - return (self.token && - self.tokenExpirationDate && - ([self.tokenExpirationDate compare:[NSDate date]] == NSOrderedDescending)); -} - -#pragma mark - Management API request generators - - -#pragma mark Access tokens -// http://apigee.com/docs/usergrid/content/accesstoken - -- (NSMutableURLRequest *) getAccessTokenForAdminWithUsername:(NSString *) username - password:(NSString *) password -{ - if (!username || !password) { - return nil; - } - NSDictionary *query = @{@"grant_type":@"password", - @"username":username, - @"password":password}; - NSString *path = [NSMutableString stringWithFormat:@"%@/management/token?%@", - self.server, [query URLQueryString]]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getAccessTokenForOrganizationWithClientID:(NSString *) clientID - clientSecret:(NSString *) clientSecret -{ - if (!clientID || !clientSecret) { - return nil; - } - NSDictionary *query = @{@"grant_type":@"client_credentials", - @"client_id":clientID, - @"client_secret":clientSecret}; - NSString *path = [NSMutableString stringWithFormat:@"%@/management/token?%@", - self.server, [query URLQueryString]]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getAccessTokenForApplicationWithUsername:(NSString *) username - password:(NSString *) password -{ - if (!username || !password) { - return nil; - } - NSDictionary *query = @{@"grant_type":@"password", - @"username":username, - @"password":password}; - NSString *path = [NSMutableString stringWithFormat:@"%@/token?%@", - self.root, [query URLQueryString]]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getAccessTokenForApplicationWithClientID:(NSString *) clientID - clientSecret:(NSString *) clientSecret -{ - if (!clientID || !clientSecret) { - return nil; - } - NSDictionary *query = @{@"grant_type":@"client_credentials", - @"client_id":clientID, - @"client_secret":clientSecret}; - NSString *path = [NSMutableString stringWithFormat:@"%@/token?%@", - self.root, [query URLQueryString]]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -#pragma mark Admin users -// http://apigee.com/docs/usergrid/content/admin-user - -- (NSMutableURLRequest *) createAdminUserWithValues:(NSDictionary *) values -{ - NSString *path = [NSString stringWithFormat:@"%@/management/users", - self.server]; - return [self authorizedRequestWithMethod:@"POST" - path:path - body:[values URLQueryData]]; -} - -- (NSMutableURLRequest *) updateAdminUser:(NSString *) adminUserIdentifier - withValues:(NSDictionary *) values -{ - NSString *path = [NSString stringWithFormat:@"%@/management/users/%@", - self.server, adminUserIdentifier]; - return [self authorizedRequestWithMethod:@"PUT" - path:path - body:[values URLQueryData]]; -} - -- (NSMutableURLRequest *) getAdminUser:(NSString *) adminUserIdentifier -{ - NSString *path = [NSString stringWithFormat:@"%@/management/users/%@", - self.server, adminUserIdentifier]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) setPasswordForAdminUser:(NSString *) adminUserIdentifier - toValue:(NSString *) password -{ - NSString *path = [NSString stringWithFormat:@"%@/management/users/%@/password", - self.server, adminUserIdentifier]; - NSDictionary *values = @{@"password":password}; - return [self authorizedRequestWithMethod:@"PUT" - path:path - body:[values URLQueryData]]; -} - -- (NSMutableURLRequest *) initiatePasswordResetForAdminUser -{ - NSString *path = [NSString stringWithFormat:@"%@/management/users/resetpw", - self.server]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) completePasswordResetForAdminUserWithValues:(NSDictionary *) values -{ - NSString *path = [NSString stringWithFormat:@"%@/management/users/resetpw", - self.server]; - return [self authorizedRequestWithMethod:@"POST" - path:path - body:[values URLQueryData]]; -} - -- (NSMutableURLRequest *) activateAdminUser:(NSString *) adminUserIdentifier - withToken:(NSString *) token - sendingConfirmationEmail:(BOOL) sendingConfirmationEmail -{ - NSString *path = [NSString stringWithFormat:@"%@/management/users/%@/activate", - self.server, adminUserIdentifier]; - NSDictionary *values = @{@"token":token, - @"confirm_email":boolean_representation(sendingConfirmationEmail)}; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:[values URLQueryData]]; -} - -- (NSMutableURLRequest *) reactivateAdminUser:(NSString *) adminUserIdentifier -{ - NSString *path = [NSString stringWithFormat:@"%@/management/users/%@/reactivate", - self.server, adminUserIdentifier]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getActivityFeedForAdminUser:(NSString *) adminUserIdentifier -{ - NSString *path = [NSString stringWithFormat:@"%@/management/users/%@/feed", - self.server, adminUserIdentifier]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -#pragma mark Client authorization -// http://apigee.com/docs/usergrid/content/client-authorization - -- (NSMutableURLRequest *) authorizeClient:(NSString *) clientIdentifier withResponseType:(NSString *) responseType -{ - NSString *path = [NSString stringWithFormat:@"%@/management/authorize", - self.server]; - NSDictionary *values = @{@"response_type":responseType, - @"client_id":clientIdentifier}; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:[values URLQueryData]]; -} - - -#pragma mark Organizations and Applications -// http://apigee.com/docs/usergrid/content/organization - -- (NSMutableURLRequest *) createOrganizationWithValues:(NSDictionary *) values -{ - NSString *path = [NSString stringWithFormat:@"%@/management/organizations", - self.server]; - return [self authorizedRequestWithMethod:@"POST" - path:path - body:[values URLQueryData]]; -} - -- (NSMutableURLRequest *) getOrganization:(NSString *) organizationIdentifier -{ - NSString *path = [NSString stringWithFormat:@"%@/management/organizations/%@", - self.server, organizationIdentifier]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) activateOrganization:(NSString *) organizationIdentifier - withToken:(NSString *) token - sendingConfirmationEmail:(BOOL) sendingConfirmationEmail -{ - NSDictionary *values = @{@"token":token, - @"confirm_email":boolean_representation(sendingConfirmationEmail)}; - NSString *path = [NSString stringWithFormat:@"%@/management/organizations/%@/activate?%@", - self.server, organizationIdentifier, [values URLQueryString]]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) reactivateOrganization:(NSString *) organizationIdentifier -{ - NSString *path = [NSString stringWithFormat:@"%@/management/organizations/%@/reactivate", - self.server, organizationIdentifier]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) generateClientCredentialsForOrganization:(NSString *) organizationIdentifier -{ - NSString *path = [NSString stringWithFormat:@"%@/management/organizations/%@/credentials", - self.server, organizationIdentifier]; - return [self authorizedRequestWithMethod:@"POST" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getClientCredentialsForOrganization:(NSString *) organizationIdentifier -{ - NSString *path = [NSString stringWithFormat:@"%@/management/organizations/%@/credentials", - self.server, organizationIdentifier]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getActivityFeedForOrganization:(NSString *) organizationIdentifier -{ - NSString *path = [NSString stringWithFormat:@"%@/management/organizations/%@/feed", - self.server, organizationIdentifier]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) createApplicationInOrganization:(NSString *)organizationIdentifier withValues:(NSDictionary *)values -{ - NSString *path = [NSMutableString stringWithFormat:@"%@/management/organizations/%@/applications", - self.server, organizationIdentifier]; - return [self authorizedRequestWithMethod:@"POST" - path:path - body:[values URLQueryData]]; -} - -- (NSMutableURLRequest *) deleteApplication:(NSString *) applicationIdentifier - inOrganization:(NSString *)organizationIdentifier -{ - NSString *path = [NSMutableString stringWithFormat:@"%@/management/organizations/%@/applications/%@", - self.server, organizationIdentifier, applicationIdentifier]; - return [self authorizedRequestWithMethod:@"DELETE" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) generateClientCredentialsForApplication:(NSString *) applicationIdentifier - inOrganization:(NSString *) organizationIdentifier -{ - NSString *path = [NSString stringWithFormat:@"%@/management/organizations/%@/applications/%@/credentials", - self.server, organizationIdentifier, applicationIdentifier]; - return [self authorizedRequestWithMethod:@"POST" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getClientCredentialsForApplication:(NSString *) applicationIdentifier - inOrganization:(NSString *) organizationIdentifier -{ - NSString *path = [NSString stringWithFormat:@"%@/management/organizations/%@/applications/%@/credentials", - self.server, organizationIdentifier, applicationIdentifier]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getApplicationsInOrganization:(NSString *) organizationIdentifier -{ - NSString *path = [NSMutableString stringWithFormat:@"%@/management/organizations/%@/applications", - self.server, organizationIdentifier]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) addAdminUser:(NSString *) adminUserIdentifier - toOrganization:(NSString *) organizationIdentifier -{ - NSString *path = [NSString stringWithFormat:@"%@/management/organizations/%@/users/%@", - self.server, organizationIdentifier, adminUserIdentifier]; - return [self authorizedRequestWithMethod:@"PUT" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getAdminUsersInOrganization:(NSString *) organizationIdentifier -{ - NSString *path = [NSString stringWithFormat:@"%@/management/organizations/%@/users", - self.server, organizationIdentifier]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) removeAdminUser:(NSString *) adminUserIdentifier - fromOrganization:(NSString *) organizationIdentifier -{ - NSString *path = [NSString stringWithFormat:@"%@/management/organizations/%@/users/%@", - self.server, organizationIdentifier, adminUserIdentifier]; - return [self authorizedRequestWithMethod:@"DELETE" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getApplication:(NSString *) applicationIdentifier - inOrganization:(NSString *) organizationIdentifier -{ - NSString *path = [NSMutableString stringWithFormat:@"%@/%@/%@", - self.server, organizationIdentifier, applicationIdentifier]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -#pragma mark - Application API request generators - - -#pragma mark Activity -// http://apigee.com/docs/usergrid/content/activity - -- (NSMutableURLRequest *) createActivityForUser:(NSString *) userIdentifier - withValues:(NSDictionary *) values -{ - NSString *path = [NSMutableString stringWithFormat:@"%@/users/%@/activities", - self.root, userIdentifier]; - return [self authorizedRequestWithMethod:@"POST" - path:path - body:[values URLQueryData]]; -} - -- (NSMutableURLRequest *) createActivityForGroup:(NSString *) groupIdentifier - withValues:(NSDictionary *) values -{ - NSString *path = [NSMutableString stringWithFormat:@"%@/groups/%@/activities", - self.root, groupIdentifier]; - return [self authorizedRequestWithMethod:@"POST" - path:path - body:[values URLQueryData]]; -} - -- (NSMutableURLRequest *) createActivityForFollowersOfUser:(NSString *) userIdentifier - inGroup:(NSString *) groupIdentifier - withValues:(NSDictionary *) values -{ - NSString *path = [NSMutableString stringWithFormat:@"%@/groups/%@/users/%@/activities", - self.root, groupIdentifier, userIdentifier]; - return [self authorizedRequestWithMethod:@"POST" - path:path - body:[values URLQueryData]]; - -} - -- (NSMutableURLRequest *) getActivitiesForUser:(NSString *) userIdentifier -{ - NSString *path = [NSMutableString stringWithFormat:@"%@/users/%@/activities", - self.root, userIdentifier]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getActivitiesForGroup:(NSString *) groupIdentifier -{ - NSString *path = [NSMutableString stringWithFormat:@"%@/groups/%@/activities", - self.root, groupIdentifier]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getActivityFeedForUser:(NSString *) userIdentifier -{ - NSString *path = [NSMutableString stringWithFormat:@"%@/users/%@/feed", - self.root, userIdentifier]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getActivityFeedForGroup:(NSString *) groupIdentifier -{ - NSString *path = [NSMutableString stringWithFormat:@"%@/groups/%@/feed", - self.root, groupIdentifier]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -#pragma mark Assets - -- (NSMutableURLRequest *) getDataForAsset:(NSString *) assetIdentifier -{ - NSString *path = [NSMutableString stringWithFormat:@"%@/assets/%@/data", - self.root, assetIdentifier]; - NSMutableURLRequest *request = [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; - return request; -} - -- (NSMutableURLRequest *) postData:(NSData *) data - forAsset:(NSString *) assetIdentifier -{ - NSString *path = [NSMutableString stringWithFormat:@"%@/assets/%@/data", - self.root, - assetIdentifier]; - NSMutableURLRequest *request = [self authorizedRequestWithMethod:@"POST" - path:path - body:data]; - [request setValue:@"application/octet-stream" forHTTPHeaderField:@"Content-Type"]; - return request; -} - -#pragma mark General-purpose endpoints -// http://apigee.com/docs/usergrid/content/general-purpose-endpoints - -- (NSMutableURLRequest *) createEntityInCollection:(NSString *) collection - withValues:(NSDictionary *)values -{ - NSString *path = [NSMutableString stringWithFormat:@"%@/%@", - self.root, collection]; - NSError *error; - NSData *data = [NSJSONSerialization dataWithJSONObject:values options:0 error:&error]; - if (!data) { - NSLog(@"%@", error); - } - return [self authorizedRequestWithMethod:@"POST" - path:path - body:data]; -} - -- (NSMutableURLRequest *) getEntity:(NSString *) entityIdentifier - inCollection:(NSString *) collection -{ - NSString *path = [NSMutableString stringWithFormat:@"%@/%@/%@", - self.root, collection, entityIdentifier]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) updateEntity:(NSString *) entityIdentifier - inCollection:(NSString *) collection - withValues:(NSDictionary *) values { - NSString *path = [NSString stringWithFormat:@"%@/%@/%@", self.root, collection, entityIdentifier]; - NSError *error; - NSData *data = [NSJSONSerialization dataWithJSONObject:values options:0 error:&error]; - if (!data) { - NSLog(@"%@", error); - } - return [self authorizedRequestWithMethod:@"PUT" - path:path - body:data]; -} - -- (NSMutableURLRequest *) deleteEntity:(NSString *) entityIdentifier - inCollection:(NSString *) collection -{ - NSString *path = [NSString stringWithFormat:@"%@/%@/%@", self.root, collection, entityIdentifier]; - return [self authorizedRequestWithMethod:@"DELETE" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getEntitiesInCollection:(NSString *) collection - limit:(int) limit -{ - NSDictionary *query = [self queryWithString:@"select *" - limit:limit - startUUID:nil - cursor:nil - reversed:NO]; - return [self getEntitiesInCollection:collection - usingQuery:query]; -} - -- (NSMutableURLRequest *) getEntitiesInCollection:(NSString *) collection - usingQuery:(NSDictionary *) query -{ - NSString *path = [NSMutableString stringWithFormat:@"%@/%@?%@", - self.root, - collection, - [query URLQueryString]]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) updateEntitiesInCollection:(NSString *) collection - usingQuery:(NSDictionary *) query - withValues:(NSDictionary *) values -{ - NSString *path = [NSMutableString stringWithFormat:@"%@/%@?%@", - self.root, - collection, - [query URLQueryString]]; - return [self authorizedRequestWithMethod:@"PUT" - path:path - body:[values URLQueryData]]; -} - -- (NSMutableURLRequest *) deleteEntitiesInCollection:(NSString *) collection -{ - NSDictionary *query = [self queryWithString:@"select *" - limit:0 - startUUID:nil - cursor:nil - reversed:NO]; - return [self deleteEntitiesInCollection:collection - usingQuery:query]; -} - -- (NSMutableURLRequest *) deleteEntitiesInCollection:(NSString *) collection - usingQuery:(NSDictionary *) query -{ - NSString *path = [NSString stringWithFormat:@"%@/%@?%@", self.root, collection, [query URLQueryString]]; - return [self authorizedRequestWithMethod:@"DELETE" - path:path - body:nil]; -} - -#pragma mark Devices -// http://apigee.com/docs/usergrid/content/device - -#pragma mark Events and Counters -// http://apigee.com/docs/usergrid/content/events-and-counters - -- (NSMutableURLRequest *) createEventWithValues:(NSDictionary *) values -{ - NSString *path = [NSString stringWithFormat:@"%@/events", self.root]; - return [self authorizedRequestWithMethod:@"POST" - path:path - body:[values URLQueryData]]; -} - -#pragma mark Groups -// http://apigee.com/docs/usergrid/content/group - -- (NSMutableURLRequest *) createGroupWithValues:(NSDictionary *) values -{ - NSString *path = [NSString stringWithFormat:@"%@/groups", self.root]; - return [self authorizedRequestWithMethod:@"POST" - path:path - body:[values URLQueryData]]; -} - -- (NSMutableURLRequest *) addUser:(NSString *) user - toGroup:(NSString *) group -{ - NSString *path = [NSString stringWithFormat:@"%@/groups/%@/users/%@", - self.root, group, user]; - return [self authorizedRequestWithMethod:@"POST" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getGroup:(NSString *) groupName -{ - NSString *path = [NSString stringWithFormat:@"%@/groups/%@", self.root, groupName]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) updateGroup:(NSString *) groupName - withValues:(NSDictionary *) values -{ - NSString *path = [NSString stringWithFormat:@"%@/groups/%@", - self.root, groupName]; - return [self authorizedRequestWithMethod:@"PUT" - path:path - body:[values URLQueryData]]; -} - -- (NSMutableURLRequest *) deleteUser:(NSString *) user - fromGroup:(NSString *) groupName -{ - NSString *path = [NSString stringWithFormat:@"%@/groups/%@/users/%@", - self.root, groupName, user]; - return [self authorizedRequestWithMethod:@"DELETE" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) deleteGroup:(NSString *) groupName -{ - NSString *path = [NSString stringWithFormat:@"%@/groups/%@", - self.root, groupName]; - return [self authorizedRequestWithMethod:@"DELETE" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getUsersInGroup:(NSString *) groupName -{ - NSString *path = [NSString stringWithFormat:@"%@/groups/%@/users", - self.root, groupName]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -#pragma mark Roles -// http://apigee.com/docs/usergrid/content/role - -- (NSMutableURLRequest *) createRoleWithValues:(NSDictionary *) values -{ - NSString *path = [NSString stringWithFormat:@"%@/roles", self.root]; - return [self authorizedRequestWithMethod:@"POST" - path:path - body:[values URLQueryData]]; -} - -- (NSMutableURLRequest *) getRoles -{ - NSString *path = [NSString stringWithFormat:@"%@/roles", self.root]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) deleteRole:(NSString *) roleName -{ - NSString *path = [NSString stringWithFormat:@"%@/roles/%@", - self.root, roleName]; - return [self authorizedRequestWithMethod:@"DELETE" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getPermissionsForRole:(NSString *) roleName -{ - NSString *path = [NSString stringWithFormat:@"%@/roles/%@", - self.root, roleName]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) addPermissionsToRole:(NSString *) roleName - withValues:(NSDictionary *) values -{ - NSString *path = [NSString stringWithFormat:@"%@/roles/%@/permissions", - self.root, roleName]; - return [self authorizedRequestWithMethod:@"POST" - path:path - body:[values URLQueryData]]; -} - -- (NSMutableURLRequest *) deletePermissionsFromRole:(NSString *) roleName - usingPattern:(NSString *) pattern -{ - NSString *path = [NSString stringWithFormat:@"%@/roles/%@/permissions?pattern=%@", - self.root, roleName, pattern]; - return [self authorizedRequestWithMethod:@"DELETE" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) addUser:(NSString *)user - toRole:(NSString *)roleName -{ - NSString *path = [NSString stringWithFormat:@"%@/roles/%@/users/%@", - self.root, roleName, user]; - return [self authorizedRequestWithMethod:@"POST" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getUsersInRole:(NSString *) roleName -{ - NSString *path = [NSString stringWithFormat:@"%@/roles/%@/users", - self.root, roleName]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) deleteUser:(NSString *) user - fromRole:(NSString *) roleName -{ - NSString *path = [NSString stringWithFormat:@"%@/roles/%@/users/%@", - self.root, roleName, user]; - return [self authorizedRequestWithMethod:@"DELETE" - path:path - body:nil]; -} - -#pragma mark Users -// http://apigee.com/docs/usergrid/content/user - -- (NSMutableURLRequest *) createUserWithValues:(NSDictionary *) values -{ - NSString *path = [NSString stringWithFormat:@"%@/users", self.root]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:[values URLQueryData]]; -} - -- (NSMutableURLRequest *) setPasswordForUser:(NSString *) username - toPassword:(NSString *) newPassword - fromPassword:(NSString *) oldPassword -{ - NSDictionary *query = @{@"newpassword":newPassword, - @"oldpassword":oldPassword}; - NSString *path = [NSString stringWithFormat:@"%@/users/%@/password", - self.root, username]; - return [self authorizedRequestWithMethod:@"POST" - path:path - body:[query URLQueryData]]; -} - -- (NSMutableURLRequest *) getUser:(NSString *) username -{ - NSString *path = [NSString stringWithFormat:@"%@/users/%@", - self.root, username]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) updateUser:(NSString *) username - withValues:(NSDictionary *) values -{ - NSString *path = [NSString stringWithFormat:@"%@/users/%@", - self.root, username]; - return [self authorizedRequestWithMethod:@"PUT" - path:path - body:[values URLQueryData]]; -} - -- (NSMutableURLRequest *) deleteUser:(NSString *) username -{ - NSString *path = [NSString stringWithFormat:@"%@/users/%@", - self.root, username]; - return [self authorizedRequestWithMethod:@"DELETE" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getUsersUsingQuery:(NSDictionary *) query -{ - NSString *path = [NSString stringWithFormat:@"%@/users?%@", - self.root, [query URLQueryString]]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) connectEntity:(NSString *) entity1 - inCollection:(NSString *) collection - toEntity:(NSString *) entity2 - throughRelationship:(NSString *) relationship -{ - NSString *path = [NSString stringWithFormat:@"%@/%@/%@/%@/%@", - self.root, collection, entity1, relationship, entity2]; - return [self authorizedRequestWithMethod:@"POST" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) disconnectEntity:(NSString *) entity1 - inCollection:(NSString *) collection - fromEntity:(NSString *) entity2 - throughRelationship:(NSString *) relationship -{ - NSString *path = [NSString stringWithFormat:@"%@/%@/%@/%@/%@", - self.root, collection, entity1, relationship, entity2]; - return [self authorizedRequestWithMethod:@"DELETE" - path:path - body:nil]; -} - -- (NSMutableURLRequest *) getConnectionsToEntity:(NSString *) entity - inCollection:(NSString *) collection - throughRelationship:(NSString *) relationship - usingQuery:(NSDictionary *) query -{ - NSString *path = [NSString stringWithFormat:@"%@/%@/%@/%@?%@", - self.root, collection, entity, relationship, [query URLQueryString]]; - return [self authorizedRequestWithMethod:@"GET" - path:path - body:nil]; -} - -@end \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/ios/UGAPI/v2/UGHTTPClient.h ---------------------------------------------------------------------- diff --git a/sdks/ios/UGAPI/v2/UGHTTPClient.h b/sdks/ios/UGAPI/v2/UGHTTPClient.h deleted file mode 100644 index 64fe9be..0000000 --- a/sdks/ios/UGAPI/v2/UGHTTPClient.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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> - -@class UGHTTPResult; - -typedef void (^UGHTTPCompletionHandler)(UGHTTPResult *result); -typedef void (^UGHTTPProgressHandler)(CGFloat progress); - -@interface UGHTTPClient : NSObject -#if TARGET_OS_IPHONE -<NSURLConnectionDataDelegate> -#endif - -@property (nonatomic, copy) UGHTTPCompletionHandler completionHandler; -@property (nonatomic, copy) UGHTTPProgressHandler progressHandler; -@property (readonly) CGFloat progress; -@property (readonly) BOOL isRunning; - -- (id) initWithRequest:(NSMutableURLRequest *) request; - -- (UGHTTPResult *) connect; - -- (void) connectWithCompletionHandler:(UGHTTPCompletionHandler) completionHandler; - -- (void) connectWithCompletionHandler:(UGHTTPCompletionHandler) completionHandler - progressHandler:(UGHTTPProgressHandler) progressHandler; - -- (void) cancel; - -@end http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/ios/UGAPI/v2/UGHTTPClient.m ---------------------------------------------------------------------- diff --git a/sdks/ios/UGAPI/v2/UGHTTPClient.m b/sdks/ios/UGAPI/v2/UGHTTPClient.m deleted file mode 100644 index 38aee42..0000000 --- a/sdks/ios/UGAPI/v2/UGHTTPClient.m +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 "UGHTTPClient.h" -#import "UGHTTPResult.h" - -@interface UGHTTPClient () -@property (nonatomic, strong) NSMutableURLRequest *request; -@property (nonatomic, strong) NSMutableData *data; -@property (nonatomic, strong) NSHTTPURLResponse *response; -@property (nonatomic, strong) NSURLConnection *connection; -@end - -@implementation UGHTTPClient - -static int activityCount = 0; - -+ (void) retainNetworkActivityIndicator { - activityCount++; -#if TARGET_OS_IPHONE - [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; -#endif -} - -+ (void) releaseNetworkActivityIndicator { - activityCount--; -#if TARGET_OS_IPHONE - if (activityCount == 0) { - [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; - } -#endif -} - -- (id) initWithRequest:(NSMutableURLRequest *)request -{ - if (self = [super init]) { - self.request = request; - } - return self; -} - -- (UGHTTPResult *) connect { - NSHTTPURLResponse *response; - NSError *error; - UGHTTPResult *result = [[UGHTTPResult alloc] init]; - result.data = [NSURLConnection sendSynchronousRequest:self.request returningResponse:&response error:&error]; - result.response = response; - result.error = error; - if (self.completionHandler) { - self.completionHandler(result); - } - return result; -} - -- (void) connectWithCompletionHandler:(UGHTTPCompletionHandler)completionHandler - progressHandler:(UGHTTPProgressHandler)progressHandler -{ - [self.request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; - self.data = nil; - self.response = nil; - self.completionHandler = completionHandler; - self.progressHandler = progressHandler; - self.connection = [[NSURLConnection alloc] initWithRequest:self.request delegate:self]; - [isa retainNetworkActivityIndicator]; -} - -- (void) connectWithCompletionHandler:(UGHTTPCompletionHandler) completionHandler -{ - [self connectWithCompletionHandler:completionHandler progressHandler:nil]; -} - -- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response -{ - self.response = response; - if (self.progressHandler) { - self.progressHandler(0.0); - } -} - -- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)newData -{ - if (!self.data) { - self.data = [NSMutableData dataWithData:newData]; - } else { - [self.data appendData:newData]; - } - if (self.progressHandler) { - long long expectedLength = [self.response expectedContentLength]; - if (expectedLength > 0) { - CGFloat progress = ((CGFloat) [self.data length]) / expectedLength; - self.progressHandler(progress); - } - } -} - -- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error -{ - if (self.completionHandler) { - UGHTTPResult *result = [[UGHTTPResult alloc] init]; - result.response = self.response; - result.data = self.data; - result.error = error; - self.completionHandler(result); - } - self.connection = nil; - self.data = nil; - [isa releaseNetworkActivityIndicator]; -} - -- (void)connectionDidFinishLoading:(NSURLConnection *)connection -{ - if (self.progressHandler) { - self.progressHandler(1.0); - } - if (self.completionHandler) { - UGHTTPResult *result = [[UGHTTPResult alloc] init]; - result.response = self.response; - result.data = self.data; - result.error = nil; - //[self.data writeToFile:@"/tmp/data" atomically:NO]; - self.completionHandler(result); - } - self.connection = nil; - self.data = nil; - [isa releaseNetworkActivityIndicator]; -} - -- (void) cancel { - if (self.connection) { - [self.connection cancel]; - } - self.connection = nil; -} - -- (BOOL) isRunning { - return (self.connection != nil); -} - -- (CGFloat) progress { - long long expectedLength = [self.response expectedContentLength]; - if (expectedLength > 0) { - return ((CGFloat) [self.data length]) / expectedLength; - } else { - return 0.0; - } -} - -@end http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/ios/UGAPI/v2/UGHTTPHelpers.h ---------------------------------------------------------------------- diff --git a/sdks/ios/UGAPI/v2/UGHTTPHelpers.h b/sdks/ios/UGAPI/v2/UGHTTPHelpers.h deleted file mode 100644 index 64c678a..0000000 --- a/sdks/ios/UGAPI/v2/UGHTTPHelpers.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - // -// UGHTTPHelpers.h -// UGHTTP -// -// Created by Tim Burks on 2/24/12. -// -#import <Foundation/Foundation.h> - -@interface NSString (UGHTTPHelpers) -- (NSString *) URLEncodedString; -- (NSString *) URLDecodedString; -- (NSDictionary *) URLQueryDictionary; -@end - -@interface NSData (UGHTTPHelpers) -- (NSDictionary *) URLQueryDictionary; -@end - -@interface NSDictionary (UGHTTPHelpers) -- (NSString *) URLQueryString; -- (NSData *) URLQueryData; -@end - - http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/ios/UGAPI/v2/UGHTTPHelpers.m ---------------------------------------------------------------------- diff --git a/sdks/ios/UGAPI/v2/UGHTTPHelpers.m b/sdks/ios/UGAPI/v2/UGHTTPHelpers.m deleted file mode 100644 index 9bad1b9..0000000 --- a/sdks/ios/UGAPI/v2/UGHTTPHelpers.m +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -// -// UGHTTPHelpers.m -// UGHTTP -// -// Created by Tim Burks on 2/24/12. -// - -#import "UGHTTPHelpers.h" -#import <wctype.h> - -static unichar char_to_int(unichar c) -{ - switch (c) { - case '0': return 0; - case '1': return 1; - case '2': return 2; - case '3': return 3; - case '4': return 4; - case '5': return 5; - case '6': return 6; - case '7': return 7; - case '8': return 8; - case '9': return 9; - case 'A': case 'a': return 10; - case 'B': case 'b': return 11; - case 'C': case 'c': return 12; - case 'D': case 'd': return 13; - case 'E': case 'e': return 14; - case 'F': case 'f': return 15; - } - return 0; // not good -} - -static char int_to_char[] = "0123456789ABCDEF"; - -@implementation NSString (UGHTTPHelpers) - -- (NSString *) URLEncodedString -{ - NSMutableString *result = [NSMutableString string]; - int i = 0; - const char *source = [self cStringUsingEncoding:NSUTF8StringEncoding]; - unsigned long max = strlen(source); - while (i < max) { - unsigned char c = source[i++]; - if (c == ' ') { - [result appendString:@"%20"]; - } - else if (iswalpha(c) || iswdigit(c) || (c == '-') || (c == '.') || (c == '_') || (c == '~')) { - [result appendFormat:@"%c", c]; - } - else { - [result appendString:[NSString stringWithFormat:@"%%%c%c", int_to_char[(c/16)%16], int_to_char[c%16]]]; - } - } - return result; -} - -- (NSString *) URLDecodedString -{ - int i = 0; - NSUInteger max = [self length]; - char *buffer = (char *) malloc ((max + 1) * sizeof(char)); - int j = 0; - while (i < max) { - char c = [self characterAtIndex:i++]; - switch (c) { - case '+': - buffer[j++] = ' '; - break; - case '%': - buffer[j++] = - char_to_int([self characterAtIndex:i])*16 - + char_to_int([self characterAtIndex:i+1]); - i = i + 2; - break; - default: - buffer[j++] = c; - break; - } - } - buffer[j] = 0; - NSString *result = [NSMutableString stringWithCString:buffer encoding:NSUTF8StringEncoding]; - if (!result) result = [NSMutableString stringWithCString:buffer encoding:NSASCIIStringEncoding]; - free(buffer); - return result; -} - -- (NSDictionary *) URLQueryDictionary -{ - NSMutableDictionary *result = [NSMutableDictionary dictionary]; - NSArray *pairs = [self componentsSeparatedByString:@"&"]; - int i; - NSUInteger max = [pairs count]; - for (i = 0; i < max; i++) { - NSArray *pair = [[pairs objectAtIndex:i] componentsSeparatedByString:@"="]; - if ([pair count] == 2) { - NSString *key = [[pair objectAtIndex:0] URLDecodedString]; - NSString *value = [[pair objectAtIndex:1] URLDecodedString]; - [result setObject:value forKey:key]; - } - } - return result; -} - -@end - -@implementation NSDictionary (UGHTTPHelpers) - -- (NSString *) URLQueryString -{ - NSMutableString *result = [NSMutableString string]; - NSEnumerator *keyEnumerator = [[[self allKeys] sortedArrayUsingSelector:@selector(compare:)] objectEnumerator]; - id key; - while ((key = [keyEnumerator nextObject])) { - id value = [self objectForKey:key]; - if (![value isKindOfClass:[NSString class]]) { - if ([value respondsToSelector:@selector(stringValue)]) { - value = [value stringValue]; - } - } - if ([value isKindOfClass:[NSString class]]) { - if ([result length] > 0) [result appendString:@"&"]; - [result appendString:[NSString stringWithFormat:@"%@=%@", - [key URLEncodedString], - [value URLEncodedString]]]; - } - } - return [NSString stringWithString:result]; -} - -- (NSData *) URLQueryData -{ - return [[self URLQueryString] dataUsingEncoding:NSUTF8StringEncoding]; -} - -@end - -@implementation NSData (UGHTTPHelpers) - -- (NSDictionary *) URLQueryDictionary { - return [[[NSString alloc] initWithData:self encoding:NSUTF8StringEncoding] URLQueryDictionary]; -} - -@end - http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/ios/UGAPI/v2/UGHTTPResult.h ---------------------------------------------------------------------- diff --git a/sdks/ios/UGAPI/v2/UGHTTPResult.h b/sdks/ios/UGAPI/v2/UGHTTPResult.h deleted file mode 100644 index e8faf9b..0000000 --- a/sdks/ios/UGAPI/v2/UGHTTPResult.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -// -// UGHTTPResult.h -// UGAPIApp -// -// Created by Tim Burks on 4/3/13. -// -// - -#import <Foundation/Foundation.h> - -@interface UGHTTPResult : NSObject -@property (nonatomic, strong) NSHTTPURLResponse *response; -@property (nonatomic, strong) NSData *data; -@property (nonatomic, strong) NSError *error; -@property (nonatomic, strong) id object; -@property (nonatomic, readonly) NSString *UTF8String; - -@end \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/ios/UGAPI/v2/UGHTTPResult.m ---------------------------------------------------------------------- diff --git a/sdks/ios/UGAPI/v2/UGHTTPResult.m b/sdks/ios/UGAPI/v2/UGHTTPResult.m deleted file mode 100644 index 2e0e115..0000000 --- a/sdks/ios/UGAPI/v2/UGHTTPResult.m +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -// -// UGHTTPResult.m -// UGAPIApp -// -// Created by Tim Burks on 4/3/13. -// -// - -#import "UGHTTPResult.h" - -@implementation UGHTTPResult - -- (id) object { - if (!_object && !_error) { - NSError *error; - // NSLog(@"JSON %@", [[NSString alloc] initWithData:_data encoding:NSUTF8StringEncoding]); - _object = [NSJSONSerialization JSONObjectWithData:_data options:0 error:&error]; - _error = error; - if (_error) { - NSLog(@"JSON ERROR: %@", [error description]); - } - } - return _object; -} - -- (NSString *) UTF8String { - return [[NSString alloc] initWithData:self.data encoding:NSUTF8StringEncoding]; -} - -@end \ No newline at end of file
