Permalink
Cannot retrieve contributors at this time
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?
SynchronyFinancialWatchApp/SynchronyFinancial/SynchronyFinancial WatchKit Extension/FetchData.swift
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
60 lines (54 sloc)
3 KB
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
// | |
// 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 } | |
print(json) | |
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"]?.string else {return} | |
guard let payDueDate = account.dictionaryValue["next_payment_due_date"]?.string else {return} | |
guard let curBal = account.dictionaryValue["current_balance"]?.string else {return} | |
guard let availCredit = account.dictionaryValue["available_credit"]?.string else {return} | |
guard let minPayDue = account.dictionaryValue["minimum_payment_due"]?.string else {return} | |
guard let statementBal = account.dictionaryValue["statement_bal"]?.string else {return} | |
guard let accountName = account.dictionaryValue["cc_program_name"]?.string else {return} | |
let creditLimitD = Double(creditLimit)! | |
let curBalD = Double(curBal)! | |
let availCreditD = Double(availCredit)! | |
let minPayDueD = Double(minPayDue)! | |
let stateBalD = Double(statementBal)! | |
debugPrint(accountAlias) | |
debugPrint(creditLimitD) | |
debugPrint(payDueDate) | |
debugPrint(curBalD) | |
debugPrint(availCreditD) | |
debugPrint(minPayDueD) | |
debugPrint(stateBalD) | |
debugPrint(accountName) | |
let inAccount = Account(accountAlias: accountAlias, creditLimit: creditLimitD, paymentDueDate: payDueDate, curBalance: curBalD, availCredit: availCreditD, minPayDue: minPayDueD, statementBal: stateBalD, accountName: accountName) | |
accountList.append(inAccount) | |
} | |
} | |
//debugPrint(json) | |
case .failure(let error): | |
NSLog("Error: %s", error.localizedDescription) | |
} | |
} | |
} | |
} |