EtsySwift is built on top of RxAlamofire for your iOS projects written in Swift 4.2. for easy API connection with Etsy.
- Add
pod 'EtsySwift'
to your Podfile - Run
pod install
- Add
import EtsySwift
wherever you want to use the library
To setup the library, you need to pass your consumer key and consumer secret keys.
Never leave your confidential keys in your repository - use any form of obfuscation or cryptography to keep your data safe.
class API {
let shared = API()
let etsy: EtsySwift
init() {
etsy = EtsySwift(consumerKey: "CONSUMER_KEY", consumerSecret: "CONSUMER_SECRET")
}
}
After that you need to login, passing your required scope, as defined in Etsy API.
API.shared.etsy.login(["email_r"], callback: "etsyintegration://oauth-callback")
The second argument you pass is the callback URL that will be triggered after user will log in - Etsy uses oAuth authorization - the library will open a Safari window for you. You need to register your custom scheme in your application and pass it there.
Additionally, you need to add following method to your AppDelegate
:
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool {
API.shared.etsy.callbackCalled(url: url)
return true
}
After you authorize with the login method, you can easilly call any method from Etsy API that you have access to. I've also added a handy Rx extension for decoding the response from the API.
For now, the API only supports resources that I needed to use for my project (such as shops listing, products listing and getting images for products), but you can use the request(method:url:)
method to request any resource you might need.
Let me know if you will need any other resources to be added to the library or submit a pull request.
API.shared.etsy.request(.shops("__SELF__")).decodedAs(EtsyResponse<EtsyShop>.self)
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Add your changes
- Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
MIT