Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <Foundation/Foundation.h>
- #import "ApiCaller.h"
- #import "MSStorePrefs.h"
- #import "MSUser.h"
- #import "MSAppDelegate.h"
- @class MSAppDelegate;
- @interface CallerDelegate : NSObject<APICallerDelegate> {
- MSAppDelegate *msAppDelegate;
- }
- @property(nonatomic, retain) MSAppDelegate *msAppDelegate;
- @end
- #import "CallerDelegate.h"
- #import "GDataXMLNode.h"
- #import "MSProduct.h"
- #import "MSCategory.h"
- #import "MSAppDelegate.h"
- @implementation CallerDelegate
- @synthesize msAppDelegate;
- #pragma mark -
- #pragma mark Api Proxy
- - (void) apiDidResponded:(NSData *)data forCall:(NSString *)urlCalled {
- NSString *XML;
- if(![urlCalled isEqualToString:@"logo_image"]){
- XML = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- DLog(@"%@", XML);
- } else {
- self.msAppDelegate.logo = [UIImage imageWithData:data];
- }
- if(urlCalled == APIURL_ListStorePreferences){
- NSArray *preferences = [Utility fromXMLToArray:XML withXPath:@"preferences/preference"];
- if(preferences){
- // Preferences global object
- self.msAppDelegate.storePrefs = [[MSStorePrefs alloc] initWithXMLData:preferences];
- NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
- self.msAppDelegate.prefsFilePath = [documentsDirectory stringByAppendingPathComponent: @"storePrefs.plist"];
- DLog(@"%@", self.msAppDelegate.prefsFilePath);
- }
- } else if(urlCalled == APIURL_ListProducts){
- NSInteger totCount = [Utility getCountFromXML:XML withXPath:@"products"];
- DLog(@"%i", totCount);
- if(totCount){
- NSArray *productsElements = [Utility fromXMLToArray:XML withXPath:@"products/product"];
- NSMutableArray *productsObjectArray = [NSMutableArray arrayWithCapacity:1];
- DLog(@"%i", [productsElements count]);
- for(GDataXMLElement *product in productsElements){
- DLog(@"%@", product);
- MSProduct *productObject = [[MSProduct alloc] initWithXMLElement:product];
- [productsObjectArray addObject:productObject];
- }
- self.msAppDelegate.products = [NSArray arrayWithArray:productsObjectArray];
- }
- } else if(urlCalled == APIURL_ListCategories){
- NSArray *categoriesElements = [Utility fromXMLToArray:XML withXPath:@"categories/category"];
- DLog(@"%@", categoriesElements);
- if(categoriesElements){
- NSMutableArray *categoriesObjectArray = [NSMutableArray arrayWithCapacity:1];
- for(GDataXMLElement *category in categoriesElements){
- MSCategory *categoryObject = [[MSCategory alloc] initWithXMLElement:category];
- [categoriesObjectArray addObject:categoryObject];
- }
- self.msAppDelegate.categories = [NSArray arrayWithArray:categoriesObjectArray];
- }
- } else if(urlCalled == APIURL_GetAuthToken){
- NSArray *userData = [Utility fromXMLToArray:XML withXPath:@""];
- DLog(@"%@", userData);
- if(userData){
- NSString *AuthToken = [[[userData objectAtIndex:0] nodesForXPath:@"AuthToken" error:nil] objectAtIndex:0];
- NSString *uid = [[[userData objectAtIndex:0] nodesForXPath:@"uid" error:nil] objectAtIndex:0];
- self.msAppDelegate.user = [[MSUser alloc] initWithXMLElements:[NSArray arrayWithObjects:AuthToken,uid,nil] username:@"+393490917523" password:@"superpippo"];
- //[proxy apiListOrdersFilteredByDate:[NSString stringWithFormat:@"<?xml version=\"1.0\"?><request timestamp=\"%@\" auth_token=\"%@\"></request>", self.ts, self.globalUser.user_AuthToken] andTimestamp:self.ts];
- }
- } else if(urlCalled == APIURL_ListOrders){
- DLog(@"%@", XML);
- } else if(urlCalled == APIURL_EditOrCreateUser){
- } else if([urlCalled isEqualToString:@"loginForm"]){
- DLog(@"%@", XML);
- }
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement