-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b93a420
commit 1eac30a
Showing
6 changed files
with
168 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// Result+JSON.cs | ||
// Adapty | ||
// | ||
// Created by Aleksei Valiano on 20.12.2022. | ||
// | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using static AdaptySDK.Adapty; | ||
|
||
namespace AdaptySDK.SimpleJSON | ||
{ | ||
internal static partial class JSONNodeExtensions | ||
{ | ||
internal static Adapty.Result<Adapty.Profile> ExtructProfileOrError(this string json) | ||
{ | ||
Adapty.Error error = null; | ||
Adapty.Profile profile = null; | ||
try | ||
{ | ||
var response = JSONNode.Parse(json); | ||
error = response.GetErrorIfPresent("error"); | ||
if (error is null) | ||
{ | ||
profile = response.GetProfile("success"); | ||
} | ||
|
||
} | ||
catch (Exception ex) | ||
{ | ||
error = new Adapty.Error(Adapty.ErrorCode.DecodingFailed, "Failed decoding Adapty.Profile Or Adapty.Error ", $"AdaptyUnityError.DecodingFailed({ex})"); | ||
} | ||
|
||
return new Adapty.Result<Adapty.Profile>(profile, error); | ||
} | ||
|
||
internal static Adapty.Result<Adapty.Paywall> ExtructPaywalleOrError(this string json) | ||
{ | ||
Adapty.Error error = null; | ||
Adapty.Paywall paywall = null; | ||
try | ||
{ | ||
var response = JSONNode.Parse(json); | ||
error = response.GetErrorIfPresent("error"); | ||
if (error is null) | ||
{ | ||
paywall = response.GetPaywall("success"); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
error = new Adapty.Error(Adapty.ErrorCode.DecodingFailed, "Failed decoding Adapty.Paywall Or Adapty.Error ", $"AdaptyUnityError.DecodingFailed({ex})"); | ||
} | ||
|
||
return new Adapty.Result<Adapty.Paywall>(paywall, error); | ||
} | ||
|
||
internal static Adapty.Result<IList<PaywallProduct>> ExtructPaywallProductListOrError(this string json) | ||
{ | ||
Adapty.Error error = null; | ||
IList<PaywallProduct> list = null; | ||
try | ||
{ | ||
var response = JSONNode.Parse(json); | ||
error = response.GetErrorIfPresent("error"); | ||
if (error is null) | ||
{ | ||
list = response.GetPaywallProductList("success"); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
error = new Adapty.Error(Adapty.ErrorCode.DecodingFailed, "Failed decoding list of Adapty.PaywallProduct Or Adapty.Error ", $"AdaptyUnityError.DecodingFailed({ex})"); | ||
} | ||
|
||
return new Adapty.Result<IList<PaywallProduct>>(list, error); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Result.cs | ||
// Adapty | ||
// | ||
// Created by Aleksei Valiano on 14.01.2022. | ||
// | ||
|
||
namespace AdaptySDK | ||
{ | ||
public static partial class Adapty | ||
{ | ||
internal class Result<T> | ||
{ | ||
public readonly Error Error; | ||
public readonly T Value; | ||
|
||
public override string ToString() | ||
{ | ||
return $"{nameof(Value)}: {Value}, " + | ||
$"{nameof(Error)}: {Error}"; | ||
} | ||
|
||
internal Result(T value, Error error) | ||
{ | ||
Error = error; | ||
Value = value; | ||
} | ||
} | ||
} | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.