@@ -30,11 +30,11 @@ impl Input {
30
30
. map ( |ad_view| Value :: Bool ( ad_view. has_custom_preferences ) )
31
31
. ok_or ( Error :: UnknownVariable ) ,
32
32
"adSlotId" => Ok ( Value :: String ( self . global . ad_slot_id . clone ( ) ) ) ,
33
+ "adSlotType" => Ok ( Value :: String ( self . global . ad_slot_type . clone ( ) ) ) ,
33
34
"adUnitId" => Ok ( Value :: String ( self . global . ad_unit_id . clone ( ) ) ) ,
34
- "adUnitType" => Ok ( Value :: String ( self . global . ad_unit_type . clone ( ) ) ) ,
35
35
"publisherId" => Ok ( Value :: String ( self . global . publisher_id . clone ( ) ) ) ,
36
36
"advertiserId" => Ok ( Value :: String ( self . global . advertiser_id . clone ( ) ) ) ,
37
- "country" => Ok ( Value :: String ( self . global . country . clone ( ) ) ) ,
37
+ "country" => self . global . country . clone ( ) . map ( Value :: String ) . ok_or ( Error :: UnknownVariable ) ,
38
38
"eventType" => Ok ( Value :: String ( self . global . event_type . clone ( ) ) ) ,
39
39
"campaignId" => Ok ( Value :: String ( self . global . campaign_id . clone ( ) ) ) ,
40
40
"campaignTotalSpent" => Ok ( Value :: String ( self . global . campaign_total_spent . clone ( ) ) ) ,
@@ -51,9 +51,9 @@ impl Input {
51
51
self . global . publisher_earned_from_campaign . clone ( ) ,
52
52
) ) ,
53
53
"secondsSinceEpoch" => Ok ( Value :: Number ( self . global . seconds_since_epoch . into ( ) ) ) ,
54
- "userAgentOS" => Ok ( Value :: String ( self . global . user_agent_os . clone ( ) ) ) ,
54
+ "userAgentOS" => self . global . user_agent_os . clone ( ) . map ( Value :: String ) . ok_or ( Error :: UnknownVariable ) ,
55
55
"userAgentBrowserFamily" => {
56
- Ok ( Value :: String ( self . global . user_agent_browser_family . clone ( ) ) )
56
+ self . global . user_agent_browser_family . clone ( ) . map ( Value :: String ) . ok_or ( Error :: UnknownVariable )
57
57
}
58
58
"adSlot.categories" => self
59
59
. ad_slot
@@ -74,8 +74,9 @@ impl Input {
74
74
. ok_or ( Error :: UnknownVariable ) ,
75
75
"adSlot.alexaRank" => {
76
76
let ad_slot = self . ad_slot . as_ref ( ) . ok_or ( Error :: UnknownVariable ) ?;
77
+ let alexa_rank = ad_slot. alexa_rank . ok_or ( Error :: UnknownVariable ) ?;
77
78
78
- match serde_json:: Number :: from_f64 ( ad_slot . alexa_rank ) {
79
+ match serde_json:: Number :: from_f64 ( alexa_rank) {
79
80
Some ( number) => Ok ( Value :: Number ( number) ) ,
80
81
None => Err ( Error :: TypeError ) ,
81
82
}
@@ -95,13 +96,19 @@ pub struct AdView {
95
96
#[ derive( Debug , Clone ) ]
96
97
#[ cfg_attr( test, derive( Default ) ) ]
97
98
pub struct Global {
99
+ /// Global scope, accessible everywhere
98
100
pub ad_slot_id : String ,
99
- pub ad_unit_id : String ,
100
- pub ad_unit_type : String ,
101
+ pub ad_slot_type : String ,
101
102
pub publisher_id : String ,
102
- pub advertiser_id : String ,
103
- pub country : String ,
103
+ pub country : Option < String > ,
104
104
pub event_type : String ,
105
+ pub seconds_since_epoch : u64 ,
106
+ pub user_agent_os : Option < String > ,
107
+ pub user_agent_browser_family : Option < String > ,
108
+ /// Global scope, accessible everywhere, campaign-dependant
109
+ pub ad_unit_id : String ,
110
+ // adUnitCategories
111
+ pub advertiser_id : String ,
105
112
pub campaign_id : String ,
106
113
pub campaign_total_spent : String ,
107
114
pub campaign_seconds_active : u64 ,
@@ -110,17 +117,14 @@ pub struct Global {
110
117
pub event_min_price : BigNum ,
111
118
pub event_max_price : BigNum ,
112
119
pub publisher_earned_from_campaign : BigNum ,
113
- pub seconds_since_epoch : u64 ,
114
- pub user_agent_os : String ,
115
- pub user_agent_browser_family : String ,
116
120
}
117
121
118
122
#[ derive( Debug , Clone ) ]
119
123
#[ cfg_attr( test, derive( Default ) ) ]
120
124
pub struct AdSlot {
121
125
pub categories : Vec < String > ,
122
126
pub hostname : String ,
123
- pub alexa_rank : f64 ,
127
+ pub alexa_rank : Option < f64 > ,
124
128
}
125
129
126
130
#[ derive( Debug ) ]
@@ -197,6 +201,12 @@ mod test {
197
201
. expect ( "Should get the global.campaign_budget field" ) ;
198
202
199
203
assert_eq ! ( Value :: BigNum ( BigNum :: from( 50 ) ) , global_campaign_budget) ;
204
+
205
+ assert_eq ! ( Err ( Error :: UnknownVariable ) , input. try_get( "adSlot.alexaRank" ) ) ;
206
+ let mut ad_slot = AdSlot :: default ( ) ;
207
+ ad_slot. alexa_rank = Some ( 20.0 ) ;
208
+ input. ad_slot = Some ( ad_slot) ;
209
+ assert ! ( input. try_get( "adSlot.alexaRank" ) . is_ok( ) ) ;
200
210
}
201
211
202
212
#[ test]
0 commit comments