Skip to content

Commit

Permalink
Getting ready for 7.0.0 release (#275)
Browse files Browse the repository at this point in the history
Adding support for user locale, networking improvements, and general cleanup. Affected Tickets: [MOB-806], [MOB-816], [MOB-818], [MOB-817], & [MOB-819]
  • Loading branch information
synackal authored and Michael Van Milligan committed Mar 6, 2018
1 parent 1f19e40 commit b240a62
Show file tree
Hide file tree
Showing 738 changed files with 16,281 additions and 14,547 deletions.
2 changes: 1 addition & 1 deletion .format.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

for DIRECTORY in Pod Examples Tests/Tests
for DIRECTORY in BVSDK Examples BVSDKTests
do
echo "Formatting code under $DIRECTORY/"
find "$DIRECTORY" \( -name '*.h' -or -name '*.m' -or -name '*.mm' \) -print0 | xargs -0 "clang-format" -i
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@ Tests/installation_tests/carthage/Cartfile
Tests/installation_tests/carthage/Cartfile.resolved
Tests/installation_tests/carthage/Carthage/*

# ignore appledoc
misc/docset
misc/html

# BV Specific
BVSDK.framework.zip
29 changes: 17 additions & 12 deletions BVSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Pod::Spec.new do |s|
s.name = "BVSDK"
s.version = '6.9.0'
s.version = '7.0.0'

This comment has been minimized.

Copy link
@caseykulm

caseykulm Mar 23, 2018

Contributor

🎉

This comment has been minimized.

Copy link
@austimkelly

austimkelly Mar 23, 2018

Contributor

🚀!

s.homepage = 'https://developer.bazaarvoice.com/'
s.license = { :type => 'Commercial', :text => 'See https://developer.bazaarvoice.com/API_Terms_of_Use' }
s.author = { 'Bazaarvoice' => '[email protected]' }
Expand All @@ -26,55 +26,60 @@ Pod::Spec.new do |s|
s.default_subspec = 'BVCommon'

s.subspec 'BVCommon' do |common|
common.source_files = 'Pod/BVCommon/**/*.{h,m}', 'Pod/BVAnalytics/**/*.{h,m}'
common.source_files = 'BVSDK/BVCommon/**/*.{h,m}', 'BVSDK/BVAnalytics/**/*.{h,m}'
common.private_header_files = 'BVSDK/BVCommon/**/Private/*.{h}', 'BVSDK/BVAnalytics/**/Private/*.{h}'
end

s.subspec 'BVCommonUI' do |commonui|
commonui.source_files = 'Pod/BVCommonUI/**/*.{h,m}'
commonui.source_files = 'BVSDK/BVCommonUI/**/*.{h,m}'
commonui.private_header_files = 'BVSDK/BVCommonUI/**/Private/*.{h}'
end

s.subspec 'BVAnalytics' do |analytics|
analytics.dependency 'BVSDK/BVCommon'
end

s.subspec 'BVConversations' do |conversations|
conversations.source_files = 'Pod/BVConversations/**/*.{h,m}'
conversations.source_files = 'BVSDK/BVConversations/**/*.{h,m}'
conversations.private_header_files = 'BVSDK/BVConversations/**/Private/*.{h}'
conversations.dependency 'BVSDK/BVCommon'
end

s.subspec 'BVConversationsStores' do |conversationsstores|
conversationsstores.source_files = 'Pod/BVConversationsStores/**/*.{h,m}'
conversationsstores.source_files = 'BVSDK/BVConversationsStores/**/*.{h,m}', 'BVSDK/BVConversations/**/Private/*.{h,m}'
conversationsstores.private_header_files = 'BVSDK/BVConversationsStores/**/Private/*.{h}'
conversationsstores.dependency 'BVSDK/BVConversations'
end

s.subspec 'BVConversationsUI' do |conversationsui|
conversationsui.source_files = 'Pod/BVConversationsUI/**/*.{h,m}'
conversationsui.source_files = 'BVSDK/BVConversationsUI/**/*.{h,m}'
conversationsui.dependency 'BVSDK/BVCommonUI'
conversationsui.dependency 'BVSDK/BVConversationsStores'
end

s.subspec 'BVCurations' do |curations|
curations.source_files = 'Pod/BVCurations/**/*.{h,m}'
curations.source_files = 'BVSDK/BVCurations/**/*.{h,m}'
curations.dependency 'BVSDK/BVCommon'
end

s.subspec 'BVCurationsUI' do |curationsui|
curationsui.source_files = 'Pod/BVCurationsUI/**/*.{h,m}'
curationsui.source_files = 'BVSDK/BVCurationsUI/**/*.{h,m}'
curationsui.dependency 'BVSDK/BVCurations'
curationsui.dependency 'BVSDK/BVCommonUI'
curationsui.resources = ["Pod/BVCurationsUI/SocialMediaIcons/*.xcassets"]
curationsui.resources = ["BVSDK/BVCurationsUI/SocialMediaIcons/*.xcassets"]
end

s.subspec 'BVNotifications' do |notifications|

notifications.source_files = 'Pod/BVNotifications/**/*.{h,m}', 'Pod/BVCommon/Private/*.{h,m}'
notifications.resources = ['Pod/BVNotifications/mapThumbnail.png']
notifications.source_files = 'BVSDK/BVNotifications/**/*.{h,m}', 'BVSDK/BVCommon/Private/*.{h,m}'
notifications.resources = ['BVSDK/BVNotifications/mapThumbnail.png']

notifications.dependency 'BVSDK/BVConversationsUI'
end

s.subspec 'BVRecommendations' do |recs|
recs.source_files = 'Pod/BVRecommendations/**/*.{h,m}'
recs.source_files = 'BVSDK/BVRecommendations/**/*.{h,m}'
recs.private_header_files = 'BVSDK/BVRecommendations/**/Private/*.{h}'
recs.dependency 'BVSDK/BVCommon'
end

Expand Down
705 changes: 478 additions & 227 deletions BVSDK.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ @interface BVAnalyticEventManager ()

@implementation BVAnalyticEventManager

static BVAnalyticEventManager *mgrInstance = nil;
__strong static BVAnalyticEventManager *mgrInstance = nil;

+ (BVAnalyticEventManager *)sharedManager {
static dispatch_once_t onceToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#import "BVBasePIIEvent.h"

static NSSet *whitelistParams;
__strong static NSSet *whitelistParams;

@implementation BVBasePIIEvent

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
/// NO
@property(nonatomic, assign) BOOL isDryRunAnalytics;

/// This can be optionally set by the configuration, otherwise, we just use the
/// current.
@property(nonatomic, strong) NSLocale *analyticsLocale;

/// Create and get the singleton instance of the analytics manager.
+ (BVAnalyticsManager *)sharedManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@

#import "BVAnalyticEventManager.h"
#import "BVAnalyticsManager.h"
#import "BVLocaleServiceManager.h"
#import "BVLogger.h"
#import "BVNetworkingManager.h"
#import "BVPersonalizationEvent.h"
#import "BVSDKConfiguration.h"
#import "BVSDKConstants.h"
#import "BVSDKManager.h"

#include <sys/sysctl.h>
#include <sys/utsname.h>

#define BV_MAGPIE_ENDPOINT @"https://network.bazaarvoice.com/event"
#define BV_MAGPIE_STAGING_ENDPOINT @"https://network-stg.bazaarvoice.com/event"

@interface BVAnalyticsManager ()

@property(strong)
Expand All @@ -28,20 +29,24 @@ @interface BVAnalyticsManager ()
@property NSTimer *queueFlushTimer;
@property NSTimeInterval queueFlushInterval;

@property(nonatomic, strong)
dispatch_queue_t localeUpdateNotificationTokenQueue;
@property(strong) id<NSObject> localeUpdateNotificationCenterToken;

@property(nonatomic, strong) dispatch_queue_t concurrentEventQueue;

@end

@implementation BVAnalyticsManager

@synthesize analyticsLocale = _analyticsLocale;

static BVAnalyticsManager *analyticsInstance = nil;

+ (BVAnalyticsManager *)sharedManager {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
analyticsInstance = [[self alloc] init];
analyticsInstance->_concurrentEventQueue = dispatch_queue_create(
"com.bazaarvoice.analyticEventQueue", DISPATCH_QUEUE_CONCURRENT);
});

return analyticsInstance;
Expand All @@ -52,6 +57,11 @@ - (id)init {
if (self != nil) {
self.eventQueue = [NSMutableArray array];
self.pageviewQueue = [NSMutableArray array];
self.concurrentEventQueue = dispatch_queue_create(
"com.bazaarvoice.analyticEventQueue", DISPATCH_QUEUE_CONCURRENT);
self.localeUpdateNotificationTokenQueue = dispatch_queue_create(
"com.bazaarvoice.notificationTokenQueue", DISPATCH_QUEUE_SERIAL);

[self setFlushInterval:10.0];
[self registerForAppStateChanges];
}
Expand Down Expand Up @@ -353,9 +363,18 @@ - (void)sendBatchedPOSTEvent:(NSDictionary *)eventData
return;
}

NSURLSessionConfiguration *config =
[NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
/// For private classes we ask for the NSURLSession but we don't hand back any
/// objects since it would be useless to the developers as they have no
/// interface to the object graph.
NSURLSession *session = nil;
id<BVURLSessionDelegate> sessionDelegate =
[BVSDKManager sharedManager].urlSessionDelegate;
if (sessionDelegate &&
[sessionDelegate respondsToSelector:@selector(URLSessionForBVObject:)]) {
session = [sessionDelegate URLSessionForBVObject:nil];
}

session = session ?: [BVNetworkingManager sharedManager].bvNetworkingSession;

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
request.HTTPMethod = @"POST";
Expand Down Expand Up @@ -413,6 +432,86 @@ - (void)sendBatchedPOSTEvent:(NSDictionary *)eventData
};
}

#pragma mark - NSLocale Analytic Handling

- (NSLocale *)analyticsLocale {
__block NSLocale *locale = nil;
dispatch_sync(self.localeUpdateNotificationTokenQueue, ^{
locale = _analyticsLocale;
});
return locale;
}

- (void)setAnalyticsLocale:(NSLocale *)analyticsLocale {
dispatch_sync(self.localeUpdateNotificationTokenQueue, ^{
_analyticsLocale = analyticsLocale;

if (_analyticsLocale) {
/// Turn off locale state changes
[self unregisterForCurrentLocaleDidChangeNotifications];
} else {
_analyticsLocale = [NSLocale autoupdatingCurrentLocale];
/// Turn on locale state changes
[self registerForCurrentLocaleDidChangeNotifications];
}

[self logAnalyticsLocaleUnsafe];
});
}

- (void)logAnalyticsLocale {
dispatch_sync(self.localeUpdateNotificationTokenQueue, ^{
[self logAnalyticsLocaleUnsafe];
});
}

- (void)logAnalyticsLocaleUnsafe {
NSString *logLocale = nil;
if (_analyticsLocale) {
logLocale =
((NSString *)[_analyticsLocale objectForKey:NSLocaleCountryCode])
.uppercaseString;
}

[[BVLogger sharedLogger]
analyticsMessage:[NSString
stringWithFormat:@"Configuration has set Locale: %@",
logLocale]];
}

- (void)registerForCurrentLocaleDidChangeNotifications {
if (!self.localeUpdateNotificationCenterToken) {
[[BVLogger sharedLogger]
analyticsMessage:
@"Analytics REGISTERING for Locale Change Notifications."];

self.localeUpdateNotificationCenterToken =
[[NSNotificationCenter defaultCenter]
addObserverForName:NSCurrentLocaleDidChangeNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
dispatch_sync(self.localeUpdateNotificationTokenQueue, ^{
_analyticsLocale = [NSLocale autoupdatingCurrentLocale];
[self logAnalyticsLocaleUnsafe];
});
}];
}
}

- (void)unregisterForCurrentLocaleDidChangeNotifications {

[[BVLogger sharedLogger]
analyticsMessage:
@"Analytics UNREGISTERING for Locale Change Notifications."];

if (self.localeUpdateNotificationCenterToken) {
[[NSNotificationCenter defaultCenter]
removeObserver:self.localeUpdateNotificationCenterToken];
self.localeUpdateNotificationCenterToken = nil;
}
}

#pragma mark - Helpers

- (NSString *)formatDate:(NSDate *)date {
Expand All @@ -427,14 +526,20 @@ - (NSString *)formatDate:(NSDate *)date {
}

- (NSString *)baseUrl {
BVLocaleServiceManager *localeServiceManager =
[BVLocaleServiceManager sharedManager];
NSAssert(localeServiceManager, @"BVLocaleServiceManager is nil.");

if (self.isStagingServer) {
[[BVLogger sharedLogger] error:@"WARNING: Using staging server for "
@"analytic events. This should only "
@"enabled for non-production."];
return BV_MAGPIE_STAGING_ENDPOINT;
} else {
return BV_MAGPIE_ENDPOINT;
[[BVLogger sharedLogger]
error:@"WARNING: Using staging server for analytic events. This should "
@"only be enabled for non-production."];
}

return [localeServiceManager
resourceForService:BVLocaleServiceManagerServiceAnalytics
withLocale:self.analyticsLocale
andIsProduction:(!self.isStagingServer)];
}

- (void)setFlushInterval:(NSTimeInterval)newInterval {
Expand Down
25 changes: 25 additions & 0 deletions BVSDK/BVAnalytics/Private/BVLocaleServiceManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// BVLocaleServiceManager.h
// BVSDK
//
// Copyright © 2018 Bazaarvoice. All rights reserved.
//

#import <Foundation/Foundation.h>

/// The types of services that require Locale specific actions.
typedef NS_ENUM(NSUInteger, BVLocaleServiceManagerService) {
BVLocaleServiceManagerServiceAnalytics
};

@interface BVLocaleServiceManager : NSObject

/// Create and get the singleton instance of the region manager.
+ (nonnull instancetype)sharedManager;

/// Acquire the base URL for service given a region object
- (nonnull NSString *)resourceForService:(BVLocaleServiceManagerService)service
withLocale:(nonnull NSLocale *)locale
andIsProduction:(BOOL)isProduction;

@end
Loading

0 comments on commit b240a62

Please sign in to comment.