Advertisement
Guest User

Untitled

a guest
Aug 9th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. #import <Foundation/Foundation.h>
  2. #import "ApiCaller.h"
  3. #import "MSStorePrefs.h"
  4. #import "MSUser.h"
  5. #import "MSAppDelegate.h"
  6.  
  7. @class MSAppDelegate;
  8.  
  9. @interface CallerDelegate : NSObject<APICallerDelegate> {
  10. MSAppDelegate *msAppDelegate;
  11. }
  12.  
  13. @property(nonatomic, retain) MSAppDelegate *msAppDelegate;
  14.  
  15. @end
  16.  
  17. #import "CallerDelegate.h"
  18. #import "GDataXMLNode.h"
  19. #import "MSProduct.h"
  20. #import "MSCategory.h"
  21. #import "MSAppDelegate.h"
  22.  
  23. @implementation CallerDelegate
  24. @synthesize msAppDelegate;
  25.  
  26. #pragma mark -
  27. #pragma mark Api Proxy
  28. - (void) apiDidResponded:(NSData *)data forCall:(NSString *)urlCalled {
  29. NSString *XML;
  30. if(![urlCalled isEqualToString:@"logo_image"]){
  31. XML = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  32. DLog(@"%@", XML);
  33. } else {
  34. self.msAppDelegate.logo = [UIImage imageWithData:data];
  35. }
  36.  
  37.  
  38. if(urlCalled == APIURL_ListStorePreferences){
  39. NSArray *preferences = [Utility fromXMLToArray:XML withXPath:@"preferences/preference"];
  40.  
  41. if(preferences){
  42. // Preferences global object
  43. self.msAppDelegate.storePrefs = [[MSStorePrefs alloc] initWithXMLData:preferences];
  44.  
  45. NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
  46. self.msAppDelegate.prefsFilePath = [documentsDirectory stringByAppendingPathComponent: @"storePrefs.plist"];
  47.  
  48. DLog(@"%@", self.msAppDelegate.prefsFilePath);
  49. }
  50. } else if(urlCalled == APIURL_ListProducts){
  51. NSInteger totCount = [Utility getCountFromXML:XML withXPath:@"products"];
  52. DLog(@"%i", totCount);
  53.  
  54. if(totCount){
  55. NSArray *productsElements = [Utility fromXMLToArray:XML withXPath:@"products/product"];
  56. NSMutableArray *productsObjectArray = [NSMutableArray arrayWithCapacity:1];
  57.  
  58. DLog(@"%i", [productsElements count]);
  59.  
  60. for(GDataXMLElement *product in productsElements){
  61. DLog(@"%@", product);
  62. MSProduct *productObject = [[MSProduct alloc] initWithXMLElement:product];
  63. [productsObjectArray addObject:productObject];
  64. }
  65.  
  66. self.msAppDelegate.products = [NSArray arrayWithArray:productsObjectArray];
  67. }
  68. } else if(urlCalled == APIURL_ListCategories){
  69. NSArray *categoriesElements = [Utility fromXMLToArray:XML withXPath:@"categories/category"];
  70. DLog(@"%@", categoriesElements);
  71.  
  72. if(categoriesElements){
  73. NSMutableArray *categoriesObjectArray = [NSMutableArray arrayWithCapacity:1];
  74.  
  75. for(GDataXMLElement *category in categoriesElements){
  76. MSCategory *categoryObject = [[MSCategory alloc] initWithXMLElement:category];
  77. [categoriesObjectArray addObject:categoryObject];
  78. }
  79.  
  80. self.msAppDelegate.categories = [NSArray arrayWithArray:categoriesObjectArray];
  81. }
  82. } else if(urlCalled == APIURL_GetAuthToken){
  83. NSArray *userData = [Utility fromXMLToArray:XML withXPath:@""];
  84. DLog(@"%@", userData);
  85.  
  86. if(userData){
  87. NSString *AuthToken = [[[userData objectAtIndex:0] nodesForXPath:@"AuthToken" error:nil] objectAtIndex:0];
  88. NSString *uid = [[[userData objectAtIndex:0] nodesForXPath:@"uid" error:nil] objectAtIndex:0];
  89.  
  90. self.msAppDelegate.user = [[MSUser alloc] initWithXMLElements:[NSArray arrayWithObjects:AuthToken,uid,nil] username:@"+393490917523" password:@"superpippo"];
  91.  
  92. //[proxy apiListOrdersFilteredByDate:[NSString stringWithFormat:@"<?xml version=\"1.0\"?><request timestamp=\"%@\" auth_token=\"%@\"></request>", self.ts, self.globalUser.user_AuthToken] andTimestamp:self.ts];
  93. }
  94. } else if(urlCalled == APIURL_ListOrders){
  95. DLog(@"%@", XML);
  96. } else if(urlCalled == APIURL_EditOrCreateUser){
  97.  
  98. } else if([urlCalled isEqualToString:@"loginForm"]){
  99. DLog(@"%@", XML);
  100. }
  101. }
  102.  
  103. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement