@@ -34,7 +34,12 @@ impl Input {
34
34
"adUnitId" => Ok ( Value :: String ( self . global . ad_unit_id . 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" => self . global . country . clone ( ) . map ( Value :: String ) . ok_or ( Error :: UnknownVariable ) ,
37
+ "country" => self
38
+ . global
39
+ . country
40
+ . clone ( )
41
+ . map ( Value :: String )
42
+ . ok_or ( Error :: UnknownVariable ) ,
38
43
"eventType" => Ok ( Value :: String ( self . global . event_type . clone ( ) ) ) ,
39
44
"campaignId" => Ok ( Value :: String ( self . global . campaign_id . clone ( ) ) ) ,
40
45
"campaignTotalSpent" => Ok ( Value :: String ( self . global . campaign_total_spent . clone ( ) ) ) ,
@@ -51,10 +56,18 @@ impl Input {
51
56
self . global . publisher_earned_from_campaign . clone ( ) ,
52
57
) ) ,
53
58
"secondsSinceEpoch" => Ok ( Value :: Number ( self . global . seconds_since_epoch . into ( ) ) ) ,
54
- "userAgentOS" => self . global . user_agent_os . clone ( ) . map ( Value :: String ) . ok_or ( Error :: UnknownVariable ) ,
55
- "userAgentBrowserFamily" => {
56
- self . global . user_agent_browser_family . clone ( ) . map ( Value :: String ) . ok_or ( Error :: UnknownVariable )
57
- }
59
+ "userAgentOS" => self
60
+ . global
61
+ . user_agent_os
62
+ . clone ( )
63
+ . map ( Value :: String )
64
+ . ok_or ( Error :: UnknownVariable ) ,
65
+ "userAgentBrowserFamily" => self
66
+ . global
67
+ . user_agent_browser_family
68
+ . clone ( )
69
+ . map ( Value :: String )
70
+ . ok_or ( Error :: UnknownVariable ) ,
58
71
"adSlot.categories" => self
59
72
. ad_slot
60
73
. as_ref ( )
@@ -70,9 +83,10 @@ impl Input {
70
83
"adSlot.hostname" => self
71
84
. ad_slot
72
85
. as_ref ( )
73
- . map ( |ad_slot| Value :: String ( ad_slot. hostname . clone ( ) ) )
86
+ . map ( |ad_slot| Value :: String ( ad_slot. hostname . clone ( ) . unwrap_or_default ( ) ) )
74
87
. ok_or ( Error :: UnknownVariable ) ,
75
88
"adSlot.alexaRank" => {
89
+ // @TODO: Decide how to handle Alexa rank values
76
90
let ad_slot = self . ad_slot . as_ref ( ) . ok_or ( Error :: UnknownVariable ) ?;
77
91
let alexa_rank = ad_slot. alexa_rank . ok_or ( Error :: UnknownVariable ) ?;
78
92
@@ -123,7 +137,7 @@ pub struct Global {
123
137
#[ cfg_attr( test, derive( Default ) ) ]
124
138
pub struct AdSlot {
125
139
pub categories : Vec < String > ,
126
- pub hostname : String ,
140
+ pub hostname : Option < String > ,
127
141
pub alexa_rank : Option < f64 > ,
128
142
}
129
143
@@ -202,7 +216,10 @@ mod test {
202
216
203
217
assert_eq ! ( Value :: BigNum ( BigNum :: from( 50 ) ) , global_campaign_budget) ;
204
218
205
- assert_eq ! ( Err ( Error :: UnknownVariable ) , input. try_get( "adSlot.alexaRank" ) ) ;
219
+ assert_eq ! (
220
+ Err ( Error :: UnknownVariable ) ,
221
+ input. try_get( "adSlot.alexaRank" )
222
+ ) ;
206
223
let mut ad_slot = AdSlot :: default ( ) ;
207
224
ad_slot. alexa_rank = Some ( 20.0 ) ;
208
225
input. ad_slot = Some ( ad_slot) ;
0 commit comments