Simple iOS Framework for Qiita API written in Swift.
Currently, Swiita supports some way to installation shown below:
- Carthage
- Swift Package Manager
First, go Register the application - Qiita to regist your Application.
In "Callback URL", set the custom URL scheme for launching your application.(e.g. swiita-testapplication)
(If you aren't set custom URL scheme yet on your project, add it in Info.plist
)
To authenticate account, you need to add it in SceneDelegate.swift
:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
Swiita.handleCallback(URLContexts: URLContexts, callBack: URL(string: "{Callback URL}")!)
}
Then add this to the part that performs the authenticate function.
swiita.authorize(presentViewController: self, authority: [.read], success: { (token) in
// access token
print(token)
}) { (error) in
// Error handling
}
In "authority", you can set access tokens authority.
It only accepts value of type QiitaAPIAuthority
.
To initialize instance, you need those params.
- clientid: Qiita APIs application client ID.
- clientsecret: Qiita APIs application client secret key.
- token(Optional): Access token(if you generated beforehand, you can set it.)
/// Generate Instance.
/// - Parameters:
/// - clientid: Qiita API client ID
/// - clientsecret: Qiita API client secret
/// - apihost: Qiita API hostname
/// - token: Access token string
Swiita(clientid: "{client id}", clientsecret: "{client secret}", apihost: "{api host}", token: "{access token}")
NOTE: about parameter apihost
:
Using Qiita API as general user, you don't have to set it.
But if you use it as Qiita Team, you need set this parameter to {team name}.qiita.com
.
Qiita Team APIs authentication needs other API endpoint. It may be supported, but it's currently unavailable.
Being finished api requests without any errors, the callback function success(HTTPStatusType, JSONObject)
will be performed.
HTTPStatusType
is enum which has response type of API request(e.g. Successful).
JSONObject
is parsed JSON object from API response.
Some Qiita API accepts parameter "page" and "per_page".
and those responses header includes informations about paging, but currently version can't check this value.
Now, this framework doesn't support "Qiita Team"s APIs.
(Not belonging any qiita team, so I can't implement and debug those.)