# Values What the SDK hands back. Every value is immutable and safe to read on any thread. *NGA SDK 0.1.0 preview: you install 0.1.0 from Maven Central and NGA's public repositories. Every 0.x version is a preview under the NGA SDK License, and the API can change until 1.0. Questions: hi@nga.network. This page: https://nga.io/docs/sdk/reference/values/* ## `NGAAd` One loaded ad, from `onLoaded`. It is single-use: once shown, it is consumed. **Unity (C#)** ```csharp public sealed class NGAAd : IEquatable { public string PlacementId { get; } public string OpportunityId { get; } public long ExpiresAtMillis { get; } public NGAAdState State { get; } public bool IsReady(); public void Show(NGAAdShowListener listener); // every format public void Close(); // the native banner } ``` **Android (Kotlin)** ```kotlin interface NGAAd { val placementId: String val opportunityId: String val expiresAtMillis: Long val state: NGAAdState fun isReady(): Boolean fun show(activity: Activity, listener: NGAAdShowListener) // every format fun close() // the native banner } ``` **Android (Java)** ```java String getPlacementId() String getOpportunityId() long getExpiresAtMillis() NGAAdState getState() boolean isReady() void show(Activity activity, NGAAdShowListener listener) // every format void close() // the native banner ``` **iOS (Swift)** ```swift @objc protocol NGAAd { var placementId: String { get } var opportunityId: String { get } var expiresAtMillis: Int64 { get } var state: NGAAdState { get } var isReady: Bool { get } func show(from viewController: UIViewController, listener: NGAAdShowListener) // every format func close() // the native banner } ``` **iOS (Objective-C)** ```objectivec @protocol NGAAd @property (readonly) NSString *placementId; @property (readonly) NSString *opportunityId; @property (readonly) int64_t expiresAtMillis; @property (readonly) NGAAdState state; @property (readonly) BOOL isReady; - (void)showFromViewController:(UIViewController *)viewController listener:(id)listener; - (void)close; @end ``` | Member | Description | | --- | --- | | `placementId` | the placement it was loaded for | | `opportunityId` | unique to this ad, and single-use: the id to key a reward by, and the id on its `NGAImpression` | | `expiresAtMillis` | when it expires, in epoch milliseconds, for display only; `isReady()` is the check to use | | `state` | [`NGAAdState`](https://nga.io/docs/sdk/reference/enums/#ngaadstate): `READY`, `SHOWING`, `CONSUMED`, `EXPIRED` or `FAILED` | | `isReady()` | true when `state` is `READY` and the ad has not expired; it checks nothing else | | `show(activity)` / `show(from:)` | shows the ad in its placement's format: full screen (interstitial, rewarded) or the [native banner](https://nga.io/docs/sdk/native-cross-promo/) at the bottom of that screen. C# `Show(listener)` uses Unity's own Activity or view controller | | `close()` | ends a native banner's show: the banner slides down, then `onCompleted` and `onClosed` (`onClosed` alone before its impression). Nothing for a full-screen ad, or a banner that is not showing | There is one `show` for every format. Every `show` ends in `onClosed` or `onShowFailed` and never throws; see [`NGAAdShowListener`](https://nga.io/docs/sdk/reference/callbacks/#ngaadshowlistener). `state` and `isReady()` read a snapshot and never block. **Expiry.** An ad can be shown for 30 minutes after it loads. Then it expires: every load callback for it gets `onExpired`, `isReady()` is false, and `show` fails with `EXPIRED`. Load again. An ad already on screen is not affected. Time asleep counts: an ad that ran out while the device slept expires when the game comes back to the front. When NGA stops the SDK (the app key switched off, or this SDK version or build retired), every loaded ad expires at once. ## `NGARewardResult` A rewarded show's outcome, through `onRewardResult`. **Unity (C#)** ```csharp public bool Granted { get; } public NGARewardDenial Denial { get; } // None when granted ``` **Android (Kotlin)** ```kotlin val granted: Boolean val denial: NGARewardDenial? // null when granted ``` **Android (Java)** ```java boolean getGranted() NGARewardDenial getDenial() // null when granted ``` **iOS (Swift)** ```swift let granted: Bool let denial: NGARewardDenial // .none when granted ``` **iOS (Objective-C)** ```objectivec @property (readonly) BOOL granted; @property (readonly) NGARewardDenial denial; // NGARewardDenialNone when granted ``` | Field | Description | | --- | --- | | `granted` | true when the reward was earned | | `denial` | why not, when `granted` is false: `SKIPPED` (closed before the reward was earned), `INTERRUPTED` (the ad stopped mid-way) or `REJECTED` (this ad grants no reward). Null, `.none` or `None` when granted | Your game defines the reward; NGA has no reward type or amount. ## `NGAImpression` One NGA impression and its payout, through the [impression listener](https://nga.io/docs/sdk/reference/ngasdk/#setimpressionlistener). **Unity (C#)** ```csharp public string PlacementId { get; } public string OpportunityId { get; } public NGAAdFormat Format { get; } public long RevenueMicros { get; } public string Currency { get; } public NGARevenuePrecision Precision { get; } public string CampaignId { get; } // may be null public string CreativeId { get; } // may be null public string AdvertiserBundle { get; } // may be null public string AdvertiserDomain { get; } // may be null ``` **Android (Kotlin)** ```kotlin val placementId: String val opportunityId: String val format: NGAAdFormat val revenueMicros: Long val currency: String val precision: NGARevenuePrecision val campaignId: String? val creativeId: String? val advertiserBundle: String? val advertiserDomain: String? ``` **Android (Java)** ```java String getPlacementId() String getOpportunityId() NGAAdFormat getFormat() long getRevenueMicros() String getCurrency() NGARevenuePrecision getPrecision() String getCampaignId() // may be null String getCreativeId() // may be null String getAdvertiserBundle() // may be null String getAdvertiserDomain() // may be null ``` **iOS (Swift)** ```swift let placementId: String let opportunityId: String let format: NGAAdFormat let revenueMicros: Int64 let currency: String let precision: NGARevenuePrecision let campaignId: String? let creativeId: String? let advertiserBundle: String? let advertiserDomain: String? ``` **iOS (Objective-C)** ```objectivec @property (readonly) NSString *placementId; @property (readonly) NSString *opportunityId; @property (readonly) NGAAdFormat format; @property (readonly) int64_t revenueMicros; @property (readonly) NSString *currency; @property (readonly) NGARevenuePrecision precision; @property (readonly, nullable) NSString *campaignId; @property (readonly, nullable) NSString *creativeId; @property (readonly, nullable) NSString *advertiserBundle; @property (readonly, nullable) NSString *advertiserDomain; ``` | Field | Description | | --- | --- | | `placementId`, `opportunityId` | as on the `NGAAd` | | `format` | `INTERSTITIAL`, `REWARDED` or `NATIVE` (the banner) | | `revenueMicros`, `currency` | your payout for this impression, in micros, and its three-letter currency. Cross-promotion of your own games pays 0 | | `precision` | `EXACT` | | `campaignId` | NGA's id for the campaign | | `creativeId` | NGA's id for the creative, which you can quote to report or block one; null for the banner | | `advertiserBundle` | the promoted game's store id: its Android package name or iOS App Store id | | `advertiserDomain` | null in 0.1.0 | ## `NGAError` Every failure. The codes and details are on [Errors](https://nga.io/docs/sdk/reference/errors/). **Unity (C#)** ```csharp public NGAErrorCode Code { get; } public string Detail { get; } public string Message { get; } public bool Retryable { get; } public long? RetryAfterMillis { get; } ``` **Android (Kotlin)** ```kotlin val code: NGAErrorCode val detail: String val message: String val retryable: Boolean val retryAfterMillis: Long? val cause: Throwable? ``` **Android (Java)** ```java NGAErrorCode getCode() String getDetail() String getMessage() boolean getRetryable() Long getRetryAfterMillis() // may be null Throwable getCause() // may be null ``` **iOS (Swift)** ```swift let code: NGAErrorCode let detail: String let message: String let retryable: Bool let retryAfterMillis: Int64? let cause: NSError? ``` **iOS (Objective-C)** ```objectivec @property (readonly) NGAErrorCode code; @property (readonly) NSString *detail; @property (readonly) NSString *message; @property (readonly) BOOL retryable; @property (readonly, nullable) NSNumber *retryAfterMillis; @property (readonly, nullable) NSError *cause; ``` | Field | Description | | --- | --- | | `code` | [`NGAErrorCode`](https://nga.io/docs/sdk/reference/enums/#ngaerrorcode); the same integer on every platform | | `detail` | a stable reason, such as `no_fill.cap`; safe to branch on | | `message` | for people; may change between releases | | `retryable` | whether trying again can help | | `retryAfterMillis` | a sensible wait, when the SDK or the server knows one; otherwise null | | `cause` | the underlying exception, when there is one; not in C# | ## `NGAResult` The immediate result of a call that validates on the spot: `setCustomerUserId`, `logAdRevenue`, `logPurchase`. **Unity (C#)** ```csharp public bool Accepted { get; } public NGAError Error { get; } // null when accepted ``` **Android (Kotlin)** ```kotlin val accepted: Boolean val error: NGAError? ``` **Android (Java)** ```java boolean getAccepted() NGAError getError() // null when accepted ``` **iOS (Swift)** ```swift let accepted: Bool let error: NGAError? ``` **iOS (Objective-C)** ```objectivec @property (readonly) BOOL accepted; @property (readonly, nullable) NGAError *error; ``` | Field | Description | | --- | --- | | `accepted` | true when the call is valid. It is then delivered, at least once, after an init succeeds in this process | | `error` | why the call was refused; null when accepted | ## `NGAInitResult` The result of `initialize`, through `onInitialized`. **Unity (C#)** ```csharp public bool Success { get; } public NGAError Error { get; } // null on success public bool FromCache { get; } ``` **Android (Kotlin)** ```kotlin val success: Boolean val error: NGAError? val fromCache: Boolean ``` **Android (Java)** ```java boolean getSuccess() NGAError getError() // null on success boolean getFromCache() ``` **iOS (Swift)** ```swift let success: Bool let error: NGAError? let fromCache: Bool ``` **iOS (Objective-C)** ```objectivec @property (readonly) BOOL success; @property (readonly, nullable) NGAError *error; @property (readonly) BOOL fromCache; ``` | Field | Description | | --- | --- | | `success` | true when init completed | | `error` | why init failed; null on success | | `fromCache` | true when init used the configuration saved at an earlier launch, online or not; a fresh one is fetched in the background | See [The answer](https://nga.io/docs/sdk/initialize/#the-answer).