merge fix, bugfix on #define myContext

This commit is contained in:
Jeremy Ellison
2009-09-03 14:20:30 -04:00
3 changed files with 44 additions and 2 deletions

View File

@@ -59,11 +59,24 @@
*/
+ (OTRestClient*)clientWithBaseURL:(NSString*)baseURL username:(NSString*)username password:(NSString*)password;
/**
* Will check for network connectivity (to google.com)
*/
- (BOOL)isNetworkAvailable;
/**
* Fetch a resource via an HTTP GET and invoke a callback with the resulting payload
*/
- (OTRestRequest*)get:(NSString*)resourcePath delegate:(id)delegate callback:(SEL)callback;
/**
* Fetch a resource via an HTTP GET with a dictionary of params and invoke a callback with the resulting payload
*
* Note that this request _only_ allows NSDictionary objects as the params. The dictionary will be coerced into a URL encoded
* string and then appended to the resourcePath as the query string of the request.
*/
- (OTRestRequest*)get:(NSString*)resourcePath params:(NSDictionary*)params delegate:(id)delegate callback:(SEL)callback;
/**
* Create a resource via an HTTP POST with a set of form parameters and invoke a callback with the resulting payload
*/

View File

@@ -8,6 +8,7 @@
#import "OTRestClient.h"
#import "OTRestModelLoader.h"
#import <SystemConfiguration/SCNetworkReachability.h>
///////////////////////////////////////////////////////////////////////////////////////////////////
// global
@@ -66,6 +67,25 @@ static OTRestClient* sharedClient = nil;
[super dealloc];
}
- (BOOL)isNetworkAvailable {
Boolean success;
const char *host_name = "google.com"; // your data source host name
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, host_name);
#ifdef TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
SCNetworkReachabilityFlags flags;
#else
SCNetworkConnectionFlags flags;
#endif
success = SCNetworkReachabilityGetFlags(reachability, &flags);
BOOL isNetworkAvailable = success && (flags & kSCNetworkFlagsReachable) && !(flags & kSCNetworkFlagsConnectionRequired);
CFRelease(reachability);
return isNetworkAvailable;
}
- (NSURL*)URLForResourcePath:(NSString*)resourcePath {
NSString* urlString = [NSString stringWithFormat:@"%@%@", self.baseURL, resourcePath];
return [NSURL URLWithString:urlString];
@@ -78,6 +98,14 @@ static OTRestClient* sharedClient = nil;
return request;
}
- (OTRestRequest*)get:(NSString*)resourcePath params:(NSDictionary*)params delegate:(id)delegate callback:(SEL)callback {
NSString* resourcePathWithQueryString = [NSString stringWithFormat:@"%@?%@", resourcePath, [params URLEncodedString]];
OTRestRequest* request = [[OTRestRequest alloc] initWithURL:[self URLForResourcePath:resourcePathWithQueryString] delegate:delegate callback:callback];
request.additionalHTTPHeaders = _HTTPHeaders;
[request get];
return request;
}
- (OTRestRequest*)post:(NSString*)resourcePath params:(NSObject<OTRestRequestSerializable>*)params delegate:(id)delegate callback:(SEL)callback {
OTRestRequest* request = [[OTRestRequest alloc] initWithURL:[self URLForResourcePath:resourcePath] delegate:delegate callback:callback];
request.additionalHTTPHeaders = _HTTPHeaders;

View File

@@ -7,7 +7,7 @@
//
#import "OTRestManagedModel.h"
#import <objc/runtime.h>
@implementation OTRestManagedModel
@@ -15,7 +15,8 @@
#pragma mark NSManagedObject helper methods
+ (NSEntityDescription*)entity {
return [NSEntityDescription entityForName:[[self class] className] inManagedObjectContext:myContext];
NSString* className = [NSString stringWithCString:class_getName([self class])];
return [NSEntityDescription entityForName:className inManagedObjectContext:myContext];
}
+ (NSFetchRequest*)request {