Open Source Happenings

 ·  iOS, Development, Open-Source  ·  Tagged TWTToast, open-source, URLMock, TWTValidation and frameworks

It’s been a busy few weeks in Two Toasters land! In addition to our normal client workload, we’ve also had major releases of each of our three major open source projects. Here’s a quick look at what’s new.

URLMock 1.2

This week, we released URLMock 1.2! The new version adds the following major features:

  • Support for stream-based requests, including those created with NSURLSession.
  • More complete support for Rails/Rack-style nested parameter query strings. We should now be able to encode and decode query strings with deeply nested objects, e.g., strings inside dictionaries inside arrays.
  • Pattern-based request matching using UMKPatternMatchingMockRequest.

We think this last feature will really improve the way you use URLMock for mocking and stubbing. With UMKPatternMatchingMockRequest, you can match requests using a URL pattern and generate a response dynamically using a block. Here’s a quick example from the README:

NSString *pattern = @"";
UMKPatternMatchingMockRequest *mockRequest =  [[UMKPatternMatchingMockRequest alloc] initWithPattern:pattern];
mockRequest.HTTPMethods = [NSSet setWithObject:kUMKMockHTTPRequestPostMethod];

mockRequest.responderGenerationBlock = ^id<UMKMockURLResponder>(NSURLRequest *request, NSDictionary *params) {
    NSDictionary *requestJSON = [request umk_JSONObjectFromHTTPBody];

    // Respond with 
    //   { 
    //     "follower_id": «New follower’s ID»,
    //     "following_id":  «Account ID that was POSTed to» 
    //   }
    UMKMockHTTPResponder *responder = [UMKMockHTTPResponder mockHTTPResponderWithStatusCode:200];
    [responder setBodyWithJSONObject:@{ @"follower_id" : requestJSON[@"follower_id"] 
                                        @"following_id" : @([params[@"accountID"] integerValue]) }];
    return responder;

[UMKMockURLProtocol addExpectedMockRequest:mockRequest];

This mock request matches all requests whose URL matches the pattern, where accountID is an account ID placeholder. The mock request dynamically generates a responder using its responder generation block. In the example above, the mock request generates a response that includes data from both the request’s URL and body. See the UMKPatternMatchingMockRequest docs for more specifics about how to use pattern-matching mock requests.

We’re really proud of this release. Drop by our GitHub page for more details!

TWTValidation 1.0

We’re also happy to announce a brand new framework from the Two Toasters team, TWTValidation! TWTValidation is a Cocoa framework for declaratively validating data. Inspired by Rails validators, TWTValidation makes it easy to declare how your objects should be validated. You can then validate your objects whenever you see fit and get detailed error objects that explain why validation failed.

There’s enough in TWTValidation to warrant a post by itself, so be on the lookout for that in the coming weeks. In the meantime, check out the README and example project on GitHub to get a taste of what you can do.

TWTToast 0.10

Finally, we’ve been steadily adding new features and functionality to our utilities project, TWTToast. In the last few months, we’ve added classes and categories that make key-value observing easier; simplify model class deserialization with Mantle; clean up segue preparation code; and more. TWTToast is used in nearly all of our client projects these days and is bound to contain something you’ll find useful. Take a look!

That’s it for this week! We’re really proud of these releases, and we hope you find them useful. We’re always looking for ways to improve our open source offerings, so if you find a bug or have an idea for a new feature, open an issue on GitHub!