-
-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
504 changed files
with
37,473 additions
and
35,043 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# How To Contribute # | ||
|
||
First of all, I'd like to express my appreciation to you for contributing to this project. | ||
|
||
## Working Branch ## | ||
|
||
You should make changes on `develop` branch, changes will be merged into `master` branch after a stable version released. | ||
You should make changes on the `maintenance` branch, changes will be merged into `master` branch after a stable version released. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.mariotaku.yandex | ||
|
||
import org.mariotaku.restfu.annotation.method.POST | ||
import org.mariotaku.restfu.annotation.param.Query | ||
import org.mariotaku.yandex.model.YandexTranslateResult | ||
|
||
interface YandexAPI { | ||
@POST("/api/v1.5/tr.json/translate") | ||
fun search(@Query("text") text: String, | ||
@Query("lang") lang: String): YandexTranslateResult | ||
} |
50 changes: 50 additions & 0 deletions
50
twidere/src/main/java/org/mariotaku/yandex/YandexAPIFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.mariotaku.yandex | ||
|
||
import org.mariotaku.restfu.RestAPIFactory | ||
import org.mariotaku.restfu.RestConverter | ||
import org.mariotaku.restfu.RestMethod | ||
import org.mariotaku.restfu.RestRequest | ||
import org.mariotaku.restfu.http.Endpoint | ||
import org.mariotaku.restfu.http.RestHttpClient | ||
import org.mariotaku.restfu.http.ValueMap | ||
import org.mariotaku.restfu.logansqaure.LoganSquareConverterFactory | ||
|
||
|
||
class YandexAPIFactory(apiKey: String, endpoint: String) { | ||
private val factory: RestAPIFactory<YandexException> = RestAPIFactory<YandexException>() | ||
|
||
init { | ||
factory.setEndpoint(Endpoint(endpoint)) | ||
factory.setExceptionFactory { cause, request, response -> | ||
cause?.let { YandexException(it) } | ||
?: YandexException() | ||
} | ||
factory.setRestConverterFactory(LoganSquareConverterFactory()) | ||
factory.setRestRequestFactory(object : RestRequest.DefaultFactory<YandexException?>() { | ||
override fun create(restMethod: RestMethod<YandexException?>, | ||
factory: RestConverter.Factory<YandexException?>, valuePool: ValueMap?): RestRequest { | ||
val method = restMethod.method | ||
val path = restMethod.path | ||
val headers = restMethod.getHeaders(valuePool) | ||
val queries = restMethod.getQueries(valuePool) | ||
val params = restMethod.getParams(factory, valuePool) | ||
val rawValue = restMethod.rawValue | ||
val bodyType = restMethod.bodyType | ||
val extras = restMethod.extras | ||
queries.add("key", apiKey) | ||
return RestRequest(method.value, method.allowBody, path, headers, queries, | ||
params, rawValue, bodyType, extras) | ||
} | ||
}) | ||
} | ||
|
||
fun setHttpClient(restClient: RestHttpClient): YandexAPIFactory { | ||
factory.setHttpClient(restClient) | ||
return this | ||
} | ||
|
||
fun build(): YandexAPI { | ||
return factory.build(YandexAPI::class.java) | ||
} | ||
} | ||
|
8 changes: 8 additions & 0 deletions
8
twidere/src/main/java/org/mariotaku/yandex/YandexException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.mariotaku.yandex | ||
|
||
class YandexException : Exception { | ||
constructor() : super() | ||
constructor(message: String?) : super(message) | ||
constructor(message: String?, cause: Throwable?) : super(message, cause) | ||
constructor(cause: Throwable?) : super(cause) | ||
} |
14 changes: 14 additions & 0 deletions
14
twidere/src/main/java/org/mariotaku/yandex/model/YandexTranslateResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.mariotaku.yandex.model | ||
|
||
import com.bluelinelabs.logansquare.annotation.JsonField | ||
import com.bluelinelabs.logansquare.annotation.JsonObject | ||
|
||
@JsonObject | ||
data class YandexTranslateResult( | ||
@JsonField(name = ["code"]) | ||
var code: Int? = null, | ||
@JsonField(name = ["lang"]) | ||
var lang: String? = null, | ||
@JsonField(name = ["text"]) | ||
var text: List<String>? = null | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.