Rec 1.0.1

Rec 1.0.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release May 2015
SPMSupports SPM

Maintained by Esteban Torres.



Rec 1.0.1

https://cldup.com/Q0g0iZrPlT.png

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


Why?OHHTTPStubsRecError CodesTODO


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?

Rec

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:

  • [ ] Support other responses (e.g.: xml, etc) • Issue #1
  • [ ] Support custom «save» paths • Issue #2
  • [ ] Support disabling automatic «injection» • Issue #3
  • [ ] Fix the race condition happening on the Example App (println() I'm :eyes: at you :unamused: ) • Issue #4
  • [x] Add support for OS XIssue #5