2 |
3 |
4 |
5 |
6 |
putio-swift
7 |
8 |
9 | Swift SDK for interacting with the put.io API.
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | ## Installation
19 |
20 | `PutioAPI` is available through [CocoaPods](https://cocoapods.org/pods/PutioAPI). To install, simply add the following line to your Podfile:
21 |
22 | ```ruby
23 | pod 'PutioAPI'
24 | ```
25 |
26 | ## Usage
27 |
28 | - For authentication, check the [Example Project](./Example/PutioAPI/ViewController.swift) for a simple [`ASWebAuthenticationSession`](https://developer.apple.com/documentation/authenticationservices/authenticating_a_user_through_a_web_service) flow.
29 | - Check [the classes folder](./PutioAPI/Classes/) for available models and respective methods.
30 | - You can also use `get`, `post`, `put`, and `delete` methods with relative URLs to make requests to the API.
31 |
32 | ## Contribution
33 |
34 | Clone the repo.
35 |
36 | ```bash
37 | git clone git@github.com:putdotio/putio-swift.git
38 | cd ./putio-swift
39 | ```
40 |
41 | Install the package managers, it's suggested to use `rbenv` and `bundler` for convenience.
42 |
43 | ```bash
44 | gem install bundler # if you don't have bundler
45 | bundle install
46 | ```
47 |
48 | Install the dependencies then open the workspace.
49 |
50 | ```bash
51 | cd ./Example
52 | bundle exec pod install
53 | open ./PutioAPI.xcworkspace
54 | ```
55 |
--------------------------------------------------------------------------------
/PutioAPI/Classes/Auth/AuthModel.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 | import SwiftyJSON
3 |
4 | open class PutioTokenValidationResult {
5 | open var result: Bool
6 | open var token_id: Int
7 | open var token_scope: String
8 | open var user_id: Int
9 |
10 | init(json: JSON) {
11 | self.result = json["result"].boolValue
12 | self.token_id = json["token_id"].intValue
13 | self.token_scope = json["token_scope"].stringValue
14 | self.user_id = json["user_id"].intValue
15 | }
16 | }
17 |
18 | open class PutioTwoFactorRecoveryCode {
19 | open var code: String
20 | open var used_at: String?
21 |
22 | init(json: JSON) {
23 | self.code = json["code"].stringValue
24 | self.used_at = json["used_at"].stringValue
25 | }
26 | }
27 |
28 | open class PutioTwoFactorRecoveryCodes {
29 | open var created_at: String
30 | open var codes: [PutioTwoFactorRecoveryCode]
31 |
32 | init(json: JSON) {
33 | self.created_at = json["created_at"].stringValue
34 | self.codes = json["codes"].arrayValue.map { PutioTwoFactorRecoveryCode(json: $0) }
35 | }
36 | }
37 |
38 | open class PutioGenerateTOTPResult {
39 | open var secret: String
40 | open var uri: String
41 | open var recovery_codes: PutioTwoFactorRecoveryCodes
42 |
43 | init(json: JSON) {
44 | self.secret = json["secret"].stringValue
45 | self.uri = json["uri"].stringValue
46 | self.recovery_codes = PutioTwoFactorRecoveryCodes(json: json["recovery_codes"])
47 | }
48 | }
49 |
50 | open class PutioVerifyTOTPResult {
51 | open var token: String
52 | open var user_id: Int
53 |
54 | init(json: JSON) {
55 | self.token = json["token"].stringValue
56 | self.user_id = json["user_id"].intValue
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/PutioAPI/Classes/Account/AccountAPI.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 | import Alamofire
3 | import SwiftyJSON
4 |
5 | extension PutioAPI {
6 | public func getAccountInfo(query: Parameters = [:], completion: @escaping (Result