usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mru...@apache.org
Subject [32/45] usergrid git commit: Moving older SDKs to a difference location and updating main README to link to new SDK locations.
Date Fri, 02 Sep 2016 17:40:13 GMT
http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/other/ios/UGAPI/UGQuery.h
----------------------------------------------------------------------
diff --git a/sdks/other/ios/UGAPI/UGQuery.h b/sdks/other/ios/UGAPI/UGQuery.h
new file mode 100755
index 0000000..b77e0a4
--- /dev/null
+++ b/sdks/other/ios/UGAPI/UGQuery.h
@@ -0,0 +1,104 @@
+/*
+ * 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>
+#import <CoreLocation/CoreLocation.h>
+
+enum
+{
+    kUGQueryOperationEquals = 0,
+    kUGQueryOperationLessThan = 1,
+    kUGQueryOperationLessThanOrEqualTo = 2,
+    kUGQueryOperationGreaterThan = 3,
+    kUGQueryOperationGreaterThanOrEqualTo = 4
+};
+
+/***************************************************************
+ QUERY MANAGEMENT:
+ 
+ All query functions take one of these as an optional parameter
+ (the client may send nil if desired). This will specify the
+ limitations of the query. 
+***************************************************************/
+
+@interface UGQuery : NSObject
+
+// url terms used in UG searches. Set as you like.
+// These are convenience methods. the same effect can be done
+// by calling addURLTerm
+-(void)setConsumer: (NSString *)consumer;
+-(void)setLastUUID: (NSString *)lastUUID;
+-(void)setTime: (long)time;
+-(void)setPrev: (int)prev;
+-(void)setNext: (int)next;
+-(void)setLimit: (int)limit;
+-(void)setPos: (NSString *)pos;
+-(void)setUpdate: (BOOL)update;
+-(void)setSynchronized: (BOOL)synchronized;
+
+// a general function for adding additional URL terms.
+// Note that all of the set functions above turn around and
+// call this.
+-(void)addURLTerm: (NSString *)urlTerm equals:(NSString *)equals;
+
+// ql operation requirements. For each of these, you provide the term, followed 
+// by the operation (a kUGQueryOperationXXXX constant) followed by the value
+// in whatever form you have it (NSString, int, or float are supported)
+// Example: [foo addRequiredOperation: @"age" kUGQueryLessThan valueInt:27] would
+// add the term "age < 27" to the ql.
+-(void)addRequiredOperation: (NSString *)term op:(int)op valueStr:(NSString *)valueStr;
+-(void)addRequiredOperation: (NSString *)term op:(int)op valueInt:(int) valueInt;
+
+// adds a "contains" requirement to the query. This adds the requirement that a value
+// contain a given string. Example: [foo addRequiredContains:@"hobbies value:@"fishing"]
+// would add the term "hobbies contains 'fishing'" to the ql.
+-(void)addRequiredContains: (NSString *)term value:(NSString *)value;
+
+// adds an "in" requirement to the query. This adds a requirement that a field
+// be within a certain range. Example [foo appendRequiredIn:@"age" low:16.0 high:22.0]
+// would add the term "age in 16.0,22.0" to the ql. 
+// Note that the qualifier is inclusive, meaning it is true if low <= term <= high. 
+-(void)addRequiredIn:(NSString *)term low:(int)low high:(int)high;
+
+// adds a "within" requirement. This adds a constraint that the term be within a 
+// certain distance of the sent-in x,y coordinates.
+-(void)addRequiredWithin:(NSString *)term latitude:(float)latitude longitude:(float)longitude distance:(float)distance;
+
+// assembles a "within" requirement with a term name, CLLocation, and distance
+-(void)addRequiredWithinLocation:(NSString *)term location:(CLLocation *)location distance:(float)distance;
+
+//-------------------- Oblique usage ----------------------------
+// adds a requirement to the query. The requirements will
+// *all* be sent when the query is adopted. This is an escalating
+// list as you add them. Requirements are in UG Querty language.
+// So something like "firstname='bob'". This is one of the few places
+// where the data you give will be sent to the server almost untouched. 
+// So if you make a mistake in your query, you are likely to cause the whole
+// transaction to return an error. 
+// NOTE: This is different thant URL terms. These are query terms sent along
+// to the *single* URL term "ql". 
+// Note: This is an oblique-usage function. You will find all the ql operations
+// supported in the various addRequiredXXXX functions above. You would only use
+// this function if you already have ql strings prepared for some reason, or if
+// there are new ql format operations that are not supported by this API.
+-(void)addRequirement: (NSString *)requirement;
+
+// returns the URL-ready string that detailes all specified requirements.
+// This is used internally by UGClient, you don't need to call it.
+-(NSString *)getURLAppend;
+
+@end

http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/other/ios/UGAPI/UGQuery.m
----------------------------------------------------------------------
diff --git a/sdks/other/ios/UGAPI/UGQuery.m b/sdks/other/ios/UGAPI/UGQuery.m
new file mode 100755
index 0000000..740ec5c
--- /dev/null
+++ b/sdks/other/ios/UGAPI/UGQuery.m
@@ -0,0 +1,277 @@
+/*
+ * 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 "UGQuery.h"
+#import "UGHTTPManager.h"
+
+@implementation UGQuery
+{
+    NSMutableArray *m_requirements;
+    NSMutableString *m_urlTerms;
+}
+
+-(id)init
+{
+    self = [super init];
+    if ( self )
+    {
+        m_requirements = [NSMutableArray new];
+        m_urlTerms = [NSMutableString new];
+    }
+    return self;
+}
+
+-(void)setConsumer: (NSString *)consumer
+{
+    [self addURLTerm:@"consumer" equals:consumer];    
+}
+
+-(void)setLastUUID: (NSString *)lastUUID
+{
+    [self addURLTerm:@"last" equals:lastUUID];    
+}
+
+-(void)setTime: (long)time
+{
+    NSMutableString *str = [NSMutableString new];
+    [str appendFormat:@"%ld", time];
+    [self addURLTerm:@"time" equals:str];
+}
+
+-(void)setPrev: (int)prev
+{
+    NSMutableString *str = [NSMutableString new];
+    [str appendFormat:@"%d", prev];
+    [self addURLTerm:@"prev" equals:str];
+}
+
+-(void)setNext: (int)next
+{
+    NSMutableString *str = [NSMutableString new];
+    [str appendFormat:@"%d", next];
+    [self addURLTerm:@"next" equals:str];
+}
+
+-(void)setLimit: (int)limit
+{
+    NSMutableString *str = [NSMutableString new];
+    [str appendFormat:@"%d", limit];
+    [self addURLTerm:@"limit" equals:str];
+}
+
+-(void)setPos: (NSString *)pos
+{
+    [self addURLTerm:@"pos" equals:pos];    
+}
+
+-(void)setUpdate: (BOOL)update
+{
+    if ( update )
+    {
+        [self addURLTerm:@"update" equals:@"true"];
+    }
+    else
+    {
+        [self addURLTerm:@"update" equals:@"false"];
+    }
+}
+
+-(void)setSynchronized: (BOOL)synchronized
+{
+    if ( synchronized )
+    {
+        [self addURLTerm:@"synchronized" equals:@"true"];
+    }
+    else
+    {
+        [self addURLTerm:@"synchronized" equals:@"false"];
+    }
+}
+
+-(void)addURLTerm: (NSString *)urlTerm equals:(NSString *)equals
+{
+    // ignore anything with a nil
+    if ( !urlTerm ) return;
+    if ( !equals ) return;
+
+    // escape the strings
+    NSString *escapedUrlTerm = [UGHTTPManager escapeSpecials:urlTerm];
+    NSString *escapedEquals = [UGHTTPManager escapeSpecials:equals];
+
+    // add it in
+    if ( [m_urlTerms length] > 0 )
+    {
+        // we already have some terms. Append an & before continuing
+        [m_urlTerms appendFormat:@"&"];
+    }
+    [m_urlTerms appendFormat:@"%@=%@", escapedUrlTerm, escapedEquals];
+}
+
+-(void)addRequiredOperation: (NSString *)term op:(int)op valueStr:(NSString *)valueStr
+{
+    // disregard invalid values
+    if ( !term ) return;
+    if ( !valueStr ) return;
+    
+    NSString *opStr = [self getOpStr: op];
+    if ( !opStr ) return; // nil opStr means they sent in an invalid op code
+    
+    // assemble the requirement string
+    NSMutableString *assembled = [NSMutableString new];
+    [assembled appendFormat:@"%@ %@ '%@'", term, opStr, valueStr];
+    
+    // add it as a req
+    [self addRequirement:assembled];
+}
+
+-(void)addRequiredOperation: (NSString *)term op:(int)op valueInt:(int) valueInt
+{
+    // disregard invalid values
+    if ( !term ) return;
+    
+    NSString *opStr = [self getOpStr: op];
+    if ( !opStr ) return; // nil opStr means they sent in an invalid op code
+    
+    // assemble the requirement string
+    NSMutableString *assembled = [NSMutableString new];
+    [assembled appendFormat:@"%@ %@ %d", term, opStr, valueInt];
+    
+    // add it as a req
+    [self addRequirement:assembled];
+}
+
+-(void)addRequiredContains: (NSString *)term value:(NSString *)value
+{
+    // disregard invalid values
+    if ( !term ) return;
+    if ( !value ) return;
+    
+    // assemble the requirement string
+    NSMutableString *assembled = [NSMutableString new];
+    [assembled appendFormat:@"%@ contains '%@'", term, value];
+    
+    // add it as a req
+    [self addRequirement:assembled];
+}
+
+-(void)addRequiredIn:(NSString *)term low:(int)low high:(int)high
+{
+    // disregard invalid values
+    if ( !term ) return;
+    
+    // assemble the requirement string
+    NSMutableString *assembled = [NSMutableString new];
+    [assembled appendFormat:@"%@ in %d,%d", term, low, high];
+    
+    // add it as a req
+    [self addRequirement:assembled];    
+}
+
+-(void)addRequiredWithin:(NSString *)term latitude:(float)latitude longitude:(float)longitude distance:(float)distance;
+{
+    // disregard invalid values
+    if ( !term ) return;
+    
+    // assemble the requirement string
+    NSMutableString *assembled = [NSMutableString new];
+    [assembled appendFormat:@"%@ within %f of %f,%f", term, distance, latitude, longitude];
+    
+    // add it as a req
+    [self addRequirement:assembled];   
+}
+
+-(void)addRequiredWithinLocation:(NSString *)term location:(CLLocation *)location distance:(float)distance
+{
+    [self addRequiredWithin:term latitude:location.coordinate.latitude longitude:location.coordinate.longitude distance:distance];
+}
+
+-(void)addRequirement: (NSString *)requirement
+{
+    // add the URL-ready requirement to our list
+    [m_requirements addObject:requirement];
+}
+
+-(NSString *)getURLAppend
+{    
+    // assemble a url append for all the requirements
+    // prep a mutable string
+    NSMutableString *ret = [NSMutableString new];
+    [ret setString:@"?"];
+  
+    // true if we've put anything in the string yet.
+    BOOL bHasContent = NO;
+    
+    // start with the ql term
+    if ( [m_requirements count] > 0 )
+    {    
+        // if we're here, there are queries
+        // assemble a single string for the ql
+        NSMutableString *ql = [NSMutableString new];
+        for ( int i=0 ; i<[m_requirements count] ; i++ )
+        {
+            if ( i>0 )
+            {
+                // connect terms
+                [ql appendFormat:@" and "];
+            }
+            [ql appendFormat:@"%@", [m_requirements objectAtIndex:i]];
+        }
+        
+        // escape it
+        NSString *escapedQL = [UGHTTPManager escapeSpecials:ql];
+        [ret appendFormat:@"ql=%@", escapedQL];
+        bHasContent = YES;
+    }
+
+    if ( [m_urlTerms length] > 0 )
+    {
+        if ( bHasContent ) 
+        {
+            [ret appendFormat:@"&%@", m_urlTerms];
+        }
+        else 
+        {
+            [ret appendFormat:@"%@", m_urlTerms];
+        }
+        bHasContent = YES;
+    }
+    
+    if ( !bHasContent )
+    {
+        // no content
+        return @"";
+    }
+    
+    // all prepared
+    return ret;
+}
+
+// Internal function
+ -(NSString *)getOpStr:(int)op
+{
+    switch (op)
+    {
+        case kUGQueryOperationEquals: return @"=";
+        case kUGQueryOperationGreaterThan: return @">";
+        case kUGQueryOperationGreaterThanOrEqualTo: return @">=";
+        case kUGQueryOperationLessThan: return @"<";
+        case kUGQueryOperationLessThanOrEqualTo: return @"<=";
+    }
+    return nil;
+}
+
+@end

http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/other/ios/UGAPI/UGUser.h
----------------------------------------------------------------------
diff --git a/sdks/other/ios/UGAPI/UGUser.h b/sdks/other/ios/UGAPI/UGUser.h
new file mode 100755
index 0000000..58e3b99
--- /dev/null
+++ b/sdks/other/ios/UGAPI/UGUser.h
@@ -0,0 +1,27 @@
+/*
+ * 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>
+
+@interface UGUser : NSObject
+
+@property NSString *username;
+@property NSString *email;
+@property NSString *uuid;
+@property NSString *picture;
+
+@end

http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/other/ios/UGAPI/UGUser.m
----------------------------------------------------------------------
diff --git a/sdks/other/ios/UGAPI/UGUser.m b/sdks/other/ios/UGAPI/UGUser.m
new file mode 100755
index 0000000..d683b6d
--- /dev/null
+++ b/sdks/other/ios/UGAPI/UGUser.m
@@ -0,0 +1,27 @@
+/*
+ * 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 "UGUser.h"
+
+@implementation UGUser
+
+@synthesize username;
+@synthesize email;
+@synthesize uuid;
+@synthesize picture;
+
+@end

http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/other/ios/UGAPI/v2/UGConnection.h
----------------------------------------------------------------------
diff --git a/sdks/other/ios/UGAPI/v2/UGConnection.h b/sdks/other/ios/UGAPI/v2/UGConnection.h
new file mode 100644
index 0000000..d44c8e9
--- /dev/null
+++ b/sdks/other/ios/UGAPI/v2/UGConnection.h
@@ -0,0 +1,289 @@
+/*
+ * 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/other/ios/UGAPI/v2/UGConnection.m
----------------------------------------------------------------------
diff --git a/sdks/other/ios/UGAPI/v2/UGConnection.m b/sdks/other/ios/UGAPI/v2/UGConnection.m
new file mode 100644
index 0000000..48840b3
--- /dev/null
+++ b/sdks/other/ios/UGAPI/v2/UGConnection.m
@@ -0,0 +1,938 @@
+/*
+ * 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/other/ios/UGAPI/v2/UGHTTPClient.h
----------------------------------------------------------------------
diff --git a/sdks/other/ios/UGAPI/v2/UGHTTPClient.h b/sdks/other/ios/UGAPI/v2/UGHTTPClient.h
new file mode 100644
index 0000000..64fe9be
--- /dev/null
+++ b/sdks/other/ios/UGAPI/v2/UGHTTPClient.h
@@ -0,0 +1,45 @@
+/*
+ * 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/other/ios/UGAPI/v2/UGHTTPClient.m
----------------------------------------------------------------------
diff --git a/sdks/other/ios/UGAPI/v2/UGHTTPClient.m b/sdks/other/ios/UGAPI/v2/UGHTTPClient.m
new file mode 100644
index 0000000..38aee42
--- /dev/null
+++ b/sdks/other/ios/UGAPI/v2/UGHTTPClient.m
@@ -0,0 +1,161 @@
+/*
+ * 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/other/ios/UGAPI/v2/UGHTTPHelpers.h
----------------------------------------------------------------------
diff --git a/sdks/other/ios/UGAPI/v2/UGHTTPHelpers.h b/sdks/other/ios/UGAPI/v2/UGHTTPHelpers.h
new file mode 100644
index 0000000..64c678a
--- /dev/null
+++ b/sdks/other/ios/UGAPI/v2/UGHTTPHelpers.h
@@ -0,0 +1,40 @@
+/*
+ * 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/other/ios/UGAPI/v2/UGHTTPHelpers.m
----------------------------------------------------------------------
diff --git a/sdks/other/ios/UGAPI/v2/UGHTTPHelpers.m b/sdks/other/ios/UGAPI/v2/UGHTTPHelpers.m
new file mode 100644
index 0000000..9bad1b9
--- /dev/null
+++ b/sdks/other/ios/UGAPI/v2/UGHTTPHelpers.m
@@ -0,0 +1,162 @@
+/*
+ * 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/other/ios/UGAPI/v2/UGHTTPResult.h
----------------------------------------------------------------------
diff --git a/sdks/other/ios/UGAPI/v2/UGHTTPResult.h b/sdks/other/ios/UGAPI/v2/UGHTTPResult.h
new file mode 100644
index 0000000..e8faf9b
--- /dev/null
+++ b/sdks/other/ios/UGAPI/v2/UGHTTPResult.h
@@ -0,0 +1,34 @@
+/*
+ * 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/other/ios/UGAPI/v2/UGHTTPResult.m
----------------------------------------------------------------------
diff --git a/sdks/other/ios/UGAPI/v2/UGHTTPResult.m b/sdks/other/ios/UGAPI/v2/UGHTTPResult.m
new file mode 100644
index 0000000..2e0e115
--- /dev/null
+++ b/sdks/other/ios/UGAPI/v2/UGHTTPResult.m
@@ -0,0 +1,46 @@
+/*
+ * 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


Mime
View raw message