Skip to content

Commit

Permalink
Initial checkin 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jeiting committed Oct 23, 2017
0 parents commit 85e2aab
Show file tree
Hide file tree
Showing 38 changed files with 3,328 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .gitignore
@@ -0,0 +1,27 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
docs/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3


Carthage
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,20 @@
## Contributing

#### 1. Create an issue to make sure its something that should be done.

#### 2. Create a fork/branch.

#### 3. Do your work.
Be sure to adhere to the prevailing style of the project.

#### 4. Write tests for your fix/new functionality.

You can run the tests by hitting Cmd+U. The tests are written swift

#### 5. Create a pull request to revenuecat/master and request review

Explain in your pull request the work that was done, the reasoning, and that tests passed.

#### 6. Make changes in response to review

#### 7. Bask in the glory of community maintained software
2 changes: 2 additions & 0 deletions Cartfile
@@ -0,0 +1,2 @@
github "AliSoftware/OHHTTPStubs"
github "Quick/Nimble"
2 changes: 2 additions & 0 deletions Cartfile.resolved
@@ -0,0 +1,2 @@
github "AliSoftware/OHHTTPStubs" "6.0.0"
github "Quick/Nimble" "v7.0.2"
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Jacob Eiting

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 20 additions & 0 deletions Purchases.podspec
@@ -0,0 +1,20 @@
Pod::Spec.new do |s|
s.name = "Purchases"
s.version = "0.1.0"
s.summary = "Subscription and in-app-purchase backend service."

s.description = <<-DESC
Save yourself the hastle of implementing a subscriptions backend. Use RevenueCat instead http://revenue.cat
DESC

s.homepage = "http://revenue.cat"
s.license = { :type => 'MIT' }
s.author = { "Revenue Cat Inc." => "jacob@revenuecat.com" }
s.source = { :git => "https://github.com/revenuecat/purchases-ios.git", :tag => s.version.to_s }

s.ios.deployment_target = '9.0'

s.source_files = [
'Purchases/Classes/**/*'
]
end
588 changes: 588 additions & 0 deletions Purchases.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 101 additions & 0 deletions Purchases.xcodeproj/xcshareddata/xcschemes/Purchases.xcscheme
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "352629FD1F7C4B9100C04F2C"
BuildableName = "Purchases.framework"
BlueprintName = "Purchases"
ReferencedContainer = "container:Purchases.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "35262A1D1F7D77E600C04F2C"
BuildableName = "PurchasesTests.xctest"
BlueprintName = "PurchasesTests"
ReferencedContainer = "container:Purchases.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "352629FD1F7C4B9100C04F2C"
BuildableName = "Purchases.framework"
BlueprintName = "Purchases"
ReferencedContainer = "container:Purchases.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "352629FD1F7C4B9100C04F2C"
BuildableName = "Purchases.framework"
BlueprintName = "Purchases"
ReferencedContainer = "container:Purchases.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "352629FD1F7C4B9100C04F2C"
BuildableName = "Purchases.framework"
BlueprintName = "Purchases"
ReferencedContainer = "container:Purchases.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
15 changes: 15 additions & 0 deletions Purchases/Classes/Public/Purchases.h
@@ -0,0 +1,15 @@
//
// Purchases.h
// Purchases
//
// Created by Jacob Eiting on 9/27/17.
// Copyright © 2017 RevenueCat, Inc. All rights reserved.
//

#import <UIKit/UIKit.h>

FOUNDATION_EXPORT double PurchasesVersionNumber;
FOUNDATION_EXPORT const unsigned char PurchasesVersionString[];

#import <Purchases/RCPurchases.h>
#import <Purchases/RCPurchaserInfo.h>
39 changes: 39 additions & 0 deletions Purchases/Classes/Public/RCPurchaserInfo.h
@@ -0,0 +1,39 @@
//
// RCPurchaserInfo.h
// Purchases
//
// Created by Jacob Eiting on 9/30/17.
// Copyright © 2017 RevenueCat, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>


NS_ASSUME_NONNULL_BEGIN

/**
A container for the most recent purchaser info returned from `RCPurchases`. These objects are non-mutable and do not update automatically.
*/
@interface RCPurchaserInfo : NSObject

/// All *subscription* product identifiers with expiration dates in the future.
@property (readonly) NSSet<NSString *> *activeSubscriptions;

/// All product identifiers purchases by the user regardless of expriration.
@property (readonly) NSSet<NSString *> *allPurchasedProductIdentifiers;

/// Returns the latest expiration date of all products, nil if there are none
@property (readonly) NSDate * _Nullable latestExpirationDate;

/**
Get the expiration date for a given product identifier.
@param productIdentifier Product identifier for subscription product
@return The expiration date for `productIdentifier`, `nil` if product never purchased
*/
- (NSDate * _Nullable)expirationDateForProductIdentifier:(NSString *)productIdentifier;

@end

NS_ASSUME_NONNULL_END
96 changes: 96 additions & 0 deletions Purchases/Classes/Public/RCPurchaserInfo.m
@@ -0,0 +1,96 @@
//
// RCPurchaserInfo.m
// Purchases
//
// Created by Jacob Eiting on 9/30/17.
// Copyright © 2017 RevenueCat, Inc. All rights reserved.
//

#import "RCPurchaserInfo.h"

@interface RCPurchaserInfo ()

@property (nonatomic) NSDictionary<NSString *, NSDate *> *expirationDates;

@end

static NSDateFormatter *dateFormatter;
static dispatch_once_t onceToken;

@implementation RCPurchaserInfo

- (instancetype _Nullable)initWithData:(NSDictionary *)data
{
if (self == [super init]) {
if (data[@"subscriber"] == nil) {
return nil;
}

NSDictionary *subscriberData = data[@"subscriber"];

dispatch_once(&onceToken, ^{
dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss";
});

NSMutableDictionary<NSString *, NSDate *> *dates = [NSMutableDictionary new];

NSDictionary *subscriptions = subscriberData[@"subscriptions"];
if (subscriptions == nil) {
return nil;
}

for (NSString *productID in subscriptions) {
NSString *dateString = subscriptions[productID][@"expires_date"];
NSDate *date = [dateFormatter dateFromString:dateString];

if (date == nil) {
return nil;
}

dates[productID] = date;
}

self.expirationDates = [NSDictionary dictionaryWithDictionary:dates];
}
return self;
}

- (NSSet<NSString *> *)allPurchasedProductIdentifiers
{
return [NSSet setWithArray:self.expirationDates.allKeys];
}

- (NSSet<NSString *> *)activeSubscriptions
{
NSMutableSet *activeSubscriptions = [NSMutableSet setWithCapacity:self.expirationDates.count];

for (NSString *productIdentifier in self.expirationDates) {
if (self.expirationDates[productIdentifier].timeIntervalSinceNow > 0) {
[activeSubscriptions addObject:productIdentifier];
}
}

return [NSSet setWithSet:activeSubscriptions];
}

- (NSDate * _Nullable)latestExpirationDate
{
NSDate *maxDate = nil;

for (NSDate *date in self.expirationDates.allValues) {
if (date.timeIntervalSince1970 > maxDate.timeIntervalSince1970) {
maxDate = date;
}
}

return maxDate;
}

- (NSDate *)expirationDateForProductIdentifier:(NSString *)productIdentifier
{
return self.expirationDates[productIdentifier];
}

@end

0 comments on commit 85e2aab

Please sign in to comment.