Skip to content

Instantly share code, notes, and snippets.

@simonpang
Last active August 29, 2015 14:14
Show Gist options
  • Save simonpang/b08353a13eb776c7639f to your computer and use it in GitHub Desktop.
Save simonpang/b08353a13eb776c7639f to your computer and use it in GitHub Desktop.
Network Request Library in Cocoa Style (Command pattern)
@interface DNSession : NSObject<NSCopying, NSCoding>
@property (copy) NSString *authToken;
@property (copy) NSString *userIdentifier;
+ (instancetype)defaultSession;
- (instancetype)initWithConfiguration:(NSDictionary *)options;
@end
@interface DNUserProfile : NSObject <NSCopying, NSCoding>
@end
@interface DNStory : NSObject <NSCopying, NSCoding>
@property (copy) NSString *identifier;
@property (copy) NSString *title;
@property (copy) NSString *body;
@end
@interface DNLaunchData : NSObject <NSCopying, NSCoding>
+ (instancetype)cachedLaunchData;
@end
@interface DNModel : NSObject <NSCopying, NSCoding>
+ (NSArray *)cachedModels;
@end
@interface DNReservation : NSObject <NSCopying, NSCoding>
@end
// Constants for updating user profile
extern NSString *DNUserProfileIdentifierKey;
extern NSString *DNUserProfileFirstNameKey;
extern NSString *DNUserProfileLastNameKey;
extern NSString *DNUserProfileBioKey;
// Constatns for reservation ask keys
extern NSString *DNReservationProductIdentifierKey;
extern NSString *DNReservationStartDateKey;
extern NSString *DNReservationEndDateKey;
extern NSString *DNReservationInsuranceIdentifierKey;
extern NSString *DNReservationCouponIdentifierKey;
@interface DNRequest : NSObject
@property (readonly) NSError *error;
@property (readonly) DNSession *session;
@property (readonly) id payload;
@property (readonly, getter=isRunning) BOOL running;
- (void)startWithCompletionBlock:(void (^)(BOOL success, NSError *error))completionHandler;
- (void)cancel;
@end
@interface DNProfileRequest : DNRequest
+ (instancetype)requestForLoginWithEmail:(NSString *)name password:(NSString *)password session:(DNSession *)session queue:(NSOperationQueue *)queue;
+ (instancetype)requestForFetchingUserProfileWithIdentifier:(NSString *)identifier session:(DNSession *)session queue:(NSOperationQueue *)queue;
+ (instancetype)requestForUpdatingUserProfileWithInfo:(NSDictionary *)info session:(DNSession *)session queue:(NSOperationQueue *)queue;
@property (readonly) DNUserProfile *fetchedUserProfile;
@end
@interface DNStoryRequest : DNRequest
+ (instancetype)requestForFetchingStoriesWithSession:(DNSession *)session queue:(NSOperationQueue *)queue;
+ (instancetype)requestForFetchingStoryWithIdentifier:(NSString *)identifier session:(DNSession *)session queue:(NSOperationQueue *)queue;
@property (readonly) NSArray *fetchedStories;
@property (readonly) DNStory *fetchedStory;
@end
@interface DNInfoRequest : DNRequest
+ (instancetype)requestForFetchingLaunchDataWithSession:(DNSession *)session queue:(NSOperationQueue *)queue;
+ (instancetype)requestForFetchingProductModelsWithSession:(DNSession *)session queue:(NSOperationQueue *)queue;
@end
@interface DNReservationRequest : DNRequest
+ (instancetype)requestForFetchingReservationAsk:(NSDictionary *)info session:(DNSession *)session queue:(NSOperationQueue *)queue;
+ (instancetype)requestForNewReservation:(NSDictionary *)info session:(DNSession *)session queue:(NSOperationQueue *)queue;
@property (readonly) DNReservation *fetchedReservation;
@end
#pragma mark - Chat
@interface DNChatConversation : NSObject
@end
@interface DNChatSession : NSObject
+ (instancetype)sharedChatSession;
- (void)configurePushOptions:(NSString *)nickname;
- (void)setupUnreadMessageCount;
@property (readonly) NSNumber *messageUnreadCount;
@property (readonly, getter=isLogined) BOOL logined;
@end
@interface DNChatRequest : NSObject
+ (instancetype)requestForLogin:(NSString *)login password:(NSString *)password session:(DNChatSession *)session queue:(NSOperationQueue *)queue;
- (void)startWithCompletionBlock:(void (^)(BOOL success, NSError *error))completionHandler;
@property (readonly) DNChatSession *session;
@property (readonly) NSError *error;
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment