Oauth complete for etsy, deauthorization complete as well, except need to put an alert that or make a webview that lets user deauthorize app from etsy

This commit is contained in:
Okechi Onyeje 2016-06-01 17:57:12 -04:00
parent 49c69c001b
commit a1a98f50b5
4 changed files with 503 additions and 53 deletions

View File

@ -74,13 +74,45 @@
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "Vendoo/NetworksTableViewController.swift" filePath = "Vendoo/NetworksTableViewController.swift"
timestampString = "486467691.902354" timestampString = "486495491.668853"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "399" startingLineNumber = "406"
endingLineNumber = "399" endingLineNumber = "406"
landmarkName = "tableView(_:didSelectRowAtIndexPath:)" landmarkName = "tableView(_:didSelectRowAtIndexPath:)"
landmarkType = "5"> landmarkType = "5">
<Locations>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.NetworksTableViewController.tableView (__ObjC.UITableView, didSelectRowAtIndexPath : __ObjC.NSIndexPath) -&gt; ()"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/NetworksTableViewController.swift"
timestampString = "486510693.893887"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "406"
endingLineNumber = "406"
offsetFromSymbolStart = "12701">
</Location>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.NetworksTableViewController.tableView (__ObjC.UITableView, didSelectRowAtIndexPath : __ObjC.NSIndexPath) -&gt; ()"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/NetworksTableViewController.swift"
timestampString = "486510693.893981"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "406"
endingLineNumber = "406"
offsetFromSymbolStart = "18866">
</Location>
</Locations>
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
<BreakpointProxy <BreakpointProxy
@ -90,11 +122,11 @@
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "Vendoo/EtsyRESTAPIManager.swift" filePath = "Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486486828.045437" timestampString = "486509277.070357"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "67" startingLineNumber = "72"
endingLineNumber = "67" endingLineNumber = "72"
landmarkName = "authorizeApp(_:)" landmarkName = "authorizeApp(_:)"
landmarkType = "5"> landmarkType = "5">
</BreakpointContent> </BreakpointContent>
@ -106,11 +138,11 @@
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "Vendoo/EtsyRESTAPIManager.swift" filePath = "Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486489301.995309" timestampString = "486509277.070357"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "145" startingLineNumber = "156"
endingLineNumber = "145" endingLineNumber = "156"
landmarkName = "authorizeApp(_:)" landmarkName = "authorizeApp(_:)"
landmarkType = "5"> landmarkType = "5">
</BreakpointContent> </BreakpointContent>
@ -122,11 +154,11 @@
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "Vendoo/EtsyRESTAPIManager.swift" filePath = "Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486489301.995309" timestampString = "486509277.070357"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "147" startingLineNumber = "158"
endingLineNumber = "147" endingLineNumber = "158"
landmarkName = "authorizeApp(_:)" landmarkName = "authorizeApp(_:)"
landmarkType = "5"> landmarkType = "5">
</BreakpointContent> </BreakpointContent>
@ -138,7 +170,199 @@
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "Vendoo/EtsyRESTAPIManager.swift" filePath = "Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486489480.473889" timestampString = "486509277.070357"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "119"
endingLineNumber = "119"
landmarkName = "authorizeApp(_:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486509277.070357"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "75"
endingLineNumber = "75"
landmarkName = "authorizeApp(_:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486509277.070357"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "104"
endingLineNumber = "104"
landmarkName = "authorizeApp(_:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486509277.070357"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "101"
endingLineNumber = "101"
landmarkName = "authorizeApp(_:)"
landmarkType = "5">
<Locations>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.EtsyRESTAPIManager.(authorizeApp (__ObjC.UIViewController) -&gt; ()).(closure #3)"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486510693.898319"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "102"
endingLineNumber = "102"
offsetFromSymbolStart = "26">
</Location>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.EtsyRESTAPIManager.(authorizeApp (__ObjC.UIViewController) -&gt; ()).(closure #3).(closure #1)"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486510693.898467"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "73"
endingLineNumber = "73"
offsetFromSymbolStart = "23">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486509277.070357"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "102"
endingLineNumber = "102"
landmarkName = "authorizeApp(_:)"
landmarkType = "5">
<Locations>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.EtsyRESTAPIManager.(authorizeApp (__ObjC.UIViewController) -&gt; ()).(closure #3)"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486510693.89948"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "102"
endingLineNumber = "102"
offsetFromSymbolStart = "26">
</Location>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.EtsyRESTAPIManager.(authorizeApp (__ObjC.UIViewController) -&gt; ()).(closure #3).(closure #1)"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486510693.899601"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "73"
endingLineNumber = "73"
offsetFromSymbolStart = "23">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486509277.070357"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "113"
endingLineNumber = "113"
landmarkName = "authorizeApp(_:)"
landmarkType = "5">
<Locations>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.EtsyRESTAPIManager.(authorizeApp (__ObjC.UIViewController) -&gt; ()).(closure #3).(closure #2)"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486510693.901579"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "113"
endingLineNumber = "113"
offsetFromSymbolStart = "236">
</Location>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.EtsyRESTAPIManager.(authorizeApp (__ObjC.UIViewController) -&gt; ()).(closure #3).(closure #2).(closure #1)"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486510693.902317"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "73"
endingLineNumber = "73"
offsetFromSymbolStart = "31">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486509277.070357"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "114" startingLineNumber = "114"
@ -154,11 +378,11 @@
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "Vendoo/EtsyRESTAPIManager.swift" filePath = "Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486489493.707548" timestampString = "486509277.070357"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "70" startingLineNumber = "129"
endingLineNumber = "70" endingLineNumber = "129"
landmarkName = "authorizeApp(_:)" landmarkName = "authorizeApp(_:)"
landmarkType = "5"> landmarkType = "5">
</BreakpointContent> </BreakpointContent>
@ -170,14 +394,142 @@
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "Vendoo/EtsyRESTAPIManager.swift" filePath = "Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486489552.994372" timestampString = "486509277.070357"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "99" startingLineNumber = "134"
endingLineNumber = "99" endingLineNumber = "134"
landmarkName = "authorizeApp(_:)" landmarkName = "authorizeApp(_:)"
landmarkType = "5"> landmarkType = "5">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/NetworksTableViewController.swift"
timestampString = "486507532.316351"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "150"
endingLineNumber = "150"
landmarkName = "tableView(_:cellForRowAtIndexPath:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486509277.070357"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "170"
endingLineNumber = "170"
landmarkName = "deAuthorizeApp(_:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/NetworksTableViewController.swift"
timestampString = "486507688.117657"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "416"
endingLineNumber = "416"
landmarkName = "tableView(_:didSelectRowAtIndexPath:)"
landmarkType = "5">
<Locations>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.NetworksTableViewController.tableView (__ObjC.UITableView, didSelectRowAtIndexPath : __ObjC.NSIndexPath) -&gt; ()"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/NetworksTableViewController.swift"
timestampString = "486510693.91126"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "416"
endingLineNumber = "416"
offsetFromSymbolStart = "13789">
</Location>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Vendoo.NetworksTableViewController.tableView (__ObjC.UITableView, didSelectRowAtIndexPath : __ObjC.NSIndexPath) -&gt; ()"
moduleName = "Vendoo"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/NetworksTableViewController.swift"
timestampString = "486510693.911432"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "416"
endingLineNumber = "416"
offsetFromSymbolStart = "18882">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486509320.432101"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "52"
endingLineNumber = "52"
landmarkName = "init()"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486510046.86719"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "227"
endingLineNumber = "227"
landmarkName = "deAuthorizeApp(_:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Vendoo/EtsyRESTAPIManager.swift"
timestampString = "486510055.419411"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "206"
endingLineNumber = "206"
landmarkName = "deAuthorizeApp(_:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints> </Breakpoints>
</Bucket> </Bucket>

View File

@ -22,6 +22,8 @@ class EtsyRESTAPIManager: NSObject {
//----------------------------------------------// //----------------------------------------------//
static let sharedInstance = EtsyRESTAPIManager() static let sharedInstance = EtsyRESTAPIManager()
let baseURL = "https://openapi.etsy.com/v2/private" let baseURL = "https://openapi.etsy.com/v2/private"
private var apiKey: String! private var apiKey: String!
@ -32,8 +34,7 @@ class EtsyRESTAPIManager: NSObject {
//User specific class variables //User specific class variables
private var etsyUser: String! private var etsyUser: String!
private var oauth_token: String! private var oauthswift: OAuth1Swift!
private var oauth_secret: String!
//private let oauthswift = OAuth1Swift(parameters: ["consumerKey":"snbs78qkfy3yqq6yhe6yv49b","consumerSecret":"4sbva4oqb6", "requestTokenUrl": "https://openapi.etsy.com/v2/oauth/request_token?scope=listings_w%20listings_r%20listings_d%20transactions_r%20transactions_w%20"]) //private let oauthswift = OAuth1Swift(parameters: ["consumerKey":"snbs78qkfy3yqq6yhe6yv49b","consumerSecret":"4sbva4oqb6", "requestTokenUrl": "https://openapi.etsy.com/v2/oauth/request_token?scope=listings_w%20listings_r%20listings_d%20transactions_r%20transactions_w%20"])
override init(){ override init(){
@ -42,12 +43,16 @@ class EtsyRESTAPIManager: NSObject {
self.apiKey = ((dict["Etsy"] as! Dictionary<String, AnyObject>)["consumerKey"] as! String) self.apiKey = ((dict["Etsy"] as! Dictionary<String, AnyObject>)["consumerKey"] as! String)
self.apiSecret = ((dict["Etsy"] as! Dictionary<String, AnyObject>)["consumerSecret"] as! String) self.apiSecret = ((dict["Etsy"] as! Dictionary<String, AnyObject>)["consumerSecret"] as! String)
oauthswift = OAuth1Swift(parameters: ["consumerKey":self.apiKey,"consumerSecret":self.apiSecret, "requestTokenUrl" : "https://openapi.etsy.com/v2/oauth/request_token?scope=listings_w%20listings_r%20listings_d%20transactions_r%20transactions_w",
"authorizeUrl": "https://www.etsy.com/oauth/signin?",
"accessTokenUrl": "https://openapi.etsy.com/v2/oauth/access_token?"])
if(self.isAuthorized){ if(self.isAuthorized){
let dictionary = Locksmith.loadDataForUserAccount(self.userEmail) let dictionary = Locksmith.loadDataForUserAccount(self.userEmail, inService: "vendoo_oauth_etsy")
let oauthDictionary = dictionary?["etsy_oauth"] as? Dictionary<String, AnyObject!> let oauthDictionary = dictionary?["etsy_oauth"] as? Dictionary<String, AnyObject!>
self.oauth_token = oauthDictionary?["token"] as? String! print((oauthDictionary?["token"] as? String!)!)
self.oauth_secret = oauthDictionary?["secret"] as? String! self.oauthswift.client.credential.oauth_token = (oauthDictionary?["token"] as? String!)!
self.oauthswift.client.credential.oauth_token_secret = (oauthDictionary?["secret"] as? String!)!
} }
@ -65,12 +70,10 @@ extension EtsyRESTAPIManager {
//makes application ready for use with users etsy account //makes application ready for use with users etsy account
func authorizeApp(viewcontroller: UIViewController){ func authorizeApp(viewcontroller: UIViewController){
var boolResult: Bool!
if(!isAuthorized){ if(!isAuthorized){
let oauthswift = OAuth1Swift(parameters: ["consumerKey":self.apiKey,"consumerSecret":self.apiSecret, "requestTokenUrl" : "https://openapi.etsy.com/v2/oauth/request_token?scope=listings_w%20listings_r%20listings_d%20transactions_r%20transactions_w",
"authorizeUrl": "https://www.etsy.com/oauth/signin?",
"accessTokenUrl": "https://openapi.etsy.com/v2/oauth/access_token?"])
oauthswift!.authorize_url_handler = SafariURLHandler(viewController: viewcontroller) oauthswift!.authorize_url_handler = SafariURLHandler(viewController: viewcontroller)
@ -94,47 +97,55 @@ extension EtsyRESTAPIManager {
) )
dispatch_async(dispatch_get_main_queue(), {() -> Void in dispatch_async(dispatch_get_main_queue(), {() -> Void in
oauthswift!.authorizeWithCallbackURL( NSURL(string: "vendoo://oauth-callback/etsy")!, success: {
self.oauthswift!.authorizeWithCallbackURL( NSURL(string: "vendoo://oauth-callback/etsy")!, success: {
credential, response, parameters in credential, response, parameters in
print(credential.oauth_token) print(credential.oauth_token)
print(credential.oauth_token_secret) print(credential.oauth_token_secret)
print(response) print(response)
boolResult = false
}, failure: { error in }, failure: { error in
print(error) print(error)
dispatch_async(dispatch_get_main_queue(), {() -> Void in dispatch_async(dispatch_get_main_queue(), {() -> Void in
print(oauthswift!.client.credential.oauth_token) print(self.oauthswift!.client.credential.oauth_token)
print(oauthswift!.client.credential.oauth_token_secret) print(self.oauthswift!.client.credential.oauth_token_secret)
//save data to keychain //save data to keychain
let creds = oauthswift?.client.credential let creds = self.oauthswift?.client.credential
let oauth: Dictionary<String, AnyObject!>? = [ "token" : creds!.oauth_token, "secret" : creds!.oauth_token_secret ] let oauth: Dictionary<String, AnyObject!>? = [ "token" : creds!.oauth_token, "secret" : creds!.oauth_token_secret ]
do{ do{
try Locksmith.saveData(["etsy_oauth" : oauth!], forUserAccount: self.userEmail) try Locksmith.saveData(["etsy_oauth" : oauth!], forUserAccount: self.userEmail, inService: "vendoo_oauth_etsy")
print("account credentials saved") print("account credentials saved")
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "etsyAuthorized") NSUserDefaults.standardUserDefaults().setBool(true, forKey: "etsyAuthorized")
self.isAuthorized = true self.isAuthorized = true
boolResult = true
self.oauthswift!.client.get("https://openapi.etsy.com/v2/oauth/scopes",
success: {
data, response in
let dataString = NSString(data: data, encoding: NSUTF8StringEncoding)
print(dataString)
boolResult = true
}
, failure: { error in
print(error)
boolResult = true
}
)
} }
catch{ catch{
(error) (error)
print(error) print(error)
//could not save data to keychain //could not save data to keychain
print("account credentials could not be saved") print("account credentials could not be saved")
boolResult = false
} }
oauthswift!.client.get(self.baseURL,
success: {
data, response in
let dataString = NSString(data: data, encoding: NSUTF8StringEncoding)
print(dataString)
}
, failure: { error in
print(error)
}
)
//return boolResult
}) })
}) })
@ -147,6 +158,7 @@ extension EtsyRESTAPIManager {
//once everything is authorized save true value to the authorization boolean //once everything is authorized save true value to the authorization boolean
/* /*
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "etsyAuthorized") NSUserDefaults.standardUserDefaults().setBool(true, forKey: "etsyAuthorized")
@ -155,13 +167,90 @@ extension EtsyRESTAPIManager {
} }
func deAuthorizeApp(viewcontroller: UIViewController) -> Bool { func deAuthorizeApp(viewcontroller: UIViewController){
oauthswift!.authorize_url_handler = SafariURLHandler(viewController: viewcontroller)
oauthswift!.client.get("https://openapi.etsy.com/v2/oauth/request_token?scope=listings_w%20listings_r%20listings_d%20transactions_r%20transactions_w",
success: {
data, response in
let dataString = NSString(data: data, encoding: NSUTF8StringEncoding)
print(dataString!)
print(response)
//getting error here when trying to retrieve the login url from the response
//var dataDictionary = self.convertStringToDictionary(dataString! as String)
//print(dataDictionary!["login_url"])
}
, failure: { error in
print(error)
}
)
dispatch_async(dispatch_get_main_queue(), {() -> Void in
self.oauthswift!.authorizeWithCallbackURL( NSURL(string: "vendoo://oauth-callback/etsy")!, success: {
credential, response, parameters in
print(credential.oauth_token)
print(credential.oauth_token_secret)
print(response)
//erase all authorization variables
do {
try Locksmith.deleteDataForUserAccount(self.userEmail, inService: "vendoo_oauth_etsy")
self.oauthswift.client.credential.oauth_token = ""
self.oauthswift.client.credential.oauth_token_secret = ""
NSUserDefaults.standardUserDefaults().setBool(false, forKey: "etsyAuthorized")
self.isAuthorized = false
print("oauth credentials deleted and app deauthorized from etsy")
}catch{
(error)
print(error)
("failed to delete credentails and deauthorize app")
}
}, failure: { error in
print(error)
dispatch_async(dispatch_get_main_queue(), {() -> Void in
//erase all authorization variables
do {
try Locksmith.deleteDataForUserAccount(self.userEmail, inService: "vendoo_oauth_etsy")
self.oauthswift.client.credential.oauth_token = ""
self.oauthswift.client.credential.oauth_token_secret = ""
NSUserDefaults.standardUserDefaults().setBool(false, forKey: "etsyAuthorized")
self.isAuthorized = false
print("oauth credentials deleted and app deauthorized from etsy")
}catch{
(error)
print(error)
("failed to delete credentails and deauthorize app")
}
})
})
})
return true
} }
} }
//MARK: - Request Methods //MARK: - Request Methods
extension EtsyRESTAPIManager { extension EtsyRESTAPIManager {

View File

@ -27,6 +27,7 @@ class NetworksTableViewController: UIViewController {
private var networksDictionary: Dictionary<String, Bool> = ["ebay":false, "amazon":false,"etsy":false,"facebook":false] private var networksDictionary: Dictionary<String, Bool> = ["ebay":false, "amazon":false,"etsy":false,"facebook":false]
private var itemListingDictionary: Dictionary<String, AnyObject>! = Dictionary<String, AnyObject>() private var itemListingDictionary: Dictionary<String, AnyObject>! = Dictionary<String, AnyObject>()
private var graphManager: FacebookGraphAPIManager! = nil private var graphManager: FacebookGraphAPIManager! = nil
private var etsyManager: EtsyRESTAPIManager! = nil
@ -149,13 +150,19 @@ extension NetworksTableViewController: UITableViewDataSource {
case 2: case 2:
//loads network cell for etsy //loads network cell for etsy
cell = (self.tableView.dequeueReusableCellWithIdentifier("etsy", forIndexPath: indexPath) as! EtsyTableViewCell) cell = (self.tableView.dequeueReusableCellWithIdentifier("etsy", forIndexPath: indexPath) as! EtsyTableViewCell)
let tabBar = self.tabBarController
if(((tabBar as? HomeViewController)?.etsyManager.isAuthorized)!){
(cell as! EtsyTableViewCell).networkToggle.setOn(true, animated: false)
}
break break
default: default:
//loads network cell for facebook //loads network cell for facebook
cell = (self.tableView.dequeueReusableCellWithIdentifier("facebook", forIndexPath: indexPath) as! FBTableViewCell) cell = (self.tableView.dequeueReusableCellWithIdentifier("facebook", forIndexPath: indexPath) as! FBTableViewCell)
let tabBar = self.tabBarController let tabBar = self.tabBarController
if((tabBar as? HomeViewController)?.fbGraphManager.isAuthorized == true){ if(((tabBar as? HomeViewController)?.fbGraphManager.isAuthorized)!){
(cell as! FBTableViewCell).networkToggle.setOn(true, animated: false) (cell as! FBTableViewCell).networkToggle.setOn(true, animated: false)
} }
@ -396,7 +403,7 @@ extension NetworksTableViewController: UITableViewDelegate {
//OAuthorization code for etsy //OAuthorization code for etsy
if(((self.tabBarController as? HomeViewController)?.fbGraphManager.isAuthorized)!){ if(((self.tabBarController as? HomeViewController)?.etsyManager.isAuthorized)!){
dispatch_async(dispatch_get_main_queue(), { () -> Void in dispatch_async(dispatch_get_main_queue(), { () -> Void in
cell.networkToggle.setOn(false, animated: true) cell.networkToggle.setOn(false, animated: true)
@ -405,8 +412,8 @@ extension NetworksTableViewController: UITableViewDelegate {
//code to deauthorize network //code to deauthorize network
let tabBar = self.tabBarController let tabBar = self.tabBarController
let didSucceed:Bool = ((tabBar as? HomeViewController)?.etsyManager.deAuthorizeApp(self))! ((tabBar as? HomeViewController)?.etsyManager.deAuthorizeApp(self))!
cell.networkToggle.on = !didSucceed cell.networkToggle.on = ((tabBar as? HomeViewController)?.etsyManager.isAuthorized)!
} }
else{ else{
@ -418,8 +425,10 @@ extension NetworksTableViewController: UITableViewDelegate {
//this is the type of code desired to access the rest management classes //this is the type of code desired to access the rest management classes
let tabBar = self.tabBarController let tabBar = self.tabBarController
(tabBar as? HomeViewController)?.etsyManager.authorizeApp(self) ((tabBar as? HomeViewController)?.etsyManager.authorizeApp(self))!
cell.networkToggle.on = ((tabBar as? HomeViewController)?.etsyManager.isAuthorized)!
//self.etsyManager.authorizeApp(self) //self.etsyManager.authorizeApp(self)