Kiwi: Simple BDD for iOS
Github
https://github.com/allending/Kiwi
Docs
https://github.com/allending/Kiwi/wiki
Screencast
http://nsscreencast.com/episodes/4-automated-testing-with-kiwi/play
Code sample
describe(@"Team", ^{
context(@"when newly created", ^{
it(@"should have a name", ^{
id team = [Team team];
[[team.name should] equal:@"Black Hawks"];
});
it(@"should have 11 players", ^{
id team = [Team team];
[[[team should] have:11] players];
});
});
});
xcode 4 storyboard resources
deploying a node.js project on cloudfoundry (mac osx)
If you don’t have your cloudfoundry credentials create here: www.cloudfoundry.com
I’ve run into a bug using Mac’s ruby. If you already use rvm and ruby 1.9.2, you can skip the first step. Found the bug solution here.
Setting up Ruby
Install rvm:
Add the following lines to ~/.bash_profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . “$HOME/.rvm/scripts/rvm”
Update your terminal env with source or open a new terminal
Now install ruby 1.9.2
$ rvm use 1.9.2
Configuring cloudfoundry
Install the vmc gem
Set the target
Login with your credentials… vmc will ask for your email and password.
Creating a simple express app
* You need Node.JS and NPM from now on
$ cd sample-project
$ express
Start your app to check its running:
Open http://localhost:3000 and see the Welcome to Express msg :)
Configuring your app to run on cloudfoundry
Install cloudfoundry module
Change your app.js to run locally and at the cloudfoundry
Require the cloudfoundry module
Go to the app.listen line at the end of the file and change to:
Create a file called package.json and put the used modules:
*jade is the view engine
”name”:”sample-app-bfuster”,
”version”: “0.0.1″,
”dependencies”: {
”express”:”",
”cloudfoundry”:”",
”jade”:”"
}
}
Bundle those modules into your project
Deploy your app
Console output:
Application Name: sample-app-bfuster
Application Deployed URL: ‘sample-app-bfuster.cloudfoundry.com’?
Detected a Node.js Application, is this correct? [Yn]: y
Memory Reservation [Default:64M] (64M, 128M, 256M, 512M or 1G)
Creating Application: OK
Would you like to bind any services to ‘sample-app-bfuster’? [yN]: n
Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (33K): OK
Push Status: OK
Staging Application: OK
Starting Application: OK
Running app: http://sample-app-bfuster.cloudfoundry.com
source: https://github.com/bfuster/cf-sample-app
Wesave, save money and help others save too!
Hi! I’ve been working hard on my first iphone app for the past year with some friends: Andre Gil, Beck Novaes and Eduardo Horvath.
We hope you enjoy and make use of it! Feel free to send us your feedback at team@wesaveapp.com!
Check it out! Wesave is a really cool app!
www.wesaveapp.com or you can install it right away on the AppStore
Video
Screenshots
uploading an image from iphone to appengine blobstore using vraptor
Its quite simple to do this. I will represent the back-end using vraptor, a really great mvc web framework.
Well, at first, you need to generate the upload URI, provided by GAE’s SDK. When you’re working with web forms, you can just call the BlobstoreService to create the Upload URI directly from your JSP, but this is not the case.
We will provide then a resource that will return an URI for the upload.
@Resource
@Path("/image")
public class ImageController {
private final BlobstoreSevice blobstoreSevice = BlobstoreServiceFactory.getBlobstoreService();
private final Result result;
public ImageController(Result result) {
this.result = result;
}
@Path("/createUploadURI")
public void uploadURI() {
String uploadURI = blobstoreService.createUploadUrl("/image/upload");
result.use(http()).body(uploadURI);
}
}
That’s enough to return the upload URI into the response body (we wont use json or xml at this time to simplify the post).
Just for the record, there’s an issue when running this at development server. Blobstore won’t return the URI with its host, although it will return the absolute URI when at production environment.
Lets consume this resource from iphone now using asihttp.
#import "ASIHTTPRequest.h"
//...
-(void) getUploadURI {
NSURL *uri = [NSURL URLWithString:@"http://yourserver.appspot.com/image/createUploadURI"]];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:uri];
[request setDelegate:self];
[request startAsynchronous];
}
-(void) requestFinished:(ASIHTTPRequest *)request {
NSString *uri = [request responseData];
}
-(void) requestFailed:(ASIHTTPRequest *)request {
NSError *error = [request error];
NSLog(@"error %@", error);
}
Now we have the URI to upload an image. Lets create a new objective-c class to handle the upload using asihttp form data (notice that we will also track the upload progress).
#import <Foundation/Foundation.h>
#import "ASIFormDataRequest.h"
@interface ImageUpload : NSObject {
ASIFormDataRequest *formData;
float progress;
}
@property (nonatomic, retain) ASIFormDataRequest *formData;
@property (nonatomic, assign) float progress;
-(id) initWithImage:(UIImage*)img uri:(NSString*)uri;
-(void) startUpload;
@end
And it’s implementation:
#import "ImageUpload.h"
@implementation ImageUpload
@synthesize formData, progress;
-(id) initWithImage:(UIImage*)img uri:(NSString*)uri {
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(img)];
self.formData = [[ASIFormDataRequest requestWithURL:[NSURL URLWithString:uri]] retain];
[self.formData setData:imageData withFileName:@"defaultImage.png" andContentType:@"image/png" forKey:@"defaultImage"];
[self.formData setDelegate:self];
[self.formData setUploadProgressDelegate:self];
return self;
}
-(void) startUpload {
[self.formData startAsynchronous];
}
#pragma mark Upload Progress Tracking
- (void)request:(ASIHTTPRequest *)theRequest didSendBytes:(long long)newLength {
if ([theRequest totalBytesSent] > 0) {
float progressAmount = (float) ([theRequest totalBytesSent]/[theRequest postLength]);
self.progress = progressAmount;
}
}
-(void) requestFinished:(ASIHTTPRequest *)request {
NSLog(@"upload finished");
}
-(void) requestFailed:(ASIHTTPRequest *)request {
NSError *error = [request error];
NSLog(@"error %@", error);
}
- (void) dealloc
{
[self.formData release];
[super dealloc];
}
@end
Let’s change the requestFinished: method for /image/getUploadURI to start the upload after its response is done.
#import "ImageUpload.h"
//...
-(void) requestFinished:(ASIHTTPRequest *)request {
ImageUpload *imageUpload = [[ImageUpload alloc] initWithImage:self.imageView.image uri:[request responseData]];
[imageUpload startUpload];
}
If you want to track the progress at this view, you can create your own delegate like [imageUpload setUploadTrackingProgress:self] or expose the asihttp method setUploadProgressDelegate:.
At last we will create the resource that Blobstore will call on your server after the upload has been completed. You can now use the Images Service to get an URI for this image and store it.
@Path("/upload")
public void upload() {
Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(request);
BlobKey blob = blobs.get("defaultImage");
ImagesService imagesService = ImagesServiceFactory.getImagesService();
String imageUrl = imagesService.getServingUrl(blob);
/* datastore.put(imageurl) */
result.use(Results.http()).body(imageUrl);
}
We just need to inject the current HttpServletRequest for the BlobstoreService like this:
@Resource
@Path("/image")
public class ImageController {
private final BlobstoreSevice blobstoreSevice = BlobstoreServiceFactory.getBlobstoreService();
private final HttpServletRequest request;
private final Result result;
public ImageController(Result result, HttpServletRequest request) {
this.result = result;
this.request = request;
}
...
References:
vraptor
asihttp
Blobstore Service
Images Service
http://ikaisays.com/2010/09/08/gwt-blobstore-the-new…
restfulie-objectivec simple post, http response codes and basic auth
Now restfulie-objectivec is using by default ASIHTTP. Its too coupled by now, but I’m working on this and you will be able to extend it and use any http lib.
You can now call a simple http post method, without a payload. I’m working on the JSON marshaller and it will be ready soon.
Response *response = [[[client at:@"http://localhost:8888/login"] authUser:@"login" andPassword:@"passwd"] post];
if (response.code == 200) {
NSLog(@"login success");
} else {
NSLog(@"login fail");
}
Restfulie Objective-C startup
Restfulie-ObjectiveC development has begun. We’re open for ObjC developers who might be interested to collaborate!
By now you can call HTTP Get methods and marshall JSON responses into objects.
For instance, a custom RestClient can be created using Restfulie’s class method customWithTypes:andCollectionNames:
id<RestClient> client = [Restfulie customWithTypes:[NSArray arrayWithObjects:[User class], nil]
andCollectionNames:[NSArray arrayWithObjects:@"users", nil]];
Response *response = [[client at:@"http://localhost:8888/users"] get];
NSArray *users = [response resource];
//or a simple user
Response *response = [[client at:@"http://localhost:8888/users/1"] get];
User *user = [response resource];
I’m refactoring the entire project to design it as closer as possible to other Restfulie’s client implementations, so it might change a lot.
If you’d like to collaborate, send me an email: brunofuster@gmail.com
I will keep you posted through this blog explaining the lastest changes and the features that are being implemented at the moment.
uploading an image from iphone to Amazon S3 with UIImagePicker and ASIHTTP
Just organizing and spreading some ideas and tools ;)
Let’s start creating an UIViewController subclass that will attend to UIImagePickerControllerDelegate protocol, so your iphone user can choose an image to upload:
UploadViewController.h
@interface UploadViewController : UIViewController <UIImagePickerControllerDelegate> {
IBOutlet UIImageView *selectedImage;
IBOutlet UIButton *selectImageButton;
IBOutlet UIButton *uploadImageButton;
UIImagePickerController *imagePicker;
}
@property (nonatomic, retain) IBOutlet UIImageView *selectedImage;
@property (nonatomic, retain) IBOutlet UIButton *selectImageButton;
@property (nonatomic, retain) IBOutlet UIButton *uploadImageButton;
@property (nonatomic, retain) UIImagePickerController *imagePicker;
- (IBAction) showImagePicker:(id) sender;
- (IBAction) uploadImage:(id) sender;
- (void) uploadToAS3Job;
#pragma mark UIImagePickerControllerDelegate methods
- (void) imagePickerController:(UIImagePickerController *) picker
didFinishPickingImage:(UIImage *) image
editingInfo:(NSDictionary *) editingInfo;
- (void) imagePickerControllerDidCancel:(UIImagePickerController *) picker;
@end
This view has an ImageView and two buttons: selectImage and uploadImage. You have to create and connect them through IB (except imagePicker) or create them programatically, its your call.
There are also two IBAction methods (showImagePicker and uploadImage). You have to connect their respective buttons using “touch down” event.
Now lets code the implementation:
Ps: Import ASIHTTPRequest into your project.
UploadViewController.m
#import "UploadViewController.h"
#import "ASIS3Request.h"
@implementation UploadViewController
@synthesize selectedImage;
@synthesize selectImageButton;
@synthesize uploadImageButton;
@synthesize imagePicker;
//create UIImagePickerController when this view has loaded
-(void) viewDidLoad {
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.allowsImageEditing = YES;
self.imagePicker.delegate = self;
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
//show a modal view with the image picker
-(IBAction) showImagePicker {
[self presentModalViewController:self.imagePicker animated:YES];
}
#pragma mark UIImagePickerControllerDelegate
//callback method when an image has been selected
- (void) imagePickerController:(UIImagePickerController *) picker
didFinishPickingImage:(UIImage *) image
editingInfo:(NSDictionary *) editingInfo {
selectedImage.image = image;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
//callback method when the user cancels the selection
- (void) imagePickerControllerDidCancel:(UIImagePickerController *) picker {
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
//upload image action, will run a task in background
- (IBAction) uploadImage:(id) sender {
if (self.selectedImage != nil) {
[self performSelectorInBackground:@selector(uploadToAS3Job) withObject:nil];
}
}
//upload in background (just a sample, you should use NSOperationQueue)
- (void) uploadToAS3Job {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[ASIS3Request setSharedSecretAccessKey:@"my-secret-access-key"];
[ASIS3Request setSharedAccessKey:@"my-access-key"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(self.selectedImage)];
ASIS3ObjectRequest *request =
[ASIS3ObjectRequest PUTRequestForData:imageData withBucket:@"bucket" key:@"images/path"];
[request setShouldCompressRequestBody:YES]; //gzip compression
[request startSynchronous];
if ([request error]) {
NSLog(@"%@",[[request error] localizedDescription]);
}
[pool release];
}
- (void) dealloc {
[imagePicker release];
[selectedImage release];
[selectImageButton release];
[uploadImageButton release];
[super dealloc];
}
@end
Security issues will be discussed in a new post.
References:
http://www.zimbio.com/iPhone/articles…
http://developer.apple.com/library/…UIImagePickerController.html
http://iphone.zcentric.com/…/using-a-uiimagepickercontroller/
http://iphone.zcentric.com/…/post-a-uiimage-to-the-web/
http://allseeing-i.com/ASIHTTPRequest/S3
http://stackoverflow.com/questions/1754184/amazon-s3-post-upload-from-iphone
http://docs.amazonwebservices.com/AmazonS3/2006-03-01/dev/index.html?UsingHTTPPOST.html
http://stackoverflow.com/questions/1053944/uploading-to-amazon-s3-services-from-iphone-app
http://developer.apple.com/library/ios/…UIImage_Class
http://blog.objectgraph.com/…/download-an-image…
http://developer.apple.com/library/mac/…NSData_Class
javageomodel with objectify
GeoModel is an useful project (originally in python) ported to java which aims to make your life easier when you want to search near by coordinates in maps using bigtable as storage.
The only thing is that javageomodel is too coupled with JPA/JDO and I want to use Objectify. Well, there’s too much code that can be refactored, but this simple change satisfied my needs:
proximityFetch #old
List<T> proximityFetch(Point center, int maxResults, double maxDistance, Class<T> entityClass, GeocellQuery baseQuery, PersistenceManager pm)
proximityFetch #new
List<T> proximityFetch(Point center, int maxResults, double maxDistance, LocationCapableRepositorySearch<T> repositorySearch)
If you want to search over your LocationCapable entities, you should give a LocationCapableRepositorySearch<T> for javageomodel (ofy sample):
public class OfyEntityLocationCapableRepositorySearchImpl implements
LocationCapableRepositorySearch<Entity> {
private Objectify ofy;
public EntityLocationCapableRepositorySearchImpl(Objectify ofy) {
this.ofy = ofy;
}
@Override
public List<Entity> search(List<String> geocells) {
return ofy.query(Entity.class)
.filter("coordinates.geocells in ", geocells).list();
}
}
You might be looking for GeocellQuery. You could just change your LocationCapableRepositorySearch constructor waiting for a query and add some new filters to your search.
Now an Objectify proximity search looks like:
LocationCapableRepositorySearch<Entity> ofySearch =
new OfyEntityLocationCapableRepositorySearchImpl(ofy);
List<Entity> entities = GeocellManager.proximityFetch(center, 20, 1000, ofySearch);
and I’ve created a JPALocationCapableRepositorySearchImpl for JPA searches:
LocationCapableRepositorySearch<Entity> jpaSearch =
new JPALocationCapableRepositorySearchImpl<Entity>(baseQuery, pm, Entity.class);
List<Entity> entities = GeocellManager.proximityFetch(center, 40, 1000, jpaSearch);
You can find the new source at http://github.com/bfuster/javageomodel
to read list
just hope to finish them all ;)
update: the appengine and scala book are great, not that i’ve finished yet…










