diff --git a/.DS_Store b/.DS_Store index e0b4cb5..9df5c91 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Podfile b/Podfile index 6d08844..2d3e320 100644 --- a/Podfile +++ b/Podfile @@ -29,8 +29,7 @@ use_frameworks! pod 'TYMActivityIndicatorView' pod 'BSImagePicker', '~> 2.3' pod 'SWRevealViewController' -# pod 'CommonCrypto' - #'~> 1.1' + pod 'CommonCrypto' target 'VendooTests' do # inherit! :search_paths diff --git a/Vendoo.xcodeproj/project.pbxproj b/Vendoo.xcodeproj/project.pbxproj index 1d67ccb..26cc8f7 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 */; }; + B63CF2871D73CCBF005EA054 /* AmazonRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B63CF2861D73CCBF005EA054 /* AmazonRequest.swift */; }; + B63CF2891D75335A005EA054 /* feedSubmissionTemplate.xml in Resources */ = {isa = PBXBuildFile; fileRef = B63CF2881D75335A005EA054 /* feedSubmissionTemplate.xml */; }; 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 */; }; @@ -111,6 +113,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 = ""; }; + 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 = ""; }; 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 = ""; }; @@ -345,6 +349,8 @@ B6FD38121D70EB27008FB41E /* AmazonWebServiceManager.swift */, B6FD38141D71CF3E008FB41E /* FeedType.swift */, B6FD38161D720540008FB41E /* QuerySigner.swift */, + B63CF2861D73CCBF005EA054 /* AmazonRequest.swift */, + B63CF2881D75335A005EA054 /* feedSubmissionTemplate.xml */, ); name = AmazonServices; sourceTree = ""; @@ -488,6 +494,7 @@ 3E7CF3FE1CF5FF8200F486B2 /* GoogleService-Info.plist in Resources */, 3E1AA4301D0D9B3F005FCCBB /* Main.storyboard in Resources */, 3E6CC3601CF2A94B00E00A70 /* Assets.xcassets in Resources */, + B63CF2891D75335A005EA054 /* feedSubmissionTemplate.xml in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -764,6 +771,7 @@ B6FD38171D720540008FB41E /* QuerySigner.swift in Sources */, 3EC3251E1CF734C100626C48 /* NetworksTableViewController.swift in Sources */, 3EC325201CF7C3AB00626C48 /* NetworkTableViewCell.swift in Sources */, + B63CF2871D73CCBF005EA054 /* AmazonRequest.swift in Sources */, 3EC325261CF7E90000626C48 /* FacebookGraphAPIManager.swift in Sources */, B6FD38131D70EB27008FB41E /* AmazonWebServiceManager.swift in Sources */, 3E7CF3FC1CF5FE9400F486B2 /* RecoverPasswordViewController.swift in Sources */, @@ -837,6 +845,7 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_LINK_OBJC_RUNTIME = NO; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; @@ -887,6 +896,7 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_LINK_OBJC_RUNTIME = NO; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; diff --git a/Vendoo/AmazonRequest.swift b/Vendoo/AmazonRequest.swift new file mode 100644 index 0000000..526fd4f --- /dev/null +++ b/Vendoo/AmazonRequest.swift @@ -0,0 +1,69 @@ +// +// AmazonRequest.swift +// Vendoo +// +// Created by cole alban on 8/28/16. +// Copyright © 2016 Okechi Onyeje. All rights reserved. +// + +import Foundation + + +/* + This class will represent a request to the Amazon MWS API. + It will contain methods for creating headers, getting the + headers back as a queryString(used to sign the request), and + metadata regarding the transaction. + */ +class AmazonRequest{ + + + /* + 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 + */ + func setRequestHeaders(request: NSMutableURLRequest, feedType: FeedType ){ + request.HTTPMethod = "POST" + request.addValue("text/xml", forHTTPHeaderField: "Content-Type") + 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 + */ + 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()) + } + + + /* + This will return a properly formatted header in string form + Note: This is before the query is signed. + */ + func getRequestHeaderAsString(request: NSMutableURLRequest)->String{ + var queryString: String = "POST\nmws.amazonservices.com\n\\"+ + queryString += "AwsAccessKeyId="+request.valueForHTTPHeaderField("AwsAccessKeyId") + queryString += "&Action="+request.valueForHTTPHeaderField("Action") + queryString += "&FeedType="+request.valueForHTTPHeaderField("FeedType") + queryString += "&SellerId="+request.valueForHTTPHeaderField("SellerId") + queryString += "&SignatureMethod="+request.valueForHTTPHeaderField("SignatureMethod") + queryString += "&SignatureVersion="+request.valueForHTTPHeaderField("SignatureVersion") + queryString += "&Timestamp="+request.valueForHTTPHeaderField("Timestamp") + queryString += "&Version="+request.valueForHTTPHeaderField("Version") + return queryString + } + +} diff --git a/Vendoo/AmazonWebServiceManager.swift b/Vendoo/AmazonWebServiceManager.swift index 6ac4053..1798d11 100644 --- a/Vendoo/AmazonWebServiceManager.swift +++ b/Vendoo/AmazonWebServiceManager.swift @@ -23,6 +23,7 @@ class AmazonWebServiceManager{ private var awsAccessKeyId: String private var secretKey: String private var developerAccountNumber: String + private var mwsApiEndpoint: String /* These values are currently hardcoded in and map to the Kroleo @@ -36,6 +37,7 @@ class AmazonWebServiceManager{ self.awsAccessKeyId = "AKIAJL6QFNV3AHMJMBRA" self.secretKey = "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" self.developerAccountNumber = "6187-7922-4188" + self.mwsApiEndpoint = "https://mws.amazonservices.com" } /* @@ -43,40 +45,12 @@ class AmazonWebServiceManager{ 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) + let mwsApiEndpointUrl = NSURL(fileURLWithPath: mwsApiEndpointUrl) + let amazonMWSRequest = 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/FeedType.swift b/Vendoo/FeedType.swift index 00a3b57..ab6e2b7 100644 --- a/Vendoo/FeedType.swift +++ b/Vendoo/FeedType.swift @@ -19,10 +19,12 @@ enum FeedType: String{ 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_" + case POST_FLAT_FILE_CONVERGENCE_LISTINGS_DATA = "_POST_FLAT_FILE_CONVERGENCE"+ + "_LISTINGS_DATA_" + case POST_FLAT_FILE_PRICEANDQUANTITYONLY_UPDATE_DATA = "_POST_FLAT_FILE_PRIC"+ + "EANDQUANTITYONLY_UPDATE_DATA_" } \ No newline at end of file diff --git a/Vendoo/feedSubmissionTemplate.xml b/Vendoo/feedSubmissionTemplate.xml new file mode 100644 index 0000000..0c7fe63 --- /dev/null +++ b/Vendoo/feedSubmissionTemplate.xml @@ -0,0 +1,42 @@ + + +
+ 1.01 + M_EXAMPLE_123456 +
+ Product + false + + 1 + Update + + 56789 + + ASIN + B0EXAMPLEG + + A_GEN_NOTAX + + Example Product Title + Example Product Brand + This is an example product description. + Example Bullet Point 1 + Example Bullet Point 2 + 25.19 + Example Product Manufacturer + example-item-type + + + + + + Example Ingredients + Example Directions + + + + + + +
\ No newline at end of file