Skip to content
Permalink
da5294af84
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
52 lines (48 sloc) 2.63 KB
//
// FetchData.swift
// SynchronyFinancial WatchKit Extension
//
// Created by Rahul Kantesaria on 3/14/19.
// Copyright © 2019 Alan Maynard. All rights reserved.
//
import Foundation
import Alamofire
import SwiftyJSON
class FetchData{
class func getAccountInfo(){
var accountList: [Account] = []
Alamofire.request(Defaults.MULTI_ACCT_URL, method: .post, parameters: Defaults.headerForMulti, encoding: JSONEncoding.default, headers: Defaults.authHeader).responseJSON { payload in
switch payload.result {
case .success(let value):
let json = JSON(value)
let dict = json.dictionaryValue
guard dict["status"]?.dictionaryValue["response_code"]?.string == "0" else { return }
if let accounts = dict["account_number_list"]?.arrayValue{
for account in accounts{
guard let accountAlias = account.dictionaryValue["account_alias"]?.string else {return}
guard let creditLimit = account.dictionaryValue["credit_limit"]?.double else {return}
guard let payDueDate = account.dictionaryValue["next_payment_due_date"]?.string else {return}
guard let curBal = account.dictionaryValue["current_balance"]?.double else {return}
guard let availCredit = account.dictionaryValue["available_credit"]?.double else {return}
guard let minPayDue = account.dictionaryValue["minimum_payment_due"]?.double else {return}
guard let statementBal = account.dictionaryValue["statement_bal"]?.double else {return}
guard let accountName = account.dictionaryValue["cc_program_name"]?.string else {return}
debugPrint(accountAlias)
debugPrint(creditLimit)
debugPrint(payDueDate)
debugPrint(curBal)
debugPrint(availCredit)
debugPrint(minPayDue)
debugPrint(statementBal)
debugPrint(accountName)
let inAccount = Account(accountAlias: accountAlias, creditLimit: creditLimit, paymentDueDate: payDueDate, curBalance: curBal, availCredit: availCredit, minPayDue: minPayDue, statementBal: statementBal, accountName: accountName)
accountList.append(inAccount)
}
}
//debugPrint(json)
case .failure(let error):
NSLog("Error: %s", error.localizedDescription)
}
}
}
}