Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add phone permission #544

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions library/Source/VKAccessToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
// User email (if passed)
@property(nonatomic, readonly, copy) NSString *email;

// User phone nubmer (if passed)
@property(nonatomic, readonly, copy) NSString *phoneNumber;

// User phone secret nubmer (if passed)
@property(nonatomic, readonly, copy) NSString *phoneAccessKey;

/// Time when token expires
@property(nonatomic, readonly, assign) NSInteger expiresIn;

Expand Down
14 changes: 14 additions & 0 deletions library/Source/VKAccessToken.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
static NSString *const USER_ID = @"user_id";
static NSString *const SECRET = @"secret";
static NSString *const EMAIL = @"email";
static NSString *const PHONE = @"phone";
static NSString *const PHONE_ACCESS_KEY = @"phone_access_key";
static NSString *const HTTPS_REQUIRED = @"https_required";
static NSString *const CREATED = @"created";
static NSString *const PERMISSIONS = @"permissions";
Expand Down Expand Up @@ -83,6 +85,8 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder {
_userId = [aDecoder decodeObjectForKey:USER_ID];
_secret = [aDecoder decodeObjectForKey:SECRET];
_email = [aDecoder decodeObjectForKey:EMAIL];
_phoneNumber = [aDecoder decodeObjectForKey:PHONE];
_phoneAccessKey = [aDecoder decodeObjectForKey:PHONE_ACCESS_KEY];
_permissions = [self restorePermissions:[aDecoder decodeObjectForKey:PERMISSIONS]];

_httpsRequired = [aDecoder decodeBoolForKey:HTTPS_REQUIRED];
Expand All @@ -105,6 +109,12 @@ - (void)encodeWithCoder:(NSCoder *)aCoder {
if (self.email) {
[aCoder encodeObject:self.email forKey:EMAIL];
}
if (self.phoneNumber) {
[aCoder encodeObject:self.phoneNumber forKey:PHONE];
}
if (self.phoneAccessKey) {
[aCoder encodeObject:self.phoneAccessKey forKey:PHONE_ACCESS_KEY];
}

NSString *permissions = [self.permissions componentsJoinedByString:@","];
if (permissions.length > 0) {
Expand Down Expand Up @@ -137,6 +147,8 @@ - (instancetype)initWithUrlString:(NSString *)urlString {
_userId = [parameters[USER_ID] copy];
_secret = [parameters[SECRET] copy];
_email = [parameters[EMAIL] copy];
_phoneNumber = [parameters[PHONE] copy];
_phoneAccessKey = [parameters[PHONE_ACCESS_KEY] copy];
_httpsRequired = NO;

_permissions = [self restorePermissions:parameters[PERMISSIONS]];
Expand All @@ -162,6 +174,8 @@ - (instancetype)initWithVKAccessToken:(VKAccessToken *)token {
_created = token.created;
_permissions = [token.permissions copy];
_email = [token.email copy];
_phoneNumber = [token.phoneNumber copy];
_phoneAccessKey = [token.phoneAccessKey copy];
_localUser = token.localUser;
}
return self;
Expand Down
1 change: 1 addition & 0 deletions library/Source/VKPermissions.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ extern NSString *const VK_PER_OFFLINE;
extern NSString *const VK_PER_NOHTTPS;
extern NSString *const VK_PER_EMAIL;
extern NSString *const VK_PER_MARKET;
extern NSString *const VK_PER_PHONE;

extern NSArray *VKParseVkPermissionsFromInteger(NSInteger permissionsValue);
3 changes: 3 additions & 0 deletions library/Source/VKPermissions.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
NSString *const VK_PER_NOHTTPS = @"nohttps";
NSString *const VK_PER_EMAIL = @"email";
NSString *const VK_PER_MARKET = @"market";
NSString *const VK_PER_PHONE = @"phone";

NSArray *VKParseVkPermissionsFromInteger(NSInteger permissionsValue) {
NSMutableArray *res = [NSMutableArray new];
Expand All @@ -61,5 +62,7 @@
if (permissionsValue & 524288) [res addObject:VK_PER_NOTIFICATIONS];
if (permissionsValue & 1048576) [res addObject:VK_PER_STATS];
if (permissionsValue & 134217728) [res addObject:VK_PER_MARKET];
if (permissionsValue & 536870912) [res addObject:VK_PER_PHONE];

return res;
}