mirror of
https://bitbucket.org/vendoo/vendoo_v1.0.git
synced 2025-12-25 11:47:40 +00:00
finished authorization portion of etsy integration, just need to do deauthorization and make the create new listing requests
This commit is contained in:
parent
0ab59c5d7b
commit
49c69c001b
Binary file not shown.
@ -90,11 +90,11 @@
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Vendoo/EtsyRESTAPIManager.swift"
|
||||
timestampString = "486467803.784775"
|
||||
timestampString = "486486828.045437"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "52"
|
||||
endingLineNumber = "52"
|
||||
startingLineNumber = "67"
|
||||
endingLineNumber = "67"
|
||||
landmarkName = "authorizeApp(_:)"
|
||||
landmarkType = "5">
|
||||
</BreakpointContent>
|
||||
@ -106,11 +106,11 @@
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Vendoo/EtsyRESTAPIManager.swift"
|
||||
timestampString = "486467838.042152"
|
||||
timestampString = "486489301.995309"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "66"
|
||||
endingLineNumber = "66"
|
||||
startingLineNumber = "145"
|
||||
endingLineNumber = "145"
|
||||
landmarkName = "authorizeApp(_:)"
|
||||
landmarkType = "5">
|
||||
</BreakpointContent>
|
||||
@ -122,59 +122,11 @@
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Vendoo/EtsyRESTAPIManager.swift"
|
||||
timestampString = "486468123.916868"
|
||||
timestampString = "486489301.995309"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "82"
|
||||
endingLineNumber = "82"
|
||||
landmarkName = "authorizeApp(_:)"
|
||||
landmarkType = "5">
|
||||
<Locations>
|
||||
<Location
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
symbolName = "Vendoo.EtsyRESTAPIManager.authorizeApp (__ObjC.UIViewController) -> ()"
|
||||
moduleName = "Vendoo"
|
||||
usesParentBreakpointCondition = "Yes"
|
||||
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/EtsyRESTAPIManager.swift"
|
||||
timestampString = "486468325.641074"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "82"
|
||||
endingLineNumber = "82"
|
||||
offsetFromSymbolStart = "1371">
|
||||
</Location>
|
||||
<Location
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
symbolName = "Vendoo.EtsyRESTAPIManager.(authorizeApp (__ObjC.UIViewController) -> ()).(closure #3)"
|
||||
moduleName = "Vendoo"
|
||||
usesParentBreakpointCondition = "Yes"
|
||||
urlString = "file:///Users/okechi/Documents/iOs%20Practice/Vendoo/Vendoo_bb/Vendoo/Vendoo/EtsyRESTAPIManager.swift"
|
||||
timestampString = "486468325.641241"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "84"
|
||||
endingLineNumber = "84"
|
||||
offsetFromSymbolStart = "23">
|
||||
</Location>
|
||||
</Locations>
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Vendoo/EtsyRESTAPIManager.swift"
|
||||
timestampString = "486468325.45733"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "86"
|
||||
endingLineNumber = "86"
|
||||
startingLineNumber = "147"
|
||||
endingLineNumber = "147"
|
||||
landmarkName = "authorizeApp(_:)"
|
||||
landmarkType = "5">
|
||||
</BreakpointContent>
|
||||
@ -186,11 +138,43 @@
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Vendoo/EtsyRESTAPIManager.swift"
|
||||
timestampString = "486468341.941555"
|
||||
timestampString = "486489480.473889"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "84"
|
||||
endingLineNumber = "84"
|
||||
startingLineNumber = "114"
|
||||
endingLineNumber = "114"
|
||||
landmarkName = "authorizeApp(_:)"
|
||||
landmarkType = "5">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Vendoo/EtsyRESTAPIManager.swift"
|
||||
timestampString = "486489493.707548"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "70"
|
||||
endingLineNumber = "70"
|
||||
landmarkName = "authorizeApp(_:)"
|
||||
landmarkType = "5">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Vendoo/EtsyRESTAPIManager.swift"
|
||||
timestampString = "486489552.994372"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "99"
|
||||
endingLineNumber = "99"
|
||||
landmarkName = "authorizeApp(_:)"
|
||||
landmarkType = "5">
|
||||
</BreakpointContent>
|
||||
|
||||
@ -11,24 +11,29 @@
|
||||
import Foundation
|
||||
import SwiftyJSON
|
||||
import OAuthSwift
|
||||
import Locksmith
|
||||
|
||||
typealias ServiceResponse = (JSON, NSError?) -> Void
|
||||
|
||||
|
||||
class EtsyRESTAPIManager: NSObject {
|
||||
|
||||
//API Manager class variables
|
||||
//----------------------------------------------//
|
||||
static let sharedInstance = EtsyRESTAPIManager()
|
||||
|
||||
let baseURL = "https://openapi.etsy.com/v2"
|
||||
let baseURL = "https://openapi.etsy.com/v2/private"
|
||||
|
||||
private var apiKey: String!
|
||||
private var apiSecret: String!
|
||||
private var userEmail:String = (NSUserDefaults.standardUserDefaults().objectForKey("email") as? String)!
|
||||
var isAuthorized: Bool = NSUserDefaults.standardUserDefaults().boolForKey("etsyAuthorized")
|
||||
//---------------------------------------------//
|
||||
|
||||
//User specific class variables
|
||||
private var etsyUser: String!
|
||||
private var oauth_token: String!
|
||||
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"])
|
||||
|
||||
override init(){
|
||||
@ -37,6 +42,16 @@ class EtsyRESTAPIManager: NSObject {
|
||||
|
||||
self.apiKey = ((dict["Etsy"] as! Dictionary<String, AnyObject>)["consumerKey"] as! String)
|
||||
self.apiSecret = ((dict["Etsy"] as! Dictionary<String, AnyObject>)["consumerSecret"] as! String)
|
||||
|
||||
if(self.isAuthorized){
|
||||
let dictionary = Locksmith.loadDataForUserAccount(self.userEmail)
|
||||
let oauthDictionary = dictionary?["etsy_oauth"] as? Dictionary<String, AnyObject!>
|
||||
self.oauth_token = oauthDictionary?["token"] as? String!
|
||||
self.oauth_secret = oauthDictionary?["secret"] as? String!
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -52,42 +67,84 @@ extension EtsyRESTAPIManager {
|
||||
func authorizeApp(viewcontroller: UIViewController){
|
||||
|
||||
|
||||
|
||||
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!.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
|
||||
oauthswift!.authorizeWithCallbackURL( NSURL(string: "vendoo://oauth-callback/etsy")!, success: {
|
||||
credential, response, parameters in
|
||||
print(credential.oauth_token)
|
||||
print(credential.oauth_token_secret)
|
||||
print(response)
|
||||
|
||||
|
||||
|
||||
}, failure: { error in
|
||||
print(error)
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), {() -> Void in
|
||||
print(oauthswift!.client.credential.oauth_token)
|
||||
print(oauthswift!.client.credential.oauth_token_secret)
|
||||
//save data to keychain
|
||||
let creds = oauthswift?.client.credential
|
||||
let oauth: Dictionary<String, AnyObject!>? = [ "token" : creds!.oauth_token, "secret" : creds!.oauth_token_secret ]
|
||||
do{
|
||||
try Locksmith.saveData(["etsy_oauth" : oauth!], forUserAccount: self.userEmail)
|
||||
print("account credentials saved")
|
||||
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "etsyAuthorized")
|
||||
self.isAuthorized = true
|
||||
}
|
||||
catch{
|
||||
(error)
|
||||
print(error)
|
||||
//could not save data to keychain
|
||||
print("account credentials could not be saved")
|
||||
|
||||
}
|
||||
oauthswift!.client.get(self.baseURL,
|
||||
success: {
|
||||
data, response in
|
||||
let dataString = NSString(data: data, encoding: NSUTF8StringEncoding)
|
||||
print(dataString)
|
||||
}
|
||||
, failure: { error in
|
||||
print(error)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
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",
|
||||
"authorizeUrl": "https://www.etsy.com/oauth/signin?",
|
||||
"accessTokenUrl": "https://openapi.etsy.com/v2/oauth/access_token?"])
|
||||
|
||||
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)
|
||||
}
|
||||
)
|
||||
|
||||
oauthswift!.authorizeWithCallbackURL( NSURL(string: "vendoo://oauth-callback/etsy")!, success: {
|
||||
credential, response, parameters in
|
||||
print(credential.oauth_token)
|
||||
print(credential.oauth_token_secret)
|
||||
print(response)
|
||||
}, failure: { error in
|
||||
print(error)
|
||||
})
|
||||
|
||||
|
||||
|
||||
//once everything is authorized save true value to the authorization boolean
|
||||
@ -98,6 +155,10 @@ extension EtsyRESTAPIManager {
|
||||
}
|
||||
|
||||
|
||||
func deAuthorizeApp(viewcontroller: UIViewController) -> Bool {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -56,6 +56,11 @@
|
||||
</array>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
|
||||
@ -396,13 +396,17 @@ extension NetworksTableViewController: UITableViewDelegate {
|
||||
|
||||
|
||||
//OAuthorization code for etsy
|
||||
if(cell.networkToggle.on == true){
|
||||
if(((self.tabBarController as? HomeViewController)?.fbGraphManager.isAuthorized)!){
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), { () -> Void in
|
||||
cell.networkToggle.setOn(false, animated: true)
|
||||
})
|
||||
|
||||
//code to deauthorize network
|
||||
let tabBar = self.tabBarController
|
||||
|
||||
let didSucceed:Bool = ((tabBar as? HomeViewController)?.etsyManager.deAuthorizeApp(self))!
|
||||
cell.networkToggle.on = !didSucceed
|
||||
}
|
||||
else{
|
||||
|
||||
@ -413,7 +417,7 @@ extension NetworksTableViewController: UITableViewDelegate {
|
||||
|
||||
|
||||
//this is the type of code desired to access the rest management classes
|
||||
|
||||
|
||||
let tabBar = self.tabBarController
|
||||
(tabBar as? HomeViewController)?.etsyManager.authorizeApp(self)
|
||||
|
||||
@ -433,6 +437,7 @@ extension NetworksTableViewController: UITableViewDelegate {
|
||||
//OAuthorization code for facebook
|
||||
if((self.tabBarController as? HomeViewController)?.fbGraphManager.isAuthorized)!{
|
||||
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), { () -> Void in
|
||||
cell.networkToggle.setOn(false, animated: true)
|
||||
})
|
||||
|
||||
@ -4,6 +4,10 @@
|
||||
<dict>
|
||||
<key>Etsy</key>
|
||||
<dict>
|
||||
<key>accessToken</key>
|
||||
<string></string>
|
||||
<key>accessSecret</key>
|
||||
<string></string>
|
||||
<key>consumerKey</key>
|
||||
<string>snbs78qkfy3yqq6yhe6yv49b</string>
|
||||
<key>consumerSecret</key>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user