Created
October 7, 2019 06:27
-
-
Save kutan74/d462a77d018712ebee49ea280cca2303 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MoyaServices.swift | |
// Sensgreen-ios | |
// | |
// Created by KUTAN ÇINGISIZ on 9.11.2018. | |
// Copyright © 2018 KUTAN ÇINGISIZ. All rights reserved. | |
// | |
import Foundation | |
import Moya | |
enum MyService { | |
case currentWeather(lat : Double, lon : Double) | |
} | |
extension MyService : TargetType { | |
var baseURL : URL { return URL(string: "https://api.openweathermap.org/data/2.5/")! } | |
var path: String { | |
switch self { | |
case .currentWeather(_,_): | |
return "/weather" | |
} | |
} | |
var method: Moya.Method { | |
switch self { | |
case .currentWeather(_,_): | |
return .get | |
} | |
} | |
var task: Task { | |
switch self { | |
case .currentWeather(let lat , let lon): | |
return .requestParameters(parameters: ["lat" : lat, "lon" : lon,"APPID":"ed41a451c1974f7a21297561cc226bf5"], encoding: URLEncoding.queryString) | |
} | |
} | |
var sampleData: Data { | |
switch self { | |
case .currentWeather(_,_): | |
return "Half measures are as bad as nothing at all.".utf8Encoded | |
} | |
} | |
var headers: [String: String]? { | |
return ["Authorization ":"Test","Content-type": "application/json"] | |
} | |
} | |
extension String { | |
var utf8Encoded: Data { | |
return data(using: .utf8)! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment