added iOS source code
[wl-app.git] / iOS / Pods / OAuthSwift / Sources / OAuthSwiftResponse.swift
1 //
2 //  OAuthSwiftResponse.swift
3 //  OAuthSwift
4 //
5 //  Created by phimage on 04/11/16.
6 //  Copyright © 2016 Dongri Jin. All rights reserved.
7 //
8
9 import Foundation
10
11 /// Response object
12 @objc
13 public class OAuthSwiftResponse: NSObject { // not a struct for objc
14     /// The data returned by the server.
15     public var data: Data
16     /// The server's response to the URL request.
17     public var response: HTTPURLResponse
18     /// The URL request sent to the server.
19     public var request: URLRequest?
20
21     public init(data: Data, response: HTTPURLResponse, request: URLRequest?) {
22         self.data = data
23         self.response = response
24         self.request = request
25     }
26
27 }
28
29 /// Extends this object to convert data into your business objects
30 extension OAuthSwiftResponse {
31
32     public func dataString(encoding: String.Encoding = OAuthSwiftDataEncoding) -> String? {
33         return String(data: self.data, encoding: encoding)
34     }
35
36     /// `data` converted to string using data encoding
37     public var string: String? {
38         return dataString()
39     }
40
41     /// Convert to json object using JSONSerialization
42     public func jsonObject(options opt: JSONSerialization.ReadingOptions = []) throws -> Any {
43         return try JSONSerialization.jsonObject(with: self.data, options: opt)
44     }
45
46     /// Convert to object using PropertyListSerialization
47     public func propertyList(options opt: PropertyListSerialization.ReadOptions = [], format: UnsafeMutablePointer<PropertyListSerialization.PropertyListFormat>? = nil) throws -> Any {
48         return try PropertyListSerialization.propertyList(from: self.data, options: opt, format: format)
49     }
50 }