Skip to content

Commit

Permalink
Add support for filters on Included Reviews and Questions for a BVPro…
Browse files Browse the repository at this point in the history
…ductDisplayPageRequest
  • Loading branch information
Tim Kelly committed Feb 21, 2017
1 parent 7b4416c commit 9ade7f6
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 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.4.0'
s.version = '6.4.1'
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 Down
4 changes: 2 additions & 2 deletions BVSDK/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>6.4.0</string>
<string>6.4.1</string>
<key>CFBundleVersion</key>
<string>6.4.0</string>
<string>6.4.1</string>
<key>LSApplicationCategoryType</key>
<string></string>
<key>NSPrincipalClass</key>
Expand Down
4 changes: 2 additions & 2 deletions Pod/BVCommon/BVSDKConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

/// Provides the master version of the SDK.

#define BV_SDK_VERSION @"6.4.0"
#define BV_SDK_VERSION @"6.4.1"

/// Conversation SDK Version
#define SDK_HEADER_NAME @"X-UA-BV-SDK"
#define SDK_HEADER_VALUE @"IOS_SDK_V640"
#define SDK_HEADER_VALUE @"IOS_SDK_V641"

/// Error domain for NSError results, when present.
#define BVErrDomain @"com.bvsdk.bazaarvoice"
Expand Down
20 changes: 20 additions & 0 deletions Pod/BVConversations/Display/Requests/BVProductDisplayPageRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#import "BVSortOptionAnswers.h"
#import "BVSort.h"
#import "PDPInclude.h"
#import "BVFilterOperator.h"
#import "BVReviewFilterType.h"
#import "BVQuestionFilterType.h"


/*
You can retrieve all information needed for a Product Display Page with this request.
Expand All @@ -22,15 +26,31 @@
*/
@interface BVProductDisplayPageRequest : BVConversationsRequest


/// Initialize the request for the product ID you are displaying on your product page.
- (nonnull instancetype)initWithProductId:(NSString * _Nonnull)productId;
- (nonnull instancetype) __unavailable init;

/// Type of social content to inlcude with the product request.
- (nonnull instancetype)includeContent:(PDPContentType)contentType limit:(int)limit;

// Includes statistics for the included content type.
- (nonnull instancetype)includeStatistics:(PDPContentType)contentType;

/// When adding reviews to include, you can add a sort parameter on the included reviews.
- (nonnull instancetype)sortIncludedReviews:(BVSortOptionReviews)option order:(BVSortOrder)order;
/// When adding questions to include, you can add a sort parameter on the included questions.
- (nonnull instancetype)sortIncludedQuestions:(BVSortOptionQuestions)option order:(BVSortOrder)order;
/// When adding answers to include, you can add a sort parameter on the included answer.
- (nonnull instancetype)sortIncludedAnswers:(BVSortOptionAnswers)option order:(BVSortOrder)order;

/// Inclusive filter to add for included reviews.
- (nonnull instancetype)addIncludedReviewsFilter:(BVReviewFilterType)type filterOperator:(BVFilterOperator)filterOperator value:(NSString * _Nonnull)value;

/// Inclusive filter to add for included questions.
- (nonnull instancetype)addIncludedQuestionsFilter:(BVQuestionFilterType)type filterOperator:(BVFilterOperator)filterOperator value:(NSString * _Nonnull)value;

/// Asynchronous call to fetch data for this request.
- (void)load:(ProductRequestCompletionHandler _Nonnull)success failure:(ConversationsFailureHandler _Nonnull)failure;

- (NSString * _Nonnull)endpoint;
Expand Down
34 changes: 34 additions & 0 deletions Pod/BVConversations/Display/Requests/BVProductDisplayPageRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ @interface BVProductDisplayPageRequest()
@property NSMutableArray<BVSort*>* _Nonnull questionSorts;
@property NSMutableArray<BVSort*>* _Nonnull answerSorts;

@property NSMutableArray<BVFilter*>* _Nonnull reviewFilters;
@property NSMutableArray<BVFilter*>* _Nonnull questionFilters;

@end

@implementation BVProductDisplayPageRequest
Expand All @@ -32,6 +35,8 @@ - (nonnull instancetype)initWithProductId:(NSString * _Nonnull)productId {
self.reviewSorts = [NSMutableArray array];
self.questionSorts = [NSMutableArray array];
self.answerSorts = [NSMutableArray array];
self.reviewFilters = [NSMutableArray array];
self.questionFilters = [NSMutableArray array];
self.PDPContentTypeStatistics = [NSMutableArray array];
}
return self;
Expand Down Expand Up @@ -66,6 +71,27 @@ - (nonnull instancetype)sortIncludedAnswers:(BVSortOptionAnswers)option order:(B
return self;
}

- (nonnull instancetype)addIncludedReviewsFilter:(BVReviewFilterType)type filterOperator:(BVFilterOperator)filterOperator value:(NSString * _Nonnull)value{

BVFilter* filter = [[BVFilter alloc]
initWithString:[BVReviewFilterTypeUtil toString:type]
filterOperator:filterOperator values:@[value]];

[self.reviewFilters addObject:filter];
return self;
}

- (nonnull instancetype)addIncludedQuestionsFilter:(BVQuestionFilterType)type filterOperator:(BVFilterOperator)filterOperator value:(NSString * _Nonnull)value{

BVFilter* filter = [[BVFilter alloc]
initWithString:[BVQuestionFilterTypeUtil toString:type]
filterOperator:filterOperator values:@[value]];

[self.questionFilters addObject:filter];
return self;

}

- (void)load:(ProductRequestCompletionHandler _Nonnull)success failure:(ConversationsFailureHandler _Nonnull)failure {
[super loadProducts:self completion:success failure:failure];
}
Expand Down Expand Up @@ -93,6 +119,14 @@ - (NSMutableArray * _Nonnull)createParams {
[params addObject:[self sortParams:self.answerSorts withKey:@"Sort_Answers"]];
}

for(BVFilter* filter in self.reviewFilters) {
[params addObject:[BVStringKeyValuePair pairWithKey:@"Filter_Reviews" value:[filter toParameterString]]];
}

for(BVFilter* filter in self.questionFilters) {
[params addObject:[BVStringKeyValuePair pairWithKey:@"Filter_Questions" value:[filter toParameterString]]];
}

if (self.includes.count > 0){
[params addObject:[BVStringKeyValuePair pairWithKey:@"Include" value:[self includesToParams:self.includes]]];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ProductDisplayTests: XCTestCase {
BVSDKManager.shared().clientId = "apitestcustomer"
BVSDKManager.shared().apiKeyConversations = "kuy3zj9pr3n7i0wxajrzj04xo"
BVSDKManager.shared().staging = true
BVSDKManager.shared().setLogLevel(.error)
}


Expand Down Expand Up @@ -60,4 +61,53 @@ class ProductDisplayTests: XCTestCase {

}


func testProductDisplayWithFilter() {

let expectation = self.expectation(description: "")

let request = BVProductDisplayPageRequest(productId: "test1")
.include(.reviews, limit: 10)
.include(.questions, limit: 5)
// only include reviews where isRatingsOnly is false
.addIncludedReviewsFilter(.isRatingsOnly, filterOperator: .equalTo, value: "false")
// only include questions where isFeatured is not equal to true
.addIncludedQuestionsFilter(.isFeatured, filterOperator: .notEqualTo, value: "true")
.includeStatistics(.reviews)

request.load({ (response) in

XCTAssertNotNil(response.result)

let product = response.result!

XCTAssertEqual(product.includedReviews.count, 10)
XCTAssertEqual(product.includedQuestions.count, 5)

// Iterate all the included reviews and verify that all the reviews have isRatingsOnly = false
for review in product.includedReviews {
XCTAssertFalse(review.isRatingsOnly)
}

// Iterate all the included questions and verify that all the questions have isFeatured = false
for question in product.includedQuestions {
XCTAssertFalse(question.isFeatured)
}

expectation.fulfill()

}) { (error) in

XCTFail("product display request error: \(error)")
expectation.fulfill()

}

self.waitForExpectations(timeout: 10) { (error) in
XCTAssertNil(error, "Something went horribly wrong, request took too long.")
}

}


}

0 comments on commit 9ade7f6

Please sign in to comment.