mirror of
https://bitbucket.org/vendoo/vendoo_v1.0.git
synced 2025-12-25 11:47:40 +00:00
Merged branch Seller-Networks-Settings into master
This commit is contained in:
commit
ecb43d0355
Binary file not shown.
@ -24,14 +24,15 @@ 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!
|
||||||
private var apiSecret: String!
|
private var apiSecret: String!
|
||||||
private var userEmail:String = (NSUserDefaults.standardUserDefaults().objectForKey("email") as? String)!
|
private var userEmail:String = (NSUserDefaults.standardUserDefaults().objectForKey("email") as? String)!
|
||||||
var isAuthorized: Bool = NSUserDefaults.standardUserDefaults().boolForKey("etsyAuthorized")
|
var isAuthorized: Bool = NSUserDefaults.standardUserDefaults().boolForKey("etsyAuthorized")
|
||||||
|
static var settingsDictionary = Dictionary<String , AnyObject>()
|
||||||
//---------------------------------------------//
|
//---------------------------------------------//
|
||||||
|
|
||||||
//User specific class variables
|
//User specific class variables
|
||||||
@ -53,7 +54,7 @@ class EtsyRESTAPIManager: NSObject {
|
|||||||
"responseType": "token"])
|
"responseType": "token"])
|
||||||
|
|
||||||
|
|
||||||
//something is wrong when here when logging back in with a diff user
|
//something is wrong when here when logging back in with a diff user
|
||||||
if(self.isAuthorized){
|
if(self.isAuthorized){
|
||||||
let dictionary = Locksmith.loadDataForUserAccount(self.userEmail, inService: "vendoo_oauth_etsy")
|
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!>
|
||||||
@ -64,6 +65,22 @@ class EtsyRESTAPIManager: NSObject {
|
|||||||
|
|
||||||
/*scope=listings_w%20listings_r%20listings_d%20transactions_r%20transactions_w"*/
|
/*scope=listings_w%20listings_r%20listings_d%20transactions_r%20transactions_w"*/
|
||||||
|
|
||||||
|
if(NSUserDefaults.standardUserDefaults().boolForKey("etsyDefaultsOverriden")) {
|
||||||
|
|
||||||
|
EtsyRESTAPIManager.settingsDictionary = (NSUserDefaults.standardUserDefaults().objectForKey("etsySettings") as? Dictionary<String, AnyObject>)!
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
|
||||||
|
EtsyRESTAPIManager.settingsDictionary = ([
|
||||||
|
"who_made":"i_did",
|
||||||
|
"is_supply":"true",
|
||||||
|
"when_made":"made_to_order"
|
||||||
|
] as Dictionary<String, AnyObject>)
|
||||||
|
|
||||||
|
NSUserDefaults.standardUserDefaults().setObject(EtsyRESTAPIManager.settingsDictionary, forKey: "etsySettings")
|
||||||
|
|
||||||
|
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "etsyDefaultsOverriden")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -86,176 +103,183 @@ extension EtsyRESTAPIManager {
|
|||||||
|
|
||||||
oauthswift!.authorize_url_handler = SafariURLHandler(viewController: viewcontroller)
|
oauthswift!.authorize_url_handler = SafariURLHandler(viewController: viewcontroller)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
let authRequest = self.oauthswift.client.makeRequest("https://openapi.etsy.com/v2/oauth/request_token?", method: OAuthSwiftHTTPRequest.Method.GET, parameters: ["scope":"listings_w%20listings_r%20listings_d%20transactions_r%20transactions_w"] , headers: nil)
|
let authRequest = self.oauthswift.client.makeRequest("https://openapi.etsy.com/v2/oauth/request_token?", method: OAuthSwiftHTTPRequest.Method.GET, parameters: ["scope":"listings_w%20listings_r%20listings_d%20transactions_r%20transactions_w"] , headers: nil)
|
||||||
|
|
||||||
do{
|
do{
|
||||||
|
|
||||||
try authRequest?.makeRequest()
|
try authRequest?.makeRequest()
|
||||||
|
|
||||||
|
|
||||||
}catch{
|
}catch{
|
||||||
(error)
|
(error)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*["scope":"listings_w%20listings_r%20listings_d%20transactions_r%20transactions_w"]*/
|
/*["scope":"listings_w%20listings_r%20listings_d%20transactions_r%20transactions_w"]*/
|
||||||
self.oauthswift!.client.get("https://openapi.etsy.com/v2/oauth/request_token?scope=listings_w%20listings_r%20listings_d%20transactions_r%20transactions_w",
|
self.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(response.allHeaderFields)
|
|
||||||
//print(dataSting)
|
|
||||||
let json = JSON(data)
|
|
||||||
print(json)
|
|
||||||
print(dataString)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
|
||||||
boolResult = false
|
|
||||||
|
|
||||||
|
|
||||||
}, failure: { error in
|
|
||||||
//print(error)
|
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), {() -> Void in
|
|
||||||
print(self.oauthswift!.client.credential.oauth_token)
|
|
||||||
print(self.oauthswift!.client.credential.oauth_token_secret)
|
|
||||||
print(self.oauthswift.client.credential.oauth_verifier)
|
|
||||||
print(self.oauthswift.allowMissingOauthVerifier = true)
|
|
||||||
//save data to keychain
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.oauthswift!.client.get("https://openapi.etsy.com/v2/oauth/access_token", parameters: ["oauth_verifier":(self.oauthswift.client.credential.oauth_verifier)],
|
|
||||||
success: {
|
success: {
|
||||||
data, response in
|
data, response in
|
||||||
|
|
||||||
let dataString = NSString(data: data, encoding: NSUTF8StringEncoding)
|
let dataString = NSString(data: data, encoding: NSUTF8StringEncoding)
|
||||||
|
|
||||||
|
|
||||||
print(response)
|
|
||||||
let json1 = JSON(response)
|
|
||||||
print(json1)
|
|
||||||
//print(response.allHeaderFields)
|
//print(response.allHeaderFields)
|
||||||
//print(dataSting)
|
//print(dataSting)
|
||||||
let json = JSON(data)
|
let json = JSON(data)
|
||||||
print(json)
|
print(json)
|
||||||
print(dataString!)
|
print(dataString)
|
||||||
|
|
||||||
//parse out token and token secret
|
|
||||||
do {
|
|
||||||
let regex = try NSRegularExpression(pattern: "[oauth_token=|oauth_token_secret=](\\w*)", options: [])
|
|
||||||
let nsString = dataString! as NSString
|
|
||||||
let all = NSRange(location: 0, length: nsString.length)
|
|
||||||
var matches : [String] = [String]()
|
|
||||||
|
|
||||||
regex.enumerateMatchesInString(nsString as String, options: NSMatchingOptions(rawValue: 0), range: all) {
|
|
||||||
(result : NSTextCheckingResult?, _, _) in
|
|
||||||
if let r = result {
|
|
||||||
let result = nsString.substringWithRange(r.range) as String
|
|
||||||
matches.append(result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print(matches)
|
|
||||||
|
|
||||||
|
|
||||||
let oauth: Dictionary<String, AnyObject!>? = [ "token" : String(matches[1].characters.dropFirst()) , "secret" : String(matches[3].characters.dropFirst()) ]
|
|
||||||
|
|
||||||
do{
|
|
||||||
try Locksmith.saveData(["etsy_oauth" : oauth!], forUserAccount: self.userEmail, inService: "vendoo_oauth_etsy")
|
|
||||||
print("account credentials saved")
|
|
||||||
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "etsyAuthorized")
|
|
||||||
self.isAuthorized = true
|
|
||||||
boolResult = true
|
|
||||||
|
|
||||||
self.oauthswift.client.credential.oauth_token = oauth!["token"]! as! String
|
|
||||||
self.oauthswift.client.credential.oauth_token_secret = oauth!["secret"]! as! String
|
|
||||||
|
|
||||||
self.oauthswift!.client.get("https://openapi.etsy.com/v2/oauth/scopes",
|
|
||||||
success: {
|
|
||||||
data, response in
|
|
||||||
let dataString = NSString(data: data, encoding: NSUTF8StringEncoding)
|
|
||||||
let json1 = JSON(dataString!)
|
|
||||||
print(json1)
|
|
||||||
print(dataString)
|
|
||||||
boolResult = true
|
|
||||||
}
|
|
||||||
, failure: { error in
|
|
||||||
print(error)
|
|
||||||
boolResult = true
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
catch{
|
|
||||||
(error)
|
|
||||||
print(error)
|
|
||||||
//could not save data to keychain
|
|
||||||
print("account credentials could not be saved")
|
|
||||||
boolResult = false
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*let results = regex.matchesInString(dataString! as String,
|
|
||||||
options: [], range: NSMakeRange(0, nsString.length))
|
|
||||||
print(results.map { nsString.substringWithRange($0.range)})*/
|
|
||||||
} catch let error as NSError {
|
|
||||||
print("invalid regex: \(error.localizedDescription)")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
},
|
self.oauthswift!.authorizeWithCallbackURL( NSURL(string: "vendoo://oauth-callback/etsy")!, success: {
|
||||||
failure: {
|
credential, response, parameters in
|
||||||
error in
|
print(credential.oauth_token)
|
||||||
print(error)
|
print(credential.oauth_token_secret)
|
||||||
})
|
|
||||||
|
print(response)
|
||||||
|
boolResult = false
|
||||||
//return boolResult
|
|
||||||
|
|
||||||
})
|
}, failure: { error in
|
||||||
})
|
//print(error)
|
||||||
|
|
||||||
//getting error here when trying to retrieve the login url from the response
|
dispatch_async(dispatch_get_main_queue(), {() -> Void in
|
||||||
//var dataDictionary = self.convertStringToDictionary(dataString! as String)
|
print(self.oauthswift!.client.credential.oauth_token)
|
||||||
//print(dataDictionary!["login_url"])
|
print(self.oauthswift!.client.credential.oauth_token_secret)
|
||||||
}
|
print(self.oauthswift.client.credential.oauth_verifier)
|
||||||
, failure: { error in
|
print(self.oauthswift.allowMissingOauthVerifier = true)
|
||||||
print(error)
|
//save data to keychain
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
self.oauthswift!.client.get("https://openapi.etsy.com/v2/oauth/access_token", parameters: ["oauth_verifier":(self.oauthswift.client.credential.oauth_verifier)],
|
||||||
|
success: {
|
||||||
|
data, response in
|
||||||
|
let dataString = NSString(data: data, encoding: NSUTF8StringEncoding)
|
||||||
|
|
||||||
|
|
||||||
|
print(response)
|
||||||
|
let json1 = JSON(response)
|
||||||
|
print(json1)
|
||||||
|
//print(response.allHeaderFields)
|
||||||
|
//print(dataSting)
|
||||||
|
let json = JSON(data)
|
||||||
|
print(json)
|
||||||
|
print(dataString!)
|
||||||
|
|
||||||
|
//parse out token and token secret
|
||||||
|
do {
|
||||||
|
let regex = try NSRegularExpression(pattern: "[oauth_token=|oauth_token_secret=](\\w*)", options: [])
|
||||||
|
let nsString = dataString! as NSString
|
||||||
|
let all = NSRange(location: 0, length: nsString.length)
|
||||||
|
var matches : [String] = [String]()
|
||||||
|
|
||||||
|
regex.enumerateMatchesInString(nsString as String, options: NSMatchingOptions(rawValue: 0), range: all) {
|
||||||
|
(result : NSTextCheckingResult?, _, _) in
|
||||||
|
if let r = result {
|
||||||
|
let result = nsString.substringWithRange(r.range) as String
|
||||||
|
matches.append(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print(matches)
|
||||||
|
|
||||||
|
|
||||||
|
let oauth: Dictionary<String, AnyObject!>? = [ "token" : String(matches[1].characters.dropFirst()) , "secret" : String(matches[3].characters.dropFirst()) ]
|
||||||
|
|
||||||
|
do{
|
||||||
|
try Locksmith.saveData(["etsy_oauth" : oauth!], forUserAccount: self.userEmail, inService: "vendoo_oauth_etsy")
|
||||||
|
print("account credentials saved")
|
||||||
|
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "etsyAuthorized")
|
||||||
|
self.isAuthorized = true
|
||||||
|
boolResult = true
|
||||||
|
|
||||||
|
self.oauthswift.client.credential.oauth_token = oauth!["token"]! as! String
|
||||||
|
self.oauthswift.client.credential.oauth_token_secret = oauth!["secret"]! as! String
|
||||||
|
|
||||||
|
self.oauthswift!.client.get("https://openapi.etsy.com/v2/users/__SELF__",
|
||||||
|
success: {
|
||||||
|
data, response in
|
||||||
|
let dataString = NSString(data: data, encoding: NSUTF8StringEncoding)
|
||||||
|
let dict = self.convertStringToDictionary(dataString! as String)
|
||||||
|
print(dict)
|
||||||
|
var dict2 = (dict!["results"] as! [[String : AnyObject]])
|
||||||
|
let json1 = JSON(dataString!)
|
||||||
|
print(json1)
|
||||||
|
print(dataString)
|
||||||
|
boolResult = true
|
||||||
|
print(dict2[0]["login_name"]!)
|
||||||
|
EtsyRESTAPIManager.settingsDictionary["userID"] = dict2[0]["login_name"]!
|
||||||
|
NSUserDefaults.standardUserDefaults().setObject(EtsyRESTAPIManager.settingsDictionary, forKey: "etsySettings")
|
||||||
|
|
||||||
|
}
|
||||||
|
, failure: { error in
|
||||||
|
print(error)
|
||||||
|
boolResult = true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
catch{
|
||||||
|
(error)
|
||||||
|
print(error)
|
||||||
|
//could not save data to keychain
|
||||||
|
print("account credentials could not be saved")
|
||||||
|
boolResult = false
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*let results = regex.matchesInString(dataString! as String,
|
||||||
|
options: [], range: NSMakeRange(0, nsString.length))
|
||||||
|
print(results.map { nsString.substringWithRange($0.range)})*/
|
||||||
|
} catch let error as NSError {
|
||||||
|
print("invalid regex: \(error.localizedDescription)")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
failure: {
|
||||||
|
error in
|
||||||
|
print(error)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
//return boolResult
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
//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)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//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")
|
||||||
self.isAuthorized = NSUserDefaults.standardUserDefaults().boolForKey("etsyAuthorized")
|
self.isAuthorized = NSUserDefaults.standardUserDefaults().boolForKey("etsyAuthorized")
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,84 +288,84 @@ extension EtsyRESTAPIManager {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
oauthswift!.authorize_url_handler = SafariURLHandler(viewController: viewcontroller)
|
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",
|
oauthswift!.client.get("https://openapi.etsy.com/v2/oauth/request_token?scope=listings_w%20listings_r%20listings_d%20transactions_r%20transactions_w",
|
||||||
success: {
|
success: {
|
||||||
data, response in
|
data, response in
|
||||||
let dataString = NSString(data: data, encoding: NSUTF8StringEncoding)
|
let dataString = NSString(data: data, encoding: NSUTF8StringEncoding)
|
||||||
print(dataString!)
|
print(dataString!)
|
||||||
print(response)
|
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)
|
//getting error here when trying to retrieve the login url from the response
|
||||||
("failed to delete credentails and deauthorize app")
|
//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")
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//MARK: - Request Methods
|
//MARK: - Request Methods
|
||||||
@ -420,7 +444,7 @@ extension EtsyRESTAPIManager {
|
|||||||
func convertStringToDictionary(text: String) -> [String:AnyObject]? {
|
func convertStringToDictionary(text: String) -> [String:AnyObject]? {
|
||||||
if let data = text.dataUsingEncoding(NSUTF8StringEncoding) {
|
if let data = text.dataUsingEncoding(NSUTF8StringEncoding) {
|
||||||
do {
|
do {
|
||||||
return try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments) as? [String:AnyObject]
|
return try NSJSONSerialization.JSONObjectWithData(data, options: []) as? [String:AnyObject]
|
||||||
} catch let error as NSError {
|
} catch let error as NSError {
|
||||||
print(error)
|
print(error)
|
||||||
}
|
}
|
||||||
@ -428,3 +452,4 @@ extension EtsyRESTAPIManager {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,29 +9,48 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class EtsySettingsViewController: UIViewController {
|
class EtsySettingsViewController: UIViewController {
|
||||||
|
var wereDefaultsChanged: Bool = NSUserDefaults.standardUserDefaults().boolForKey("etsyDefaultsOverriden")
|
||||||
|
|
||||||
|
@IBOutlet weak var userID: UILabel!
|
||||||
|
|
||||||
|
@IBOutlet weak var whoMadeBtn: UIButton!
|
||||||
|
|
||||||
|
@IBOutlet weak var isSupplierBtn: UIButton!
|
||||||
|
|
||||||
|
@IBOutlet weak var productAgeBtn: UIButton!
|
||||||
|
|
||||||
|
var etsyManager: EtsyRESTAPIManager!
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
// Do any additional setup after loading the view.
|
// Do any additional setup after loading the view.
|
||||||
|
if(wereDefaultsChanged) {
|
||||||
|
//change button labels to reflect user selected defaults
|
||||||
|
}
|
||||||
|
//dispatch_async(dispatch_get_main_queue(), {
|
||||||
|
print(EtsyRESTAPIManager.settingsDictionary["userID"] as? String)
|
||||||
|
self.userID.text = (EtsyRESTAPIManager.settingsDictionary["userID"] as! String)
|
||||||
|
|
||||||
|
//})
|
||||||
}
|
}
|
||||||
|
|
||||||
override func didReceiveMemoryWarning() {
|
override func didReceiveMemoryWarning() {
|
||||||
super.didReceiveMemoryWarning()
|
super.didReceiveMemoryWarning()
|
||||||
// Dispose of any resources that can be recreated.
|
// Dispose of any resources that can be recreated.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// MARK: - Navigation
|
// MARK: Navigation
|
||||||
|
|
||||||
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
||||||
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
||||||
// Get the new view controller using segue.destinationViewController.
|
// Get the new view controller using segue.destinationViewController.
|
||||||
// Pass the selected object to the new view controller.
|
// Pass the selected object to the new view controller.
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//MARK:- IBActions
|
//MARK:- IBActions
|
||||||
@ -43,4 +62,12 @@ extension EtsySettingsViewController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//MARK:- Class Methods
|
||||||
|
extension EtsySettingsViewController {
|
||||||
|
|
||||||
|
func loadManager (etsyManager: EtsyRESTAPIManager) {
|
||||||
|
self.etsyManager = etsyManager
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -111,6 +111,9 @@ extension NetworksTableViewController {
|
|||||||
(segue.destinationViewController as! ListingPreviewViewController).setManagers(self.graphManager, fireManager: self.firManager, ebayManager: self.ebayManager)
|
(segue.destinationViewController as! ListingPreviewViewController).setManagers(self.graphManager, fireManager: self.firManager, ebayManager: self.ebayManager)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if(segue.identifier == "EtsySettingsSegue") {
|
||||||
|
(segue.destinationViewController as! EtsySettingsViewController).loadManager(self.etsyManager)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user