mirror of
https://bitbucket.org/vendoo/vendoo_v1.0.git
synced 2025-12-25 03:37:39 +00:00
108 lines
4.1 KiB
Swift
108 lines
4.1 KiB
Swift
//
|
|
// ServiceNotificationManager.swift
|
|
// Vendoo
|
|
//
|
|
// Created by Okechi Onyeje on 8/30/16.
|
|
// Copyright © 2016 Okechi Onyeje. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
protocol ServiceNotificationManagerDelegate {
|
|
func listingHasEnded(fbInfo: AnyObject?, ebayInfo: AnyObject?, amazonInfo: AnyObject?, etsyInfo: AnyObject?)
|
|
func listingHasNewNotifications(fbInfo: AnyObject?, ebayInfo: AnyObject?, amazonInfo: AnyObject?, etsyInfo: AnyObject?)
|
|
}
|
|
|
|
class ServiceNotificationManager: NSObject {
|
|
|
|
var etsyManager: EtsyRESTAPIManager!
|
|
var fbGraphManager: FacebookGraphAPIManager!
|
|
var firebaseManager: FirebaseManager!
|
|
var ebayGraphManager: EbayWebServiceManager!
|
|
var userListings: [Listing] = []
|
|
var timer: NSTimer!
|
|
var delegate: ServiceNotificationManagerDelegate?
|
|
|
|
override init() {
|
|
super.init()
|
|
|
|
|
|
}
|
|
|
|
func startServicePolling() {
|
|
timer = NSTimer.scheduledTimerWithTimeInterval(10.0, target: self, selector: #selector(ServiceNotificationManager.pollServices), userInfo: nil, repeats: true)
|
|
}
|
|
|
|
func stopServicePolling() {
|
|
timer.invalidate()
|
|
}
|
|
|
|
func setManagers(fbManager: FacebookGraphAPIManager, fireManager: FirebaseManager, ebayManager: EbayWebServiceManager, etsyManager: EtsyRESTAPIManager){
|
|
self.fbGraphManager = fbManager
|
|
self.firebaseManager = fireManager
|
|
self.ebayGraphManager = ebayManager
|
|
self.etsyManager = etsyManager
|
|
}
|
|
|
|
func setListings(listings: [Listing]) {
|
|
self.userListings = listings
|
|
}
|
|
|
|
func pollServices(){
|
|
let notificationGroup = dispatch_group_create()
|
|
for listing in userListings {
|
|
dispatch_group_enter(notificationGroup)
|
|
|
|
self.firebaseManager.ref.child("Users/\(self.firebaseManager.user_email)/user_Listings/\(listing.key)").observeSingleEventOfType( .Value, withBlock: {
|
|
(snapshot) -> Void in
|
|
|
|
let listingDict = snapshot.value as? [String : AnyObject]
|
|
|
|
if !(listingDict!["isListingDraft"] as! Bool) {
|
|
if let networksDict = listingDict!["networkIDs"] as? [String : AnyObject] {
|
|
let ebayID = (networksDict["ebay"] as? String)
|
|
let facebookID = (networksDict["facebook"] as? String)
|
|
let etsyID = (networksDict["etsy"] as? Int)
|
|
let amazonID = (networksDict["amazon"] as? String)
|
|
|
|
//@TODO: Skeleton for Notfications Manager is set up. Need to implement listing request for each listing to retrieve relevant notifications for user such as if listing has ended
|
|
if(ebayID != nil){
|
|
/*if self.ebayGraphManager.isAuthorized {
|
|
self.ebayGraphManager.getListingInfo(ebayID!, onComplete: {
|
|
(listingStatus, error) -> Void in
|
|
dispatch_group_leave(notificationGroup)
|
|
|
|
})
|
|
}*/
|
|
}
|
|
if(facebookID != nil){
|
|
|
|
}
|
|
if(etsyID != nil){
|
|
|
|
}
|
|
if(amazonID != nil){
|
|
|
|
}
|
|
//dispatch_group_leave(notificationGroup)
|
|
}else {
|
|
dispatch_group_leave(notificationGroup)
|
|
}
|
|
|
|
|
|
}else {
|
|
dispatch_group_leave(notificationGroup)
|
|
}
|
|
})
|
|
}
|
|
|
|
dispatch_group_notify(notificationGroup, dispatch_get_main_queue(), {
|
|
self.delegate?.listingHasEnded(nil, ebayInfo: nil, amazonInfo: nil, etsyInfo: nil)
|
|
self.delegate?.listingHasNewNotifications(nil, ebayInfo: nil, amazonInfo: nil, etsyInfo: nil)
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|