-
Notifications
You must be signed in to change notification settings - Fork 749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation of Categories Http fetcher #882
Changes from 3 commits
b735807
7bf0358
e617bd2
be41c4b
925cc9f
2528a08
20d6f7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,9 +56,10 @@ func NewFetcher(client *http.Client, endpoint string) *HttpFetcher { | |
} | ||
|
||
type HttpFetcher struct { | ||
client *http.Client | ||
Endpoint string | ||
hasQuery bool | ||
client *http.Client | ||
Endpoint string | ||
hasQuery bool | ||
Categories map[string]map[string]stored_requests.Category | ||
} | ||
|
||
func (fetcher *HttpFetcher) FetchRequests(ctx context.Context, requestIDs []string, impIDs []string) (requestData map[string]json.RawMessage, impData map[string]json.RawMessage, errs []error) { | ||
|
@@ -80,8 +81,45 @@ func (fetcher *HttpFetcher) FetchRequests(ctx context.Context, requestIDs []stri | |
return | ||
} | ||
|
||
func (fetcher *HttpFetcher) FetchCategories(primaryAdServer, publisherId, iabCategory string) (string, error) { | ||
return "", nil | ||
func (fetcher *HttpFetcher) FetchCategories(ctx context.Context, primaryAdServer, publisherId, iabCategory string) (string, error) { | ||
if fetcher.Categories == nil { | ||
fetcher.Categories = make(map[string]map[string]stored_requests.Category) | ||
} | ||
|
||
if publisherId == "" { | ||
publisherId = primaryAdServer | ||
} | ||
|
||
dataName := fmt.Sprintf("%s_%s", primaryAdServer, publisherId) | ||
if data, ok := fetcher.Categories[dataName]; ok { | ||
return data[iabCategory].Id, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall the PR LGTM. I just have one small question though: Are we sure that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mansinahar yes, it's good to have this check. Thank you! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @Kalypsonika ! |
||
} | ||
//in NewFetcher function there is a code to add "?" at the end of url | ||
//in case of categories we don't expect to have any parameters, that's why we need to remove "?" | ||
url := fmt.Sprintf("%s/%s/%s.json", strings.Replace(fetcher.Endpoint, "?", "", -1), primaryAdServer, publisherId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably just removing the ? isn't going to work if the fetcher.Endpoint contains query params in the URL, we should just have this function throw an appropriate error if the endpoint has a ? here (instead of trying to handle that case). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made it because in
because of this there is always There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh ok I see why that's there then. I guess the difference is category fetcher is expecting it's variable parts to be in the URL path where as other fetchers are passing them in URL query params. Maybe this is fine then, but please add a comment to the effect that you are stripping away the question mark that gets added in NewFetcher code. Also we're assuming endpoints used for category mappings aren't going to contain query params, which maybe is ok since they'll probably just be statically hosted files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment added. |
||
|
||
httpReq, err := http.NewRequest("GET", url, nil) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
httpResp, err := ctxhttp.Do(ctx, fetcher.client, httpReq) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer httpResp.Body.Close() | ||
|
||
respBytes, err := ioutil.ReadAll(httpResp.Body) | ||
tmp := make(map[string]stored_requests.Category) | ||
|
||
if err := json.Unmarshal(respBytes, &tmp); err != nil { | ||
return "", fmt.Errorf("Unable to unmarshal categories for adserver: '%s', publisherId: '%s'", primaryAdServer, publisherId) | ||
} | ||
fetcher.Categories[dataName] = tmp | ||
|
||
resultCategory := tmp[iabCategory].Id | ||
|
||
return resultCategory, nil | ||
} | ||
|
||
func buildRequest(endpoint string, requestIDs []string, impIDs []string) (*http.Request, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means we could have something like
freewheel_freewheel
as thedataName
below. Is this correct, or should it resolve to justfreewheel
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, fixed!