@@ -24,10 +24,6 @@ open class AgroProvider {
2424 self . client = AgroClient ( apiKey: apiKey)
2525 }
2626
27- private func postThis( data: Data ) -> AnyPublisher < AgroPolyResponse ? , AgroAPIError > {
28- return client. postThis ( bodyData: data)
29- }
30-
3127 /// send an Agro polygon to the server and return the server response
3228 ///
3329 /// - Parameter poly: the polygon to send
@@ -46,7 +42,7 @@ open class AgroProvider {
4642 /// - closure completion: AgroPolyResponse
4743 open func createPoly( poly: AgroPolygon , completion: @escaping ( AgroPolyResponse ? ) -> Void ) {
4844 let jsonData = ( try ? JSONEncoder ( ) . encode ( poly) ) ?? Data ( )
49- cancellable = postThis ( data : jsonData)
45+ cancellable = client . postThis ( bodyData : jsonData)
5046 . sink ( receiveCompletion: { completion in
5147 switch completion {
5248 case . finished:
@@ -58,11 +54,7 @@ open class AgroProvider {
5854 return completion ( resp)
5955 } )
6056 }
61-
62- private func fetchPoly( param: String ) -> AnyPublisher < AgroPolyResponse ? , AgroAPIError > {
63- return client. fetchThis ( param: param)
64- }
65-
57+
6658 /// get the specific Agro polygon info from the server
6759 ///
6860 /// - Parameter id: the id of the polygon to get
@@ -80,7 +72,7 @@ open class AgroProvider {
8072 /// - Parameter id: the id of the polygon to get
8173 /// - closure completion: AgroPolyResponse
8274 open func getPoly( id: String , completion: @escaping ( AgroPolyResponse ? ) -> Void ) {
83- cancellable = fetchPoly ( param: id)
75+ cancellable = client . fetchThis ( param: id)
8476 . sink ( receiveCompletion: { completion in
8577 switch completion {
8678 case . finished:
@@ -93,10 +85,6 @@ open class AgroProvider {
9385 } )
9486 }
9587
96- private func fetchPolyList( param: String ) -> AnyPublisher < [ AgroPolyResponse ] ? , AgroAPIError > {
97- return client. fetchThis ( param: param)
98- }
99-
10088 /// get the Agro polygon list from the server
10189 ///
10290 /// - Binding reponse: AgroPolyResponse
@@ -112,7 +100,7 @@ open class AgroProvider {
112100 ///
113101 /// - closure completion: [AgroPolyResponse]
114102 open func getPolyList( completion: @escaping ( [ AgroPolyResponse ] ? ) -> Void ) {
115- cancellable = fetchPolyList ( param: " " )
103+ cancellable = client . fetchThis ( param: " " )
116104 . sink ( receiveCompletion: { completion in
117105 switch completion {
118106 case . finished:
@@ -125,10 +113,6 @@ open class AgroProvider {
125113 } )
126114 }
127115
128- private func deleteThis( param: String ) -> AnyPublisher < AgroPolyResponse ? , AgroAPIError > {
129- return client. deleteThis ( param: param)
130- }
131-
132116 /// delete the specific Agro polygon from the server
133117 ///
134118 /// - Parameter id: the id of the polygon to delete
@@ -146,7 +130,7 @@ open class AgroProvider {
146130 /// - Parameter id: the id of the polygon to delete
147131 /// - closure completion: AgroPolyResponse
148132 open func deletePoly( id: String , completion: @escaping ( AgroPolyResponse ? ) -> Void ) {
149- cancellable = deleteThis ( param: id)
133+ cancellable = client . deleteThis ( param: id)
150134 . sink ( receiveCompletion: { completion in
151135 switch completion {
152136 case . finished:
@@ -204,11 +188,7 @@ open class AgroProvider {
204188 return completion ( resp)
205189 } )
206190 }
207-
208- private func fetchImagery( options: AgroOptions ) -> AnyPublisher < [ AgroImagery ] ? , AgroAPIError > {
209- return client. fetchThis ( options: options)
210- }
211-
191+
212192 /// get all available satellite imageries for the polygon and return the info
213193 ///
214194 /// - Parameter options: the options
@@ -226,7 +206,7 @@ open class AgroProvider {
226206 /// - Parameter options: the options
227207 /// - closure completion: [AgroImagery]
228208 open func getImagery( options: AgroOptions , completion: @escaping ( [ AgroImagery ] ? ) -> Void ) {
229- cancellable = fetchImagery ( options: options)
209+ cancellable = client . fetchThis ( options: options)
230210 . sink ( receiveCompletion: { completion in
231211 switch completion {
232212 case . finished:
@@ -239,10 +219,6 @@ open class AgroProvider {
239219 } )
240220 }
241221
242- private func fetchStatsInfo( urlString: String ) -> AnyPublisher < AgroStatsInfo ? , AgroAPIError > {
243- return client. fetchThisUrl ( urlString: urlString)
244- }
245-
246222 /// get the satellite imageries stats for the polygon
247223 ///
248224 /// - Parameter urlString: the url to fetch
@@ -260,7 +236,7 @@ open class AgroProvider {
260236 /// - Parameter urlString: the url to fetch
261237 /// - closure completion: AgroStatsInfo
262238 open func getStatsInfo( urlString: String , completion: @escaping ( AgroStatsInfo ? ) -> Void ) {
263- cancellable = fetchStatsInfo ( urlString: urlString)
239+ cancellable = client . fetchThisUrl ( urlString: urlString)
264240 . sink ( receiveCompletion: { completion in
265241 switch completion {
266242 case . finished:
@@ -272,11 +248,7 @@ open class AgroProvider {
272248 return completion ( resp)
273249 } )
274250 }
275-
276- private func fetchThisData( urlString: String ) -> AnyPublisher < Data ? , AgroAPIError > {
277- return client. fetchThisData ( urlString: urlString)
278- }
279-
251+
280252 /// get the satellite imageries tile data for the polygon
281253 ///
282254 /// - Parameter urlString: the url to fetch
@@ -294,7 +266,7 @@ open class AgroProvider {
294266 /// - Parameter urlString: the url to fetch
295267 /// - closure completion: Data
296268 open func getTile( urlString: String , completion: @escaping ( Data ? ) -> Void ) {
297- cancellable = fetchThisData ( urlString: urlString)
269+ cancellable = client . fetchThisData ( urlString: urlString)
298270 . sink ( receiveCompletion: { completion in
299271 switch completion {
300272 case . finished:
@@ -325,7 +297,7 @@ open class AgroProvider {
325297 /// - closure completion: Data
326298 open func getPngImageData( urlString: String , paletteid: Int , completion: @escaping ( Data ? ) -> Void ) {
327299 let theUrl = urlString + " &paletteid= \( paletteid) "
328- cancellable = fetchThisData ( urlString: theUrl)
300+ cancellable = client . fetchThisData ( urlString: theUrl)
329301 . sink ( receiveCompletion: { completion in
330302 switch completion {
331303 case . finished:
@@ -409,16 +381,12 @@ open class AgroProvider {
409381 }
410382 }
411383
412- private func fetchCurrentWeather( param: String ) -> AnyPublisher < Current ? , AgroAPIError > {
413- return client. fetchThisWeather ( param: param, isForecast: false )
414- }
415-
416384 /// get the current weather for the polygon
417385 ///
418386 /// - Parameter param: the polygon id
419387 /// - closure completion: Current weather
420388 open func getCurrentWeather( id: String , completion: @escaping ( Current ? ) -> Void ) {
421- cancellable = fetchCurrentWeather ( param: id)
389+ cancellable = client . fetchThisWeather ( param: id, isForecast : false )
422390 . sink ( receiveCompletion: { completion in
423391 switch completion {
424392 case . finished:
@@ -442,17 +410,13 @@ open class AgroProvider {
442410 }
443411 }
444412 }
445-
446- private func fetchWeather( param: String , options: WeatherOptions ? = nil ) -> AnyPublisher < [ Current ] ? , AgroAPIError > {
447- return client. fetchThisWeather ( param: param, isForecast: true , options: options)
448- }
449-
413+
450414 /// get the forecast weather for the polygon
451415 ///
452416 /// - Parameter param: the polygon id
453417 /// - closure completion: Current weather
454418 open func getForecastWeather( id: String , completion: @escaping ( [ Current ] ? ) -> Void ) {
455- cancellable = fetchWeather ( param: id)
419+ cancellable = client . fetchThisWeather ( param: id, isForecast : true )
456420 . sink ( receiveCompletion: { completion in
457421 switch completion {
458422 case . finished:
@@ -478,7 +442,7 @@ open class AgroProvider {
478442 /// - Parameter param: the polygon id
479443 /// - closure completion: Current weather
480444 open func getHistoricalWeather( options: WeatherOptions , completion: @escaping ( [ Current ] ? ) -> Void ) {
481- cancellable = fetchWeather ( param: options. polygon_id, options: options)
445+ cancellable = client . fetchThisWeather ( param: options. polygon_id, isForecast : true , options: options)
482446 . sink ( receiveCompletion: { completion in
483447 switch completion {
484448 case . finished:
@@ -498,17 +462,13 @@ open class AgroProvider {
498462 }
499463 }
500464 }
501-
502- private func fetchHistory( options: AgroOptions ) -> AnyPublisher < [ AgroHistoryNDVI ] ? , AgroAPIError > {
503- return client. fetchThisHistory ( options: options)
504- }
505-
465+
506466 /// get the historical NDVI for the polygon
507467 ///
508468 /// - Parameter options: options for the request
509469 /// - closure completion: historical NDVI
510470 open func getHistoricalNDVI( options: AgroOptions , completion: @escaping ( [ AgroHistoryNDVI ] ? ) -> Void ) {
511- cancellable = fetchHistory ( options: options)
471+ cancellable = client . fetchThisHistory ( options: options)
512472 . sink ( receiveCompletion: { completion in
513473 switch completion {
514474 case . finished:
0 commit comments