Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Release v1.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarbo committed Jan 13, 2022
1 parent 4607a45 commit 76b39e5
Show file tree
Hide file tree
Showing 30 changed files with 313 additions and 143 deletions.
8 changes: 4 additions & 4 deletions Glassfy.podspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Pod::Spec.new do |s|
s.name = "Glassfy"
s.version = "1.1.6"
s.version = "1.1.7"
s.summary = "Subscription and in-app-purchase service."
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.source = { :git => "https://github.com/glassfy/ios-sdk.git", :tag => s.version.to_s }
s.homepage = "https://glassfy.net/"
s.author = { "Glassfy" => "support@glassfy.net" }
s.homepage = "https://glassfy.io/"
s.author = { "Glassfy" => "support@glassfy.io" }
s.framework = 'StoreKit'

s.ios.deployment_target = '9.0'
s.ios.deployment_target = '10.0'
s.osx.deployment_target = '10.15'

s.source_files = 'Source/Public/*.h', 'Source/*.{h,m}'
Expand Down
8 changes: 4 additions & 4 deletions Glassfy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -636,7 +636,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -668,7 +668,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.1.6;
MARKETING_VERSION = 1.1.7;
PRODUCT_BUNDLE_IDENTIFIER = net.glassfy.sdk;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -695,7 +695,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.1.6;
MARKETING_VERSION = 1.1.7;
PRODUCT_BUNDLE_IDENTIFIER = net.glassfy.sdk;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription
let package = Package(
name: "Glassfy",
platforms: [
.iOS(.v9),
.iOS(.v10),
.macOS(.v10_15)
],
products: [
Expand Down
3 changes: 2 additions & 1 deletion Source/GYAPIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#import <Foundation/Foundation.h>
#import "GYTypes.h"
#import "GYUserProperties+Private.h"
#import "GYAPIInitResponse.h"
#import "GYAPIPermissionsResponse.h"
#import "GYAPIOfferingsResponse.h"
Expand Down Expand Up @@ -55,7 +56,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)postLogoutWithCompletion:(GYLogoutCompletion _Nullable)block;
- (void)postLogin:(NSString *)userId withCompletion:(GYLoginCompletion _Nullable)block;

- (void)postProperty:(GYUserPropertyType)property obj:(id _Nullable)obj completion:(GYGetPropertiesCompletion _Nullable)block;
- (void)postProperty:(GYUserPropertyType)property obj:(id _Nullable)obj completion:(GYPropertyCompletion _Nullable)block;
- (void)getPropertiesWithCompletion:(GYGetPropertiesCompletion _Nullable)block;

- (void)getSignatureForProductId:(NSString *)productId offerId:(NSString *)offerId completion:(GYGetSignatureCompletion _Nullable)block;
Expand Down
59 changes: 35 additions & 24 deletions Source/GYAPIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
#import "GYCacheManager.h"
#import "GYUtils.h"

#define BASE_URL @"https://api.glassfy.io/v0"
#define BASE_URL @"https://api.glassfy.io"

typedef NSString * GYAPIVersion;
#define GYAPIVersionV0 @"v0"
#define GYAPIVersionV1 @"v1"

typedef void(^GYBaseAPICompletion)(id<GYDecodeProtocol>, NSError *);

Expand Down Expand Up @@ -56,25 +60,33 @@ - (instancetype)initWithApiKey:(NSString *)apiKey cache:(GYCacheManager *)cache
return self;
}

- (NSURLComponents *)baseURL
- (NSURLComponents *)baseURL:(GYAPIVersion)apiVersion
{
NSURLComponents *baseURL = [NSURLComponents componentsWithString:BASE_URL];
NSURLComponents *baseURL = [NSURLComponents componentsWithString:[BASE_URL stringByAppendingPathComponent:apiVersion]];

NSString *installationId = self.cache.installationId;
NSMutableArray *queryItems = [NSMutableArray array];
[queryItems addObject:[NSURLQueryItem queryItemWithName:@"installationid" value:installationId]];
[queryItems addObject:[NSURLQueryItem queryItemWithName:@"installationid" value:self.cache.installationId]];
[queryItems addObject:[NSURLQueryItem queryItemWithName:@"glii" value:self.glii]];
baseURL.queryItems = [queryItems copy];

return baseURL;
}

- (NSURLComponents *)baseURLV0
{
return [self baseURL:GYAPIVersionV0];
}

- (NSURLComponents *)baseURLV1
{
return [self baseURL:GYAPIVersionV1];
}

#pragma mark - public

- (void)getInitWithInfoWithCompletion:(GYGetInitCompletion)block
{
NSURLComponents *url = [self baseURL];
NSURLComponents *url = [self baseURLV0];
url.path = [url.path stringByAppendingPathComponent:@"init"];

NSURLRequest *req = [self authorizedRequestWithComponents:url];
Expand All @@ -83,7 +95,7 @@ - (void)getInitWithInfoWithCompletion:(GYGetInitCompletion)block

- (void)getSku:(NSString *)skuid withCompletion:(GYGetSkuCompletion)block
{
NSURLComponents *url = [self baseURL];
NSURLComponents *url = [self baseURLV0];
url.path = [url.path stringByAppendingPathComponent:@"sku"];
NSMutableArray<NSURLQueryItem*> *queryItems = [(url.queryItems ?: @[]) mutableCopy];
[queryItems addObject:[NSURLQueryItem queryItemWithName:@"identifier" value:skuid]];
Expand All @@ -95,7 +107,7 @@ - (void)getSku:(NSString *)skuid withCompletion:(GYGetSkuCompletion)block

- (void)getOfferingsWithCompletion:(GYGetOfferingsCompletion)block
{
NSURLComponents *url = [self baseURL];
NSURLComponents *url = [self baseURLV0];
url.path = [url.path stringByAppendingPathComponent:@"offerings"];

NSURLRequest *req = [self authorizedRequestWithComponents:url];
Expand All @@ -106,7 +118,7 @@ - (void)getSignatureForProductId:(NSString *)productid
offerId:(NSString *)offerId
completion:(GYGetSignatureCompletion)block
{
NSURLComponents *url = [self baseURL];
NSURLComponents *url = [self baseURLV0];
url.path = [url.path stringByAppendingPathComponent:@"signature"];
NSMutableArray<NSURLQueryItem*> *queryItems = [(url.queryItems ?: @[]) mutableCopy];
[queryItems addObject:[NSURLQueryItem queryItemWithName:@"productid" value:productid]];
Expand All @@ -120,7 +132,7 @@ - (void)getSignatureForProductId:(NSString *)productid

- (void)getPermissionsWithCompletion:(GYGetPermissionsCompletion)block
{
NSURLComponents *url = [self baseURL];
NSURLComponents *url = [self baseURLV0];
url.path = [url.path stringByAppendingPathComponent:@"permissions"];

NSURLRequest *req = [self authorizedRequestWithComponents:url];
Expand Down Expand Up @@ -157,7 +169,7 @@ - (void)postProducts:(NSArray<SKProduct *> *)products completion:(GYBaseCompleti
return;
}

NSURLComponents *url = [self baseURL];
NSURLComponents *url = [self baseURLV0];
url.path = [url.path stringByAppendingPathComponent:@"products"];

NSMutableURLRequest *req = [self authorizedRequestWithComponents:url];
Expand Down Expand Up @@ -198,7 +210,7 @@ - (void)postReceipt:(NSData *)receipt
return;
}

NSURLComponents *url = [self baseURL];
NSURLComponents *url = [self baseURLV0];
url.path = [url.path stringByAppendingPathComponent:@"receipt"];

NSMutableURLRequest *req = [self authorizedRequestWithComponents:url];
Expand All @@ -210,7 +222,7 @@ - (void)postReceipt:(NSData *)receipt

- (void)postLogoutWithCompletion:(GYLogoutCompletion _Nullable)block
{
NSURLComponents *url = [self baseURL];
NSURLComponents *url = [self baseURLV0];
url.path = [url.path stringByAppendingPathComponent:@"logout"];

NSMutableURLRequest *req = [self authorizedRequestWithComponents:url];
Expand All @@ -221,7 +233,7 @@ - (void)postLogoutWithCompletion:(GYLogoutCompletion _Nullable)block

- (void)postLogin:(NSString *)userId withCompletion:(GYLoginCompletion _Nullable)block
{
NSURLComponents *url = [self baseURL];
NSURLComponents *url = [self baseURLV0];
url.path = [url.path stringByAppendingPathComponent:@"login"];

NSMutableDictionary *bodyEncoded = [NSMutableDictionary dictionary];
Expand Down Expand Up @@ -255,20 +267,19 @@ - (void)postLogin:(NSString *)userId withCompletion:(GYLoginCompletion _Nullable

- (void)putLastSeen
{
NSURLComponents *url = [self baseURL];
NSURLComponents *url = [self baseURLV0];
url.path = [url.path stringByAppendingPathComponent:@"lastseen"];
NSMutableURLRequest *req = [self authorizedRequestWithComponents:url];
[req setHTTPMethod:@"PUT"];
[self callApiWithRequest:req response:nil completion:nil];
}

- (void)postProperty:(GYUserPropertyType)property obj:(id _Nullable)obj completion:(GYGetPropertiesCompletion _Nullable)block
- (void)postProperty:(GYUserPropertyType)property obj:(id _Nullable)obj completion:(GYPropertyCompletion _Nullable)block
{
NSURLComponents *url = [self baseURL];
NSURLComponents *url = [self baseURLV1];
url.path = [url.path stringByAppendingPathComponent:@"property"];

NSString *propertyStr = [GYUserProperties stringWithPropertyType:property];
NSDictionary *bodyEncoded = @{propertyStr: obj ?: NSNull.null};
NSDictionary *bodyEncoded = @{property: obj ?: NSNull.null};

NSError *err;
NSData *body;
Expand All @@ -285,7 +296,7 @@ - (void)postProperty:(GYUserPropertyType)property obj:(id _Nullable)obj completi

if (err) {
dispatch_async(Glassfy.shared.glqueue, ^{
GYGetPropertiesCompletion completion = block;
GYPropertyCompletion completion = block;
if (completion) {
completion(nil, err);
}
Expand All @@ -297,12 +308,12 @@ - (void)postProperty:(GYUserPropertyType)property obj:(id _Nullable)obj completi
[req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:body];
[self callApiWithRequest:req response:GYAPIPropertiesResponse.class completion:block];
[self callApiWithRequest:req response:GYAPIBaseResponse.class completion:block];
}

- (void)getPropertiesWithCompletion:(GYGetPropertiesCompletion _Nullable)block
{
NSURLComponents *url = [self baseURL];
NSURLComponents *url = [self baseURLV0];
url.path = [url.path stringByAppendingPathComponent:@"property"];

NSURLRequest *req = [self authorizedRequestWithComponents:url];
Expand Down Expand Up @@ -344,7 +355,7 @@ - (void)callApiWithRequest:(NSURLRequest *)req
}
}

__weak typeof(self) weakSelf = self;
typeof(self) __weak weakSelf = self;
[[self.session dataTaskWithRequest:req completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
//ToDO test NSHTTPURLResponse code != 200?
id obj;
Expand Down
5 changes: 3 additions & 2 deletions Source/GYAPIPermissionsResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ NS_ASSUME_NONNULL_BEGIN

@interface GYAPIPermissionsResponse: GYAPIBaseResponse
@property(nonatomic, strong) NSArray<GYPermission *> *permissions;
@property(nonatomic, strong) NSString *originalApplicationVersion;
@property(nonatomic, strong) NSDate *originalApplicationDate;
@property(nonatomic, nullable, strong) NSString *originalApplicationVersion;
@property(nonatomic, nullable, strong) NSDate *originalApplicationDate;
@property(nonatomic, nullable, strong) NSString *subscriberId;
@end

NS_ASSUME_NONNULL_END
6 changes: 6 additions & 0 deletions Source/GYAPIPermissionsResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ - (instancetype _Nullable)initWithObject:(NSDictionary *)obj error:(NSError **)e
if ([originalApplicationDate isKindOfClass:NSNumber.class] && originalApplicationDate.integerValue > 0) {
self.originalApplicationDate = [NSDate dateWithTimeIntervalSince1970:originalApplicationDate.integerValue];
}

NSString *subscriberId = obj[@"subscriberid"];
if ([subscriberId isKindOfClass:NSString.class] && subscriberId.length > 0) {
self.subscriberId = subscriberId;
}

}
return self;
}
Expand Down
1 change: 1 addition & 0 deletions Source/GYAPISignatureResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, strong) NSString *keyIdentifier;
@property(nonatomic, strong) NSUUID *nonce;
@property(nonatomic, strong) NSNumber *timestamp;
@property(nonatomic, strong) NSString *applicationUsername;
@end

NS_ASSUME_NONNULL_END
5 changes: 5 additions & 0 deletions Source/GYAPISignatureResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ - (instancetype _Nullable)initWithObject:(NSDictionary *)obj error:(NSError **)e
self.timestamp = @(timestamp.integerValue);
}

NSString *applicationUsername = obj[@"applicationusername"];
if ([applicationUsername isKindOfClass:NSString.class] && applicationUsername.length > 0) {
self.applicationUsername = applicationUsername;
}

// verify
if (!self.signature || !self.keyIdentifier || !self.nonce || self.timestamp == nil) {
if (error) {
Expand Down
5 changes: 5 additions & 0 deletions Source/GYError.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ + (NSError *)storeProductNotFound
return [NSError errorWithDomain:GYErrorDomain code:GYErrorCodeStoreProductNotFound userInfo:@{NSLocalizedDescriptionKey:@"Store does not return the SKProduct"}];
}

+ (NSError *)wrongParameterType
{
return [NSError errorWithDomain:GYErrorDomain code:GYErrorCodeWrongParameterType userInfo:@{NSLocalizedDescriptionKey:@"Wrong parameter type"}];
}

+ (NSError *)serverError:(GYErrorCode)code description:(nullable NSString *)description
{
return [NSError errorWithDomain:GYErrorDomain code:code userInfo:description ? @{NSLocalizedDescriptionKey:description} : nil];
Expand Down
7 changes: 5 additions & 2 deletions Source/GYManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ NS_ASSUME_NONNULL_BEGIN
- (void)skuWithIdentifier:(NSString *)skuid completion:(GYSkuBlock)block;

- (void)purchaseSku:(GYSku *)sku completion:(GYPaymentTransactionBlock)block;
- (void)purchaseSku:(GYSku *)sku withDiscount:(SKProductDiscount *_Nullable)discount completion:(GYPaymentTransactionBlock)block API_AVAILABLE(ios(12.2));
- (void)purchaseSku:(GYSku *)sku withDiscount:(SKProductDiscount *_Nullable)discount completion:(GYPaymentTransactionBlock)block API_AVAILABLE(ios(12.2), macos(10.14.4), watchos(6.2));

- (void)setEmailUserProperty:(NSString *)email completion:(GYErrorCompletion)block;
- (void)setDeviceToken:(NSString *)deviceToken completion:(GYErrorCompletion)block;
- (void)setExtraUserProperty:(NSDictionary<NSString*,NSString*> *)extra completion:(GYErrorCompletion)block;

- (void)setUserProperty:(GYUserPropertyType)property value:(id)obj completion:(GYUserPropertiesCompletion)block;
- (void)getUserProperties:(GYUserPropertiesCompletion)block;

- (void)restorePurchasesWithCompletion:(GYPermissionsCompletion)block;
Expand Down
Loading

0 comments on commit 76b39e5

Please sign in to comment.