Skip to content

Commit

Permalink
🎉 Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Marthijn van den Heuvel committed Oct 18, 2024
1 parent f090b01 commit af4921e
Show file tree
Hide file tree
Showing 65 changed files with 2,176 additions and 1 deletion.
26 changes: 26 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "nuget" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
groups:
microsoft:
patterns:
- "Microsoft*"
tests:
patterns:
- "AutoFixture"
- "FluentAssertions"
- "xunit*"
- "*Test*"
- "coverlet*"
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
48 changes: 48 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: build

on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- '*'

env:
DOTNET_NOLOGO: true

jobs:
build:

runs-on: ubuntu-22.04

strategy:
matrix:
dotnet-version: [ '8.0.x' ]

steps:
- uses: actions/checkout@v4
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release
- name: Test with dotnet
run: dotnet test --configuration Release
/p:CollectCoverage=true
/p:CoverletOutputFormat="\"cobertura,json\""
/p:CoverletOutput=coverage/
/p:IncludeTestAssembly=false
- name: Upload dotnet test results
uses: coverallsapp/github-action@v2.3.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
files: ${{ github.workspace }}/src/Sidio.OpenGraph.Tests/coverage/coverage.net8.0.cobertura.xml ${{ github.workspace }}/src/Sidio.OpenGraph.Tests/coverage/coverage.net481.cobertura.xml ${{ github.workspace }}/src/Sidio.OpenGraph.AspNetCore.Tests/coverage/coverage.cobertura.xml
format: cobertura
base-path: ${{ github.workspace }}
debug: true
if: ${{ always() }}
43 changes: 43 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: release

on:
workflow_dispatch:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"
- "[0-9]+.[0-9]+.[0-9]+-preview"

env:
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace}}/nuget/release

jobs:
build:
runs-on: ubuntu-22.04
timeout-minutes: 15
strategy:
matrix:
dotnet-version: [ '8.0.x' ]
steps:
- uses: actions/checkout@v4
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Set RELEASE_VERSION variable from tag
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Print release version
run: |
echo $RELEASE_VERSION
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release /p:Version=${RELEASE_VERSION}
- name: Test
run: dotnet test --configuration Release /p:Version=${RELEASE_VERSION} --no-build
- name: Pack
run: dotnet pack --configuration Release /p:Version=${RELEASE_VERSION} --output ${{ env.NuGetDirectory }} -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg
- name: Push
run: dotnet nuget push ${{ env.NuGetDirectory }}/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_API_KEY}
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,4 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml
.idea/
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# Sidio.RevenueCat
Unofficial RevenueCat API and webhook SDK
An unofficial .NET SDK for the RevenueCat API and webhooks. This library is not affiliated with RevenueCat.

[![build](https://github.com/marthijn/Sidio.RevenueCat/actions/workflows/build.yml/badge.svg)](https://github.com/marthijn/Sidio.RevenueCat/actions/workflows/build.yml)
[![NuGet Version](https://img.shields.io/nuget/v/Sidio.RevenueCat)](https://www.nuget.org/packages/Sidio.RevenueCat/)

# Installation
Add [the package](https://www.nuget.org/packages/Sidio.RevenueCat/) to your project.

# Project status
This package is currently in preview mode and is not yet feature complete.
6 changes: 6 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Security policy
## Reporting a vulnerability
Please report (suspected) security vulnerabilities by opening a GitHub Security Advisory private
vulnerability report.
You will receive a response from us within 48 hours. If the issue is confirmed, we will release a patch as soon
as possible depending on complexity.
45 changes: 45 additions & 0 deletions Sidio.RevenueCat.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sidio.RevenueCat", "src\Sidio.RevenueCat\Sidio.RevenueCat.csproj", "{6FA8977A-7796-4585-8B5B-2A3962EA4B66}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Src", "Src", "{C1E71605-FACC-45BE-920E-CA28CD039CE4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{03B0397E-E392-4C0E-8B88-A3E884F4EB64}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{8A28614B-AFF2-4D40-A97F-E9CC3299BB91}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
LICENSE = LICENSE
README.md = README.md
SECURITY.md = SECURITY.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sidio.RevenueCat.Tests", "src\Sidio.RevenueCat.Tests\Sidio.RevenueCat.Tests.csproj", "{2B15D9FF-99D9-4D50-BBA2-159A1E8B48A8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Workflows", "Workflows", "{4FB399C5-DA44-4C3E-BADC-67B3D6A99BDD}"
ProjectSection(SolutionItems) = preProject
.github\dependabot.yml = .github\dependabot.yml
.github\workflows\build.yml = .github\workflows\build.yml
.github\workflows\release.yml = .github\workflows\release.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6FA8977A-7796-4585-8B5B-2A3962EA4B66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6FA8977A-7796-4585-8B5B-2A3962EA4B66}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6FA8977A-7796-4585-8B5B-2A3962EA4B66}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6FA8977A-7796-4585-8B5B-2A3962EA4B66}.Release|Any CPU.Build.0 = Release|Any CPU
{2B15D9FF-99D9-4D50-BBA2-159A1E8B48A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B15D9FF-99D9-4D50-BBA2-159A1E8B48A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B15D9FF-99D9-4D50-BBA2-159A1E8B48A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B15D9FF-99D9-4D50-BBA2-159A1E8B48A8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{6FA8977A-7796-4585-8B5B-2A3962EA4B66} = {C1E71605-FACC-45BE-920E-CA28CD039CE4}
{2B15D9FF-99D9-4D50-BBA2-159A1E8B48A8} = {03B0397E-E392-4C0E-8B88-A3E884F4EB64}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Reflection;
using System.Text.Json;
using Essentia.Web.RevenueCat.Api.V1.Responses;

namespace Sidio.RevenueCat.Tests.Api.V1.Responses;

public sealed class SubscriberResponseTests
{
[Fact]
public void Deserialize_ReturnsModel()
{
// arrange
var fileContent = GetFileContents("SubscriberResponse.json");

// act
var result = JsonSerializer.Deserialize<SubscriberResponse>(fileContent);

// assert
result.Should().NotBeNull();
result!.Subscriber.OriginalAppUserId.Should().Be("XXX-XXXXX-XXXXX-XX");
result.Subscriber.Entitlements.Count.Should().Be(2);
result.Subscriber.Entitlements.Should().ContainKeys("pro_cat", "pro_cat2");
}

private static string GetFileContents(string filename)
{
var fullPath =
$"Sidio.RevenueCat.Tests.Api.V1.Responses.TestData.{filename}";
var assembly = Assembly.GetExecutingAssembly();

using var stream = assembly.GetManifestResourceStream(fullPath);
using var reader = new StreamReader(stream!);

var jsonFile = reader.ReadToEnd();

jsonFile.Should().NotBeNullOrEmpty("{0} should not be null or empty.", filename);

return jsonFile;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"request_date": "2019-07-26T17:40:10Z",
"request_date_ms": 1564162810884,
"subscriber": {
"entitlements": {
"pro_cat": {
"expires_date": null,
"grace_period_expires_date": null,
"product_identifier": "onetime",
"purchase_date": "2019-04-05T21:52:45Z"
},
"pro_cat2": {
"expires_date": "2019-05-10T21:52:45Z",
"grace_period_expires_date": null,
"product_identifier": "onetime",
"purchase_date": "2019-04-05T21:52:45Z"
}
},
"first_seen": "2019-02-21T00:08:41Z",
"management_url": "https://apps.apple.com/account/subscriptions",
"non_subscriptions": {
"onetime": [
{
"id": "cadba0c81b",
"is_sandbox": true,
"purchase_date": "2019-04-05T21:52:45Z",
"store": "app_store"
}
]
},
"original_app_user_id": "XXX-XXXXX-XXXXX-XX",
"original_application_version": "1.0",
"original_purchase_date": "2019-01-30T23:54:10Z",
"other_purchases": {},
"subscriptions": {
"annual": {
"auto_resume_date": null,
"billing_issues_detected_at": null,
"expires_date": "2019-08-14T21:07:40Z",
"grace_period_expires_date": null,
"is_sandbox": true,
"original_purchase_date": "2019-02-21T00:42:05Z",
"ownership_type": "PURCHASED",
"period_type": "normal",
"purchase_date": "2019-07-14T20:07:40Z",
"refunded_at": null,
"store": "app_store",
"unsubscribe_detected_at": "2019-07-17T22:48:38Z"
},
"onemonth": {
"auto_resume_date": null,
"billing_issues_detected_at": null,
"expires_date": "2019-06-17T22:47:55Z",
"grace_period_expires_date": null,
"is_sandbox": true,
"original_purchase_date": "2019-02-21T00:42:05Z",
"ownership_type": "PURCHASED",
"period_type": "normal",
"purchase_date": "2019-06-17T22:42:55Z",
"refunded_at": null,
"store": "app_store",
"unsubscribe_detected_at": "2019-06-17T22:48:38Z"
},
"rc_promo_pro_cat_monthly": {
"auto_resume_date": null,
"billing_issues_detected_at": null,
"expires_date": "2019-08-26T01:02:16Z",
"grace_period_expires_date": null,
"is_sandbox": false,
"original_purchase_date": "2019-07-26T01:02:16Z",
"ownership_type": "FAMILY_SHARED",
"period_type": "normal",
"purchase_date": "2019-07-26T01:02:16Z",
"refunded_at": null,
"store": "promotional",
"unsubscribe_detected_at": null
}
}
}
}
45 changes: 45 additions & 0 deletions src/Sidio.RevenueCat.Tests/Api/V1/RevenueCatV1ClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Net;
using System.Text.Json;
using Essentia.Web.RevenueCat.Api.V1.Responses;
using RestSharp;
using RestSharp.Serializers;
using Sidio.RevenueCat.Api.V1;

namespace Sidio.RevenueCat.Tests.Api.V1;

public sealed class RevenueCatV1ClientTests
{
private readonly IFixture _fixture = new Fixture();

[Fact]
public async Task GetOrCreateSubscriberAsync_ReturnsData()
{
// arrange
var client = CreateClient(out var restClientMock);
var userId = _fixture.Create<string>();
var data = _fixture.Create<SubscriberResponse>();
var responseData = JsonSerializer.Serialize(data);
var response = new RestResponse<SubscriberResponse>(new RestRequest()) { StatusCode = HttpStatusCode.OK, Content = responseData, };

restClientMock.Setup(x => x.ExecuteAsync(It.IsAny<RestRequest>(), It.IsAny<CancellationToken>())).ReturnsAsync(response);

// act
var result = await client.GetOrCreateSubscriberAsync(userId);

// assert
result.Should().NotBeNull();
result.StatusCode.Should().Be(HttpStatusCode.OK);
result.Data.Should().BeEquivalentTo(data);
}

private static RevenueCatV1Client CreateClient(out Mock<IRestClient> restClientMock)
{
var config = new SerializerConfig();
config.UseDefaultSerializers();
restClientMock = new Mock<IRestClient>();
restClientMock.Setup(x => x.Serializers).Returns(new RestSerializers(config));

var client = new RevenueCatV1Client(restClientMock.Object);
return client;
}
}
16 changes: 16 additions & 0 deletions src/Sidio.RevenueCat.Tests/Api/V2/RevenueCatV2ClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using RestSharp;
using Sidio.RevenueCat.Api.V2;

namespace Sidio.RevenueCat.Tests.Api.V2;

public sealed class RevenueCatV2ClientTests
{
private readonly IFixture _fixture = new Fixture();

private static RevenueCatV2Client CreateClient(out Mock<IRestClient> restClientMock)
{
restClientMock = new Mock<IRestClient>();
var client = new RevenueCatV2Client(restClientMock.Object);
return client;
}
}
Loading

0 comments on commit af4921e

Please sign in to comment.