diff --git a/Vendoo.xcodeproj/project.pbxproj b/Vendoo.xcodeproj/project.pbxproj index 908bce8..7b1404b 100644 --- a/Vendoo.xcodeproj/project.pbxproj +++ b/Vendoo.xcodeproj/project.pbxproj @@ -43,6 +43,8 @@ 3EFB0E331D0B968300A05D7A /* SideMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EFB0E321D0B968300A05D7A /* SideMenuView.swift */; }; 3F8E0464700649BDD8B552B1 /* Pods_Vendoo_VendooTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B876489113F498AF1D2FD7E9 /* Pods_Vendoo_VendooTests.framework */; }; A87525ED0EE7D42D9A7708D8 /* Pods_Vendoo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 23ECC3C8465826BD6AC74A02 /* Pods_Vendoo.framework */; }; + B6FD38131D70EB27008FB41E /* AmazonWebServiceManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6FD38121D70EB27008FB41E /* AmazonWebServiceManager.swift */; }; + B6FD38151D71CF3E008FB41E /* FeedType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6FD38141D71CF3E008FB41E /* FeedType.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -108,6 +110,8 @@ 3EFB0E321D0B968300A05D7A /* SideMenuView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SideMenuView.swift; sourceTree = ""; }; 7D1FC6F6278B48A7BA9A9E03 /* Pods_Vendoo_VendooUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Vendoo_VendooUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A44ED233D6B5454EF92FEB08 /* Pods-Vendoo-VendooUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Vendoo-VendooUITests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Vendoo-VendooUITests/Pods-Vendoo-VendooUITests.debug.xcconfig"; sourceTree = ""; }; + B6FD38121D70EB27008FB41E /* AmazonWebServiceManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AmazonWebServiceManager.swift; sourceTree = ""; }; + B6FD38141D71CF3E008FB41E /* FeedType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedType.swift; sourceTree = ""; }; B876489113F498AF1D2FD7E9 /* Pods_Vendoo_VendooTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Vendoo_VendooTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; E16BF843456476262BD075A1 /* Pods-Vendoo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Vendoo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Vendoo/Pods-Vendoo.debug.xcconfig"; sourceTree = ""; }; E25BEE3F146F38C121B72346 /* Pods-Vendoo-VendooTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Vendoo-VendooTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Vendoo-VendooTests/Pods-Vendoo-VendooTests.debug.xcconfig"; sourceTree = ""; }; @@ -169,6 +173,7 @@ 3E4897CE1D0062860069F742 /* Services */ = { isa = PBXGroup; children = ( + B676704A1D6FB9EA0014C99F /* AmazonServices */, 3EA668941D026E2A00EE57A8 /* EbayServices */, 3E4897CF1D00629B0069F742 /* FirebaseServices */, 3E7CF3FF1CF6363200F486B2 /* EtsyServices */, @@ -332,6 +337,15 @@ name = Menu; sourceTree = ""; }; + B676704A1D6FB9EA0014C99F /* AmazonServices */ = { + isa = PBXGroup; + children = ( + B6FD38121D70EB27008FB41E /* AmazonWebServiceManager.swift */, + B6FD38141D71CF3E008FB41E /* FeedType.swift */, + ); + name = AmazonServices; + sourceTree = ""; + }; D989DD70699180D9DB9DA709 /* Frameworks */ = { isa = PBXGroup; children = ( @@ -747,11 +761,13 @@ 3EC3251E1CF734C100626C48 /* NetworksTableViewController.swift in Sources */, 3EC325201CF7C3AB00626C48 /* NetworkTableViewCell.swift in Sources */, 3EC325261CF7E90000626C48 /* FacebookGraphAPIManager.swift in Sources */, + B6FD38131D70EB27008FB41E /* AmazonWebServiceManager.swift in Sources */, 3E7CF3FC1CF5FE9400F486B2 /* RecoverPasswordViewController.swift in Sources */, 3E1DC3CF1D42328C0091BC60 /* CategoryCell.swift in Sources */, 3EC325111CF703A600626C48 /* ItemCell.swift in Sources */, 3EA668A11D02836C00EE57A8 /* EbayWebServiceManager.swift in Sources */, 3ECEDB871CF9C722003566B3 /* ListingPreviewViewController.swift in Sources */, + B6FD38151D71CF3E008FB41E /* FeedType.swift in Sources */, 3E1B1F0B1D2493EE00DBCF08 /* EtsySettingsViewController.swift in Sources */, 3EC325231CF7DA5500626C48 /* HomeViewController.swift in Sources */, 3EC3252D1CF894C400626C48 /* ItemImagePickerViewController.swift in Sources */, diff --git a/Vendoo/.DS_Store b/Vendoo/.DS_Store index 8d98363..10bee23 100644 Binary files a/Vendoo/.DS_Store and b/Vendoo/.DS_Store differ diff --git a/Vendoo/AmazonWebServiceManager.swift b/Vendoo/AmazonWebServiceManager.swift new file mode 100644 index 0000000..6ac4053 --- /dev/null +++ b/Vendoo/AmazonWebServiceManager.swift @@ -0,0 +1,82 @@ +// +// AmazonWebServiceManager.swift +// Vendoo +// +// Created by cole alban on 8/26/16. +// Copyright © 2016 Okechi Onyeje. All rights reserved. +// + +import Foundation + + +/* + This class will manage the posting of items to Amazon using the MWS + (MarketPlaceWebServicesAPI). + */ +class AmazonWebServiceManager{ + + /* + These values all correspond to authentication information + */ + private var sellerId: String + private var marketPlaceId: String + private var awsAccessKeyId: String + private var secretKey: String + private var developerAccountNumber: String + + /* + These values are currently hardcoded in and map to the Kroleo + seller account. Once authnetication for amazon is solved, these + will be able to dynamically update to the respective user information + Usually, this will take in parameters with the right info for init. + */ + init(){ + self.sellerId = "A2RZVRHXWN051E" + self.marketPlaceId = "A2RZVRHXWN051E" + self.awsAccessKeyId = "AKIAJL6QFNV3AHMJMBRA" + self.secretKey = "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" + self.developerAccountNumber = "6187-7922-4188" + } + + /* + This function will take an item and post it to amazon. + params: Hash of information used to post an item to amazon + */ + func listItem(params: [String: AnyObject]){ + let mwsApiEndpointUrl: NSURL = NSURL(fileURLWithPath: "https://mws.amazonservices.com") + let amazonMWSRequest: NSMutableURLRequest = NSMutableURLRequest(URL: mwsApiEndpointUrl) + setRequestHeaders(amazonMWSRequest, feedType: FeedType.POST_PRODUCT_DATA) + + } + + + /* + This helper function will set the headers for the posting a new item to mws + request: The request headers will be set for + feedType: The type of feed this request will be for + */ + private func setRequestHeaders(request: NSMutableURLRequest, feedType: FeedType ){ + request.HTTPMethod = "POST" + request.addValue("SubmitFeed", forHTTPHeaderField: "Action") + request.addValue(self.awsAccessKeyId, forHTTPHeaderField: "AWSAccessKeyId") + request.addValue(self.sellerId, forHTTPHeaderField: "Merchant") + request.addValue(getIso8601DateTimeString(), forHTTPHeaderField: "Timestamp") + request.addValue("2009-01-01", forHTTPHeaderField: "Version") + request.addValue(feedType.rawValue, forHTTPHeaderField: "FeedType") + request.addValue("HmacSHA256", forHTTPHeaderField: "SignatureMethod") + request.addValue("2", forHTTPHeaderField: "SignatureVersion") + } + + /* + This helper function will return an iso8601 formatted datetime string + return: an iso8601 formatted datetime string + */ + private func getIso8601DateTimeString()->String{ + let dateFormatter: NSDateFormatter = NSDateFormatter() + dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" + dateFormatter.timeZone = NSTimeZone(forSecondsFromGMT: 0) + dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX") + return dateFormatter.stringFromDate(NSDate()) + } + +} diff --git a/Vendoo/EbayWebServiceManager.swift b/Vendoo/EbayWebServiceManager.swift index 59d8111..8cf9463 100644 --- a/Vendoo/EbayWebServiceManager.swift +++ b/Vendoo/EbayWebServiceManager.swift @@ -13,6 +13,10 @@ protocol EbayWebServiceManagerDelegate { func signInUser(string: String!) } + +/* + This class will manage the API requests for Ebay + */ class EbayWebServiceManager: NSObject { @@ -103,7 +107,12 @@ class EbayWebServiceManager: NSObject { //MARK: - authentication methods extension EbayWebServiceManager { - private func requestMaker(soapMessage: String!, theRequest: NSMutableURLRequest!) { + /* + This function will take in a mutable request and modify it for the given request. + soapMessage: The xml body to be placed in the request + theRequest: The request to be modified + */ + private func requestMaker(soapMessage: String!, theRequest: NSMutableURLRequest!){ let msgLength = soapMessage.characters.count theRequest.addValue("text/xml", forHTTPHeaderField: "Content-Type") theRequest.addValue(String(msgLength), forHTTPHeaderField: "Content-Length") @@ -123,12 +132,19 @@ extension EbayWebServiceManager { } } + + /* + This function will authorize ebay for this application. + It creates a soapMessage that will serve as the body + for an http request that will fire to the ebay API + to get a session ID. + */ func authorizeApp(){ let soapMessage = "" + - "" + - "Kroleo-Kroleo-Vendoo-S-ktqeobkk" + - "" + "" + + "Kroleo-Kroleo-Vendoo-S-ktqeobkk" + + "" let url = NSURL(string: self.baseURL) let theRequest = NSMutableURLRequest(URL: url!) diff --git a/Vendoo/FeedType.swift b/Vendoo/FeedType.swift new file mode 100644 index 0000000..00a3b57 --- /dev/null +++ b/Vendoo/FeedType.swift @@ -0,0 +1,28 @@ +// +// FeedType.swift +// Vendoo +// +// Created by cole alban on 8/27/16. +// Copyright © 2016 Okechi Onyeje. All rights reserved. +// + +import Foundation + + +enum FeedType: String{ + case POST_PRODUCT_DATA = "_POST_PRODUCT_DATA_" + case POST_INVENTORY_AVAILABILITY_DATA = "_POST_INVENTORY_AVAILABILITY_DATA_" + case POST_PRODUCT_OVERRIDES_DATA = "_POST_PRODUCT_OVERRIDES_DATA_" + case POST_PRODUCT_PRICING_DATA = "_POST_PRODUCT_PRICING_DATA_" + case POST_PRODUCT_IMAGE_DATA = "_POST_PRODUCT_IMAGE_DATA_" + case POST_PRODUCT_RELATIONSHIP_DATA = "_POST_PRODUCT_RELATIONSHIP_DATA_" + case POST_FLAT_FILE_INVLOADER_DATA = "_POST_FLAT_FILE_INVLOADER_DATA_" + case POST_FLAT_FILE_LISTINGS_DATA = "_POST_FLAT_FILE_LISTINGS_DATA_" + case POST_FLAT_FILE_BOOKLOADER_DATA = "_POST_FLAT_FILE_BOOKLOADER_DATA_" + case POST_FLAT_FILE_CONVERGENCE_LISTINGS_DATA = "_POST_FLAT_FILE_CONVERGENCE_LISTINGS_DATA_" + case POST_FLAT_FILE_PRICEANDQUANTITYONLY_UPDATE_DATA = "_POST_FLAT_FILE_PRICEANDQUANTITYONLY_UPDATE_DATA_" + case POST_UIEE_BOOKLOADER_DATA = " _POST_UIEE_BOOKLOADER_DATA_" + case POST_STD_ACES_DATA = "_POST_STD_ACES_DATA_" + + +} \ No newline at end of file diff --git a/Vendoo/ListingPreviewViewController.swift b/Vendoo/ListingPreviewViewController.swift index a402872..f922768 100644 --- a/Vendoo/ListingPreviewViewController.swift +++ b/Vendoo/ListingPreviewViewController.swift @@ -33,6 +33,7 @@ class ListingPreviewViewController: UIViewController { private var firManager: FirebaseManager! = nil private var ebayManager: EbayWebServiceManager! = nil private var etsyManager: EtsyRESTAPIManager! = nil + private var amazonManager: AmazonWebServiceManager! = nil private var itemListingDictionary: Dictionary! = Dictionary() private var alert = UIAlertController(title: "Listing Published", message: "Your listing has been published", preferredStyle: .Alert) private var lastListingKey: String! @@ -60,8 +61,6 @@ class ListingPreviewViewController: UIViewController { } func setListing(){ - - self.itemPicture.image = (self.itemListingDictionary["pictures"] as? [UIImageView])![0].image self.itemTitle.text = self.itemListingDictionary["title"] as! String self.itemDescription.text = self.itemListingDictionary["description"] as! String @@ -272,7 +271,13 @@ extension ListingPreviewViewController { //post to amazon if(self.networksDictionary["amazon"]!){ - + var listingParameters: [String: AnyObject] = [ + "title": self.itemTitle.text, + "quantity": self.itemQuantity.text, + "price": self.self.itemPrice.text, + "photo": self.itemPicture.image! + ] + self.amazonManager.listItem(listingParameters) } diff --git a/Vendoo/Main.storyboard b/Vendoo/Main.storyboard index 98bbf3b..5601300 100755 --- a/Vendoo/Main.storyboard +++ b/Vendoo/Main.storyboard @@ -470,7 +470,7 @@ - + @@ -505,7 +505,7 @@ - + @@ -540,7 +540,7 @@ - + @@ -575,7 +575,7 @@ - + @@ -610,7 +610,7 @@ - +