@@ -106,12 +106,16 @@ open class StatsServiceRemoteV2: ServiceRemoteWordPressComREST {
106106 /// e.g. if you want data spanning 11-17 Feb 2019, you should pass in a period of `.week` and an
107107 /// ending date of `Feb 17 2019`.
108108 /// - limit: Limit of how many objects you want returned for your query. Default is `10`. `0` means no limit.
109- open func getData< TimeStatsType: StatsTimeIntervalData > ( for period: StatsPeriodUnit ,
110- unit: StatsPeriodUnit ? = nil ,
111- startDate: Date ? = nil ,
112- endingOn: Date ,
113- limit: Int = 10 ,
114- completion: @escaping ( ( TimeStatsType ? , Error ? ) -> Void ) ) {
109+ open func getData< TimeStatsType: StatsTimeIntervalData > (
110+ for period: StatsPeriodUnit ,
111+ unit: StatsPeriodUnit ? = nil ,
112+ startDate: Date ? = nil ,
113+ endingOn: Date ,
114+ limit: Int = 10 ,
115+ summarize: Bool ? = nil ,
116+ parameters: [ String : String ] ? = nil ,
117+ completion: @escaping ( ( TimeStatsType ? , Error ? ) -> Void )
118+ ) {
115119 let pathComponent = TimeStatsType . pathComponent
116120 let path = self . path ( forEndpoint: " sites/ \( siteID) / \( pathComponent) / " , withVersion: . _1_1)
117121
@@ -124,6 +128,14 @@ open class StatsServiceRemoteV2: ServiceRemoteWordPressComREST {
124128 if let startDate {
125129 staticProperties [ " start_date " ] = dateFormatter. string ( from: startDate) as AnyObject
126130 }
131+ if let summarize {
132+ staticProperties [ " summarize " ] = summarize. description as NSString
133+ }
134+ if let parameters {
135+ for (key, value) in parameters {
136+ staticProperties [ key] = value as NSString
137+ }
138+ }
127139
128140 let classProperties = TimeStatsType . queryProperties ( with: endingOn, period: unit ?? period, maxCount: limit) as [ String : AnyObject ]
129141
@@ -397,14 +409,15 @@ extension StatsTimeIntervalData {
397409 // Most of the responses for time data come in a unwieldy format, that requires awkwkard unwrapping
398410 // at the call-site — unfortunately not _all of them_, which means we can't just do it at the request level.
399411 static func unwrapDaysDictionary( jsonDictionary: [ String : AnyObject ] ) -> [ String : AnyObject ] ? {
400- guard
401- let days = jsonDictionary [ " days " ] as? [ String : AnyObject ] ,
402- let firstKey = days. keys. first,
403- let firstDay = days [ firstKey] as? [ String : AnyObject ]
404- else {
405- return nil
412+ if let summary = jsonDictionary [ " summary " ] as? [ String : AnyObject ] {
413+ return summary
414+ }
415+ if let days = jsonDictionary [ " days " ] as? [ String : AnyObject ] ,
416+ let firstKey = days. keys. first,
417+ let firstDay = days [ firstKey] as? [ String : AnyObject ] {
418+ return firstDay
406419 }
407- return firstDay
420+ return nil
408421 }
409422
410423}
0 commit comments