diff --git a/.DS_Store b/.DS_Store index 9df5c91..1dc1c82 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Vendoo.xcodeproj/project.pbxproj b/Vendoo.xcodeproj/project.pbxproj index 26cc8f7..354cc99 100644 --- a/Vendoo.xcodeproj/project.pbxproj +++ b/Vendoo.xcodeproj/project.pbxproj @@ -45,6 +45,8 @@ A87525ED0EE7D42D9A7708D8 /* Pods_Vendoo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 23ECC3C8465826BD6AC74A02 /* Pods_Vendoo.framework */; }; B63CF2871D73CCBF005EA054 /* AmazonRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B63CF2861D73CCBF005EA054 /* AmazonRequest.swift */; }; B63CF2891D75335A005EA054 /* feedSubmissionTemplate.xml in Resources */ = {isa = PBXBuildFile; fileRef = B63CF2881D75335A005EA054 /* feedSubmissionTemplate.xml */; }; + B63CF28B1D7539B2005EA054 /* AmazonXmlBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = B63CF28A1D7539B2005EA054 /* AmazonXmlBody.swift */; }; + B63CF28D1D753A6E005EA054 /* AmazonListing.swift in Sources */ = {isa = PBXBuildFile; fileRef = B63CF28C1D753A6E005EA054 /* AmazonListing.swift */; }; B6FD38131D70EB27008FB41E /* AmazonWebServiceManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6FD38121D70EB27008FB41E /* AmazonWebServiceManager.swift */; }; B6FD38151D71CF3E008FB41E /* FeedType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6FD38141D71CF3E008FB41E /* FeedType.swift */; }; B6FD38171D720540008FB41E /* QuerySigner.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6FD38161D720540008FB41E /* QuerySigner.swift */; }; @@ -115,6 +117,8 @@ 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 = ""; }; B63CF2861D73CCBF005EA054 /* AmazonRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AmazonRequest.swift; sourceTree = ""; }; B63CF2881D75335A005EA054 /* feedSubmissionTemplate.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = feedSubmissionTemplate.xml; sourceTree = ""; }; + B63CF28A1D7539B2005EA054 /* AmazonXmlBody.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AmazonXmlBody.swift; sourceTree = ""; }; + B63CF28C1D753A6E005EA054 /* AmazonListing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AmazonListing.swift; 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 = ""; }; B6FD38161D720540008FB41E /* QuerySigner.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuerySigner.swift; sourceTree = ""; }; @@ -351,6 +355,8 @@ B6FD38161D720540008FB41E /* QuerySigner.swift */, B63CF2861D73CCBF005EA054 /* AmazonRequest.swift */, B63CF2881D75335A005EA054 /* feedSubmissionTemplate.xml */, + B63CF28A1D7539B2005EA054 /* AmazonXmlBody.swift */, + B63CF28C1D753A6E005EA054 /* AmazonListing.swift */, ); name = AmazonServices; sourceTree = ""; @@ -780,7 +786,9 @@ 3EA668A11D02836C00EE57A8 /* EbayWebServiceManager.swift in Sources */, 3ECEDB871CF9C722003566B3 /* ListingPreviewViewController.swift in Sources */, B6FD38151D71CF3E008FB41E /* FeedType.swift in Sources */, + B63CF28B1D7539B2005EA054 /* AmazonXmlBody.swift in Sources */, 3E1B1F0B1D2493EE00DBCF08 /* EtsySettingsViewController.swift in Sources */, + B63CF28D1D753A6E005EA054 /* AmazonListing.swift in Sources */, 3EC325231CF7DA5500626C48 /* HomeViewController.swift in Sources */, 3EC3252D1CF894C400626C48 /* ItemImagePickerViewController.swift in Sources */, 3E1DC3CD1D4232490091BC60 /* CategoriesTableViewController.swift in Sources */, diff --git a/Vendoo/AmazonListing.swift b/Vendoo/AmazonListing.swift new file mode 100644 index 0000000..2725338 --- /dev/null +++ b/Vendoo/AmazonListing.swift @@ -0,0 +1,32 @@ +// +// AmazonListing.swift +// Vendoo +// +// Created by cole alban on 8/29/16. +// Copyright © 2016 Okechi Onyeje. All rights reserved. +// + +/* + This class will represent a single listing being posted to Amazon + */ +import Foundation + + +class AmazonListing{ + + private var price: Int + private var title: String + private var quantity: Int + private var description: String + + + //Initalizer, require a price, title, quantity, and description + init(price: Int, title: String, quantity: Int, description: String){ + self.price = price + self.title = title + self.quantity = quantity + self.description = description + } + + +} \ No newline at end of file diff --git a/Vendoo/AmazonRequest.swift b/Vendoo/AmazonRequest.swift index 526fd4f..7269750 100644 --- a/Vendoo/AmazonRequest.swift +++ b/Vendoo/AmazonRequest.swift @@ -17,6 +17,19 @@ import Foundation */ class AmazonRequest{ + private var listing: AmazonListing + private var xmlBody: AmazonXmlBody + + + /* + This constructor will create a request with the given listing and then + construct the xml body with the given listing. + listing: The listing to create the request from + */ + init(listing: AmazonListing){ + self.listing = listing + self.xmlBody = AmazonXmlBody(listing) + } /* This helper function will set the headers for the posting a new item to mws @@ -36,6 +49,16 @@ class AmazonRequest{ request.addValue("2", forHTTPHeaderField: "SignatureVersion") } + /* + This will set the body of the request to be the xml body + that was created in the constructor. + If the xml body is "Error" then nothing will be done as there was an + error in the parsing of the body upon creation + */ + func setRequestBody(){ + if(self.xmlBody) + } + /* This helper function will return an iso8601 formatted datetime string return: an iso8601 formatted datetime string diff --git a/Vendoo/AmazonXmlBody.swift b/Vendoo/AmazonXmlBody.swift new file mode 100644 index 0000000..eb83ff2 --- /dev/null +++ b/Vendoo/AmazonXmlBody.swift @@ -0,0 +1,76 @@ +// +// AmazonXmlBody.swift +// Vendoo +// +// Created by cole alban on 8/29/16. +// Copyright © 2016 Okechi Onyeje. All rights reserved. +// + +import Foundation + +/* + This class will represent the xml body of an xml feed for Amazon + */ +class AmazonXmlBody{ + + private var listing: AmazonListing + private var xmlString: String + + //Init will take in a listing and parse it into the xml string + init(listing: AmazonListing){ + self.listing = listing + self.xmlString = parseListing(self.listing) + } + + + /* + This helper function will take in a listing and insert the pertinent + information into the respective locations. + listing: The listing to parse into the xml string + return: The xml string with all pertinent order information + */ + private func parseListing(listing: AmazonListing)->String{ + var xmlTemplate = getXmlTemplate() + xmlTemplate.replace("{{target}}", replacement: self.listing.title) + xmlTemplate.replace("{{description}}", replacement: self.listing.description) + xmlTemplate.replace("{{price}}", replacement: self.listing.title) + return xmlTemplate + } + + /* + This function will get the initial XML template + return: String representing the xml template + */ + private func getXmlTemplate()->String{ + var xmlString: String + let manager = NSFileManager.defaultManager() + let path = manager.currentDirectoryPath+"/feedSubmissionTemplate.xml" + do{ + xmlString = try{ + NSString(contentsOfURL: path, encoding: String.encoding.utf8.rawValue) as String + } + return xmlString + } + catch{ + return "Error" + } + } + + + +} + + +//A small extension to give string a replace function with persistence +extenstion String{ + + /* + Replaces target with replacement in the string instance. + Target: The string to replace + replacement: The new string to insert + return: the new string with the replaced snippet + */ + func replace(target: String, replacement: String)->String{ + self = self.stringByReplacingOccurrencesOfString(target, withString: replacement) + } +} \ No newline at end of file diff --git a/Vendoo/feedSubmissionTemplate.xml b/Vendoo/feedSubmissionTemplate.xml index 0c7fe63..c12f1a6 100644 --- a/Vendoo/feedSubmissionTemplate.xml +++ b/Vendoo/feedSubmissionTemplate.xml @@ -18,13 +18,13 @@ A_GEN_NOTAX - Example Product Title - Example Product Brand - This is an example product description. + {{title}} + Vendoo + {{description}} Example Bullet Point 1 Example Bullet Point 2 - 25.19 - Example Product Manufacturer + {{price}} + Kroleo example-item-type