Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

Update dv360 query to deal with advertiser-level query #62

Merged
merged 5 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/src/public_api_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'dart:convert';

import 'proto/insertion_order_query.pb.dart';

/// TODO: parse and handle dv360 public api error.
/// Issue:https://github.com/googleinterns/dv360-excel-plugin/issues/52
class PublicApiParser {
static const _emptyEntry = '';

Expand Down Expand Up @@ -42,11 +44,16 @@ class PublicApiParser {
static List<InsertionOrder> parseInsertionOrders(String jsonString) {
if (jsonString == null || jsonString.isEmpty) return [];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kind of concerned about the possibility of null or empty values popping up in any method. If a response was invalid i think we should fail and throw rather than propagate a null or empty string. it'll also make your life easier i think being confident in your inputs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in real cases that jsonString can never be null or empty, since even if a request fails, it still returns a json object with the error message. I'm thinking that we should add parsing to the error json and display the error to users to let them know that they have entered the wrong id, etc. I guess we should do this for all queries.

i will create an issue and address this at end when all the queries are set.

And the sanity check is actually just for component testing, since mock class will pass in null to this function.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can set the mock class to return a default value in setUp. i think it's better to facilitate testing needs in the test code rather than your business code

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wanted to reply to this as part of a review to draw your attention to it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh right. I will just get rid of the sanity checks then. The TODO for adding parsing support to error is at the top of the file.

Map<String, dynamic> map = json.decode(jsonString);
return map.containsKey('insertionOrders')
? List.from(map['insertionOrders'])
.map((ioMap) => _createInsertionOrder(ioMap))
.toList()
: [_createInsertionOrder(map)];

// If map contains key 'insertionOrders', multiple IOs are returned.
// And if it doesn't, the map itself represents one insertion order.
if (map.containsKey('insertionOrders')) {
return List.from(map['insertionOrders'])
.map((ioMap) => _createInsertionOrder(ioMap))
.toList();
} else {
return [_createInsertionOrder(map)];
}
}

/// Parses the nextPageToken from a [jsonString].
Expand Down
27 changes: 16 additions & 11 deletions lib/src/query_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import 'util.dart';
placeholder="Insertion Order ID: 8127549" debugId="io-id-input">
<br>

<input type="checkbox" [(ngModel)]="isAdvertiserQuery" name="advertiser-query">
<input type="radio" [(ngModel)]="advertiserQuery" name="advertiser-query">
<label for="advertiser-query">By advertiser</label><br>
<input type="checkbox" [(ngModel)]="isInsertionOrderQuery" name="advertiser-query">
<input type="radio" [(ngModel)]="insertionOrderQuery" name="advertiser-query">
<label for="advertiser-query">By insertion order</label><br>

<input type="checkbox" [(ngModel)]="highlightUnderpacing"
Expand All @@ -31,7 +31,11 @@ import 'util.dart';
{{buttonName}}
</button>
''',
providers: [ClassProvider(QueryService), ClassProvider(ExcelDart)],
providers: [
ClassProvider(QueryService),
ClassProvider(ExcelDart),
FORM_PROVIDERS,
],
directives: [coreDirectives, formDirectives],
)
class QueryComponent {
Expand All @@ -45,17 +49,18 @@ class QueryComponent {
String insertionOrderId;
bool highlightUnderpacing = false;

QueryComponent(this._queryService, this._excel);

bool get isAdvertiserQuery => _queryType == QueryType.byAdvertiser;
set isAdvertiserQuery(bool checked) =>
checked ? _queryType = QueryType.byAdvertiser : null;
// Radio button states with byAdvertiser selected as default.
RadioButtonState advertiserQuery = RadioButtonState(true, 'byAdvertiser');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the radio button can only take string values :(

Saw other people complain about this too.

RadioButtonState insertionOrderQuery = RadioButtonState(false, 'byIO');

bool get isInsertionOrderQuery => _queryType == QueryType.byInsertionOrder;
set isInsertionOrderQuery(bool checked) =>
checked ? _queryType = QueryType.byInsertionOrder : null;
QueryComponent(this._queryService, this._excel);

void onClick() async {
// Determines the query type from radio buttons.
_queryType = advertiserQuery.checked
? QueryType.byAdvertiser
: QueryType.byInsertionOrder;

// Uses DV360 public APIs to fetch entity data.
var insertionOrders = await _queryAndParseInsertionOrderEntityData();

Expand Down
14 changes: 5 additions & 9 deletions lib/src/query_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,13 @@ class QueryService {
}

case QueryType.byInsertionOrder:
{
return RequestArgs(
path: 'https://displayvideo.googleapis.com/v1/advertisers/'
'$advertiserId/insertionOrders/$insertionOrderId',
method: 'GET');
}
return RequestArgs(
path: 'https://displayvideo.googleapis.com/v1/advertisers/'
'$advertiserId/insertionOrders/$insertionOrderId',
method: 'GET');

default:
{
return RequestArgs();
}
return RequestArgs();
}
}
}