Yandex Mobile Ads
Loading...
Searching...
No Matches
AdRequest.cs
Go to the documentation of this file.
1/*
2 * This file is a part of the Yandex Advertising Network
3 *
4 * Version for Unity (C) 2023 YANDEX
5 *
6 * You may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at https://legal.yandex.com/partner_ch/
8 */
9
10using System;
11using System.Collections.Generic;
12
14{
19 public class AdRequest
20 {
24 public string Age { get; private set; }
25
29 public string ContextQuery { get; private set; }
30
34 public List<string> ContextTags { get; private set; }
35
39 public string Gender { get; private set; }
40
44 public Location Location { get; private set; }
45
49 public AdTheme AdTheme { get; private set; }
50
54 public Dictionary<string, string> Parameters { get; private set; }
55
56 private AdRequest(Builder builder)
57 {
58 this.Age = builder.Age;
59 this.ContextQuery = builder.ContextQuery;
60
61 if (builder.ContextTags != null)
62 {
63 this.ContextTags = new List<string>(builder.ContextTags);
64 }
65
66 this.Gender = builder.Gender;
67 this.Location = builder.Location;
68 this.AdTheme = builder.AdTheme;
69
70 if (builder.Parameters != null)
71 {
72 this.Parameters = new Dictionary<string, string>(builder.Parameters);
73 }
74 }
75
79 public class Builder
80 {
81
82 internal string Age { get; private set; }
83
84 internal string ContextQuery { get; private set; }
85
86 internal List<string> ContextTags { get; private set; }
87
88 internal string Gender { get; private set; }
89
90 internal Location Location { get; private set; }
91
92 internal AdTheme AdTheme { get; private set; }
93
94 internal Dictionary<string, string> Parameters { get; private set; }
95
101 public Builder WithAge(string age)
102 {
103 this.Age = age;
104 return this;
105 }
106
112 public Builder WithContextQuery(string contextQuery)
113 {
114 this.ContextQuery = contextQuery;
115 return this;
116 }
117
123 public Builder WithContextTags(List<string> contextTags)
124 {
125 this.ContextTags = contextTags;
126 return this;
127 }
128
134 public Builder WithGender(string gender)
135 {
136 this.Gender = gender;
137 return this;
138 }
139
146 {
147 this.Location = location;
148 return this;
149 }
150
156 public Builder WithAdTheme(AdTheme preferredTheme)
157 {
158 this.AdTheme = preferredTheme;
159 return this;
160 }
161
167 public Builder WithParameters(Dictionary<string, string> parameters)
168 {
169 this.Parameters = parameters;
170 return this;
171 }
172
179 {
180 if (adRequest != null)
181 {
182 this.ContextQuery = adRequest.ContextQuery;
183 this.ContextTags = adRequest.ContextTags;
184 this.Parameters = adRequest.Parameters;
185 this.Location = adRequest.Location;
186 this.Age = adRequest.Age;
187 this.AdTheme = adRequest.AdTheme;
188 this.Gender = adRequest.Gender;
189 }
190 return this;
191 }
192
198 {
199 if (this.Parameters == null)
200 {
201 this.Parameters = new Dictionary<string, string>();
202 }
203 return new AdRequest(this);
204 }
205 }
206 }
207}
A class responsible for creating AdRequest objects.
Definition AdRequest.cs:80
Builder WithParameters(Dictionary< string, string > parameters)
AdRequest Builder initialized with custom Parameters.
Definition AdRequest.cs:167
Builder WithAge(string age)
AdRequest Builder initialized with user's Age for targeting process.
Definition AdRequest.cs:101
Builder WithGender(string gender)
AdRequest Builder initialized with user's Gender for targeting process.
Definition AdRequest.cs:134
AdRequest Build()
Creates AdRequest based on current builder parameters.
Definition AdRequest.cs:197
Builder WithContextQuery(string contextQuery)
AdRequest Builder initialized with current user query entered inside app.
Definition AdRequest.cs:112
Builder WithAdRequest(AdRequest adRequest)
AdRequest Builder initialized with AdRequest.
Definition AdRequest.cs:178
Builder WithAdTheme(AdTheme preferredTheme)
Sets preferred theme.
Definition AdRequest.cs:156
Builder WithLocation(Location location)
AdRequest Builder initialized with user's Location for targeting process.
Definition AdRequest.cs:145
Builder WithContextTags(List< string > contextTags)
AdRequest Builder initialized with tags describing current user context inside app.
Definition AdRequest.cs:123
Contains targeting information used to fetch an ad. new instance should be created using AdRequestCon...
Definition AdRequest.cs:20
AdTheme AdTheme
Preferred theme.
Definition AdRequest.cs:49
Dictionary< string, string > Parameters
A set of arbitrary input parameters.
Definition AdRequest.cs:54
string Age
The string representation of user's age.
Definition AdRequest.cs:24
Location Location
User location.
Definition AdRequest.cs:44
List< string > ContextTags
An array of tags.Matches the context in which the ad will be displayed.
Definition AdRequest.cs:34
string Gender
The string representation of user's gender. See the list of values in Gender.
Definition AdRequest.cs:39
string ContextQuery
The search query that the user entered in the app.
Definition AdRequest.cs:29
The gender of the user.
Definition Gender.cs:16
Current user location.
Definition Location.cs:18