Latest1.0.1
Homepagehttps://github.com/esttorhe/Rec
LicenseMIT
Platformsios 8.0, osx 10.9, requires ARC
DependenciesResult
Authors

Carthage compatible
Version
Circle CI
CI Status
Coverage Status
License
Platform

https://cldup.com/Q0g0iZrPlT.png

Helper library to record URL requests and save them locally (great for fixtures in HTTP stubbing)


Why?
OHHTTPStubs
Rec
Error Codes
TODO
Swift 2.0


Why?

@Orta told me once over Skype how he has incorporated into their API teams some way to have a "sample" JSON for each call (I’m paraphrasing) so they can actually test with «real life» sample data and even support an «offline» mode for the app for when developing while riding the :train:, etc.

Sadly for me I work at a company that does multiple projects a year and not always we control the API development part which kinds of "cripples" the addition of "sample" JSONs.

OHHTTPStubs

Enter OHHTTPStubs; I started adding HTTP Stubs to my projects for testing purposes and had to manually enter the URL for each request and save the resulting JSON in each file to add it to the fixtures folder for the test cases.

As an engineer (and more importantly an overly lazy person) I decided that this was a terribly tedious and slow process; so… why not automate it?

This is where Rec comes to play; it’s an NSURLProtocol that intercepts each NSURL request made from NSURLSessions (with defaultSessionConfiguration & ephemeralSessionConfiguration) and adds itself as the delegate for the connection; once the request succeeds the framework will save it to the application’s Documents folder (under «Fixtures» folder).

Rec follows in the steps of OHHTTPStubs and «automagically» adds itself as the listener (it does so by swizzling defaultSessionConfiguration & ephemeralSessionConfiguration and returning a "pre configured" session configuration object).

Error Codes

Here’s the list of «internal» error codes:

  • -666: Unable to start loading the request
  • -667: Failed to connect to URL
  • -668: Unable to correctly parse as a JSON response
  • -669: Unable to get the Document‘s directory path
  • -670: Unable to extract the request’s last path component for file name generation.
  • -671: Unable to save file to path
  • -672: Unable to get a successful response from URL.

TODO:

Swift 2.0

There’s a branch called swift-2.0 that currently supports Rec with 2.0 syntax.
This means no longer µFrameworks Result & Box and the inclusion of throws and custom ErrorType for the error handling in the framework.

Latest podspec

{
    "name": "Rec",
    "version": "1.0.1",
    "summary": "Helper library to record URL requests and save them locally (great for fixtures in HTTP stubbing).",
    "description": "Rec is a `NSURLProtocol` that intercepts each `NSURL` request made from `NSURLSession`s (with `defaultSessionConfiguration` & `ephemeralSessionConfiguration`) and adds itself as the delegate for the connection; once the request succeeds the framework will save it to the application's `Documents` folder (under u00abFixturesu00bb folder).n",
    "homepage": "https://github.com/esttorhe/Rec",
    "license": "MIT",
    "authors": {
        "esttorhe": "[email protected]"
    },
    "source": {
        "git": "https://github.com/esttorhe/Rec.git",
        "tag": "1.0.1"
    },
    "social_media_url": "https://twitter.com/esttorhe",
    "requires_arc": true,
    "source_files": "Rec/*.swift",
    "dependencies": {
        "Result": [
            "~> 0.4"
        ]
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.9"
    },
    "module_name": "Rec"
}

Pin It on Pinterest

Share This