Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Can follow people, UGClientApiUrl includes app name, some better look…

…ing message board
  • Loading branch information...
commit 03358a7f4ff736d4f385e07003d279d1e2cb9b5c 1 parent 60c6fea
Ernesto Vargas authored
View
6 Messagee.xcodeproj/project.pbxproj
@@ -27,6 +27,7 @@
9474287A14E7A1EB00BD402C /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 9474287914E7A1EB00BD402C /* Default@2x.png */; };
947A5D7814E860B200B2F426 /* UGUser.m in Sources */ = {isa = PBXBuildFile; fileRef = 947A5D7714E860B200B2F426 /* UGUser.m */; };
947A5D7B14E860D500B2F426 /* UGActivitie.m in Sources */ = {isa = PBXBuildFile; fileRef = 947A5D7A14E860D500B2F426 /* UGActivitie.m */; };
+ 94871D5214ED906100C4785A /* UGActor.m in Sources */ = {isa = PBXBuildFile; fileRef = 94871D5114ED906100C4785A /* UGActor.m */; };
94F5F03314E5659100E1ED55 /* libRestKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 94F5F02914E5650000E1ED55 /* libRestKit.a */; };
94F5F03A14E565E600E1ED55 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 94F5F03414E565E600E1ED55 /* CFNetwork.framework */; };
94F5F03B14E565E600E1ED55 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 94F5F03514E565E600E1ED55 /* CoreData.framework */; };
@@ -124,6 +125,8 @@
947A5D7714E860B200B2F426 /* UGUser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UGUser.m; path = Usergrid/UGUser.m; sourceTree = "<group>"; };
947A5D7914E860D500B2F426 /* UGActivitie.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UGActivitie.h; sourceTree = "<group>"; };
947A5D7A14E860D500B2F426 /* UGActivitie.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UGActivitie.m; sourceTree = "<group>"; };
+ 94871D5014ED906100C4785A /* UGActor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UGActor.h; path = Usergrid/UGActor.h; sourceTree = "<group>"; };
+ 94871D5114ED906100C4785A /* UGActor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UGActor.m; path = Usergrid/UGActor.m; sourceTree = "<group>"; };
94F5F01E14E5650000E1ED55 /* RestKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RestKit.xcodeproj; path = RestKit/RestKit.xcodeproj; sourceTree = "<group>"; };
94F5F03414E565E600E1ED55 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
94F5F03514E565E600E1ED55 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
@@ -266,6 +269,8 @@
947A5D7714E860B200B2F426 /* UGUser.m */,
947A5D7914E860D500B2F426 /* UGActivitie.h */,
947A5D7A14E860D500B2F426 /* UGActivitie.m */,
+ 94871D5014ED906100C4785A /* UGActor.h */,
+ 94871D5114ED906100C4785A /* UGActor.m */,
);
name = Usergrid;
sourceTree = "<group>";
@@ -434,6 +439,7 @@
947A5D7B14E860D500B2F426 /* UGActivitie.m in Sources */,
9448BDB314EA1EC400689915 /* ServerViewController.m in Sources */,
9448BDB614EA1FD300689915 /* RegisterViewController.m in Sources */,
+ 94871D5214ED906100C4785A /* UGActor.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
BIN  ...odeproj/project.xcworkspace/xcuserdata/ernesto.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown
View
10 Messagee.xcodeproj/xcuserdata/ernesto.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
@@ -9,13 +9,13 @@
continueAfterRunningActions = "No"
isPathRelative = "1"
filePath = "Messagee/LoginViewController.m"
- timestampString = "351028395.849619"
+ timestampString = "351126327.050673"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "199"
- endingLineNumber = "199"
- landmarkName = "-request:didLoadResponse:"
- landmarkType = "5">
+ startingLineNumber = "220"
+ endingLineNumber = "220"
+ landmarkName = "@implementation LoginViewController"
+ landmarkType = "3">
</FileBreakpoint>
</FileBreakpoints>
</Bucket>
View
5 Messagee/AppDelegate.m
@@ -15,9 +15,8 @@ @implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
- // Usergrid Settings
- [[UGClient sharedInstance] UGClientApiUrl:@"http://apigee-test.usergrid.com"];//Usergid Server
- [[UGClient sharedInstance] setUsergridApp:@"Messagee"];//Usergrid Appname
+ // Usergrid default server url
+ [[UGClient sharedInstance] UGClientApiUrl:@"http://api.usergrid.com/Messagee"];//Usergid Server
// UsergridKey and UsergidSecret are obtained
// from the app settings http://http://apigee.github.com/usergrid-portal-internal/
View
9 Messagee/LoginViewController.m
@@ -16,18 +16,17 @@ @implementation LoginViewController
@synthesize passwordTextField;
- (void)authorizeUser:(NSString *)username withPassword:(NSString *)password {
- // GET access token and map user data
- //from: /<App>/token?grand_type=password&username=<username>&password=<password>
-
+ // GET access token and map user data
RKObjectMapping* userMapping = [RKObjectMapping mappingForClass:[UGUser class]];
[userMapping mapKeyPath:@"username" toAttribute:@"username"];
[userMapping mapKeyPath:@"email" toAttribute:@"email"];
[userMapping mapKeyPath:@"picture" toAttribute:@"picture"];
[[RKObjectManager sharedManager].mappingProvider setMapping:userMapping forKeyPath:@"user"];
+ // From: token?grand_type=password&username=<username>&password=<password>
[[RKObjectManager sharedManager]
- loadObjectsAtResourcePath:[NSString stringWithFormat:@"%@/token?grant_type=password&username=%@&password=%@",
- [[UGClient sharedInstance] usergridApp], username, password]
+ loadObjectsAtResourcePath:[NSString stringWithFormat:@"token?grant_type=password&username=%@&password=%@",
+ username, password]
delegate:self];
}
View
1  Messagee/MessageViewController.h
@@ -10,6 +10,7 @@
#import "UGActivitie.h"
#import "UGClient.h"
#import "UGUser.h"
+#import "UGActor.h"
@interface MessageViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, RKObjectLoaderDelegate> {
UITableView *_tableView;
View
44 Messagee/MessageViewController.m
@@ -21,16 +21,11 @@ - (void)didReceiveMemoryWarning
#pragma mark - View lifecycle
- (void)loadMessageBoard {
- // Message Maping
- RKObjectMapping* userMapping = [RKObjectMapping mappingForClass:[UGActivitie class]];
- [userMapping mapKeyPath:@"content" toAttribute:@"content"];
- [userMapping mapKeyPath:@"type" toAttribute:@"type"];
- [[RKObjectManager sharedManager].mappingProvider setMapping:userMapping forKeyPath:@"entities"];
-
// Request user feed
- [[RKObjectManager sharedManager]
- loadObjectsAtResourcePath:[NSString stringWithFormat:@"%@/user/%@/feed?limit=20",
- [[UGClient sharedInstance] usergridApp], [[UGUser sharedInstance] username]]
+ // GET feed from users/<username>/feed?limit=30
+ [[RKObjectManager sharedManager]
+ loadObjectsAtResourcePath:[NSString stringWithFormat:@"user/%@/feed?limit=30",
+ [[UGUser sharedInstance] username]]
delegate:self];
}
@@ -51,6 +46,19 @@ - (void)viewDidLoad
[self.scrollView addSubview:_tableView];
[self loadMessageBoard];
+
+ // Message Mapping
+ RKObjectMapping* actorMapping = [RKObjectMapping mappingForClass:[UGActor class]];
+ [actorMapping mapAttributes:@"displayName", @"picture", nil];
+
+ RKObjectMapping* messageMapping = [RKObjectMapping mappingForClass:[UGActivitie class]];
+ [messageMapping mapKeyPath:@"content" toAttribute:@"content"];
+ [messageMapping mapKeyPath:@"type" toAttribute:@"type"];
+
+ [messageMapping mapKeyPath:@"actor" toRelationship:@"actor" withMapping:actorMapping];
+
+ [[RKObjectManager sharedManager].mappingProvider setMapping:messageMapping forKeyPath:@"entities"];
+
// Load message board every 5 seconds
[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(loadMessageBoard) userInfo:NULL repeats:YES];
}
@@ -90,10 +98,9 @@ - (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {
}
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
- [self.scrollView setContentSize:CGSizeMake(320, [_tableView contentSize].height)];
_statuses = objects;
[_tableView reloadData];
-
+
}
- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error {
@@ -106,7 +113,7 @@ - (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)er
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGSize size = [[[_statuses objectAtIndex:indexPath.row] content] sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(300, 9000)];
- return size.height + 10;
+ return size.height + 40;
}
#pragma mark UITableViewDataSource methods
@@ -119,15 +126,20 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
NSString* reuseIdentifier = @"Cell Identifier";
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (nil == cell) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
+ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:12];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.numberOfLines = 0;
cell.textLabel.backgroundColor = [UIColor clearColor];
- //cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"listbg.png"]];
+ cell.detailTextLabel.font = [UIFont fontWithName:@"Helvetica" size:16];
+ cell.detailTextLabel.textColor = [UIColor whiteColor];
}
- cell.textLabel.text = [[_statuses objectAtIndex:indexPath.row] content];
+ NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:[NSString stringWithFormat:@"%@", [[[_statuses objectAtIndex:indexPath.row] actor] picture] ]]];
+ cell.imageView.image = [UIImage imageWithData: imageData];
+ //cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"listbg.png"]];
+ cell.textLabel.text = [[[_statuses objectAtIndex:indexPath.row] actor] displayName];
+ cell.detailTextLabel.text = [[_statuses objectAtIndex:indexPath.row] content];
return cell;
}
-@end
+@end
View
4 Messagee/NewMessageViewController.m
@@ -81,8 +81,8 @@ - (IBAction)postMessage:(id)sender {
NSString *json = [parser stringFromObject:rpcData error:&error];
if (!error){
- // POST json message to: /<app_name>/user/<username>/activities/
- [[[RKClient sharedClient] post:[NSString stringWithFormat:@"/%@/user/%@/activities/", [[UGClient sharedInstance] usergridApp], [[UGUser sharedInstance] username]]
+ // POST json message to: /user/<username>/activities/
+ [[[RKClient sharedClient] post:[NSString stringWithFormat:@"user/%@/activities/", [[UGUser sharedInstance] username]]
params:[RKRequestSerialization serializationWithData:[json dataUsingEncoding:NSUTF8StringEncoding] MIMEType:RKMIMETypeJSON]
delegate:self] send];
}
View
6 Messagee/PeopleViewController.h
@@ -7,8 +7,12 @@
//
#import <UIKit/UIKit.h>
+#import <RestKit/RestKit.h>
+#import <RestKit/RKRequestSerialization.h>
+#import "UGUser.h"
-@interface PeopleViewController : UIViewController
+@interface PeopleViewController : UIViewController <RKRequestDelegate>{
+}
@property (weak, nonatomic) IBOutlet UITextField *usernameTextField;
View
35 Messagee/PeopleViewController.m
@@ -54,7 +54,18 @@ - (void)viewDidDisappear:(BOOL)animated
}
- (IBAction)addPeople:(id)sender {
- NSLog(@"Add people Action");
+ // Parsing rpcData to JSON!
+ NSMutableDictionary *rpcData = [[NSMutableDictionary alloc] init ];
+
+ id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:RKMIMETypeJSON];
+ NSError *error = nil;
+ NSString *json = [parser stringFromObject:rpcData error:&error];
+
+ //POST json new follower blank parameters
+ [[[RKClient sharedClient] post:[NSString stringWithFormat:@"users/%@/following/user/%@",
+ [[UGUser sharedInstance] username], [usernameTextField text]]
+ params:[RKRequestSerialization serializationWithData:[json dataUsingEncoding:NSUTF8StringEncoding] MIMEType:RKMIMETypeJSON]
+ delegate:self] send];
}
- (void)textFieldDidBeginEditing:(UITextField *)textFieldView {
@@ -67,4 +78,26 @@ - (void)hideKeyboard:(UITapGestureRecognizer *)sender {
[usernameTextField resignFirstResponder];
}
+
+- (void)requestDidStartLoad:(RKRequest *)request {
+ //NSLog(@"Request did start load %@", request.params);
+}
+
+- (void)request:(RKRequest *)request didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite {
+ //NSLog(@"Request did send body data: %@", request.HTTPBody);
+}
+
+- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response {
+ if ((response.isOK)&&(response.isJSON)) {
+ NSLog(@"json: %@", [response parsedBody:nil]);
+ //TODO: Show a success message for following new user
+ } else {
+ RKLogCritical(@"Loading of RKRequest %@ completed with status code %d. Response body: %@", request, response.statusCode, [response bodyAsString]);
+ }
+}
+
+- (void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error {
+ NSLog(@"Did Fail Load with error %@", error);
+}
+
@end
View
2  Messagee/RegisterViewController.m
@@ -78,7 +78,7 @@ - (IBAction)registerButton:(id)sender {
NSString *json = [parser stringFromObject:params error:&error];
if (!error){
- [[[RKClient sharedClient] post:@"/Messagee/users?"
+ [[[RKClient sharedClient] post:@"users"
params:[RKRequestSerialization serializationWithData:[json dataUsingEncoding:NSUTF8StringEncoding] MIMEType:RKMIMETypeJSON]
delegate:self] send];
}
View
3  Messagee/UGActivitie.h
@@ -8,13 +8,16 @@
#import <Foundation/Foundation.h>
#import <RestKit/RestKit.h>
+#import "UGActor.h"
@interface UGActivitie : NSObject {
NSString *_content;
NSString *_type;
+ UGActor *_actor;
}
@property (nonatomic, retain) NSString *content;
@property (nonatomic, retain) NSString *type;
+@property (nonatomic, retain) UGActor *actor;
@end
View
1  Messagee/UGActivitie.m
@@ -12,5 +12,6 @@ @implementation UGActivitie
@synthesize content = _content;
@synthesize type = _type;
+@synthesize actor = _actor;
@end
View
2  Messagee/UGClient.h
@@ -12,7 +12,6 @@
@interface UGClient: NSObject <RKRequestDelegate> {
NSString *usergridApiUrl;
- NSString *usergridApp;
NSString *usergridKey;
NSString *usergridSecret;
@@ -24,7 +23,6 @@
}
@property(nonatomic, strong) NSString *usergridApiUrl;
-@property(nonatomic, strong) NSString *usergridApp;
@property(nonatomic, strong) NSString *usergridKey;
@property(nonatomic, strong) NSString *usergridSecret;
View
5 Messagee/UGClient.m
@@ -12,7 +12,6 @@
@implementation UGClient
@synthesize usergridApiUrl = _usergridApiUrl;
-@synthesize usergridApp = _usergridApp;
@synthesize usergridKey = _usergridKey;
@synthesize usergridSecret = _usergridSecret;
@@ -51,8 +50,8 @@ - (void)UGClientAccessToken:(NSString *)accessToken {
- (void)requestClientCredentials {
[RKClient sharedClient].baseURL = [self usergridApiUrl];
[[RKClient sharedClient]
- get:[NSString stringWithFormat:@"%@/token?grant_type=client_credentials&client_id=%@&client_secret=%@",
- self.usergridApp, self.usergridKey, self.usergridSecret]
+ get:[NSString stringWithFormat:@"token?grant_type=client_credentials&client_id=%@&client_secret=%@",
+ self.usergridKey, self.usergridSecret]
delegate:self];
}
View
19 Messagee/Usergrid/UGActor.h
@@ -0,0 +1,19 @@
+//
+// UGActor.h
+// Messagee
+//
+// Created by Ernesto Vargas on 2/16/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface UGActor : NSObject {
+ NSString* _displayName;
+ NSString* _picture;
+}
+
+@property (nonatomic, retain) NSString* displayName;
+@property (nonatomic, retain) NSString* picture;
+
+@end
View
15 Messagee/Usergrid/UGActor.m
@@ -0,0 +1,15 @@
+//
+// UGActor.m
+// Messagee
+//
+// Created by Ernesto Vargas on 2/16/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import "UGActor.h"
+
+@implementation UGActor
+
+@synthesize displayName = _displayName;
+@synthesize picture = _picture;
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.