Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #9 from timburks/development

Development
  • Loading branch information...
commit 65c5785fd86b41c35d029d08a981232cf0864619 2 parents e3775cc + 56afdaf
@rodsimpson rodsimpson authored
Showing with 8,564 additions and 122 deletions.
  1. +7 −0 .travis.yml
  2. BIN  Default-568h@2x.png
  3. +1 −1  README.md
  4. +179 −27 UGAPI/v2/UGConnection.h
  5. +649 −89 UGAPI/v2/UGConnection.m
  6. +2 −1  UGAPI/v2/UGHTTPResult.m
  7. +4 −0 UGAPIApp.xcodeproj/project.pbxproj
  8. +342 −0 samples/Books/books.xcodeproj/project.pbxproj
  9. +10 −0 samples/Books/books/AddBookViewController.h
  10. +152 −0 samples/Books/books/AddBookViewController.m
  11. +12 −0 samples/Books/books/AppDelegate.h
  12. +26 −0 samples/Books/books/AppDelegate.m
  13. +10 −0 samples/Books/books/BooksViewController.h
  14. +137 −0 samples/Books/books/BooksViewController.m
  15. BIN  samples/Books/books/Default-568h@2x.png
  16. BIN  samples/Books/books/Default.png
  17. BIN  samples/Books/books/Default@2x.png
  18. +9 −0 samples/Books/books/UGSignInViewController.h
  19. +167 −0 samples/Books/books/UGSignInViewController.m
  20. +45 −0 samples/Books/books/books-Info.plist
  21. +14 −0 samples/Books/books/books-Prefix.pch
  22. +2 −0  samples/Books/books/en.lproj/InfoPlist.strings
  23. +15 −0 samples/Books/books/main.m
  24. +487 −0 samples/Browser/browser.xcodeproj/project.pbxproj
  25. BIN  samples/Browser/browser/Default-568h@2x.png
  26. BIN  samples/Browser/browser/Default.png
  27. BIN  samples/Browser/browser/Default@2x.png
  28. +10 −0 samples/Browser/browser/UGAppDelegate.h
  29. +22 −0 samples/Browser/browser/UGAppDelegate.m
  30. +13 −0 samples/Browser/browser/UGAppViewController.h
  31. +126 −0 samples/Browser/browser/UGAppViewController.m
  32. +9 −0 samples/Browser/browser/UGCollectionViewController.h
  33. +98 −0 samples/Browser/browser/UGCollectionViewController.m
  34. +8 −0 samples/Browser/browser/UGEntityViewController.h
  35. +69 −0 samples/Browser/browser/UGEntityViewController.m
  36. +10 −0 samples/Browser/browser/UGSignInViewController.h
  37. +168 −0 samples/Browser/browser/UGSignInViewController.m
  38. +9 −0 samples/Browser/browser/UGTextViewController.h
  39. +26 −0 samples/Browser/browser/UGTextViewController.m
  40. +45 −0 samples/Browser/browser/browser-Info.plist
  41. +14 −0 samples/Browser/browser/browser-Prefix.pch
  42. +2 −0  samples/Browser/browser/en.lproj/InfoPlist.strings
  43. +13 −0 samples/Browser/browser/main.m
  44. +4,620 −0 samples/parties/Icon.ai
  45. +481 −0 samples/parties/parties.xcodeproj/project.pbxproj
  46. +14 −0 samples/parties/parties/AppDelegate.h
  47. +56 −0 samples/parties/parties/AppDelegate.m
  48. BIN  samples/parties/parties/Default-568h@2x.png
  49. BIN  samples/parties/parties/Default.png
  50. BIN  samples/parties/parties/Default@2x.png
  51. BIN  samples/parties/parties/Icon.png
  52. +12 −0 samples/parties/parties/PartiesViewController.h
  53. +224 −0 samples/parties/parties/PartiesViewController.m
  54. +12 −0 samples/parties/parties/PartyViewController.h
  55. +149 −0 samples/parties/parties/PartyViewController.m
  56. +2 −0  samples/parties/parties/en.lproj/InfoPlist.strings
  57. +18 −0 samples/parties/parties/main.m
  58. +45 −0 samples/parties/parties/parties-Info.plist
  59. +15 −0 samples/parties/parties/parties-Prefix.pch
  60. +4 −4 test/test_connection.nu
View
7 .travis.yml
@@ -0,0 +1,7 @@
+language: objective-c
+before_script:
+ - mkdir tmp
+ - cd tmp; git clone git://github.com/timburks/nu.git
+ - cd nu; make; ./mininush tools/nuke install
+ - cd ../..
+script: nuke test
View
BIN  Default-568h@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
2  README.md
@@ -78,7 +78,7 @@ To run the unit tests written for the SDK use the command `nuke test` this will
## Contributing
We welcome your enhancements!
-Like [Usergrid](https://github.com/apigee/usergrid-node-module), the Usergrid Javascript SDK is open source and licensed under the Apache License, Version 2.0.
+Like [Usergrid](https://github.com/apigee/usergrid-node-module), the Usergrid Objective-C SDK is open source and licensed under the Apache License, Version 2.0.
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
View
206 UGAPI/v2/UGConnection.h
@@ -11,24 +11,36 @@
@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
//
@@ -46,76 +58,216 @@
- (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 *) createOrganization:(NSDictionary *) organization;
+- (NSMutableURLRequest *) createOrganizationWithValues:(NSDictionary *) values;
-- (NSMutableURLRequest *) getOrganization;
+- (NSMutableURLRequest *) getOrganization:(NSString *) organizationIdentifier;
-- (NSMutableURLRequest *) createApplication:(NSDictionary *) application;
+- (NSMutableURLRequest *) activateOrganization:(NSString *) organizationIdentifier
+ withToken:(NSString *) token
+ sendingConfirmationEmail:(BOOL) sendingConfirmationEmail;
-- (NSMutableURLRequest *) deleteApplication;
+- (NSMutableURLRequest *) reactivateOrganization:(NSString *) organizationIdentifier;
-- (NSMutableURLRequest *) getApplicationsForOrganization;
+- (NSMutableURLRequest *) generateClientCredentialsForOrganization:(NSString *) organizationIdentifier;
-- (NSMutableURLRequest *) getApplication;
+- (NSMutableURLRequest *) getClientCredentialsForOrganization:(NSString *) organizationIdentifier;
-// Admin users http://apigee.com/docs/usergrid/content/admin-user
+- (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 *) createAdminUser:(NSDictionary *) organization;
+- (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 *) getDataForAssetWithUUID:(NSString *) uuid;
+- (NSMutableURLRequest *) getDataForAsset:(NSString *) assetIdentifier;
- (NSMutableURLRequest *) postData:(NSData *) data
- forAssetWithUUID:(NSString *) uuid;
+ forAsset:(NSString *) assetIdentifier;
-// General-purpose endpoints http://apigee.com/docs/usergrid/content/general-purpose-endpoints
+// Collections (aka 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 *) getEntity:(NSString *) entityIdentifier
+ inCollection:(NSString *) collection;
-- (NSMutableURLRequest *) updateEntityInCollection:(NSString *) collection
- withUUID:(NSString *) uuid
- newValues:(NSDictionary *) newValues;
+- (NSMutableURLRequest *) updateEntity:(NSString *) entityIdentifier
+ inCollection:(NSString *) collection
+ withValues:(NSDictionary *) values;
-- (NSMutableURLRequest *) deleteEntityInCollection:(NSString *) collection
- withUUID:(NSString *) uuid;
+- (NSMutableURLRequest *) deleteEntity:(NSString *) entityIdentifier
+ inCollection:(NSString *) collection;
- (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;
+ usingQuery:(NSDictionary *) query;
- (NSMutableURLRequest *) updateEntitiesInCollection:(NSString *) collection
- withQueryString:(NSString *) queryString
- newValues:(NSDictionary *) newValues;
+ usingQuery:(NSDictionary *) query
+ withValues:(NSDictionary *) values;
- (NSMutableURLRequest *) deleteEntitiesInCollection:(NSString *) collection;
- (NSMutableURLRequest *) deleteEntitiesInCollection:(NSString *) collection
- withQueryString:(NSString *) queryString;
+ 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
View
738 UGAPI/v2/UGConnection.m
@@ -9,6 +9,11 @@
#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;
@@ -32,6 +37,17 @@ - (id) init {
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
@@ -56,13 +72,40 @@ - (NSMutableURLRequest *) authorizedRequestWithMethod:(NSString *) method
#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;
- id expires = results[@"expires_in"];
self.token = results[@"access_token"];
+ id expires = results[@"expires_in"];
self.tokenExpirationDate = [NSDate dateWithTimeIntervalSinceNow:[expires intValue]];
return [self isAuthenticated];
}
@@ -82,114 +125,328 @@ - (BOOL) isAuthenticated
- (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];
+ 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];
+ 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];
+ 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];
+ 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 *) createOrganization:(NSDictionary *) organization
+- (NSMutableURLRequest *) createOrganizationWithValues:(NSDictionary *) values
{
- NSString *path = [NSString stringWithFormat:@"%@/management/organizations", self.server];
+ NSString *path = [NSString stringWithFormat:@"%@/management/organizations",
+ self.server];
return [self authorizedRequestWithMethod:@"POST"
path:path
- body:[organization URLQueryData]];
+ body:[values URLQueryData]];
}
-- (NSMutableURLRequest *) getOrganization
+- (NSMutableURLRequest *) getOrganization:(NSString *) organizationIdentifier
{
NSString *path = [NSString stringWithFormat:@"%@/management/organizations/%@",
- self.server, self.organization];
+ 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 *) createApplication:(NSDictionary *) application
+- (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,
- self.organization];
+ self.server, organizationIdentifier];
return [self authorizedRequestWithMethod:@"POST"
path:path
- body:[application URLQueryData]];
+ body:[values URLQueryData]];
}
-- (NSMutableURLRequest *) deleteApplication
+- (NSMutableURLRequest *) deleteApplication:(NSString *) applicationIdentifier
+ inOrganization:(NSString *)organizationIdentifier
{
+ NSString *path = [NSMutableString stringWithFormat:@"%@/management/organizations/%@/applications/%@",
+ self.server, organizationIdentifier, applicationIdentifier];
return [self authorizedRequestWithMethod:@"DELETE"
- path:self.root
+ 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 *) getApplication
+- (NSMutableURLRequest *) getClientCredentialsForApplication:(NSString *) applicationIdentifier
+ inOrganization:(NSString *) organizationIdentifier
{
+ NSString *path = [NSString stringWithFormat:@"%@/management/organizations/%@/applications/%@/credentials",
+ self.server, organizationIdentifier, applicationIdentifier];
return [self authorizedRequestWithMethod:@"GET"
- path:self.root
+ path:path
body:nil];
}
-- (NSMutableURLRequest *) getApplicationsForOrganization
+- (NSMutableURLRequest *) getApplicationsInOrganization:(NSString *) organizationIdentifier
{
NSString *path = [NSMutableString stringWithFormat:@"%@/management/organizations/%@/applications",
- self.server,
- self.organization];
+ self.server, organizationIdentifier];
return [self authorizedRequestWithMethod:@"GET"
path:path
body:nil];
}
-#pragma mark Admin users
-// http://apigee.com/docs/usergrid/content/admin-user
+- (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 *) createAdminUser:(NSDictionary *) user
+- (NSMutableURLRequest *) getAdminUsersInOrganization:(NSString *) organizationIdentifier
{
- NSString *path = [NSString stringWithFormat:@"%@/management/users", self.server];
- return [self authorizedRequestWithMethod:@"POST"
+ 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:[user URLQueryData]];
+ body:nil];
}
#pragma mark - Application API request generators -
@@ -197,13 +454,80 @@ - (NSMutableURLRequest *) createAdminUser:(NSDictionary *) user
#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 *) getDataForAssetWithUUID:(NSString *) uuid
+- (NSMutableURLRequest *) getDataForAsset:(NSString *) assetIdentifier
{
NSString *path = [NSMutableString stringWithFormat:@"%@/assets/%@/data",
- self.root,
- uuid];
+ self.root, assetIdentifier];
NSMutableURLRequest *request = [self authorizedRequestWithMethod:@"GET"
path:path
body:nil];
@@ -211,11 +535,11 @@ - (NSMutableURLRequest *) getDataForAssetWithUUID:(NSString *) uuid
}
- (NSMutableURLRequest *) postData:(NSData *) data
- forAssetWithUUID:(NSString *) uuid
+ forAsset:(NSString *) assetIdentifier
{
NSString *path = [NSMutableString stringWithFormat:@"%@/assets/%@/data",
self.root,
- uuid];
+ assetIdentifier];
NSMutableURLRequest *request = [self authorizedRequestWithMethod:@"POST"
path:path
body:data];
@@ -230,8 +554,7 @@ - (NSMutableURLRequest *) createEntityInCollection:(NSString *) collection
withValues:(NSDictionary *)values
{
NSString *path = [NSMutableString stringWithFormat:@"%@/%@",
- self.root,
- collection];
+ self.root, collection];
NSError *error;
NSData *data = [NSJSONSerialization dataWithJSONObject:values options:0 error:&error];
if (!data) {
@@ -242,24 +565,22 @@ - (NSMutableURLRequest *) createEntityInCollection:(NSString *) collection
body:data];
}
-- (NSMutableURLRequest *) getEntityInCollection:(NSString *)collection
- withUUID:(NSString *)uuid
+- (NSMutableURLRequest *) getEntity:(NSString *) entityIdentifier
+ inCollection:(NSString *) collection
{
NSString *path = [NSMutableString stringWithFormat:@"%@/%@/%@",
- self.root,
- collection,
- uuid];
+ self.root, collection, entityIdentifier];
return [self authorizedRequestWithMethod:@"GET"
path:path
body:nil];
}
-- (NSMutableURLRequest *) updateEntityInCollection:(NSString *) collection
- withUUID:(NSString *) uuid
- newValues:(NSDictionary *) newValues {
- NSString *path = [NSString stringWithFormat:@"%@/%@/%@", self.root, collection, uuid];
+- (NSMutableURLRequest *) updateEntity:(NSString *) entityIdentifier
+ inCollection:(NSString *) collection
+ withValues:(NSDictionary *) values {
+ NSString *path = [NSString stringWithFormat:@"%@/%@/%@", self.root, collection, entityIdentifier];
NSError *error;
- NSData *data = [NSJSONSerialization dataWithJSONObject:newValues options:0 error:&error];
+ NSData *data = [NSJSONSerialization dataWithJSONObject:values options:0 error:&error];
if (!data) {
NSLog(@"%@", error);
}
@@ -268,10 +589,10 @@ - (NSMutableURLRequest *) updateEntityInCollection:(NSString *) collection
body:data];
}
-- (NSMutableURLRequest *) deleteEntityInCollection:(NSString *) collection
- withUUID:(NSString *) uuid
+- (NSMutableURLRequest *) deleteEntity:(NSString *) entityIdentifier
+ inCollection:(NSString *) collection
{
- NSString *path = [NSString stringWithFormat:@"%@/%@/%@", self.root, collection, uuid];
+ NSString *path = [NSString stringWithFormat:@"%@/%@/%@", self.root, collection, entityIdentifier];
return [self authorizedRequestWithMethod:@"DELETE"
path:path
body:nil];
@@ -280,37 +601,18 @@ - (NSMutableURLRequest *) deleteEntityInCollection:(NSString *) collection
- (NSMutableURLRequest *) getEntitiesInCollection:(NSString *) collection
limit:(int) limit
{
+ NSDictionary *query = [self queryWithString:@"select *"
+ limit:limit
+ startUUID:nil
+ cursor:nil
+ reversed:NO];
return [self getEntitiesInCollection:collection
- withQueryString:@"select *"
- limit:limit
- startUUID:nil
- cursor:nil
- reversed:NO];
+ usingQuery:query];
}
- (NSMutableURLRequest *) getEntitiesInCollection:(NSString *) collection
- withQueryString:(NSString *) queryString
- limit:(int) limit
- startUUID:(NSString *) startUUID
- cursor:(NSString *) cursor
- reversed:(BOOL) reversed
+ usingQuery:(NSDictionary *) query
{
- 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";
- }
NSString *path = [NSMutableString stringWithFormat:@"%@/%@?%@",
self.root,
collection,
@@ -321,23 +623,32 @@ - (NSMutableURLRequest *) getEntitiesInCollection:(NSString *) collection
}
- (NSMutableURLRequest *) updateEntitiesInCollection:(NSString *) collection
- withQueryString:(NSString *) queryString
- newValues:(NSDictionary *) newValues
+ usingQuery:(NSDictionary *) query
+ withValues:(NSDictionary *) values
{
- assert(0); // todo
- return nil;
+ 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
- withQueryString:@"select *"];
+ usingQuery:query];
}
- (NSMutableURLRequest *) deleteEntitiesInCollection:(NSString *) collection
- withQueryString:(NSString *) queryString
+ usingQuery:(NSDictionary *) query
{
- NSDictionary *query = @{@"ql":queryString};
NSString *path = [NSString stringWithFormat:@"%@/%@?%@", self.root, collection, [query URLQueryString]];
return [self authorizedRequestWithMethod:@"DELETE"
path:path
@@ -350,13 +661,262 @@ - (NSMutableURLRequest *) deleteEntitiesInCollection:(NSString *) collection
#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
-@end
+- (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
View
3  UGAPI/v2/UGHTTPResult.m
@@ -13,7 +13,8 @@ @implementation UGHTTPResult
- (id) object {
if (!_object && !_error) {
NSError *error;
- _object = [NSJSONSerialization JSONObjectWithData:_data options:NSJSONReadingMutableLeaves error:&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]);
View
4 UGAPIApp.xcodeproj/project.pbxproj
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ 22CA67241732087600C03C70 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 22CA67231732087600C03C70 /* Default-568h@2x.png */; };
22D61E75171CBBF100E9CD17 /* UGConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 22D61E6E171CBBF100E9CD17 /* UGConnection.m */; };
22D61E76171CBBF100E9CD17 /* UGHTTPClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 22D61E70171CBBF100E9CD17 /* UGHTTPClient.m */; };
22D61E77171CBBF100E9CD17 /* UGHTTPHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 22D61E72171CBBF100E9CD17 /* UGHTTPHelpers.m */; };
@@ -58,6 +59,7 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
+ 22CA67231732087600C03C70 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
22D61E6D171CBBF100E9CD17 /* UGConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UGConnection.h; sourceTree = "<group>"; };
22D61E6E171CBBF100E9CD17 /* UGConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UGConnection.m; sourceTree = "<group>"; };
22D61E6F171CBBF100E9CD17 /* UGHTTPClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UGHTTPClient.h; sourceTree = "<group>"; };
@@ -172,6 +174,7 @@
E89D6C91150E5B2E005F5FB9 = {
isa = PBXGroup;
children = (
+ 22CA67231732087600C03C70 /* Default-568h@2x.png */,
E89D6D18150E5C54005F5FB9 /* CoreLocation.framework */,
E89D6CDC150E5B99005F5FB9 /* UGAPI */,
E89D6CA6150E5B2E005F5FB9 /* UGAPIApp */,
@@ -375,6 +378,7 @@
E89D6CAB150E5B2E005F5FB9 /* InfoPlist.strings in Resources */,
E89D6CB4150E5B2E005F5FB9 /* MainStoryboard_iPhone.storyboard in Resources */,
E89D6CB7150E5B2E005F5FB9 /* MainStoryboard_iPad.storyboard in Resources */,
+ 22CA67241732087600C03C70 /* Default-568h@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
342 samples/Books/books.xcodeproj/project.pbxproj
@@ -0,0 +1,342 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 46;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 224EA246170F6F63002B136A /* UGConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 224EA23F170F6F63002B136A /* UGConnection.m */; };
+ 224EA247170F6F63002B136A /* UGHTTPClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 224EA241170F6F63002B136A /* UGHTTPClient.m */; };
+ 224EA248170F6F63002B136A /* UGHTTPHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 224EA243170F6F63002B136A /* UGHTTPHelpers.m */; };
+ 224EA249170F6F63002B136A /* UGHTTPResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 224EA245170F6F63002B136A /* UGHTTPResult.m */; };
+ 227AE09F170DF424004F6E20 /* UGSignInViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 227AE09E170DF424004F6E20 /* UGSignInViewController.m */; };
+ 227AE0A2170E01CF004F6E20 /* AddBookViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 227AE0A1170E01CF004F6E20 /* AddBookViewController.m */; };
+ 228ADD73170DE2ED0030F962 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 228ADD72170DE2ED0030F962 /* UIKit.framework */; };
+ 228ADD75170DE2ED0030F962 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 228ADD74170DE2ED0030F962 /* Foundation.framework */; };
+ 228ADD77170DE2ED0030F962 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 228ADD76170DE2ED0030F962 /* CoreGraphics.framework */; };
+ 228ADD7D170DE2ED0030F962 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 228ADD7B170DE2ED0030F962 /* InfoPlist.strings */; };
+ 228ADD7F170DE2ED0030F962 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 228ADD7E170DE2ED0030F962 /* main.m */; };
+ 228ADD83170DE2ED0030F962 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 228ADD82170DE2ED0030F962 /* AppDelegate.m */; };
+ 228ADD85170DE2ED0030F962 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 228ADD84170DE2ED0030F962 /* Default.png */; };
+ 228ADD87170DE2ED0030F962 /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 228ADD86170DE2ED0030F962 /* Default@2x.png */; };
+ 228ADD89170DE2ED0030F962 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 228ADD88170DE2ED0030F962 /* Default-568h@2x.png */; };
+ 228ADD91170DE3170030F962 /* BooksViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 228ADD90170DE3170030F962 /* BooksViewController.m */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+ 224EA23E170F6F63002B136A /* UGConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UGConnection.h; sourceTree = "<group>"; };
+ 224EA23F170F6F63002B136A /* UGConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UGConnection.m; sourceTree = "<group>"; };
+ 224EA240170F6F63002B136A /* UGHTTPClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UGHTTPClient.h; sourceTree = "<group>"; };
+ 224EA241170F6F63002B136A /* UGHTTPClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UGHTTPClient.m; sourceTree = "<group>"; };
+ 224EA242170F6F63002B136A /* UGHTTPHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UGHTTPHelpers.h; sourceTree = "<group>"; };
+ 224EA243170F6F63002B136A /* UGHTTPHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UGHTTPHelpers.m; sourceTree = "<group>"; };
+ 224EA244170F6F63002B136A /* UGHTTPResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UGHTTPResult.h; sourceTree = "<group>"; };
+ 224EA245170F6F63002B136A /* UGHTTPResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UGHTTPResult.m; sourceTree = "<group>"; };
+ 227AE09D170DF424004F6E20 /* UGSignInViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UGSignInViewController.h; sourceTree = "<group>"; };
+ 227AE09E170DF424004F6E20 /* UGSignInViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UGSignInViewController.m; sourceTree = "<group>"; };
+ 227AE0A0170E01CF004F6E20 /* AddBookViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddBookViewController.h; sourceTree = "<group>"; };
+ 227AE0A1170E01CF004F6E20 /* AddBookViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AddBookViewController.m; sourceTree = "<group>"; };
+ 228ADD6F170DE2ED0030F962 /* books.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = books.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ 228ADD72170DE2ED0030F962 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
+ 228ADD74170DE2ED0030F962 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+ 228ADD76170DE2ED0030F962 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
+ 228ADD7A170DE2ED0030F962 /* books-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "books-Info.plist"; sourceTree = "<group>"; };
+ 228ADD7C170DE2ED0030F962 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+ 228ADD7E170DE2ED0030F962 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ 228ADD80170DE2ED0030F962 /* books-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "books-Prefix.pch"; sourceTree = "<group>"; };
+ 228ADD81170DE2ED0030F962 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
+ 228ADD82170DE2ED0030F962 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
+ 228ADD84170DE2ED0030F962 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = "<group>"; };
+ 228ADD86170DE2ED0030F962 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = "<group>"; };
+ 228ADD88170DE2ED0030F962 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
+ 228ADD8F170DE3170030F962 /* BooksViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BooksViewController.h; sourceTree = "<group>"; };
+ 228ADD90170DE3170030F962 /* BooksViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BooksViewController.m; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 228ADD6C170DE2ED0030F962 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 228ADD73170DE2ED0030F962 /* UIKit.framework in Frameworks */,
+ 228ADD75170DE2ED0030F962 /* Foundation.framework in Frameworks */,
+ 228ADD77170DE2ED0030F962 /* CoreGraphics.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 224EA23D170F6F63002B136A /* UGAPI */ = {
+ isa = PBXGroup;
+ children = (
+ 224EA23E170F6F63002B136A /* UGConnection.h */,
+ 224EA23F170F6F63002B136A /* UGConnection.m */,
+ 224EA240170F6F63002B136A /* UGHTTPClient.h */,
+ 224EA241170F6F63002B136A /* UGHTTPClient.m */,
+ 224EA242170F6F63002B136A /* UGHTTPHelpers.h */,
+ 224EA243170F6F63002B136A /* UGHTTPHelpers.m */,
+ 224EA244170F6F63002B136A /* UGHTTPResult.h */,
+ 224EA245170F6F63002B136A /* UGHTTPResult.m */,
+ );
+ name = UGAPI;
+ path = ../../UGAPI/v2;
+ sourceTree = "<group>";
+ };
+ 228ADD66170DE2ED0030F962 = {
+ isa = PBXGroup;
+ children = (
+ 224EA23D170F6F63002B136A /* UGAPI */,
+ 228ADD78170DE2ED0030F962 /* books */,
+ 228ADD79170DE2ED0030F962 /* Supporting Files */,
+ 228ADD71170DE2ED0030F962 /* Frameworks */,
+ 228ADD70170DE2ED0030F962 /* Products */,
+ );
+ sourceTree = "<group>";
+ };
+ 228ADD70170DE2ED0030F962 /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 228ADD6F170DE2ED0030F962 /* books.app */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ 228ADD71170DE2ED0030F962 /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 228ADD72170DE2ED0030F962 /* UIKit.framework */,
+ 228ADD74170DE2ED0030F962 /* Foundation.framework */,
+ 228ADD76170DE2ED0030F962 /* CoreGraphics.framework */,
+ );
+ name = Frameworks;
+ sourceTree = "<group>";
+ };
+ 228ADD78170DE2ED0030F962 /* books */ = {
+ isa = PBXGroup;
+ children = (
+ 228ADD81170DE2ED0030F962 /* AppDelegate.h */,
+ 228ADD82170DE2ED0030F962 /* AppDelegate.m */,
+ 228ADD8F170DE3170030F962 /* BooksViewController.h */,
+ 228ADD90170DE3170030F962 /* BooksViewController.m */,
+ 227AE09D170DF424004F6E20 /* UGSignInViewController.h */,
+ 227AE09E170DF424004F6E20 /* UGSignInViewController.m */,
+ 227AE0A0170E01CF004F6E20 /* AddBookViewController.h */,
+ 227AE0A1170E01CF004F6E20 /* AddBookViewController.m */,
+ );
+ path = books;
+ sourceTree = "<group>";
+ };
+ 228ADD79170DE2ED0030F962 /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ 228ADD7A170DE2ED0030F962 /* books-Info.plist */,
+ 228ADD7B170DE2ED0030F962 /* InfoPlist.strings */,
+ 228ADD7E170DE2ED0030F962 /* main.m */,
+ 228ADD80170DE2ED0030F962 /* books-Prefix.pch */,
+ 228ADD84170DE2ED0030F962 /* Default.png */,
+ 228ADD86170DE2ED0030F962 /* Default@2x.png */,
+ 228ADD88170DE2ED0030F962 /* Default-568h@2x.png */,
+ );
+ name = "Supporting Files";
+ path = books;
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ 228ADD6E170DE2ED0030F962 /* books */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 228ADD8C170DE2ED0030F962 /* Build configuration list for PBXNativeTarget "books" */;
+ buildPhases = (
+ 228ADD6B170DE2ED0030F962 /* Sources */,
+ 228ADD6C170DE2ED0030F962 /* Frameworks */,
+ 228ADD6D170DE2ED0030F962 /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = books;
+ productName = books;
+ productReference = 228ADD6F170DE2ED0030F962 /* books.app */;
+ productType = "com.apple.product-type.application";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 228ADD67170DE2ED0030F962 /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0460;
+ ORGANIZATIONNAME = Radtastical;
+ };
+ buildConfigurationList = 228ADD6A170DE2ED0030F962 /* Build configuration list for PBXProject "books" */;
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ );
+ mainGroup = 228ADD66170DE2ED0030F962;
+ productRefGroup = 228ADD70170DE2ED0030F962 /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 228ADD6E170DE2ED0030F962 /* books */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ 228ADD6D170DE2ED0030F962 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 228ADD7D170DE2ED0030F962 /* InfoPlist.strings in Resources */,
+ 228ADD85170DE2ED0030F962 /* Default.png in Resources */,
+ 228ADD87170DE2ED0030F962 /* Default@2x.png in Resources */,
+ 228ADD89170DE2ED0030F962 /* Default-568h@2x.png in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 228ADD6B170DE2ED0030F962 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 228ADD7F170DE2ED0030F962 /* main.m in Sources */,
+ 228ADD83170DE2ED0030F962 /* AppDelegate.m in Sources */,
+ 228ADD91170DE3170030F962 /* BooksViewController.m in Sources */,
+ 227AE09F170DF424004F6E20 /* UGSignInViewController.m in Sources */,
+ 227AE0A2170E01CF004F6E20 /* AddBookViewController.m in Sources */,
+ 224EA246170F6F63002B136A /* UGConnection.m in Sources */,
+ 224EA247170F6F63002B136A /* UGHTTPClient.m in Sources */,
+ 224EA248170F6F63002B136A /* UGHTTPHelpers.m in Sources */,
+ 224EA249170F6F63002B136A /* UGHTTPResult.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXVariantGroup section */
+ 228ADD7B170DE2ED0030F962 /* InfoPlist.strings */ = {
+ isa = PBXVariantGroup;
+ children = (
+ 228ADD7C170DE2ED0030F962 /* en */,
+ );
+ name = InfoPlist.strings;
+ sourceTree = "<group>";
+ };
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+ 228ADD8A170DE2ED0030F962 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ COPY_PHASE_STRIP = NO;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 6.1;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = iphoneos;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ };
+ name = Debug;
+ };
+ 228ADD8B170DE2ED0030F962 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ COPY_PHASE_STRIP = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 6.1;
+ OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
+ SDKROOT = iphoneos;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ VALIDATE_PRODUCT = YES;
+ };
+ name = Release;
+ };
+ 228ADD8D170DE2ED0030F962 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "books/books-Prefix.pch";
+ INFOPLIST_FILE = "books/books-Info.plist";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ WRAPPER_EXTENSION = app;
+ };
+ name = Debug;
+ };
+ 228ADD8E170DE2ED0030F962 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "books/books-Prefix.pch";
+ INFOPLIST_FILE = "books/books-Info.plist";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ WRAPPER_EXTENSION = app;
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 228ADD6A170DE2ED0030F962 /* Build configuration list for PBXProject "books" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 228ADD8A170DE2ED0030F962 /* Debug */,
+ 228ADD8B170DE2ED0030F962 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 228ADD8C170DE2ED0030F962 /* Build configuration list for PBXNativeTarget "books" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 228ADD8D170DE2ED0030F962 /* Debug */,
+ 228ADD8E170DE2ED0030F962 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 228ADD67170DE2ED0030F962 /* Project object */;
+}
View
10 samples/Books/books/AddBookViewController.h
@@ -0,0 +1,10 @@
+//
+// AddBookViewController.h
+// books
+//
+
+#import <UIKit/UIKit.h>
+
+@interface AddBookViewController : UITableViewController
+
+@end
View
152 samples/Books/books/AddBookViewController.m
@@ -0,0 +1,152 @@
+//
+// AddBookViewController.m
+// books
+//
+
+#import "AddBookViewController.h"
+#import "UGConnection.h"
+#import "UGHTTPClient.h"
+#import "UGHTTPResult.h"
+
+@interface FormTableViewCell : UITableViewCell <UITextFieldDelegate>
+@property (nonatomic, strong) UILabel *label;
+@property (nonatomic, strong) UITextField *textField;
+@property (nonatomic, strong) NSString *key;
+@property (nonatomic, weak) id binding;
+@end
+
+@implementation FormTableViewCell
+
+- (id) initWithTitle:(NSString *)title key:(NSString *) key binding:(id) binding
+{
+ if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]) {
+ self.label = [[UILabel alloc] initWithFrame:CGRectMake(10,0,90,14)];
+ self.label.backgroundColor = [UIColor clearColor];
+ self.label.font = [UIFont systemFontOfSize:10];
+ self.label.textColor = [UIColor grayColor];
+ self.label.textAlignment = NSTextAlignmentLeft;
+ [self.contentView addSubview:self.label];
+ self.textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 14, 100, 30)];
+ self.textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
+ self.textField.font = [UIFont systemFontOfSize:18];
+ self.textField.autocorrectionType = UITextAutocorrectionTypeNo;
+ self.textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
+ self.textField.delegate = self;
+ if ([key isEqualToString:@"password"]) {
+ self.textField.secureTextEntry = YES;
+ }
+ [self.contentView addSubview:self.textField];
+ self.selectionStyle = UITableViewCellSelectionStyleNone;
+ // individual cell properties
+ self.label.text = title;
+ self.key = key;
+ self.binding = binding;
+ }
+ return self;
+}
+
+- (void) layoutSubviews
+{
+ [super layoutSubviews];
+ CGRect textFieldFrame = self.textField.frame;
+ textFieldFrame.size.width = self.textField.superview.bounds.size.width - textFieldFrame.origin.x - 5;
+ self.textField.frame = textFieldFrame;
+}
+
+- (void) textFieldDidEndEditing:(UITextField *)textField
+{
+ [self.binding setObject:textField.text forKey:self.key];
+}
+
+@end
+
+@interface AddBookViewController ()
+@property (nonatomic, strong) NSMutableDictionary *values;
+@property (nonatomic, strong) NSArray *cells;
+@end
+
+@implementation AddBookViewController
+
+- (id)init {
+ if (self = [super initWithStyle:UITableViewStyleGrouped]) {
+ self.values = [[[NSUserDefaults standardUserDefaults] objectForKey:@"usergrid"] mutableCopy];
+ if (!self.values) {
+ self.values = [NSMutableDictionary dictionary];
+ }
+ self.cells =
+ @[[[FormTableViewCell alloc] initWithTitle:@"Title" key:@"title" binding:self.values],
+ [[FormTableViewCell alloc] initWithTitle:@"Author" key:@"author" binding:self.values]];
+ }
+ return self;
+}
+
+- (void) loadView
+{
+ [super loadView];
+ self.title = @"Connection";
+ self.tableView.backgroundView = nil;
+ self.tableView.backgroundColor = [UIColor darkGrayColor];
+ self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
+ initWithTitle:@"Cancel"
+ style:UIBarButtonItemStyleBordered
+ target:self
+ action:@selector(cancel:)];
+ self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
+ initWithTitle:@"Save"
+ style:UIBarButtonItemStyleBordered
+ target:self
+ action:@selector(save:)];
+}
+
+#pragma mark - Table view data source
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+ return 1;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+ return [self.cells count];
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ return [self.cells objectAtIndex:[indexPath row]];
+}
+
+#pragma mark - Table view delegate
+
+- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ FormTableViewCell *formCell = (FormTableViewCell *) cell;
+ formCell.textField.text = [formCell.binding objectForKey:formCell.key];
+}
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ FormTableViewCell *formCell = (FormTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
+ [formCell.textField becomeFirstResponder];
+}
+
+#pragma mark - Sign In
+
+- (void) cancel:(id) sender
+{
+ [self dismissViewControllerAnimated:YES completion:nil];
+}
+
+- (void) save:(id) sender
+{
+ for (FormTableViewCell *cell in self.cells) {
+ [cell.textField resignFirstResponder];
+ }
+ UGConnection *connection = [UGConnection sharedConnection];
+ [[[UGHTTPClient alloc] initWithRequest:
+ [connection createEntityInCollection:@"books" withValues:self.values]]
+ connectWithCompletionHandler:^(UGHTTPResult *result) {
+ [self dismissViewControllerAnimated:YES completion:nil];
+ }];
+}
+
+@end
View
12 samples/Books/books/AppDelegate.h
@@ -0,0 +1,12 @@
+//
+// AppDelegate.h
+// books
+//
+
+#import <UIKit/UIKit.h>
+
+@interface AppDelegate : UIResponder <UIApplicationDelegate>
+
+@property (strong, nonatomic) UIWindow *window;
+
+@end
View
26 samples/Books/books/AppDelegate.m
@@ -0,0 +1,26 @@
+//
+// AppDelegate.m
+// books
+//
+
+#import "AppDelegate.h"
+#import "BooksViewController.h"
+
+@implementation AppDelegate
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ UINavigationController *navigationController = [[UINavigationController alloc]
+ initWithRootViewController:[[BooksViewController alloc] init]];
+ navigationController.navigationBar.tintColor = [UIColor colorWithRed:100.0/255.0
+ green:150.0/255.0
+ blue:200.0/255.0
+ alpha:1];
+ self.window.rootViewController = navigationController;
+ self.window.backgroundColor = [UIColor whiteColor];
+ [self.window makeKeyAndVisible];
+ return YES;
+}
+
+@end
View
10 samples/Books/books/BooksViewController.h
@@ -0,0 +1,10 @@
+//
+// BooksViewController.h
+// books
+//
+
+#import <UIKit/UIKit.h>
+
+@interface BooksViewController : UITableViewController
+
+@end
View
137 samples/Books/books/BooksViewController.m
@@ -0,0 +1,137 @@
+//
+// BooksViewController.m
+// books
+//
+
+#import "BooksViewController.h"
+#import "UGSignInViewController.h"
+#import "UGConnection.h"
+#import "UGHTTPClient.h"
+#import "UGHTTPResult.h"
+#import "AddBookViewController.h"
+
+@interface BooksViewController ()
+@property (nonatomic, strong) NSDictionary *content;
+@end
+
+@implementation BooksViewController
+
+- (id)initWithStyle:(UITableViewStyle)style
+{
+ self = [super initWithStyle:style];
+ if (self) {
+ // Custom initialization
+ }
+ return self;
+}
+
+- (void)loadView
+{
+ [super loadView];
+ self.navigationItem.title = @"My Books";
+ self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Add Book"
+ style:UIBarButtonItemStyleBordered target:self action:@selector(addbook:)];
+ self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
+ initWithTitle:@"Connection"
+ style:UIBarButtonItemStyleBordered
+ target:self
+ action:@selector(connect:)];
+}
+
+- (void) connect:(id) sender
+{
+ UGSignInViewController *signinViewController = [[UGSignInViewController alloc] init];
+ UINavigationController *signinNavigationController =
+ [[UINavigationController alloc] initWithRootViewController:signinViewController];
+ signinNavigationController.modalPresentationStyle = UIModalPresentationFormSheet;
+ signinNavigationController.navigationBar.tintColor = self.navigationController.navigationBar.tintColor;
+ [self presentViewController:signinNavigationController animated:YES completion:nil];
+}
+
+- (void) addbook:(id) sender
+{
+ AddBookViewController *addBookViewController = [[AddBookViewController alloc] init];
+ UINavigationController *navigationController =
+ [[UINavigationController alloc] initWithRootViewController:addBookViewController];
+ navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
+ navigationController.navigationBar.tintColor = self.navigationController.navigationBar.tintColor;
+ [self presentViewController:navigationController animated:YES completion:nil];
+}
+
+- (void) viewWillAppear:(BOOL)animated
+{
+ [self reload];
+}
+
+- (void) reload {
+ UGConnection *usergrid = [UGConnection sharedConnection];
+ if ([usergrid isAuthenticated]) {
+ NSLog(@"loading...");
+ UGHTTPClient *client = [[UGHTTPClient alloc] initWithRequest:
+ [usergrid getEntitiesInCollection:@"books" limit:100]];
+ [client connectWithCompletionHandler:^(UGHTTPResult *result) {
+ NSLog(@"%@", result.object);
+ self.content = result.object;
+ [self.tableView reloadData];
+ }];
+ }
+}
+
+#pragma mark - Table view data source
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+ // Return the number of sections.
+ return 1;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+ // Return the number of rows in the section.
+ return self.content ? [self.content[@"entities"] count] : 1;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
+}
+
+#pragma mark - Table view delegate
+
+- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ if (!self.content) {
+ cell.textLabel.text = @"Please sign in.";
+ } else {
+ id entity = self.content[@"entities"][[indexPath row]];
+ cell.textLabel.text = entity[@"title"];
+ cell.detailTextLabel.text = entity[@"author"];
+ UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
+ cell.accessoryView = deleteButton;
+ [deleteButton setTitle:@"X" forState:UIControlStateNormal];
+ deleteButton.tag = [indexPath row];
+ [deleteButton addTarget:self action:@selector(deleteItem:) forControlEvents:UIControlEventTouchUpInside];
+ [deleteButton sizeToFit];
+ }
+ cell.selectionStyle = UITableViewCellSelectionStyleNone;
+}
+
+- (void) deleteItem:(UIButton *) sender {
+ int row = [sender tag];
+ id entity = self.content[@"entities"][row];
+ NSString *uuid = [entity objectForKey:@"uuid"];
+ UGHTTPClient *client = [[UGHTTPClient alloc] initWithRequest:
+ [[UGConnection sharedConnection] deleteEntity:uuid inCollection:@"books"]];
+ [client connectWithCompletionHandler:^(UGHTTPResult *result) {
+ [self reload];
+ }];
+}
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ if (!self.content) {
+ [self connect:nil];
+ }
+}
+
+@end
View
BIN  samples/Books/books/Default-568h@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  samples/Books/books/Default.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  samples/Books/books/Default@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
9 samples/Books/books/UGSignInViewController.h
@@ -0,0 +1,9 @@
+//
+// UGSignInViewController.h
+// books
+//
+
+@class UGAppViewController;
+
+@interface UGSignInViewController : UITableViewController
+@end
View
167 samples/Books/books/UGSignInViewController.m
@@ -0,0 +1,167 @@
+//
+// UGSignInViewController.m
+// books
+//
+
+
+#import "UGHTTPClient.h"
+#import "UGConnection.h"
+#import "UGSignInViewController.h"
+
+#define SERVER @"http://api.usergrid.com"
+
+@interface UGFormTableViewCell : UITableViewCell <UITextFieldDelegate>
+@property (nonatomic, strong) UILabel *label;
+@property (nonatomic, strong) UITextField *textField;
+@property (nonatomic, strong) NSString *key;
+@property (nonatomic, weak) id binding;
+@end
+
+@implementation UGFormTableViewCell
+
+- (id) initWithTitle:(NSString *)title key:(NSString *) key binding:(id) binding
+{
+ if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]) {
+ self.label = [[UILabel alloc] initWithFrame:CGRectMake(10,0,90,14)];
+ self.label.backgroundColor = [UIColor clearColor];
+ self.label.font = [UIFont systemFontOfSize:10];
+ self.label.textColor = [UIColor grayColor];
+ self.label.textAlignment = NSTextAlignmentLeft;
+ [self.contentView addSubview:self.label];
+ self.textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 14, 100, 30)];
+ self.textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
+ self.textField.font = [UIFont systemFontOfSize:18];
+ self.textField.autocorrectionType = UITextAutocorrectionTypeNo;
+ self.textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
+ self.textField.delegate = self;
+ if ([key isEqualToString:@"password"]) {
+ self.textField.secureTextEntry = YES;
+ }
+ [self.contentView addSubview:self.textField];
+ self.selectionStyle = UITableViewCellSelectionStyleNone;
+ // individual cell properties
+ self.label.text = title;
+ self.key = key;
+ self.binding = binding;
+ }
+ return self;
+}
+
+- (void) layoutSubviews
+{
+ [super layoutSubviews];
+ CGRect textFieldFrame = self.textField.frame;
+ textFieldFrame.size.width = self.textField.superview.bounds.size.width - textFieldFrame.origin.x - 5;
+ self.textField.frame = textFieldFrame;
+}
+
+- (void) textFieldDidEndEditing:(UITextField *)textField
+{
+ [self.binding setObject:textField.text forKey:self.key];
+}
+
+@end
+
+@interface UGSignInViewController ()
+@property (nonatomic, strong) NSMutableDictionary *values;
+@property (nonatomic, strong) NSArray *cells;
+@end
+
+@implementation UGSignInViewController
+
+- (id)init {
+ if (self = [super initWithStyle:UITableViewStyleGrouped]) {
+ self.values = [[[NSUserDefaults standardUserDefaults] objectForKey:@"usergrid"] mutableCopy];
+ if (!self.values) {
+ self.values = [NSMutableDictionary dictionary];
+ [self.values setObject:SERVER forKey:@"server"];
+ }
+ self.cells =
+ @[[[UGFormTableViewCell alloc] initWithTitle:@"Server" key:@"server" binding:self.values],
+ [[UGFormTableViewCell alloc] initWithTitle:@"Organization" key:@"organization" binding:self.values],
+ [[UGFormTableViewCell alloc] initWithTitle:@"Application" key:@"application" binding:self.values],
+ [[UGFormTableViewCell alloc] initWithTitle:@"Username" key:@"username" binding:self.values],
+ [[UGFormTableViewCell alloc] initWithTitle:@"Password" key:@"password" binding:self.values]];
+ }
+ return self;
+}
+
+- (void) loadView
+{
+ [super loadView];
+ self.title = @"Connection";
+ self.tableView.backgroundView = nil;
+ self.tableView.backgroundColor = [UIColor darkGrayColor];
+ self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
+ initWithTitle:@"Cancel"
+ style:UIBarButtonItemStyleBordered
+ target:self
+ action:@selector(cancel:)];
+ self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
+ initWithTitle:@"Sign In"
+ style:UIBarButtonItemStyleBordered
+ target:self
+ action:@selector(signin:)];
+}
+
+#pragma mark - Table view data source
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+ return 1;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+ return [self.cells count];
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ return [self.cells objectAtIndex:[indexPath row]];
+}
+
+#pragma mark - Table view delegate
+
+- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ UGFormTableViewCell *formCell = (UGFormTableViewCell *) cell;
+ formCell.textField.text = [formCell.binding objectForKey:formCell.key];
+}
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ UGFormTableViewCell *formCell = (UGFormTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
+ [formCell.textField becomeFirstResponder];
+}
+
+#pragma mark - Sign In
+
+- (void) cancel:(id) sender
+{
+ [self dismissViewControllerAnimated:YES completion:nil];