-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from superwall/develop
1.4.1
- Loading branch information
Showing
11 changed files
with
194 additions
and
3 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
40 changes: 40 additions & 0 deletions
40
android/src/main/java/com/superwallreactnative/models/PresentationResult.kt
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,40 @@ | ||
package com.superwallreactnative.models | ||
|
||
import com.facebook.react.bridge.Arguments | ||
import com.facebook.react.bridge.ReadableMap | ||
|
||
import com.superwall.sdk.paywall.presentation.result.PresentationResult | ||
|
||
fun PresentationResult.toJson(): ReadableMap { | ||
val map = Arguments.createMap() | ||
|
||
when (this) { | ||
is PresentationResult.Holdout -> { | ||
map.putString("type", "Holdout") | ||
map.putMap("experiment", Experiment.toJson(experiment)) | ||
} | ||
|
||
is PresentationResult.Paywall -> { | ||
map.putString("type", "Paywall") | ||
map.putMap("experiment", Experiment.toJson(experiment)) | ||
} | ||
|
||
is PresentationResult.NoRuleMatch -> { | ||
map.putString("type", "NoRuleMatch") | ||
} | ||
|
||
is PresentationResult.EventNotFound -> { | ||
map.putString("type", "EventNotFound") | ||
} | ||
|
||
is PresentationResult.UserIsSubscribed -> { | ||
map.putString("type", "UserIsSubscribed") | ||
} | ||
|
||
is PresentationResult.PaywallNotAvailable -> { | ||
map.putString("type", "PaywallNotAvailable") | ||
} | ||
} | ||
|
||
return map | ||
} |
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,27 @@ | ||
import Foundation | ||
import SuperwallKit | ||
|
||
extension PresentationResult { | ||
func toJson() -> [String: Any] { | ||
switch self { | ||
case .holdout(let experiment): | ||
return [ | ||
"type": "Holdout", | ||
"experiment": experiment.toJson(), | ||
] | ||
case .paywall(let experiment): | ||
return [ | ||
"type": "Paywall", | ||
"experiment": experiment.toJson(), | ||
] | ||
case .noRuleMatch: | ||
return ["type": "NoRuleMatch"] | ||
case .eventNotFound: | ||
return ["type": "EventNotFound"] | ||
case .userIsSubscribed: | ||
return ["type": "UserIsSubscribed"] | ||
case .paywallNotAvailable: | ||
return ["type": "PaywallNotAvailable"] | ||
} | ||
} | ||
} |
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
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,56 @@ | ||
import { Experiment } from './Experiment'; | ||
|
||
export abstract class PresentationResult { | ||
static fromJson(json: any): PresentationResult { | ||
let experiment: Experiment | undefined; | ||
if (json.experiment) { | ||
experiment = Experiment.fromJson(json.experiment); | ||
} | ||
|
||
switch (json.type) { | ||
case 'Holdout': | ||
if (!experiment) throw new Error('Holdout requires an experiment'); | ||
return new PresentationResultHoldout(experiment); | ||
case 'Paywall': | ||
if (!experiment) throw new Error('Paywall requires an experiment'); | ||
return new PresentationResultPaywall(experiment); | ||
case 'NoRuleMatch': | ||
return new PresentationResultNoRuleMatch(); | ||
case 'EventNotFound': | ||
return new PresentationResultEventNotFound(); | ||
case 'UserIsSubscribed': | ||
return new PresentationResultUserIsSubscribed(); | ||
case 'PaywallNotAvailable': | ||
return new PresentationResultPaywallNotAvailable(); | ||
default: | ||
throw new Error('Unknown PresentationResult type'); | ||
} | ||
} | ||
} | ||
|
||
// Derived classes | ||
export class PresentationResultEventNotFound extends PresentationResult {} | ||
|
||
export class PresentationResultNoRuleMatch extends PresentationResult {} | ||
|
||
export class PresentationResultUserIsSubscribed extends PresentationResult {} | ||
|
||
export class PresentationResultPaywallNotAvailable extends PresentationResult {} | ||
|
||
export class PresentationResultHoldout extends PresentationResult { | ||
experiment: Experiment; | ||
|
||
constructor(experiment: Experiment) { | ||
super(); | ||
this.experiment = experiment; | ||
} | ||
} | ||
|
||
export class PresentationResultPaywall extends PresentationResult { | ||
experiment: Experiment; | ||
|
||
constructor(experiment: Experiment) { | ||
super(); | ||
this.experiment = experiment; | ||
} | ||
} |