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

Commit

Permalink
Release v1.3.0-beta.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarbo committed Apr 8, 2022
1 parent b37e50a commit 1892b12
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Glassfy.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Glassfy"
s.version = "1.2.0"
s.version = "1.3.0-beta.0"
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 }
Expand Down
8 changes: 6 additions & 2 deletions Glassfy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
8138BAB325924D0A005CB44E /* SKProductSubscriptionPeriod+GYEncode.m in Sources */ = {isa = PBXBuildFile; fileRef = 8138BAB125924D0A005CB44E /* SKProductSubscriptionPeriod+GYEncode.m */; };
8161C42825948D82009CA563 /* GYError.m in Sources */ = {isa = PBXBuildFile; fileRef = 8161C42625948D82009CA563 /* GYError.m */; };
8161C4992594DD2F009CA563 /* GYTransaction.m in Sources */ = {isa = PBXBuildFile; fileRef = 8161C4972594DD2F009CA563 /* GYTransaction.m */; };
8168224727F1DC5E002B9857 /* GYPlatform.h in Headers */ = {isa = PBXBuildFile; fileRef = 8168224627F1DB5E002B9857 /* GYPlatform.h */; settings = {ATTRIBUTES = (Private, ); }; };
816830B8258B6EE400565968 /* GYManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 816830B6258B6EE400565968 /* GYManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
816830B9258B6EE400565968 /* GYManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 816830B7258B6EE400565968 /* GYManager.m */; };
816EF28A2661161200513FB1 /* GYUserProperties.m in Sources */ = {isa = PBXBuildFile; fileRef = 816EF2882661161200513FB1 /* GYUserProperties.m */; };
Expand Down Expand Up @@ -125,6 +126,7 @@
8161C42625948D82009CA563 /* GYError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GYError.m; sourceTree = "<group>"; };
8161C4972594DD2F009CA563 /* GYTransaction.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GYTransaction.m; sourceTree = "<group>"; };
8161C49E2594DF87009CA563 /* GYTransaction+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GYTransaction+Private.h"; sourceTree = "<group>"; };
8168224627F1DB5E002B9857 /* GYPlatform.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GYPlatform.h; sourceTree = "<group>"; };
8168309F258B6D9C00565968 /* Glassfy.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Glassfy.framework; sourceTree = BUILT_PRODUCTS_DIR; };
816830A3258B6D9C00565968 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
816830B6258B6EE400565968 /* GYManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GYManager.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -314,6 +316,7 @@
81C2816825E3F6AC0048189D /* GYPermissions+Private.h */,
810F6FB725E50D2000D3009E /* GYOfferings+Private.h */,
816EF28F26611CF100513FB1 /* GYUserProperties+Private.h */,
8168224627F1DB5E002B9857 /* GYPlatform.h */,
);
name = Core;
sourceTree = "<group>";
Expand Down Expand Up @@ -379,6 +382,7 @@
811F31A826317EBB00777020 /* GYOfferings+Private.h in Headers */,
818880B52717153A00128A10 /* GYAPIPaywallResponse.h in Headers */,
81B49B552729A31C000BDDA1 /* GYFormatter.h in Headers */,
8168224727F1DC5E002B9857 /* GYPlatform.h in Headers */,
811F31BC26317ED300777020 /* GYTransaction+Private.h in Headers */,
816EF29026611CF700513FB1 /* GYUserProperties+Private.h in Headers */,
811F31B226317EC800777020 /* GYOffering+Private.h in Headers */,
Expand Down Expand Up @@ -701,7 +705,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 1.3.0-beta.0;
PRODUCT_BUNDLE_IDENTIFIER = net.glassfy.sdk;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -729,7 +733,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 1.3.0-beta.0;
PRODUCT_BUNDLE_IDENTIFIER = net.glassfy.sdk;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Our SDK can be easly integrated through Cocoapods or Swift Package Manager
#### Integrate using Cocoapods
Add the pod to your Podfile:

```pod 'Glassfy', '~> 1.2.0'```
```pod 'Glassfy', '~> 1.3.0-beta.0'```

Then, run the following command:

Expand Down
2 changes: 1 addition & 1 deletion Source/GYAPIBaseResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ - (instancetype)initWithObject:(NSDictionary *)obj error:(NSError **)error {
NSDictionary *err = obj[@"error"];
if ([err isKindOfClass:NSDictionary.class]) {
NSInteger errorCode = [err[@"code"] integerValue];
if (errorCode < GYErrorCodeInvalidAPIToken || errorCode > GYErrorCodeInvalidFieldNameError) {
if (errorCode < GYErrorCodeInvalidAPIToken) {
errorCode = GYErrorCodeUnknow;
}
NSString *description;
Expand Down
4 changes: 4 additions & 0 deletions Source/GYAPIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef GYBaseCompletion GYProductsCompletion;
typedef GYBaseCompletion GYLogoutCompletion;
typedef GYBaseCompletion GYLoginCompletion;
typedef GYBaseCompletion GYPropertyCompletion;
typedef GYBaseCompletion GYPlatformCompletion;


NS_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -62,6 +63,9 @@ NS_ASSUME_NONNULL_BEGIN
- (void)postProperty:(GYUserPropertyType)property obj:(id _Nullable)obj completion:(GYPropertyCompletion _Nullable)block;
- (void)getPropertiesWithCompletion:(GYGetPropertiesCompletion _Nullable)block;

- (void)postConnectUser:(NSString *_Nullable)customId completion:(GYPlatformCompletion _Nullable)block;
- (void)postConnectPaddleLicenseKey:(NSString *)licenseKey force:(BOOL)force completion:(GYPlatformCompletion _Nullable)block;

- (void)getSignatureForProductId:(NSString *)productId offerId:(NSString *)offerId completion:(GYGetSignatureCompletion _Nullable)block;

- (void)getPaywall:(NSString *)paywallId locale:(NSString *_Nullable)locale completion:(GYGetPaywallCompletion _Nullable)block;
Expand Down
72 changes: 72 additions & 0 deletions Source/GYAPIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import "GYLogger.h"
#import "GYCacheManager.h"
#import "GYUtils.h"
#import "GYPlatform.h"

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

Expand Down Expand Up @@ -326,6 +327,77 @@ - (void)postProperty:(GYUserPropertyType)property obj:(id _Nullable)obj completi
[self callApiWithRequest:req response:GYAPIBaseResponse.class completion:block];
}

- (void)postConnectUser:(NSString *_Nullable)customId
completion:(GYPlatformCompletion _Nullable)block
{
NSURLComponents *url = [self baseURLV0];
url.path = [url.path stringByAppendingPathComponent:@"connect"];

NSDictionary *bodyEncoded = @{@"customid": customId ?: NSNull.null};

NSError *err;
NSData *body;
if (![NSJSONSerialization isValidJSONObject:bodyEncoded]) {
err = GYError.encodeData;
}
else {
body = [NSJSONSerialization dataWithJSONObject:bodyEncoded options:kNilOptions error:&err];
}
if (err) {
dispatch_async(Glassfy.shared.glqueue, ^{
GYLoginCompletion completion = block;
if (completion) {
completion(nil, err);
}
});
return;
}

NSMutableURLRequest *req = [self authorizedRequestWithComponents:url];
[req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:body];
[self callApiWithRequest:req response:GYAPIBaseResponse.class completion:block];
}

- (void)postConnectPaddleLicenseKey:(NSString *)licenseKey
force:(BOOL)force
completion:(GYPlatformCompletion _Nullable)block
{
NSURLComponents *url = [self baseURLV0];
url.path = [url.path stringByAppendingPathComponent:@"connect"];

NSDictionary *bodyEncoded = @{
@"store": GYPlatformTypePaddle,
@"licensekey": licenseKey,
@"force": [NSNumber numberWithBool:force]
};

NSError *err;
NSData *body;
if (![NSJSONSerialization isValidJSONObject:bodyEncoded]) {
err = GYError.encodeData;
}
else {
body = [NSJSONSerialization dataWithJSONObject:bodyEncoded options:kNilOptions error:&err];
}
if (err) {
dispatch_async(Glassfy.shared.glqueue, ^{
GYLoginCompletion completion = block;
if (completion) {
completion(nil, err);
}
});
return;
}

NSMutableURLRequest *req = [self authorizedRequestWithComponents:url];
[req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:body];
[self callApiWithRequest:req response:GYAPIBaseResponse.class completion:block];
}

- (void)getPropertiesWithCompletion:(GYGetPropertiesCompletion _Nullable)block
{
NSURLComponents *url = [self baseURLV0];
Expand Down
4 changes: 3 additions & 1 deletion Source/GYManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ NS_ASSUME_NONNULL_BEGIN
- (void)setEmailUserProperty:(NSString *)email completion:(GYErrorCompletion)block;
- (void)setDeviceToken:(NSString *)deviceToken completion:(GYErrorCompletion)block;
- (void)setExtraUserProperty:(NSDictionary<NSString*,NSString*> *)extra completion:(GYErrorCompletion)block;

- (void)getUserProperties:(GYUserPropertiesCompletion)block;

- (void)connectPaddleLicenseKey:(NSString *_Nullable)licenseKey force:(BOOL)force completion:(GYErrorCompletion)block;
- (void)connectCustomSubscriber:(NSString *_Nullable)customId completion:(GYErrorCompletion)block;

- (void)getPaywall:(NSString *)paywallId completion:(GYPaywallCompletion)block API_UNAVAILABLE(macos, watchos);

- (void)restorePurchasesWithCompletion:(GYPermissionsCompletion)block;
Expand Down
26 changes: 25 additions & 1 deletion Source/GYManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#import "GYAPIManager.h"
#import "GYStoreRequest.h"
#import "GYOffering.h"
#import "GYSku+Private.h"
#import "GYLogger.h"
#import "GYError.h"
#import "GYTypes.h"
#import "GYSku+Private.h"
#import "GYPermission+Private.h"
#import "GYTransaction+Private.h"
#import "GYOffering+Private.h"
Expand Down Expand Up @@ -349,6 +349,29 @@ - (void)getPaywall:(NSString *)paywallId completion:(GYPaywallCompletion)block
}];
}

- (void)connectPaddleLicenseKey:(NSString *)licenseKey force:(BOOL)force completion:(GYErrorCompletion)block
{
[self.api postConnectPaddleLicenseKey:licenseKey force:force completion:^(GYAPIBaseResponse *res, NSError *err) {
typeof(block) __strong completion = block;
if (completion) {
dispatch_async(dispatch_get_main_queue(), ^{
completion(err);
});
}
}];
}

- (void)connectCustomSubscriber:(NSString *_Nullable)customId completion:(GYErrorCompletion)block
{
[self.api postConnectUser:customId completion:^(GYAPIBaseResponse *res, NSError *err) {
typeof(block) __strong completion = block;
if (completion) {
dispatch_async(dispatch_get_main_queue(), ^{
completion(err);
});
}
}];
}

#pragma mark - Notification

Expand Down Expand Up @@ -742,4 +765,5 @@ - (void)setUserProperty:(GYUserPropertyType)property value:(id)obj completion:(G
}];
}


@end
14 changes: 14 additions & 0 deletions Source/GYPlatform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// GYPlatform.h
// Glassfy
//
// Created by Luca Garbolino on 28/03/22.
//

#ifndef GYPlatform_h
#define GYPlatform_h

typedef NSString * GYPlatformType;
#define GYPlatformTypePaddle @"3"

#endif /* GYPlatform_h */
1 change: 1 addition & 0 deletions Source/GYUserProperties.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ @interface GYUserProperties()
@implementation GYUserProperties (Private)

- (instancetype)initWithObject:(nonnull NSDictionary *)obj error:(NSError **)error {

self = [super init];
if (self) {
NSString *email = obj[GYUserPropertyTypeEmail];
Expand Down
21 changes: 20 additions & 1 deletion Source/Glassfy.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ + (Glassfy *)shared

+ (NSString *)sdkVersion
{
return @"1.2.0";
return @"1.3.0-beta.0";
}

+ (void)initializeWithAPIKey:(NSString *)apiKey
Expand Down Expand Up @@ -167,6 +167,25 @@ + (void)setPurchaseDelegate:(id<GYPurchaseDelegate>)delegate
});
}

+ (void)connectPaddleLicenseKey:(NSString *_Nullable)licenseKey completion:(GYErrorCompletion)block
{
[self connectPaddleLicenseKey:licenseKey force:NO completion:block];
}

+ (void)connectPaddleLicenseKey:(NSString *_Nullable)licenseKey force:(BOOL)force completion:(GYErrorCompletion)block
{
dispatch_async(Glassfy.shared.glqueue, ^{
[Glassfy.shared.manager connectPaddleLicenseKey:licenseKey force:force completion:block];
});
}

+ (void)connectCustomSubscriber:(NSString *_Nullable)customId completion:(GYErrorCompletion)block
{
dispatch_async(Glassfy.shared.glqueue, ^{
[Glassfy.shared.manager connectCustomSubscriber:customId completion:block];
});
}


#pragma mark - Deprecations

Expand Down
2 changes: 2 additions & 0 deletions Source/Public/GYError.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ typedef NS_ERROR_ENUM(GYErrorDomain, GYErrorCode) {
GYErrorCodeAppleReceiptStatusError = 1011,
GYErrorCodeInvalidFieldValueError = 1012,
GYErrorCodeInvalidFieldNameError = 1013,
GYErrorCodeLicenseAlreadyConnected = 1050,
GYErrorCodeLicenseNotFound = 1051,
GYErrorCodeUnknow = -1
} NS_SWIFT_NAME(Glassfy.ErrorCode);

Expand Down
26 changes: 26 additions & 0 deletions Source/Public/Glassfy.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,32 @@ Save extra user properties
*/
+ (void)paywallWithId:(NSString *)paywallid completion:(GYPaywallCompletion)block API_UNAVAILABLE(macos, watchos) NS_SWIFT_NAME(paywall(id:completion:));

/**
Connect paddle license key
@param licenseKey Paddle license key
@param block Completion block
@note Check error code in GYDomain - GYErrorCodeLicenseAlreadyConnected, GYErrorCodeLicenseNotFound to handle those cases
*/
+ (void)connectPaddleLicenseKey:(NSString *_Nullable)licenseKey completion:(GYErrorCompletion)block NS_SWIFT_NAME(connectPaddle(licenseKey:completion:));

/**
Connect paddle license key
@param licenseKey Paddle license key
@param force Disconnect license from other subscriber(s) and connect with current subscriber
@param block Completion block
@note Check error code in GYDomain - GYErrorCodeLicenseAlreadyConnected, GYErrorCodeLicenseInvalid to handle those cases
*/
+ (void)connectPaddleLicenseKey:(NSString *_Nullable)licenseKey force:(BOOL)force completion:(GYErrorCompletion)block NS_SWIFT_NAME(connectPaddle(licenseKey:force:completion:));

/**
Connect custom subscriber
@param customId Custom subscriber id
@param block Completion block
*/
+ (void)connectCustomSubscriber:(NSString *_Nullable)customId completion:(GYErrorCompletion)block NS_SWIFT_NAME(connectCustomSubscriber(_:completion:));

/// Deprecations
+ (void)skuWithIdentifier:(NSString *)skuid completion:(GYSkuBlock)block NS_SWIFT_NAME(sku(identifier:completion:)) __attribute__((deprecated("Renamed to +skuWithId:completion:")));
Expand Down

0 comments on commit 1892b12

Please sign in to comment.