Today's Menu  Portugal
journal and plan nutrition
Z5GmailDataController.m
Go to the documentation of this file.
1 //
2 // Z5GmailDataController.m
3 // TodaysMenu
4 //
5 // Created by Don Zeek on 4/13/18.
6 // Copyright © 2018 net.dzeek.y2015.ios.portfolio. All rights reserved.
7 //
8 
9 #import <UIKit/UIKit.h>
10 #import "Z5DataController.h"
13 
14 @implementation Z5GmailDataController {
15  // GIDGoogleUser *signedInUser;
16  // NSMutableDictionary *partIdDictionary;
17  // NSMutableDictionary *encodeDictionary;
18  NSMutableDictionary *messageByUidDictionary;
19 
20  NSMutableDictionary *mesgUidDictionary;
21 
23 
24  NSMutableArray *localDataListeners;
25 }
26 
27 - (id) init
28 {
29  // Initialize the service object.
30  self.service = [[GTLRGmailService alloc] init];
31 
32  messageByUidDictionary = [[NSMutableDictionary alloc] init];
33  nutritionJournalDataTitleKey = @"Nutrition Journal Information";
34  localDataListeners = [[NSMutableArray alloc] init];
35  mesgUidDictionary = [[NSMutableDictionary alloc] init];
36 
37  return self;
38 }
39 
40 - (void) addDataListener: (id<Z5GmailDataListener>)ear
41 {
42  [self connectToLogin];
43  [localDataListeners addObject:ear];
44 }
45 - (void) removeDataListener: (id<Z5GmailDataListener>)ear
46 {
47  [localDataListeners removeObject:ear];
48 }
49 - (void) connectToLogin
50 {
51  Z5GoogleLoginController *loginControl = [[[Z5DataController sharedInstance] remoteDataController] loginController];
52  [loginControl addLoginListener:self];
53 }
54 
55 #pragma mark - Z5GoogleLoginListener
56 - (void) signedIn: (GIDGoogleUser *)user
57 {
58  NSLog(@"GmailDataController.signedIn: %@", user.profile.name);
59  // signedInUser = user;
60  // self.signedIn = [NSNumber numberWithBool:YES];
61 
62  // NSString *fullName = user.profile.name;
63  // self.signedIn = [NSNumber numberWithBool:YES];
64  self.service.authorizer = user.authentication.fetcherAuthorizer;
65  self.service.shouldFetchNextPages = true;
66 
67  NSLog(@"GmailDataController.signedIn: auth: %@", self.service.authorizer );
68 }
69 - (void) signedOut:(GIDGoogleUser *)user
70 {
71  self.service.authorizer = nil;
72 }
73 
74 
75 - (void)fetchJournalHeaders:(id<Z5GmailDataListener>)listener
76 {
77 // self.output.text = @"Getting journal headers...";
78  GTLRGmailQuery_UsersMessagesList *query2 = [GTLRGmailQuery_UsersMessagesList queryWithUserId:@"me"];
79  query2.maxResults = 1000;
80  // query2.fields
81  [query2 setQ:@"subject:(Nutrition Journal Information)"];
82  [self.service executeQuery:query2 delegate:listener didFinishSelector:@selector(rcvdNutriJournInfoHeadersWithTicket:finishedWithObject:error:)];
83 }
84 
85 - (GTLRServiceTicket *)fetchJournalMessage:(NSString *) identifier withListener: (id<Z5GmailDataListener>)listener
86 {
87  GTLRGmailQuery_UsersMessagesGet *query3 = [GTLRGmailQuery_UsersMessagesGet queryWithUserId:@"me" identifier:identifier];
88  [query3 setFormat:kGTLRGmailFormatFull];
89  NSLog(@"GmailController.fetchJournalMessage: identifier: %@", identifier);
90 
91  return [self.service executeQuery:query3 delegate:listener didFinishSelector:@selector(rcvdMessageWithTicket:finishedWithObject:error:)];
92 }
93 - (GTLRServiceTicket *)fetchMessageAttachment:(NSString *) identifier
94  onMessage:(NSString *) msgId
95  withListener: (id<Z5GmailDataListener>)listener
96 {
97  GTLRGmailQuery_UsersMessagesAttachmentsGet *queryAttachment = [GTLRGmailQuery_UsersMessagesAttachmentsGet queryWithUserId:@"me" messageId:msgId identifier:identifier];
98 
99  queryAttachment.executionParameters.ticketProperties = @{ @"Message ID": msgId };
100  return [self.service executeQuery:queryAttachment delegate:listener didFinishSelector:@selector(rcvdAttachmentWithTicket:finishedWithObject:error:)];
101 
102 }
103 
104 @end
GIDProfileData * profile
Definition: GIDGoogleUser.h:24
void addLoginListener:(id< Z5GoogleLoginListener > ear)
NSMutableArray * localDataListeners
instancetype sharedInstance()
id< GTMFetcherAuthorizationProtocol > fetcherAuthorizer()
Singleton interface to both core and remote data sources.
NSString * name
NSMutableDictionary * mesgUidDictionary
GIDAuthentication * authentication
Definition: GIDGoogleUser.h:27
NSString * nutritionJournalDataTitleKey