diff --git a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate
index dc2f0c7..8169c3e 100644
Binary files a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate and b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
index c78dbce..533f5c9 100644
--- a/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
+++ b/Vendoo.xcworkspace/xcuserdata/okechi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -35,5 +35,117 @@
landmarkType = "5">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Vendoo/EtsyRESTAPIManager.swift b/Vendoo/EtsyRESTAPIManager.swift
index d9e1204..e36346e 100644
--- a/Vendoo/EtsyRESTAPIManager.swift
+++ b/Vendoo/EtsyRESTAPIManager.swift
@@ -608,6 +608,28 @@ extension EtsyRESTAPIManager {
)
}
+ //gets listing info
+ func getListingInfo (request: String, onCompletion: ServiceResponse?) {
+ self.oauthswift.client.get(self.baseURL + request,
+ success: {
+ (data, response) -> Void in
+ let dataString = NSString(data: data, encoding: NSUTF8StringEncoding)
+ let dict = self.convertStringToDictionary(dataString! as String)
+ print(dict)
+ print(response)
+ var dict2 = (dict!["results"] as! [[String : AnyObject]])
+
+ let listingState = dict2[0]["state"] as! String
+
+ onCompletion!(["status":listingState], nil)
+
+
+ }, failure: {
+ (error) -> Void in
+ print(error)
+ }
+ )}
+
//sends the pregenerated url as a request to api service
func sendPOSTRequest(request: String, var body: [String: AnyObject]?, onCompletion: ServiceResponse?) {
diff --git a/Vendoo/HomeViewController.swift b/Vendoo/HomeViewController.swift
index 8a1ee65..4d3c1a3 100644
--- a/Vendoo/HomeViewController.swift
+++ b/Vendoo/HomeViewController.swift
@@ -257,12 +257,25 @@ extension HomeViewController: ServiceNotificationManagerDelegate {
self.notifications.append(
[
"network": "etsy",
- "message": (ebayInfo as! [String : AnyObject])["notification"] as! String,
+ "message": (etsyInfo as! [String : AnyObject])["notification"] as! String,
"type": "ended",
- "key": (ebayInfo as! [String : AnyObject])["listingKey"] as! String,
+ "key": (etsyInfo as! [String : AnyObject])["listingKey"] as! String,
"UUID": NSUUID().UUIDString
]
)
+ self.endedListings.appendContentsOf( self.userListings.filter({$0.key == ((etsyInfo as! [String : AnyObject])["listingKey"] as! String)}))
+ self.userListings = self.userListings.filter({$0.key != ((etsyInfo as! [String : AnyObject])["listingKey"] as! String)})
+ let itemsView = self.viewControllers![0] as! ItemTableViewController
+
+ self.firebaseManager.ref.child("Users/\(self.firebaseManager.user_email)/user_Listings/\(((etsyInfo as! [String : AnyObject])["listingKey"] as! String))").observeSingleEventOfType( .Value, withBlock: {
+ (snapshot) -> Void in
+
+ var listingDict = snapshot.value as? [String : AnyObject]
+ listingDict!["listingStatus"] = "Ended"
+ self.firebaseManager.ref.child("Users/\(self.firebaseManager.user_email)/user_Listings/\(((etsyInfo as! [String : AnyObject])["listingKey"] as! String))").setValue(listingDict)
+
+ itemsView.itemTable.reloadData()
+ })
}
}
@@ -310,13 +323,15 @@ extension HomeViewController: ServiceNotificationManagerDelegate {
self.notifications.append(
[
"network": "etsy",
- "message": (ebayInfo as! [String : AnyObject])["notification"] as! String,
- "type": "",
- "key": (ebayInfo as! [String : AnyObject])["listingKey"] as! String,
+ "message": (etsyInfo as! [String : AnyObject])["notification"] as! String,
+ "type": (etsyInfo as! [String : AnyObject])["type"] as! String,
+ "key": (etsyInfo as! [String : AnyObject])["listingKey"] as! String,
"UUID": NSUUID().UUIDString
]
)
}
+ //@TODO: add firbase logic to add notifications and delete already viewed notifications
+
}
}
diff --git a/Vendoo/ServiceNotificationManager.swift b/Vendoo/ServiceNotificationManager.swift
index cac2c7e..a59fee3 100644
--- a/Vendoo/ServiceNotificationManager.swift
+++ b/Vendoo/ServiceNotificationManager.swift
@@ -114,7 +114,45 @@ class ServiceNotificationManager: NSObject {
}
if(etsyID != nil){
+ if (self.etsyManager.isAuthorized) {
+ self.etsyManager.getListingInfo ("/listings/\(etsyID!)", onCompletion: {
+ (listingNotificationInfo, error) -> Void in
+
+ let info = (listingNotificationInfo as! [String : AnyObject])
+
+ //@TODO: Test this code with the draft condition for both expired and sold_out
+ if ((info["status"] as! String == "expired") || (info["status"] as! String == "removed")) {
+
+ ServiceNotificationManager.delegate?.listingHasEnded(
+ nil,
+ ebayInfo: nil,
+ amazonInfo: nil,
+ etsyInfo: [
+ "type": "Ended",
+ "notification": "Your listing \"\(listingDict!["listingTitle"] as! String)\" has ended on etsy.",
+ "listingKey": listing.key]
+ )
+
+
+ }else if info["status"] as! String == "sold_out" {
+
+ ServiceNotificationManager.delegate?.listingHasNewNotifications(
+ nil,
+ ebayInfo: nil,
+ amazonInfo: nil,
+ etsyInfo: [
+ "type": "Sold",
+ "notification": "Your listing \"\(listingDict!["listingTitle"] as! String)\" has sold out on etsy.",
+ "listingKey": listing.key]
+ )
+
+ } else if info["status"] as! String == "draft" {
+
+ }
+
+ })
+ }
}
if(amazonID != nil){