Code Monkey home page Code Monkey logo

seriously's Introduction

Seriously

The iPhone needs a better way to make HTTP requests, specifically calls to REST web services. Seriously mixes Blocks with NSURLConnection & NSOperationQueue to do just that. It also will automatically parse the JSON response into a dictionary if the response headers are set correctly.

Install

Just drag the files from the "src" directory into your project. You can also try using the included "Seriously.framework" file

Parse JSON EXAMPLE

NSString *url = @"http://api.twitter.com/1/users/show.json?screen_name=probablycorey";

[Seriously get:url handler:^(id body, NSHTTPURLResponse *response, NSError *error) {
    if (error) {
        NSLog(@"Error: %@", error);
    }
    else {
        NSLog(@"Look, JSON is parsed into a dictionary!");
        NSLog(@"%@", [body objectForKey:@"profile_background_image_url"]);
    }
}];

Simple Queue Example

NSArray *urls = [NSArray arrayWithObjects:
                 @"http://farm5.static.flickr.com/4138/4744205956_1f08ae40e3_o.jpg",
                 @"http://farm5.static.flickr.com/4123/4744238252_d11d0df5a3_b.jpg",
                 @"http://farm5.static.flickr.com/4097/4743596319_50cce97d80_o.jpg",
                 @"http://farm5.static.flickr.com/4099/4743581287_7c50529b36_o.jpg",
                 @"http://farm5.static.flickr.com/4123/4743587437_78f0906e8a_o.jpg",
                 @"http://farm5.static.flickr.com/4136/4743562971_d5f5c6d5b1_o.jpg",
                 @"http://farm5.static.flickr.com/4073/4744205142_be44e64ab7_o.jpg",
                 nil];

// By default the NSOperation will only do 3 requests at a time
for (NSString *url in urls) {
    NSOperation *o = [Seriously request:url options:nil handler:^(id body,
    NSHTTPURLResponse *response, NSError *error) {            
        NSLog(@"got %d (%@)", [urls indexOfObject:url], url);
    }];
}

Why Are You Using Blocks?

Welcome to the future dude!

TODO

  • Document
  • Add XML parsing
  • Add more options for NSOperationQueue management

Currently Maintained By:

@adamvduke

seriously's People

Contributors

adamvduke avatar bpoweski avatar defunkt avatar probablycorey avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.