IAOHTTPStubsHandler is an extension to AliSoftware/OHHTTPStubs project that returns stubbed responses saved locally and enables easy mappings between file stubs and remote request URLS. The handler automatically imports all stubs files, and serves them as best it can falling back on smart defaults. The system will provide a HTTP status code, response time, and content type.
The code below will return a 200 OK, image/jpeg, WiFi speed result
"http://photos-e.ak.fbcdn.net/hphotos-ak-ash4/5041_98423808305_6704612_s.jpg" : {
"file" : "file2.jpg",
}
The code below will return a 200 OK, text/json, WiFi speed result
"https://graph.facebook.com/19292868552" : {
"file" : "file1.json",
"response_code" : 200,
"response_speed" : "OHHTTPStubsDownloadSpeedWifi",
"content_type" : "text/json"
}
Built and tested on iOS 5.1 only. Should be backwards compatible to iOS 5.0.
- ARC
- MobileCoreServices Framework
- NSJSONSerialization Methods
- Add the MobileCoreServices Framework to your project
- Copy and paste the folders and files inside the 'Classes' folder inside the project, add them to your project and #import "IAOHTTPStubsHandler.h" in your App Delegate
- Copy and paste the 'Stubs' folder and 'mappings.json' file inside the 'Stubs' folder into the root of your project.
- Add the 'Stubs' folder to your project - making sure to select 'Create folder references for any added folders'. This will save time as you add more stubs to your project.
- In application:didFinishLaunchingWithOptions: enable stubbed responses by adding the line:
[IAOHTTPStubsHandler activateStubsResponses];
Alter the mappings.json file by adding your own stubs. The format is as follows:
"REMOTE_URL" : {
"file" : "LOCAL_FILENAME_AND_EXTENSION",
"response_code" : HTTP_RESPONSE_CODE,
"response_speed" : "OHHTTPSTUBS_DOWNLOAD_SPEED",
"content_type" : "MIME_TYPE"
}
A small iPhone example is inside the project to demo functionality.
In addition to the creator, the following are credited:
A Licence file is included. Code is completely Open Source, just give me a credit if you use ;).
I hereby accept NO liability or responsibility if using this code causes any problems for you. Always check and test before you import other frameworks / libraries and files into your projects! See LICENCE file.