mvcgen 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/LICENSE +21 -0
 - data/README.md +115 -0
 - data/bin/mvcgen +9 -0
 - data/lib/mvcgen.rb +6 -0
 - data/lib/mvcgen/dirutils.rb +17 -0
 - data/lib/mvcgen/filemanager.rb +51 -0
 - data/lib/mvcgen/generator.rb +58 -0
 - data/lib/mvcgen/mvcthor.rb +19 -0
 - data/lib/mvcgen/templatemanager.rb +53 -0
 - data/lib/mvcgen/version.rb +4 -0
 - data/lib/templates/default/mvcspec.yml +4 -0
 - data/lib/templates/default/objc/DataManager/VIPERDataManager.h +15 -0
 - data/lib/templates/default/objc/DataManager/VIPERDataManager.m +11 -0
 - data/lib/templates/default/objc/Interactor/VIPERInteractor.h +16 -0
 - data/lib/templates/default/objc/Interactor/VIPERInteractor.m +10 -0
 - data/lib/templates/default/objc/Presenter/VIPERPresenter.h +18 -0
 - data/lib/templates/default/objc/Presenter/VIPERPresenter.m +11 -0
 - data/lib/templates/default/objc/Protocols/VIPERProtocols.h +64 -0
 - data/lib/templates/default/objc/ViewController/VIPERViewController.h +13 -0
 - data/lib/templates/default/objc/ViewController/VIPERViewController.m +32 -0
 - data/lib/templates/default/objc/WireFrame/VIPERWireFrame.h +19 -0
 - data/lib/templates/default/objc/WireFrame/VIPERWireFrame.m +31 -0
 - data/lib/templates/default/swift/Config/Config.plist +58 -0
 - data/lib/templates/default/swift/Config/Config.swift +50 -0
 - data/lib/templates/default/swift/Extensions/Buttons.swift +110 -0
 - data/lib/templates/default/swift/Extensions/ColorHex.swift +32 -0
 - data/lib/templates/default/swift/Helper/APIHelper.swift +98 -0
 - data/lib/templates/default/swift/Helper/APIManager.swift +217 -0
 - data/lib/templates/default/swift/Helper/APIRequestBody.swift +81 -0
 - data/lib/templates/default/swift/Helper/AWSManager.swift +29 -0
 - data/lib/templates/default/swift/Helper/FilesManager.swift +97 -0
 - data/lib/templates/default/swift/Helper/S3Manager.swift +113 -0
 - data/lib/templates/default/swift/Helper/Utils.swift +69 -0
 - data/lib/templates/default/swift/Models/Managers/UserManager.swift +56 -0
 - data/lib/templates/default/swift/Models/Responses/BaseResponse.swift +75 -0
 - data/lib/templates/default/swift/Models/Responses/UserResponse.swift +30 -0
 - data/lib/templates/default/swift/Models/Responses/UserSingupResponse.swift +27 -0
 - data/lib/templates/default/swift/Models/User.swift +92 -0
 - data/spec/mvcgen/mvcgen_spec.rb +131 -0
 - data/spec/spec_helper.rb +4 -0
 - metadata +159 -0
 
| 
         @@ -0,0 +1,217 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            //
         
     | 
| 
      
 2 
     | 
    
         
            +
            //  APIManager.swift
         
     | 
| 
      
 3 
     | 
    
         
            +
            //  MVCGEN
         
     | 
| 
      
 4 
     | 
    
         
            +
            //
         
     | 
| 
      
 5 
     | 
    
         
            +
            //  Created by Daniel Martinez on 23/7/18.
         
     | 
| 
      
 6 
     | 
    
         
            +
            //  Copyright © 2018 DanielMartinez. All rights reserved.
         
     | 
| 
      
 7 
     | 
    
         
            +
            //
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            import Alamofire
         
     | 
| 
      
 10 
     | 
    
         
            +
            import AlamofireObjectMapper
         
     | 
| 
      
 11 
     | 
    
         
            +
            import CryptoSwift
         
     | 
| 
      
 12 
     | 
    
         
            +
            import OneSignal
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            class APIManager {
         
     | 
| 
      
 15 
     | 
    
         
            +
                
         
     | 
| 
      
 16 
     | 
    
         
            +
                // MARK: - Singleton
         
     | 
| 
      
 17 
     | 
    
         
            +
                static let sharedInstance = APIManager()
         
     | 
| 
      
 18 
     | 
    
         
            +
                
         
     | 
| 
      
 19 
     | 
    
         
            +
                lazy var servicesURL = Config.sharedInstance.servicesURL()
         
     | 
| 
      
 20 
     | 
    
         
            +
                
         
     | 
| 
      
 21 
     | 
    
         
            +
               let errorMsg = NSLocalizedString("Error connecting to services. Please try again", comment: "")
         
     | 
| 
      
 22 
     | 
    
         
            +
                
         
     | 
| 
      
 23 
     | 
    
         
            +
                // MARK: - Endpoints
         
     | 
| 
      
 24 
     | 
    
         
            +
                
         
     | 
| 
      
 25 
     | 
    
         
            +
                func login(withParameters parameters: Parameters, completion: @escaping (_ result: VoidResult) -> Void){
         
     | 
| 
      
 26 
     | 
    
         
            +
                    
         
     | 
| 
      
 27 
     | 
    
         
            +
                    Alamofire.request(APIHelper.sharedInstance.servicesURL + Endpoints.login, method: .post, parameters: parameters,
         
     | 
| 
      
 28 
     | 
    
         
            +
                                      encoding: JSONEncoding.default,
         
     | 
| 
      
 29 
     | 
    
         
            +
                                      headers: nil).responseObject { (response: DataResponse<UserResponse>) in
         
     | 
| 
      
 30 
     | 
    
         
            +
                                        
         
     | 
| 
      
 31 
     | 
    
         
            +
                                        switch response.result {
         
     | 
| 
      
 32 
     | 
    
         
            +
                                            case .success(_):
         
     | 
| 
      
 33 
     | 
    
         
            +
                                                if let responseValue = response.result.value {
         
     | 
| 
      
 34 
     | 
    
         
            +
                                                    switch responseValue.result {
         
     | 
| 
      
 35 
     | 
    
         
            +
                                                    case true:
         
     | 
| 
      
 36 
     | 
    
         
            +
                                                        if let user = responseValue.user, let token = responseValue.token {
         
     | 
| 
      
 37 
     | 
    
         
            +
                                                            UserManager.sharedInstance.saveUser(newUser: user, withToken: token)
         
     | 
| 
      
 38 
     | 
    
         
            +
                                                            completion(.success)
         
     | 
| 
      
 39 
     | 
    
         
            +
                                                        } else {
         
     | 
| 
      
 40 
     | 
    
         
            +
                                                            APIHelper.sharedInstance.showErrorMessage(with: responseValue.showMessage, and: "")
         
     | 
| 
      
 41 
     | 
    
         
            +
                                                            completion(.failure)
         
     | 
| 
      
 42 
     | 
    
         
            +
                                                        }
         
     | 
| 
      
 43 
     | 
    
         
            +
                                                        break
         
     | 
| 
      
 44 
     | 
    
         
            +
                                                    case false:
         
     | 
| 
      
 45 
     | 
    
         
            +
                                                        let errorCode = responseValue.errorCode
         
     | 
| 
      
 46 
     | 
    
         
            +
                                                        APIHelper.sharedInstance.wsResponse(onError: errorCode, andMessage: responseValue.message)
         
     | 
| 
      
 47 
     | 
    
         
            +
                                                        completion(.failure)
         
     | 
| 
      
 48 
     | 
    
         
            +
                                                        break
         
     | 
| 
      
 49 
     | 
    
         
            +
                                                    }
         
     | 
| 
      
 50 
     | 
    
         
            +
                                                }
         
     | 
| 
      
 51 
     | 
    
         
            +
                                            case .failure(_):
         
     | 
| 
      
 52 
     | 
    
         
            +
                                                APIHelper.sharedInstance.showErrorMessage(with: errorMsg, and: "")
         
     | 
| 
      
 53 
     | 
    
         
            +
                                                completion(.failure)
         
     | 
| 
      
 54 
     | 
    
         
            +
                                                break
         
     | 
| 
      
 55 
     | 
    
         
            +
                                        }
         
     | 
| 
      
 56 
     | 
    
         
            +
                    }
         
     | 
| 
      
 57 
     | 
    
         
            +
                }
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                // If you use Codable instead of mappable:
         
     | 
| 
      
 60 
     | 
    
         
            +
                //     func login(withParameters parameters: Parameters, completion: @escaping (_ result: VoidResult) -> Void){
         
     | 
| 
      
 61 
     | 
    
         
            +
                    
         
     | 
| 
      
 62 
     | 
    
         
            +
                //     Alamofire.request(APIHelper.sharedInstance.servicesURL + Endpoints.login, method: .post, parameters: parameters,
         
     | 
| 
      
 63 
     | 
    
         
            +
                //                       encoding: JSONEncoding.default,
         
     | 
| 
      
 64 
     | 
    
         
            +
                //                       headers: nil).responseJSON { response in
         
     | 
| 
      
 65 
     | 
    
         
            +
                                        
         
     | 
| 
      
 66 
     | 
    
         
            +
                //                         switch response.result {
         
     | 
| 
      
 67 
     | 
    
         
            +
                //                             case .success(_):
         
     | 
| 
      
 68 
     | 
    
         
            +
                //                                 if let responseValue = response.result.value as? [String:Any]{
         
     | 
| 
      
 69 
     | 
    
         
            +
                //                                     if responseValue["result"] != nil {
         
     | 
| 
      
 70 
     | 
    
         
            +
                //                                         let jsonData = try? JSONSerialization.data(withJSONObject: responseValue["result"], options: .prettyPrinted)
         
     | 
| 
      
 71 
     | 
    
         
            +
                //                                         let reqJSONStr = String(data: jsonData, encoding: .utf8)
         
     | 
| 
      
 72 
     | 
    
         
            +
                //                                         if let jsonData = reqJSONStr.data(using: .utf8)
         
     | 
| 
      
 73 
     | 
    
         
            +
                //                                         {
         
     | 
| 
      
 74 
     | 
    
         
            +
                //                                             let baseResponse = try? JSONDecoder().decode(BaseResponse.self, from: jsonData)
         
     | 
| 
      
 75 
     | 
    
         
            +
                //                                             switch baseResponse.response {
         
     | 
| 
      
 76 
     | 
    
         
            +
                //                                             case true:
         
     | 
| 
      
 77 
     | 
    
         
            +
                //                                                 let jsonData = try? JSONSerialization.data(withJSONObject: responseValue["data"], options: .prettyPrinted)
         
     | 
| 
      
 78 
     | 
    
         
            +
                //                                                 let reqJSONStr = String(data: jsonData, encoding: .utf8)
         
     | 
| 
      
 79 
     | 
    
         
            +
                //                                                 if let jsonData = reqJSONStr.data(using: .utf8) {
         
     | 
| 
      
 80 
     | 
    
         
            +
                //                                                     let userResponse = try? JSONDecoder().decode(User.self, from: jsonData)
         
     | 
| 
      
 81 
     | 
    
         
            +
                //                                                     UserManager.sharedInstance.saveUser(newUser: userResponse.user, withToken: userResponse.token)
         
     | 
| 
      
 82 
     | 
    
         
            +
                //                                                     completion(.success)
         
     | 
| 
      
 83 
     | 
    
         
            +
                //                                                 }else {
         
     | 
| 
      
 84 
     | 
    
         
            +
                //                                                     APIHelper.sharedInstance.showErrorMessage(with: baseResponse.showMessage, and: "")
         
     | 
| 
      
 85 
     | 
    
         
            +
                //                                                     completion(.failure)
         
     | 
| 
      
 86 
     | 
    
         
            +
                //                                                 }
         
     | 
| 
      
 87 
     | 
    
         
            +
                //                                                 break
         
     | 
| 
      
 88 
     | 
    
         
            +
                //                                             case false:
         
     | 
| 
      
 89 
     | 
    
         
            +
                //                                                 let errorCode = responseValue.errorCode
         
     | 
| 
      
 90 
     | 
    
         
            +
                //                                                 APIHelper.sharedInstance.wsResponse(onError: errorCode, andMessage: responseValue.message)
         
     | 
| 
      
 91 
     | 
    
         
            +
                //                                                 completion(.failure)
         
     | 
| 
      
 92 
     | 
    
         
            +
                //                                                 break
         
     | 
| 
      
 93 
     | 
    
         
            +
                //                                             }
         
     | 
| 
      
 94 
     | 
    
         
            +
                //                                         }
         
     | 
| 
      
 95 
     | 
    
         
            +
                //                                     }
         
     | 
| 
      
 96 
     | 
    
         
            +
                                                    
         
     | 
| 
      
 97 
     | 
    
         
            +
                //                                 }
         
     | 
| 
      
 98 
     | 
    
         
            +
                //                             case .failure(_):
         
     | 
| 
      
 99 
     | 
    
         
            +
                //                                 APIHelper.sharedInstance.showErrorMessage(with: errorMsg, and: "")
         
     | 
| 
      
 100 
     | 
    
         
            +
                //                                 completion(.failure)
         
     | 
| 
      
 101 
     | 
    
         
            +
                //                                 break
         
     | 
| 
      
 102 
     | 
    
         
            +
                //                         }
         
     | 
| 
      
 103 
     | 
    
         
            +
                //     }
         
     | 
| 
      
 104 
     | 
    
         
            +
                // }
         
     | 
| 
      
 105 
     | 
    
         
            +
                
         
     | 
| 
      
 106 
     | 
    
         
            +
                func loginfb(withParameters parameters: Parameters, completion: @escaping (_ result: VoidResult) -> Void){
         
     | 
| 
      
 107 
     | 
    
         
            +
                    
         
     | 
| 
      
 108 
     | 
    
         
            +
                    Alamofire.request(APIHelper.sharedInstance.servicesURL + Endpoints.fbLogin, method: .post, parameters: parameters,
         
     | 
| 
      
 109 
     | 
    
         
            +
                                      encoding: JSONEncoding.default,
         
     | 
| 
      
 110 
     | 
    
         
            +
                                      headers: nil).responseObject { (response: DataResponse<UserResponse>) in
         
     | 
| 
      
 111 
     | 
    
         
            +
                                        
         
     | 
| 
      
 112 
     | 
    
         
            +
                                        switch response.result {
         
     | 
| 
      
 113 
     | 
    
         
            +
                                        case .success(_):
         
     | 
| 
      
 114 
     | 
    
         
            +
                                            if let responseValue = response.result.value {
         
     | 
| 
      
 115 
     | 
    
         
            +
                                                switch responseValue.result {
         
     | 
| 
      
 116 
     | 
    
         
            +
                                                case true:
         
     | 
| 
      
 117 
     | 
    
         
            +
                                                    if let user = responseValue.user, let token = responseValue.token {
         
     | 
| 
      
 118 
     | 
    
         
            +
                                                        UserManager.sharedInstance.saveUser(newUser: user, withToken: token)
         
     | 
| 
      
 119 
     | 
    
         
            +
                                                        completion(.success)
         
     | 
| 
      
 120 
     | 
    
         
            +
                                                    } else {
         
     | 
| 
      
 121 
     | 
    
         
            +
                                                        APIHelper.sharedInstance.showErrorMessage(with: responseValue.showMessage, and: "")
         
     | 
| 
      
 122 
     | 
    
         
            +
                                                        completion(.failure)
         
     | 
| 
      
 123 
     | 
    
         
            +
                                                    }
         
     | 
| 
      
 124 
     | 
    
         
            +
                                                    break
         
     | 
| 
      
 125 
     | 
    
         
            +
                                                case false:
         
     | 
| 
      
 126 
     | 
    
         
            +
                                                    let errorCode = responseValue.errorCode
         
     | 
| 
      
 127 
     | 
    
         
            +
                                                    APIHelper.sharedInstance.wsResponse(onError: errorCode, andMessage: responseValue.message)
         
     | 
| 
      
 128 
     | 
    
         
            +
                                                    completion(.failure)
         
     | 
| 
      
 129 
     | 
    
         
            +
                                                    break
         
     | 
| 
      
 130 
     | 
    
         
            +
                                                }
         
     | 
| 
      
 131 
     | 
    
         
            +
                                            }
         
     | 
| 
      
 132 
     | 
    
         
            +
                                        case .failure(_):
         
     | 
| 
      
 133 
     | 
    
         
            +
                                            APIHelper.sharedInstance.showErrorMessage(with: errorMsg, and: "")
         
     | 
| 
      
 134 
     | 
    
         
            +
                                            completion(.failure)
         
     | 
| 
      
 135 
     | 
    
         
            +
                                            break
         
     | 
| 
      
 136 
     | 
    
         
            +
                                        }
         
     | 
| 
      
 137 
     | 
    
         
            +
                    }
         
     | 
| 
      
 138 
     | 
    
         
            +
                }
         
     | 
| 
      
 139 
     | 
    
         
            +
                
         
     | 
| 
      
 140 
     | 
    
         
            +
                func logout(completion: @escaping (VoidResult) -> Void) {
         
     | 
| 
      
 141 
     | 
    
         
            +
                    Alamofire.request(APIHelper.sharedInstance.servicesURL + Endpoints.logout, method: .post, parameters: nil, encoding: JSONEncoding.default, headers: APIHelper.sharedInstance.getHeaders()).responseObject { (response: DataResponse<BaseResponse>) in
         
     | 
| 
      
 142 
     | 
    
         
            +
                        
         
     | 
| 
      
 143 
     | 
    
         
            +
                        switch response.result {
         
     | 
| 
      
 144 
     | 
    
         
            +
                        case .success(_):
         
     | 
| 
      
 145 
     | 
    
         
            +
                            
         
     | 
| 
      
 146 
     | 
    
         
            +
                            if let baseResponse = response.result.value {
         
     | 
| 
      
 147 
     | 
    
         
            +
                                switch baseResponse.result {
         
     | 
| 
      
 148 
     | 
    
         
            +
                                case true:
         
     | 
| 
      
 149 
     | 
    
         
            +
                                    completion(.success)
         
     | 
| 
      
 150 
     | 
    
         
            +
                                    break
         
     | 
| 
      
 151 
     | 
    
         
            +
                                case false:
         
     | 
| 
      
 152 
     | 
    
         
            +
                                    let errorCode = baseResponse.errorCode
         
     | 
| 
      
 153 
     | 
    
         
            +
                                    APIHelper.sharedInstance.wsResponse(onError: errorCode, andMessage: baseResponse.message)
         
     | 
| 
      
 154 
     | 
    
         
            +
                                    completion(.failure)
         
     | 
| 
      
 155 
     | 
    
         
            +
                                    break
         
     | 
| 
      
 156 
     | 
    
         
            +
                                }
         
     | 
| 
      
 157 
     | 
    
         
            +
                            }
         
     | 
| 
      
 158 
     | 
    
         
            +
                        case .failure(_):
         
     | 
| 
      
 159 
     | 
    
         
            +
                            APIHelper.sharedInstance.showErrorMessage(with: errorMsg, and: "")
         
     | 
| 
      
 160 
     | 
    
         
            +
                            completion(.failure)
         
     | 
| 
      
 161 
     | 
    
         
            +
                            break
         
     | 
| 
      
 162 
     | 
    
         
            +
                        }
         
     | 
| 
      
 163 
     | 
    
         
            +
                    }
         
     | 
| 
      
 164 
     | 
    
         
            +
                }
         
     | 
| 
      
 165 
     | 
    
         
            +
                
         
     | 
| 
      
 166 
     | 
    
         
            +
                func signup(withParameters parameters: Parameters, completion: @escaping (_ result: VoidResult, _ user: User?) -> Void) {
         
     | 
| 
      
 167 
     | 
    
         
            +
                    Alamofire.request(APIHelper.sharedInstance.servicesURL + Endpoints.signup, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: nil).responseObject { (response: DataResponse<UserSignupResponse>) in
         
     | 
| 
      
 168 
     | 
    
         
            +
                        
         
     | 
| 
      
 169 
     | 
    
         
            +
                        switch response.result {
         
     | 
| 
      
 170 
     | 
    
         
            +
                        case .success(_):
         
     | 
| 
      
 171 
     | 
    
         
            +
                            
         
     | 
| 
      
 172 
     | 
    
         
            +
                            if let baseResponse = response.result.value {
         
     | 
| 
      
 173 
     | 
    
         
            +
                                switch baseResponse.result {
         
     | 
| 
      
 174 
     | 
    
         
            +
                                case true:
         
     | 
| 
      
 175 
     | 
    
         
            +
                                    completion(.success,nil)
         
     | 
| 
      
 176 
     | 
    
         
            +
                                    break
         
     | 
| 
      
 177 
     | 
    
         
            +
                                case false:
         
     | 
| 
      
 178 
     | 
    
         
            +
                                    let errorCode = baseResponse.errorCode
         
     | 
| 
      
 179 
     | 
    
         
            +
                                    APIHelper.sharedInstance.wsResponse(onError: errorCode, andMessage: baseResponse.message)
         
     | 
| 
      
 180 
     | 
    
         
            +
                                    completion(.failure,nil)
         
     | 
| 
      
 181 
     | 
    
         
            +
                                    break
         
     | 
| 
      
 182 
     | 
    
         
            +
                                }
         
     | 
| 
      
 183 
     | 
    
         
            +
                            }
         
     | 
| 
      
 184 
     | 
    
         
            +
                        case .failure(_):
         
     | 
| 
      
 185 
     | 
    
         
            +
                            APIHelper.sharedInstance.showErrorMessage(with: errorMsg, comment: ""), and: "")
         
     | 
| 
      
 186 
     | 
    
         
            +
                            completion(.failure,nil)
         
     | 
| 
      
 187 
     | 
    
         
            +
                            break
         
     | 
| 
      
 188 
     | 
    
         
            +
                        }
         
     | 
| 
      
 189 
     | 
    
         
            +
                    }
         
     | 
| 
      
 190 
     | 
    
         
            +
                }
         
     | 
| 
      
 191 
     | 
    
         
            +
                
         
     | 
| 
      
 192 
     | 
    
         
            +
                func forgotPwd(withParameters parameters: Parameters, completion: @escaping (_ result: VoidResult) -> Void) {
         
     | 
| 
      
 193 
     | 
    
         
            +
                    Alamofire.request(APIHelper.sharedInstance.servicesURL + Endpoints.forgotPwd, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: nil).responseObject { (response: DataResponse<BaseResponse>) in
         
     | 
| 
      
 194 
     | 
    
         
            +
                        
         
     | 
| 
      
 195 
     | 
    
         
            +
                        switch response.result {
         
     | 
| 
      
 196 
     | 
    
         
            +
                        case .success(_):
         
     | 
| 
      
 197 
     | 
    
         
            +
                            
         
     | 
| 
      
 198 
     | 
    
         
            +
                            if let baseResponse = response.result.value {
         
     | 
| 
      
 199 
     | 
    
         
            +
                                switch baseResponse.result {
         
     | 
| 
      
 200 
     | 
    
         
            +
                                case true:
         
     | 
| 
      
 201 
     | 
    
         
            +
                                    completion(.success)
         
     | 
| 
      
 202 
     | 
    
         
            +
                                    break
         
     | 
| 
      
 203 
     | 
    
         
            +
                                case false:
         
     | 
| 
      
 204 
     | 
    
         
            +
                                    let errorCode = baseResponse.errorCode
         
     | 
| 
      
 205 
     | 
    
         
            +
                                    APIHelper.sharedInstance.wsResponse(onError: errorCode, andMessage: baseResponse.message)
         
     | 
| 
      
 206 
     | 
    
         
            +
                                    completion(.failure)
         
     | 
| 
      
 207 
     | 
    
         
            +
                                    break
         
     | 
| 
      
 208 
     | 
    
         
            +
                                }
         
     | 
| 
      
 209 
     | 
    
         
            +
                            }
         
     | 
| 
      
 210 
     | 
    
         
            +
                        case .failure(_):
         
     | 
| 
      
 211 
     | 
    
         
            +
                            APIHelper.sharedInstance.showErrorMessage(with: NSLocalizedString("Error connecting to services. Please try again", comment: ""), and: "")
         
     | 
| 
      
 212 
     | 
    
         
            +
                            completion(.failure)
         
     | 
| 
      
 213 
     | 
    
         
            +
                            break
         
     | 
| 
      
 214 
     | 
    
         
            +
                        }
         
     | 
| 
      
 215 
     | 
    
         
            +
                    }
         
     | 
| 
      
 216 
     | 
    
         
            +
                }
         
     | 
| 
      
 217 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,81 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            //
         
     | 
| 
      
 2 
     | 
    
         
            +
            //  APIRequestBody.swift
         
     | 
| 
      
 3 
     | 
    
         
            +
            //  MVCGEN
         
     | 
| 
      
 4 
     | 
    
         
            +
            //
         
     | 
| 
      
 5 
     | 
    
         
            +
            //  Created by Daniel Martinez on 23/7/18.
         
     | 
| 
      
 6 
     | 
    
         
            +
            //  Copyright © 2018 DanielMartinez. All rights reserved.
         
     | 
| 
      
 7 
     | 
    
         
            +
            //
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            import Alamofire
         
     | 
| 
      
 10 
     | 
    
         
            +
            import OneSignal
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            struct APIRequestBody {
         
     | 
| 
      
 13 
     | 
    
         
            +
                
         
     | 
| 
      
 14 
     | 
    
         
            +
                static func getLoginBody(withEmail email: String, withPassword password: String) -> Parameters{
         
     | 
| 
      
 15 
     | 
    
         
            +
                    
         
     | 
| 
      
 16 
     | 
    
         
            +
                    var loginBody: Parameters = Parameters()
         
     | 
| 
      
 17 
     | 
    
         
            +
                    
         
     | 
| 
      
 18 
     | 
    
         
            +
                    loginBody.updateValue(email, forKey: "email")
         
     | 
| 
      
 19 
     | 
    
         
            +
                    
         
     | 
| 
      
 20 
     | 
    
         
            +
                    if let pwdData = password.data(using: .utf8) {
         
     | 
| 
      
 21 
     | 
    
         
            +
                        let hash = pwdData.sha256()
         
     | 
| 
      
 22 
     | 
    
         
            +
                        loginBody.updateValue(hash.toHexString(), forKey: "password")
         
     | 
| 
      
 23 
     | 
    
         
            +
                    }
         
     | 
| 
      
 24 
     | 
    
         
            +
                    
         
     | 
| 
      
 25 
     | 
    
         
            +
                    loginBody.updateValue(UIDevice.current.model + " iOS: " + UIDevice.current.systemVersion, forKey: "device")
         
     | 
| 
      
 26 
     | 
    
         
            +
                    loginBody.updateValue(APIHelper.sharedInstance.getVersionBuild(), forKey: "version")
         
     | 
| 
      
 27 
     | 
    
         
            +
                    
         
     | 
| 
      
 28 
     | 
    
         
            +
                    if let playerId = OneSignal.getPermissionSubscriptionState().subscriptionStatus.userId{
         
     | 
| 
      
 29 
     | 
    
         
            +
                        loginBody.updateValue(playerId, forKey: "onesignalPlayerId")
         
     | 
| 
      
 30 
     | 
    
         
            +
                    }
         
     | 
| 
      
 31 
     | 
    
         
            +
                    
         
     | 
| 
      
 32 
     | 
    
         
            +
                    return loginBody
         
     | 
| 
      
 33 
     | 
    
         
            +
                }
         
     | 
| 
      
 34 
     | 
    
         
            +
                
         
     | 
| 
      
 35 
     | 
    
         
            +
                static func getFbLoginBody(withAccesToken accessToken: String) -> Parameters{
         
     | 
| 
      
 36 
     | 
    
         
            +
                    
         
     | 
| 
      
 37 
     | 
    
         
            +
                    var loginBody: Parameters = Parameters()
         
     | 
| 
      
 38 
     | 
    
         
            +
                    
         
     | 
| 
      
 39 
     | 
    
         
            +
                    loginBody.updateValue(accessToken, forKey: "accessToken")
         
     | 
| 
      
 40 
     | 
    
         
            +
                    
         
     | 
| 
      
 41 
     | 
    
         
            +
                    loginBody.updateValue(UIDevice.current.model + " iOS: " + UIDevice.current.systemVersion, forKey: "device")
         
     | 
| 
      
 42 
     | 
    
         
            +
                    loginBody.updateValue(APIHelper.sharedInstance.getVersionBuild(), forKey: "version")
         
     | 
| 
      
 43 
     | 
    
         
            +
                    
         
     | 
| 
      
 44 
     | 
    
         
            +
                    if let playerId = OneSignal.getPermissionSubscriptionState().subscriptionStatus.userId{
         
     | 
| 
      
 45 
     | 
    
         
            +
                        loginBody.updateValue(playerId, forKey: "onesignalPlayerId")
         
     | 
| 
      
 46 
     | 
    
         
            +
                    }
         
     | 
| 
      
 47 
     | 
    
         
            +
                    
         
     | 
| 
      
 48 
     | 
    
         
            +
                    return loginBody
         
     | 
| 
      
 49 
     | 
    
         
            +
                }
         
     | 
| 
      
 50 
     | 
    
         
            +
                
         
     | 
| 
      
 51 
     | 
    
         
            +
                static func getSignupBody(withEmail email: String, withPassword password: String, withFirstName firstname: String, withLastname lastname: String, withPhone phone: String, withProfilePic profilePic: String, withStudies studies: String, withCertifications certifications: String, withAbout about: String) -> Parameters{
         
     | 
| 
      
 52 
     | 
    
         
            +
                    
         
     | 
| 
      
 53 
     | 
    
         
            +
                    var signupBody: Parameters = Parameters()
         
     | 
| 
      
 54 
     | 
    
         
            +
                    
         
     | 
| 
      
 55 
     | 
    
         
            +
                    signupBody.updateValue(email, forKey: "email")
         
     | 
| 
      
 56 
     | 
    
         
            +
                    
         
     | 
| 
      
 57 
     | 
    
         
            +
                    if let pwdData = password.data(using: .utf8) {
         
     | 
| 
      
 58 
     | 
    
         
            +
                        let hash = pwdData.sha256()
         
     | 
| 
      
 59 
     | 
    
         
            +
                        signupBody.updateValue(hash.toHexString(), forKey: "password")
         
     | 
| 
      
 60 
     | 
    
         
            +
                    }
         
     | 
| 
      
 61 
     | 
    
         
            +
                    
         
     | 
| 
      
 62 
     | 
    
         
            +
                    signupBody.updateValue(firstname, forKey: "firstname")
         
     | 
| 
      
 63 
     | 
    
         
            +
                    signupBody.updateValue(lastname, forKey: "lastname")
         
     | 
| 
      
 64 
     | 
    
         
            +
                    signupBody.updateValue(phone, forKey: "phone")
         
     | 
| 
      
 65 
     | 
    
         
            +
                    
         
     | 
| 
      
 66 
     | 
    
         
            +
                    return signupBody
         
     | 
| 
      
 67 
     | 
    
         
            +
                }
         
     | 
| 
      
 68 
     | 
    
         
            +
                
         
     | 
| 
      
 69 
     | 
    
         
            +
                static func forgotPwd(withEmail email: String) -> Parameters{
         
     | 
| 
      
 70 
     | 
    
         
            +
                    
         
     | 
| 
      
 71 
     | 
    
         
            +
                    var forgotPwdBody: Parameters = Parameters()
         
     | 
| 
      
 72 
     | 
    
         
            +
                    
         
     | 
| 
      
 73 
     | 
    
         
            +
                    forgotPwdBody.updateValue(email, forKey: "email")
         
     | 
| 
      
 74 
     | 
    
         
            +
                    
         
     | 
| 
      
 75 
     | 
    
         
            +
                    return forgotPwdBody
         
     | 
| 
      
 76 
     | 
    
         
            +
                }
         
     | 
| 
      
 77 
     | 
    
         
            +
                
         
     | 
| 
      
 78 
     | 
    
         
            +
            }
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
         @@ -0,0 +1,29 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            //
         
     | 
| 
      
 2 
     | 
    
         
            +
            //  AWSManager.swift
         
     | 
| 
      
 3 
     | 
    
         
            +
            //  MVCGEN
         
     | 
| 
      
 4 
     | 
    
         
            +
            //
         
     | 
| 
      
 5 
     | 
    
         
            +
            //  Created by Daniel Martinez on 23/7/18.
         
     | 
| 
      
 6 
     | 
    
         
            +
            //  Copyright © 2018 DanielMartinez. All rights reserved.
         
     | 
| 
      
 7 
     | 
    
         
            +
            //
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            import UIKit
         
     | 
| 
      
 10 
     | 
    
         
            +
            import AWSCore
         
     | 
| 
      
 11 
     | 
    
         
            +
            import AWSCognito
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            class AWSManager: NSObject {
         
     | 
| 
      
 14 
     | 
    
         
            +
                
         
     | 
| 
      
 15 
     | 
    
         
            +
                // MARK: - Singleton
         
     | 
| 
      
 16 
     | 
    
         
            +
                
         
     | 
| 
      
 17 
     | 
    
         
            +
                static let sharedInstance = AWSManager()
         
     | 
| 
      
 18 
     | 
    
         
            +
                
         
     | 
| 
      
 19 
     | 
    
         
            +
                private override init() {
         
     | 
| 
      
 20 
     | 
    
         
            +
                    
         
     | 
| 
      
 21 
     | 
    
         
            +
                    let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: Config.sharedInstance.awsIdentityPoolId())
         
     | 
| 
      
 22 
     | 
    
         
            +
                    
         
     | 
| 
      
 23 
     | 
    
         
            +
                    let configuration = AWSServiceConfiguration(region:.USEast1, credentialsProvider:credentialProvider)
         
     | 
| 
      
 24 
     | 
    
         
            +
                    
         
     | 
| 
      
 25 
     | 
    
         
            +
                    AWSServiceManager.default().defaultServiceConfiguration = configuration
         
     | 
| 
      
 26 
     | 
    
         
            +
                    
         
     | 
| 
      
 27 
     | 
    
         
            +
                }
         
     | 
| 
      
 28 
     | 
    
         
            +
                
         
     | 
| 
      
 29 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,97 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            //
         
     | 
| 
      
 2 
     | 
    
         
            +
            //  FilesManager.swift
         
     | 
| 
      
 3 
     | 
    
         
            +
            //  MVCGEN
         
     | 
| 
      
 4 
     | 
    
         
            +
            //
         
     | 
| 
      
 5 
     | 
    
         
            +
            //  Created by Daniel Martinez on 23/7/18.
         
     | 
| 
      
 6 
     | 
    
         
            +
            //  Copyright © 2018 DanielMartinez. All rights reserved.
         
     | 
| 
      
 7 
     | 
    
         
            +
            //
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            import UIKit
         
     | 
| 
      
 10 
     | 
    
         
            +
            import AVKit
         
     | 
| 
      
 11 
     | 
    
         
            +
            import AVFoundation
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            class FilesManager: NSObject {
         
     | 
| 
      
 14 
     | 
    
         
            +
                
         
     | 
| 
      
 15 
     | 
    
         
            +
                static let sharedInstance = FilesManager()
         
     | 
| 
      
 16 
     | 
    
         
            +
                
         
     | 
| 
      
 17 
     | 
    
         
            +
                fileprivate override init() {
         
     | 
| 
      
 18 
     | 
    
         
            +
                    super.init()
         
     | 
| 
      
 19 
     | 
    
         
            +
                }
         
     | 
| 
      
 20 
     | 
    
         
            +
                
         
     | 
| 
      
 21 
     | 
    
         
            +
                func getDocumentsURL() -> URL {
         
     | 
| 
      
 22 
     | 
    
         
            +
                    
         
     | 
| 
      
 23 
     | 
    
         
            +
                    let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
         
     | 
| 
      
 24 
     | 
    
         
            +
                    return documentsURL
         
     | 
| 
      
 25 
     | 
    
         
            +
                    
         
     | 
| 
      
 26 
     | 
    
         
            +
                }
         
     | 
| 
      
 27 
     | 
    
         
            +
                
         
     | 
| 
      
 28 
     | 
    
         
            +
                func fileInDocumentsDirectory(_ filename: String) -> String {
         
     | 
| 
      
 29 
     | 
    
         
            +
                    
         
     | 
| 
      
 30 
     | 
    
         
            +
                    let fileURL = self.getDocumentsURL().appendingPathComponent(filename)
         
     | 
| 
      
 31 
     | 
    
         
            +
                    return fileURL.path
         
     | 
| 
      
 32 
     | 
    
         
            +
                    
         
     | 
| 
      
 33 
     | 
    
         
            +
                }
         
     | 
| 
      
 34 
     | 
    
         
            +
                
         
     | 
| 
      
 35 
     | 
    
         
            +
                func fileModificationDate(_ filename: String) -> Date? {
         
     | 
| 
      
 36 
     | 
    
         
            +
                    do {
         
     | 
| 
      
 37 
     | 
    
         
            +
                        let path = self.fileInDocumentsDirectory(filename)
         
     | 
| 
      
 38 
     | 
    
         
            +
                        let attr = try FileManager.default.attributesOfItem(atPath: path)
         
     | 
| 
      
 39 
     | 
    
         
            +
                        return attr[FileAttributeKey.modificationDate] as? Date
         
     | 
| 
      
 40 
     | 
    
         
            +
                    } catch {
         
     | 
| 
      
 41 
     | 
    
         
            +
                        return nil
         
     | 
| 
      
 42 
     | 
    
         
            +
                    }
         
     | 
| 
      
 43 
     | 
    
         
            +
                }
         
     | 
| 
      
 44 
     | 
    
         
            +
                
         
     | 
| 
      
 45 
     | 
    
         
            +
                func saveMedia(_ media: Data, filename: String ) -> Bool {
         
     | 
| 
      
 46 
     | 
    
         
            +
                    let path = self.fileInDocumentsDirectory(filename)
         
     | 
| 
      
 47 
     | 
    
         
            +
                    let result = (try? media.write(to: URL(fileURLWithPath: path), options: [.atomic])) != nil
         
     | 
| 
      
 48 
     | 
    
         
            +
                    print("Save media at: \(self.fileInDocumentsDirectory(filename))")
         
     | 
| 
      
 49 
     | 
    
         
            +
                    print("Result: \(result)")
         
     | 
| 
      
 50 
     | 
    
         
            +
                    return result
         
     | 
| 
      
 51 
     | 
    
         
            +
                }
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                func loadMedia(_ filename: String) -> Data? {
         
     | 
| 
      
 54 
     | 
    
         
            +
                    
         
     | 
| 
      
 55 
     | 
    
         
            +
                    let path = self.fileInDocumentsDirectory(filename)
         
     | 
| 
      
 56 
     | 
    
         
            +
                    
         
     | 
| 
      
 57 
     | 
    
         
            +
                    let media = try? Data(contentsOf: URL(fileURLWithPath: path))
         
     | 
| 
      
 58 
     | 
    
         
            +
                    
         
     | 
| 
      
 59 
     | 
    
         
            +
                    if media == nil {
         
     | 
| 
      
 60 
     | 
    
         
            +
                        print("Missing media at: \(path)")
         
     | 
| 
      
 61 
     | 
    
         
            +
                    }
         
     | 
| 
      
 62 
     | 
    
         
            +
                    print("Loading media from path: \(path)")
         
     | 
| 
      
 63 
     | 
    
         
            +
                    
         
     | 
| 
      
 64 
     | 
    
         
            +
                    return media
         
     | 
| 
      
 65 
     | 
    
         
            +
                }
         
     | 
| 
      
 66 
     | 
    
         
            +
                
         
     | 
| 
      
 67 
     | 
    
         
            +
                func removeMedia(filename: String) -> Bool {
         
     | 
| 
      
 68 
     | 
    
         
            +
                    let fileURL = fileInDocumentsDirectory(filename)
         
     | 
| 
      
 69 
     | 
    
         
            +
                    do {
         
     | 
| 
      
 70 
     | 
    
         
            +
                        try FileManager.default.removeItem(atPath: fileURL)
         
     | 
| 
      
 71 
     | 
    
         
            +
                        return true
         
     | 
| 
      
 72 
     | 
    
         
            +
                    } catch {
         
     | 
| 
      
 73 
     | 
    
         
            +
                        print("Error removing media \(filename) error: \(error)")
         
     | 
| 
      
 74 
     | 
    
         
            +
                        return false
         
     | 
| 
      
 75 
     | 
    
         
            +
                    }
         
     | 
| 
      
 76 
     | 
    
         
            +
                }
         
     | 
| 
      
 77 
     | 
    
         
            +
                
         
     | 
| 
      
 78 
     | 
    
         
            +
                func removeAllAppLocalFiles() {
         
     | 
| 
      
 79 
     | 
    
         
            +
                    do {
         
     | 
| 
      
 80 
     | 
    
         
            +
                        let fileManager = FileManager.default
         
     | 
| 
      
 81 
     | 
    
         
            +
                        let documentsPath = getDocumentsURL().path
         
     | 
| 
      
 82 
     | 
    
         
            +
                        let fileNames = try fileManager.contentsOfDirectory(atPath: "\(documentsPath)")
         
     | 
| 
      
 83 
     | 
    
         
            +
                        print("all files : \(fileNames)")
         
     | 
| 
      
 84 
     | 
    
         
            +
                        
         
     | 
| 
      
 85 
     | 
    
         
            +
                        for fileName in fileNames {
         
     | 
| 
      
 86 
     | 
    
         
            +
                            let filePathName = "\(documentsPath)/\(fileName)"
         
     | 
| 
      
 87 
     | 
    
         
            +
                            print(filePathName)
         
     | 
| 
      
 88 
     | 
    
         
            +
                            try fileManager.removeItem(atPath: filePathName)
         
     | 
| 
      
 89 
     | 
    
         
            +
                        }
         
     | 
| 
      
 90 
     | 
    
         
            +
                        print("All app files cleared")
         
     | 
| 
      
 91 
     | 
    
         
            +
                    } catch {
         
     | 
| 
      
 92 
     | 
    
         
            +
                        print("Couldn't clear all files")
         
     | 
| 
      
 93 
     | 
    
         
            +
                    }
         
     | 
| 
      
 94 
     | 
    
         
            +
                
         
     | 
| 
      
 95 
     | 
    
         
            +
                }
         
     | 
| 
      
 96 
     | 
    
         
            +
                
         
     | 
| 
      
 97 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,113 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            //
         
     | 
| 
      
 2 
     | 
    
         
            +
            //  S3Manager.swift
         
     | 
| 
      
 3 
     | 
    
         
            +
            //  MVCGEN
         
     | 
| 
      
 4 
     | 
    
         
            +
            //
         
     | 
| 
      
 5 
     | 
    
         
            +
            //  Created by Daniel Martinez on 23/7/18.
         
     | 
| 
      
 6 
     | 
    
         
            +
            //  Copyright © 2018 DanielMartinez. All rights reserved.
         
     | 
| 
      
 7 
     | 
    
         
            +
            //
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            import UIKit
         
     | 
| 
      
 10 
     | 
    
         
            +
            import AWSS3
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            class S3Manager: NSObject{
         
     | 
| 
      
 13 
     | 
    
         
            +
                
         
     | 
| 
      
 14 
     | 
    
         
            +
                // MARK: - Singleton
         
     | 
| 
      
 15 
     | 
    
         
            +
                static let sharedInstance = S3Manager()
         
     | 
| 
      
 16 
     | 
    
         
            +
                
         
     | 
| 
      
 17 
     | 
    
         
            +
                let transferManager = AWSS3TransferManager.default()
         
     | 
| 
      
 18 
     | 
    
         
            +
                
         
     | 
| 
      
 19 
     | 
    
         
            +
                private override init() {}
         
     | 
| 
      
 20 
     | 
    
         
            +
                
         
     | 
| 
      
 21 
     | 
    
         
            +
                func uploadToS3(url uploadingFileURL: URL, name key: String, completeBlock: @escaping (Bool) -> Void) {
         
     | 
| 
      
 22 
     | 
    
         
            +
                    
         
     | 
| 
      
 23 
     | 
    
         
            +
                    if let uploadRequest = AWSS3TransferManagerUploadRequest() {
         
     | 
| 
      
 24 
     | 
    
         
            +
                        
         
     | 
| 
      
 25 
     | 
    
         
            +
                        uploadRequest.bucket = Config.sharedInstance.s3BucketName()
         
     | 
| 
      
 26 
     | 
    
         
            +
                        uploadRequest.key = key
         
     | 
| 
      
 27 
     | 
    
         
            +
                        uploadRequest.body = uploadingFileURL
         
     | 
| 
      
 28 
     | 
    
         
            +
                        self.transferManager.upload(uploadRequest).continueWith(executor: AWSExecutor.mainThread(), block: { (task:AWSTask<AnyObject>) -> Any? in
         
     | 
| 
      
 29 
     | 
    
         
            +
                            
         
     | 
| 
      
 30 
     | 
    
         
            +
                            if let error = task.error as NSError? {
         
     | 
| 
      
 31 
     | 
    
         
            +
                                if error.domain == AWSS3TransferManagerErrorDomain, let code = AWSS3TransferManagerErrorType(rawValue: error.code) {
         
     | 
| 
      
 32 
     | 
    
         
            +
                                    switch code {
         
     | 
| 
      
 33 
     | 
    
         
            +
                                    case .cancelled, .paused:
         
     | 
| 
      
 34 
     | 
    
         
            +
                                        break
         
     | 
| 
      
 35 
     | 
    
         
            +
                                    default:
         
     | 
| 
      
 36 
     | 
    
         
            +
                                        print("Error uploading: \(uploadRequest.key!) Error: \(error)")
         
     | 
| 
      
 37 
     | 
    
         
            +
                                    }
         
     | 
| 
      
 38 
     | 
    
         
            +
                                } else {
         
     | 
| 
      
 39 
     | 
    
         
            +
                                    print("Error uploading: \(uploadRequest.key!) Error: \(error)")
         
     | 
| 
      
 40 
     | 
    
         
            +
                                }
         
     | 
| 
      
 41 
     | 
    
         
            +
                                completeBlock(false)
         
     | 
| 
      
 42 
     | 
    
         
            +
                                return nil
         
     | 
| 
      
 43 
     | 
    
         
            +
                            }
         
     | 
| 
      
 44 
     | 
    
         
            +
                            
         
     | 
| 
      
 45 
     | 
    
         
            +
                            if let uploadOutput = task.result {
         
     | 
| 
      
 46 
     | 
    
         
            +
                                print("Upload complete for: \(uploadRequest.key!) - Output \(uploadOutput)")
         
     | 
| 
      
 47 
     | 
    
         
            +
                                completeBlock(true)
         
     | 
| 
      
 48 
     | 
    
         
            +
                            }
         
     | 
| 
      
 49 
     | 
    
         
            +
                            
         
     | 
| 
      
 50 
     | 
    
         
            +
                            return nil
         
     | 
| 
      
 51 
     | 
    
         
            +
                        })
         
     | 
| 
      
 52 
     | 
    
         
            +
                    }
         
     | 
| 
      
 53 
     | 
    
         
            +
                }
         
     | 
| 
      
 54 
     | 
    
         
            +
                
         
     | 
| 
      
 55 
     | 
    
         
            +
                func downloadFromS3(downloadingFilename: String, name key: String, completeBlock: @escaping (String, Bool) -> Void) {
         
     | 
| 
      
 56 
     | 
    
         
            +
                    if let downloadRequest = AWSS3TransferManagerDownloadRequest() {
         
     | 
| 
      
 57 
     | 
    
         
            +
                        
         
     | 
| 
      
 58 
     | 
    
         
            +
                        downloadRequest.bucket = Config.sharedInstance.s3BucketName()
         
     | 
| 
      
 59 
     | 
    
         
            +
                        downloadRequest.key = key
         
     | 
| 
      
 60 
     | 
    
         
            +
                        downloadRequest.downloadingFileURL = URL(fileURLWithPath: FilesManager.sharedInstance.fileInDocumentsDirectory(downloadingFilename))
         
     | 
| 
      
 61 
     | 
    
         
            +
                        self.transferManager.download(downloadRequest).continueWith(executor: AWSExecutor.mainThread(), block: { (task: AWSTask<AnyObject>) -> Any? in
         
     | 
| 
      
 62 
     | 
    
         
            +
                            if let error = task.error as NSError? {
         
     | 
| 
      
 63 
     | 
    
         
            +
                                if error.domain == AWSS3TransferManagerErrorDomain, let code = AWSS3TransferManagerErrorType(rawValue: error.code) {
         
     | 
| 
      
 64 
     | 
    
         
            +
                                    switch code {
         
     | 
| 
      
 65 
     | 
    
         
            +
                                    case .cancelled, .paused:
         
     | 
| 
      
 66 
     | 
    
         
            +
                                        break
         
     | 
| 
      
 67 
     | 
    
         
            +
                                    default:
         
     | 
| 
      
 68 
     | 
    
         
            +
                                        print("Error downloading: \(downloadRequest.key!) Error: \(error)")
         
     | 
| 
      
 69 
     | 
    
         
            +
                                    }
         
     | 
| 
      
 70 
     | 
    
         
            +
                                } else {
         
     | 
| 
      
 71 
     | 
    
         
            +
                                    print("Error downloading: \(downloadRequest.key!) Error: \(error)")
         
     | 
| 
      
 72 
     | 
    
         
            +
                                }
         
     | 
| 
      
 73 
     | 
    
         
            +
                                completeBlock(downloadingFilename, false)
         
     | 
| 
      
 74 
     | 
    
         
            +
                                return nil
         
     | 
| 
      
 75 
     | 
    
         
            +
                            }
         
     | 
| 
      
 76 
     | 
    
         
            +
                            
         
     | 
| 
      
 77 
     | 
    
         
            +
                            if let downloadOutput = task.result {
         
     | 
| 
      
 78 
     | 
    
         
            +
                                print("Download complete for: \(downloadRequest.key!) - Output \(downloadOutput)")
         
     | 
| 
      
 79 
     | 
    
         
            +
                                completeBlock(downloadingFilename, true)
         
     | 
| 
      
 80 
     | 
    
         
            +
                            }
         
     | 
| 
      
 81 
     | 
    
         
            +
                            return nil
         
     | 
| 
      
 82 
     | 
    
         
            +
                        })
         
     | 
| 
      
 83 
     | 
    
         
            +
                    }
         
     | 
| 
      
 84 
     | 
    
         
            +
                }
         
     | 
| 
      
 85 
     | 
    
         
            +
                
         
     | 
| 
      
 86 
     | 
    
         
            +
                func downloadFromS3Aux(downloadRequest: AWSS3TransferManagerDownloadRequest,downloadingFilename:String,completeBlock: @escaping (String, Bool) -> Void) {
         
     | 
| 
      
 87 
     | 
    
         
            +
                   self.transferManager.download(downloadRequest).continueWith(executor: AWSExecutor.mainThread(), block: { (task: AWSTask<AnyObject>) -> Any? in
         
     | 
| 
      
 88 
     | 
    
         
            +
                        if let error = task.error as NSError? {
         
     | 
| 
      
 89 
     | 
    
         
            +
                            if error.domain == AWSS3TransferManagerErrorDomain, let code = AWSS3TransferManagerErrorType(rawValue: error.code) {
         
     | 
| 
      
 90 
     | 
    
         
            +
                                switch code {
         
     | 
| 
      
 91 
     | 
    
         
            +
                                case .cancelled, .paused:
         
     | 
| 
      
 92 
     | 
    
         
            +
                                    break
         
     | 
| 
      
 93 
     | 
    
         
            +
                                default:
         
     | 
| 
      
 94 
     | 
    
         
            +
                                    break
         
     | 
| 
      
 95 
     | 
    
         
            +
                                    print("Error downloading: \(downloadRequest.key!) Error: \(error)")
         
     | 
| 
      
 96 
     | 
    
         
            +
                                }
         
     | 
| 
      
 97 
     | 
    
         
            +
                            } else {
         
     | 
| 
      
 98 
     | 
    
         
            +
                                print("Error downloading: \(downloadRequest.key!) Error: \(error)")
         
     | 
| 
      
 99 
     | 
    
         
            +
                            }
         
     | 
| 
      
 100 
     | 
    
         
            +
                            completeBlock(downloadingFilename, false)
         
     | 
| 
      
 101 
     | 
    
         
            +
                            return nil
         
     | 
| 
      
 102 
     | 
    
         
            +
                        }
         
     | 
| 
      
 103 
     | 
    
         
            +
                        print("Download complete for: \(downloadRequest.key!)")
         
     | 
| 
      
 104 
     | 
    
         
            +
                        
         
     | 
| 
      
 105 
     | 
    
         
            +
                        if let downloadOutput = task.result {
         
     | 
| 
      
 106 
     | 
    
         
            +
                            print("Download complete for: \(downloadRequest.key!) - Output \(downloadOutput)")
         
     | 
| 
      
 107 
     | 
    
         
            +
                            completeBlock(downloadingFilename, true)
         
     | 
| 
      
 108 
     | 
    
         
            +
                        }
         
     | 
| 
      
 109 
     | 
    
         
            +
                        return nil
         
     | 
| 
      
 110 
     | 
    
         
            +
                    })
         
     | 
| 
      
 111 
     | 
    
         
            +
                }
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
            }
         
     |