Skip to content

Instantly share code, notes, and snippets.

@hellyeah
Created December 2, 2015 17:28
Show Gist options
  • Save hellyeah/31c8c3fa4f645a912871 to your computer and use it in GitHub Desktop.
Save hellyeah/31c8c3fa4f645a912871 to your computer and use it in GitHub Desktop.
//
// Vendor.swift
// Cash In
//
// Created by David Fontenot on 12/1/15.
// Copyright © 2015 MChackathon. All rights reserved.
//
import Foundation
var params = []
//["api-key": "53eb9541b4374660d6f3c0001d6249ca:19:70900879"]
let resourceUrl = "http://intense-lake-3556.herokuapp.com/api/"
let manager = AFHTTPRequestOperationManager()
class Customer {
var customer_firstname: String?
var customer_lastname: String?
var customer_fullname: String?
var customer_cell: String?
var customer_latitude: Double?
var customer_longitude: Double?
var customer_id: Int?
var ETA: Double?
init() {
customer_id = Int(1)
customer_firstname = "David"
customer_lastname = "Fontenot"
customer_fullname = "\(customer_firstname) \(customer_lastname)"
customer_cell = "9542604240"
customer_latitude = Double(25.807505)
customer_longitude = Double(-80.143874)
ETA = Double(1)
}
func updateCustomer(customerObject: AnyObject){
//customerObject
}
func postCustomerUpdate() {
}
}
class Vendor {
var vendor_firstname: String?
var vendor_lastname: String?
var vendor_fullname: String?
var vendor_cell: String?
var vendor_latitude: Double?
var vendor_longitude: Double?
var vendor_id: Int?
var ETA: Double?
init() {
vendor_id = Int(1)
vendor_firstname = "David"
vendor_lastname = "Fontenot"
vendor_fullname = "\(vendor_firstname) \(vendor_lastname)"
vendor_cell = "9542604240"
vendor_latitude = Double(25.807505)
vendor_longitude = Double(-80.143874)
ETA = Double(1)
}
func updateCustomer(customerObject: AnyObject){
//customerObject
}
func populateVendor(vendorID: Int) {
let fullUrl = resourceUrl + "vendor/\(vendorID)"
manager.GET(fullUrl, parameters: params, success: { (operation, responseObject) -> Void in
self.vendor_id = responseObject["vendor_id"] as? Int
self.vendor_firstname = responseObject["vendor_firstname"] as? String
self.vendor_lastname = responseObject["vendor_lastname"] as? String
self.vendor_fullname = "\(self.vendor_firstname) \(self.vendor_lastname)"
self.vendor_cell = responseObject["vendor_cell"] as? String
self.vendor_latitude = responseObject["vendor_latitude"] as? Double
self.vendor_longitude = responseObject["vendor_longitude"] as? Double
print(responseObject)
//print(responseObject[0])
}, failure: nil)
}
}
class Transaction {
var transaction_id: Int?
var transaction_state: String?
var transaction_currency: String?
var transaction_currency_amount: Int?
var vendor_id: Int?
var customer_id: Int?
init() {
transaction_id = Int(1)
transaction_state = "David"
transaction_currency = "Fontenot"
transaction_currency_amount = Int(20000)
vendor_id = Int(1)
customer_id = Int(1)
}
func updateCustomer(customerObject: AnyObject){
//customerObject
}
}
class LocalAPI {
var customer = Customer()
var current_transaction_id: Int?
var current_vendor_id: Int?
var current_customer_id = Int(1)
//var customer = Customer.init()
//customer.init()
var params = []
//["api-key": "53eb9541b4374660d6f3c0001d6249ca:19:70900879"]
let resourceUrl = "http://intense-lake-3556.herokuapp.com/api/"
let manager = AFHTTPRequestOperationManager()
var customerObject: AnyObject?
var vendorObject: AnyObject?
var transactionObject: AnyObject?
var presetObject: AnyObject?
func updateAllObjects() {
updateCustomer()
updateVendor()
updateTransaction()
updatePreset()
}
func updateCustomer() {
let fullUrl = resourceUrl + "customer"
manager.GET(fullUrl, parameters: params, success: { (operation, responseObject) -> Void in
self.customerObject = responseObject
print(responseObject)
//print(responseObject[0])
}, failure: nil)
}
func updateVendor() {
let fullUrl = resourceUrl + "vendor"
manager.GET(fullUrl, parameters: params, success: { (operation, responseObject) -> Void in
self.vendorObject = responseObject
print(responseObject)}, failure: nil)
}
//this one is most important to poll
func updateTransaction() {
let fullUrl = resourceUrl + "transaction"
manager.GET(fullUrl, parameters: params, success: { (operation, responseObject) -> Void in
self.transactionObject = responseObject
print(responseObject)}, failure: nil)
}
func updatePreset() {
let fullUrl = resourceUrl + "preset"
manager.GET(fullUrl, parameters: params, success: { (operation, responseObject) -> Void in
self.presetObject = responseObject
print(responseObject)}, failure: nil)
}
func startTransaction() {
let fullUrl = resourceUrl + "transaction"
let params = ["customer_id": Int(1), "transaction_currency": "MXN", "transaction_currency_amount": Int(20000), "transaction_state": "taken", "vendor_id": Int(2)]
manager.POST(fullUrl, parameters: params, success: { (operation, responseObject) -> Void in
//self.presetObject = responseObject
print(responseObject["transaction_id"])
self.current_transaction_id = responseObject["transaction_id"]! as? Int
//self.current_vendor_id = responseObject["vendor_id"]! as? Int
print(responseObject)}, failure: nil)
}
func checkAFNetworking() {
manager.GET(resourceUrl, parameters: params, success: { (operation, responseObject) -> Void in
self.vendorObject = responseObject
print(responseObject)}, failure: nil)
// manager.GET(resourceUrl, parameters: params, success: { (operation, responseObject) -> Void in
// if let results = responseObject["results"] as? NSArray {
// print(results)
// }, failure: {(operation, requestError) -> Void in
// if let errorCallback = error? {
// errorCallback(requestError)
// }
// }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment