Permalink
Browse files

New SDK classes and tools for unit testing.

This commit adds new classes in the UGAPI/v2 directory that
provide direct access to the Usergrid HTTP API. Instances
of the UGConnection class can be used to create NSMutableURLRequests
that can then be performed to call the Usergrid API. These
calls can be made with any HTTP framework desired by the
app developer, but as a convenience, this commit also includes
the UGHTTPClient class, which can make calls synchronously or
asynchronously. Synchronous calls will block and return a
UGHTTPResult instance, and asynchronous calls take C blocks
which they call when the requests complete or fail. All
information about HTTP calls is returned in the UGHTTPResult
instance, including errors. This gives app developers full
visibility of any network problems that could occur.

It is also now possible to build the SDK on the command line
as a Mac framework, which can then be used to interactively
use the SDK from the command line or to write interpreted
utilities and unit tests. This requires Nu (http://programming.nu).
Builds and tests are supported by the included "Nukefile".
After installing Nu, you can type "nuke" at the command
line to build Usergrid.framework, and "nuke install" to
install Usergrid.framework in /Library/Frameworks. Then
you can interact with the Usergrid.framework using the Nu
shell by typing "nush" at the command line.

========= EXAMPLE ==========
tim% nush
Nu Shell.
% (load "Usergrid")
t
% (set client ((UGClient alloc) initWithOrganizationId:"1hotrod" withApplicationID:"fred"))
<UGClient:7fc7ddb04250>
% (set response (client logInUser:"alice" password:"test1test"))
<UGClientResponse:7fc7dba1acd0>
% (set object ((response rawResponse) JSONValue))
<__NSDictionaryM:7fc7ddb1e900>
% (puts (object JSONValue))
Nu uncaught exception: NuUndefinedSymbol: undefined symbol JSONValue while evaluating expression (object JSONValue)
  from <TopLevel>:1: in object
  from <TopLevel>:1: in puts

% (puts (object description))
{
    "access_token" = YWMtTqsVbqYiEeKmQALoGuNOzAAAAT40B3oDr8iBRVTNHwVgBc3TL63UVqHO4LM;
    "expires_in" = 604800;
    user =     {
        activated = 1;
        created = 1359834587923;
        email = "alice@alice.com";
        modified = 1359834587923;
        name = alice;
        picture = "http://www.gravatar.com/avatar/37bed650c57b657c441a586579edfea6";
        type = user;
        username = alice;
        uuid = "b32b56df-6d71-11e2-81cf-02e81ac5a17b";
        "validate-password" = test1test;
    };
}
()
%
============================

To run the unit tests, type "nuke test" at the command line.

For more information about Nu, see http://programming.nu and http://github.com/timburks/nu
  • Loading branch information...
1 parent 74087bf commit 4dd954718dba24eac41db33f958e6a5f3be86272 @timburks timburks committed Apr 15, 2013
View
@@ -0,0 +1,29 @@
+;;
+;; If you've installed Nu (http://github.com/timburks/nu),
+;; then you can build the Usergrid SDK as a Mac framework
+;; by typing "nuke" in this directory. Type "nuke install"
+;; to install it in /Library/Frameworks.
+;;
+(set @m_files (filelist "^UGAPI/.*.m$"))
+(@m_files addObjectsFromSet:(filelist "^UGAPI/SBJSON/.*.m$"))
+(@m_files addObjectsFromSet:(filelist "^UGAPI/v2/.*.m$"))
+
+(set @arch '("x86_64"))
+
+;; framework description
+(set @framework "Usergrid")
+(set @framework_identifier "com.apigee.usergrid")
+
+(set @cc "clang")
+(set @cflags "-fobjc-arc -I UGAPI -I UGAPI/SBJSON -I UGAPI/v2")
+(set @ldflags "-framework Foundation ")
+
+(compilation-tasks)
+(framework-tasks)
+
+(task "clobber" => "clean" is
+ (SH "rm -rf #{@framework_dir}"))
+
+(task "default" => "framework")
+
+
View
@@ -0,0 +1,121 @@
+//
+// UGConnection.h
+// UGAPIApp
+//
+// Created by Tim Burks on 3/30/13.
+//
+//
+#import <Foundation/Foundation.h>
+
+@class UGHTTPResult;
+
+@interface UGConnection : NSObject
+
+@property (nonatomic, strong) NSString *server;
+@property (nonatomic, strong) NSString *organization;
+@property (nonatomic, strong) NSString *application;
+
++ (UGConnection *) sharedConnection;
+
+// 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;
+
+// Organizations and Applications http://apigee.com/docs/usergrid/content/organization
+
+- (NSMutableURLRequest *) createOrganization:(NSDictionary *) organization;
+
+- (NSMutableURLRequest *) getOrganization;
+
+- (NSMutableURLRequest *) createApplication:(NSDictionary *) application;
+
+- (NSMutableURLRequest *) deleteApplication;
+
+- (NSMutableURLRequest *) getApplicationsForOrganization;
+
+- (NSMutableURLRequest *) getApplication;
+
+// Admin users http://apigee.com/docs/usergrid/content/admin-user
+
+- (NSMutableURLRequest *) createAdminUser:(NSDictionary *) organization;
+
+// Activity http://apigee.com/docs/usergrid/content/activity
+
+// Assets
+
+- (NSMutableURLRequest *) getDataForAssetWithUUID:(NSString *) uuid;
+
+- (NSMutableURLRequest *) postData:(NSData *) data
+ forAssetWithUUID:(NSString *) uuid;
+
+// General-purpose endpoints http://apigee.com/docs/usergrid/content/general-purpose-endpoints
+
+- (NSMutableURLRequest *) createEntityInCollection:(NSString *) collection
+ withValues:(NSDictionary *) values;
+
+- (NSMutableURLRequest *) getEntityInCollection:(NSString *) collection
+ withUUID:(NSString *) uuid;
+
+- (NSMutableURLRequest *) updateEntityInCollection:(NSString *) collection
+ withUUID:(NSString *) uuid
+ newValues:(NSDictionary *) newValues;
+
+- (NSMutableURLRequest *) deleteEntityInCollection:(NSString *) collection
+ withUUID:(NSString *) uuid;
+
+- (NSMutableURLRequest *) getEntitiesInCollection:(NSString *) collection
+ limit:(int) limit;
+
+- (NSMutableURLRequest *) getEntitiesInCollection:(NSString *) collection
+ withQueryString:(NSString *) queryString
+ limit:(int) limit
+ startUUID:(NSString *) startUUID
+ cursor:(NSString *) cursor
+ reversed:(BOOL) reversed;
+
+- (NSMutableURLRequest *) updateEntitiesInCollection:(NSString *) collection
+ withQueryString:(NSString *) queryString
+ newValues:(NSDictionary *) newValues;
+
+- (NSMutableURLRequest *) deleteEntitiesInCollection:(NSString *) collection;
+
+- (NSMutableURLRequest *) deleteEntitiesInCollection:(NSString *) collection
+ withQueryString:(NSString *) queryString;
+
+
+// Devices http://apigee.com/docs/usergrid/content/device
+
+// Events and Counters http://apigee.com/docs/usergrid/content/events-and-counters
+
+// Groups http://apigee.com/docs/usergrid/content/group
+
+// Roles http://apigee.com/docs/usergrid/content/role
+
+// Users http://apigee.com/docs/usergrid/content/user
+
+@end
Oops, something went wrong.

0 comments on commit 4dd9547

Please sign in to comment.