Skip to content

Commit

Permalink
Merge pull request #10 from prebid/prep-for-release
Browse files Browse the repository at this point in the history
Update podspec file for release
  • Loading branch information
nhedley authored Aug 16, 2017
2 parents b9a8c9f + 36f74fb commit fb24d17
Show file tree
Hide file tree
Showing 365 changed files with 2,002 additions and 998 deletions.
2 changes: 1 addition & 1 deletion PrebidMobile.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "PrebidMobile"
s.version = "0.0.1"
s.version = "0.0.2"
s.summary = "PrebidMobile is a lightweight framework that integrates directly with Prebid Server."

s.description = <<-DESC
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion examples/PrebidMobileDemo/MoPubSDK/Internal/Common/MPAdBrowserController.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#import "MPLogEvent.h"
#import "MPLogEventRecorder.h"
#import "MPAdConfiguration.h"
#import "MPAPIEndPoints.h"
#import "MPAPIEndpoints.h"
#import "NSBundle+MPAdditions.h"

static NSString * const kAdBrowserControllerNibName = @"MPAdBrowserController";
Expand Down
Empty file.
8 changes: 5 additions & 3 deletions examples/PrebidMobileDemo/MoPubSDK/Internal/Common/MPAdConfiguration.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extern NSString * const kIsVastVideoPlayerKey;
extern NSString * const kRewardedVideoCurrencyNameHeaderKey;
extern NSString * const kRewardedVideoCurrencyAmountHeaderKey;
extern NSString * const kRewardedVideoCompletionUrlHeaderKey;
extern NSString * const kRewardedCurrenciesHeaderKey;
extern NSString * const kRewardedPlayableDurationHeaderKey;
extern NSString * const kRewardedPlayableRewardOnClickHeaderKey;

Expand All @@ -54,6 +55,8 @@ extern NSString * const kAdTypeClear;
extern NSString * const kAdTypeNative;
extern NSString * const kAdTypeNativeVideo;

extern NSString * const kClickthroughExperimentBrowserAgent;

@interface MPAdConfiguration : NSObject

@property (nonatomic, assign) MPAdType adType;
Expand Down Expand Up @@ -86,12 +89,11 @@ extern NSString * const kAdTypeNativeVideo;
@property (nonatomic, assign) NSTimeInterval nativeVideoImpressionVisible;
@property (nonatomic, assign) NSTimeInterval nativeVideoMaxBufferingTime;
@property (nonatomic) NSDictionary *nativeVideoTrackers;
@property (nonatomic) MPRewardedVideoReward *rewardedVideoReward;
@property (nonatomic, readonly) NSArray *availableRewards;
@property (nonatomic, strong) MPRewardedVideoReward *selectedReward;
@property (nonatomic, copy) NSString *rewardedVideoCompletionUrl;
@property (nonatomic, assign) NSTimeInterval rewardedPlayableDuration;
@property (nonatomic, assign) BOOL rewardedPlayableShouldRewardOnClick;
//TODO: Remove `forceUIWebView` once WKWebView is proven
@property (nonatomic, assign) BOOL forceUIWebView;

- (id)initWithHeaders:(NSDictionary *)headers data:(NSData *)data;

Expand Down
107 changes: 94 additions & 13 deletions examples/PrebidMobileDemo/MoPubSDK/Internal/Common/MPAdConfiguration.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
#import "math.h"
#import "NSJSONSerialization+MPAdditions.h"
#import "MPRewardedVideoReward.h"
#import "MOPUBExperimentProvider.h"

#if MP_HAS_NATIVE_PACKAGE
#import "MPVASTTrackingEvent.h"
#endif

NSString * const kAdTypeHeaderKey = @"X-Adtype";
NSString * const kAdUnitWarmingUpHeaderKey = @"X-Warmup";
Expand All @@ -35,8 +39,6 @@
NSString * const kDspCreativeIdKey = @"X-DspCreativeid";
NSString * const kPrecacheRequiredKey = @"X-PrecacheRequired";
NSString * const kIsVastVideoPlayerKey = @"X-VastVideoPlayer";
//TODO: Remove `kForceUIWebViewKey` once WKWebView is proven
NSString * const kForceUIWebViewKey = @"X-ForceUIWebView";

NSString * const kInterstitialAdTypeHeaderKey = @"X-Fulladtype";
NSString * const kOrientationTypeHeaderKey = @"X-Orientation";
Expand All @@ -59,6 +61,7 @@
NSString * const kRewardedVideoCurrencyNameHeaderKey = @"X-Rewarded-Video-Currency-Name";
NSString * const kRewardedVideoCurrencyAmountHeaderKey = @"X-Rewarded-Video-Currency-Amount";
NSString * const kRewardedVideoCompletionUrlHeaderKey = @"X-Rewarded-Video-Completion-Url";
NSString * const kRewardedCurrenciesHeaderKey = @"X-Rewarded-Currencies";

// rewarded playables
NSString * const kRewardedPlayableDurationHeaderKey = @"X-Rewarded-Duration";
Expand All @@ -71,10 +74,16 @@
NSString * const kNativeVideoTrackerEventDictionaryKey = @"event";
NSString * const kNativeVideoTrackerTextDictionaryKey = @"text";

// clickthrough experiment
NSString * const kClickthroughExperimentBrowserAgent = @"X-Browser-Agent";
static const NSInteger kMaximumVariantForClickthroughExperiment = 2;


@interface MPAdConfiguration ()

@property (nonatomic, copy) NSString *adResponseHTMLString;
@property (nonatomic, strong, readwrite) NSArray *availableRewards;
@property (nonatomic) MOPUBDisplayAgentType clickthroughExperimentBrowserAgent;

- (MPAdType)adTypeFromHeaders:(NSDictionary *)headers;
- (NSString *)networkTypeFromHeaders:(NSDictionary *)headers;
Expand Down Expand Up @@ -137,8 +146,6 @@ - (id)initWithHeaders:(NSDictionary *)headers data:(NSData *)data

self.isVastVideoPlayer = [[headers objectForKey:kIsVastVideoPlayerKey] boolValue];

self.forceUIWebView = [[headers objectForKey:kForceUIWebViewKey] boolValue];

self.creationTimestamp = [NSDate date];

self.creativeId = [headers objectForKey:kCreativeIdHeaderKey];
Expand All @@ -154,27 +161,54 @@ - (id)initWithHeaders:(NSDictionary *)headers data:(NSData *)data
self.nativeVideoImpressionVisible = [self timeIntervalFromMsHeaders:headers forKey:kNativeVideoImpressionVisibleMsHeaderKey];

self.nativeVideoMaxBufferingTime = [self timeIntervalFromMsHeaders:headers forKey:kNativeVideoMaxBufferingTimeMsHeaderKey];

#if MP_HAS_NATIVE_PACKAGE
self.nativeVideoTrackers = [self nativeVideoTrackersFromHeaders:headers key:kNativeVideoTrackersHeaderKey];
#endif


// rewarded video
NSString *currencyName = [headers objectForKey:kRewardedVideoCurrencyNameHeaderKey];
NSNumber *currencyAmount = [self adAmountFromHeaders:headers key:kRewardedVideoCurrencyAmountHeaderKey];
if (!currencyName) {
currencyName = kMPRewardedVideoRewardCurrencyTypeUnspecified;

// Attempt to parse the multiple currency header first since this will take
// precedence over the older single currency approach.
self.availableRewards = [self parseAvailableRewardsFromHeaders:headers];
if (self.availableRewards != nil) {
// Multiple currencies exist. We will select the first entry in the list
// as the default selected reward.
if (self.availableRewards.count > 0) {
self.selectedReward = self.availableRewards[0];
}
// In the event that the list of available currencies is empty, we will
// follow the behavior from the single currency approach and create an unspecified reward.
else {
MPRewardedVideoReward * defaultReward = [[MPRewardedVideoReward alloc] initWithCurrencyType:kMPRewardedVideoRewardCurrencyTypeUnspecified amount:@(kMPRewardedVideoRewardCurrencyAmountUnspecified)];
self.availableRewards = [NSArray arrayWithObject:defaultReward];
self.selectedReward = defaultReward;
}
}
if (currencyAmount.integerValue > 0 ) {
self.rewardedVideoReward = [[MPRewardedVideoReward alloc] initWithCurrencyType:currencyName amount:currencyAmount];
} else {
self.rewardedVideoReward = [[MPRewardedVideoReward alloc] initWithCurrencyType:currencyName amount:@(kMPRewardedVideoRewardCurrencyAmountUnspecified)];
// Multiple currencies are not available; attempt to process single currency
// headers.
else {
NSString *currencyName = [headers objectForKey:kRewardedVideoCurrencyNameHeaderKey] ?: kMPRewardedVideoRewardCurrencyTypeUnspecified;

NSNumber *currencyAmount = [self adAmountFromHeaders:headers key:kRewardedVideoCurrencyAmountHeaderKey];
if (currencyAmount.integerValue <= 0) {
currencyAmount = @(kMPRewardedVideoRewardCurrencyAmountUnspecified);
}

MPRewardedVideoReward * reward = [[MPRewardedVideoReward alloc] initWithCurrencyType:currencyName amount:currencyAmount];
self.availableRewards = [NSArray arrayWithObject:reward];
self.selectedReward = reward;
}

self.rewardedVideoCompletionUrl = [headers objectForKey:kRewardedVideoCompletionUrlHeaderKey];

// rewarded playables
self.rewardedPlayableDuration = [self timeIntervalFromHeaders:headers forKey:kRewardedPlayableDurationHeaderKey];
self.rewardedPlayableShouldRewardOnClick = [[headers objectForKey:kRewardedPlayableRewardOnClickHeaderKey] boolValue];

// clickthrough experiment
self.clickthroughExperimentBrowserAgent = [self clickthroughExperimentVariantFromHeaders:headers forKey:kClickthroughExperimentBrowserAgent];
[MOPUBExperimentProvider setDisplayAgentFromAdServer:self.clickthroughExperimentBrowserAgent];
}
return self;
}
Expand Down Expand Up @@ -373,6 +407,7 @@ - (MPInterstitialOrientationType)orientationTypeFromHeaders:(NSDictionary *)head
}
}

#if MP_HAS_NATIVE_PACKAGE
- (NSDictionary *)nativeVideoTrackersFromHeaders:(NSDictionary *)headers key:(NSString *)key
{
NSDictionary *dictFromHeader = [self dictionaryFromHeaders:headers forKey:key];
Expand Down Expand Up @@ -410,4 +445,50 @@ - (void)setVideoTrackers:(NSMutableDictionary *)videoTrackerDict event:(NSString
}
}

#endif

- (NSArray *)parseAvailableRewardsFromHeaders:(NSDictionary *)headers {
// The X-Rewarded-Currencies header key doesn't exist. This is probably
// not a rewarded ad.
NSDictionary * currencies = [self dictionaryFromHeaders:headers forKey:kRewardedCurrenciesHeaderKey];
if (currencies == nil) {
return nil;
}

// Either the list of available rewards doesn't exist or is empty.
// This is an error.
NSArray * rewards = [currencies objectForKey:@"rewards"];
if (rewards.count == 0) {
MPLogError(@"No available rewards found.");
return nil;
}

// Parse the list of JSON rewards into objects.
NSMutableArray * availableRewards = [NSMutableArray arrayWithCapacity:rewards.count];
[rewards enumerateObjectsUsingBlock:^(NSDictionary * rewardDict, NSUInteger idx, BOOL * _Nonnull stop) {
NSString * name = rewardDict[@"name"] ?: kMPRewardedVideoRewardCurrencyTypeUnspecified;
NSNumber * amount = rewardDict[@"amount"] ?: @(kMPRewardedVideoRewardCurrencyAmountUnspecified);

MPRewardedVideoReward * reward = [[MPRewardedVideoReward alloc] initWithCurrencyType:name amount:amount];
[availableRewards addObject:reward];
}];

return availableRewards;
}

- (MOPUBDisplayAgentType)clickthroughExperimentVariantFromHeaders:(NSDictionary *)headers forKey:(NSString *)key
{
NSString *variantString = [headers objectForKey:key];
NSInteger variant = 0;
if (variantString) {
int parsedInt = -1;
BOOL isNumber = [[NSScanner scannerWithString:variantString] scanInt:&parsedInt];
if (isNumber && parsedInt >= 0 && parsedInt <= kMaximumVariantForClickthroughExperiment) {
variant = parsedInt;
}
}

return variant;
}

@end
7 changes: 7 additions & 0 deletions examples/PrebidMobileDemo/MoPubSDK/Internal/Common/MPAdDestinationDisplayAgent.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
#import "MPAdBrowserController.h"
#import "MPStoreKitProvider.h"

typedef NS_ENUM(NSInteger, MOPUBDisplayAgentType) {
MOPUBDisplayAgentTypeInApp = 0,
MOPUBDisplayAgentTypeNativeSafari,
MOPUBDisplayAgentTypeSafariViewController
};

@protocol MPAdDestinationDisplayAgentDelegate;

@interface MPAdDestinationDisplayAgent : NSObject <MPProgressOverlayViewDelegate,
Expand All @@ -22,6 +28,7 @@
@property (nonatomic, weak) id<MPAdDestinationDisplayAgentDelegate> delegate;

+ (MPAdDestinationDisplayAgent *)agentWithDelegate:(id<MPAdDestinationDisplayAgentDelegate>)delegate;
+ (BOOL)shouldUseSafariViewController;
- (void)displayDestinationForURL:(NSURL *)URL;
- (void)cancel;

Expand Down
Loading

0 comments on commit fb24d17

Please sign in to comment.