Skip to content

Commit

Permalink
Merge pull request #499 from vimeo/release-2-prep
Browse files Browse the repository at this point in the history
Release 2.0.0 Preparation
  • Loading branch information
anthonycr authored Jul 27, 2021
2 parents 3e9520c + b8e7884 commit 72dbb96
Show file tree
Hide file tree
Showing 206 changed files with 1,749 additions and 3,326 deletions.
12 changes: 7 additions & 5 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
To [contribute](https://guides.github.com/activities/contributing-to-open-source/) to this project,
To [contribute](https://guides.github.com/activities/contributing-to-open-source/) to this project:

1. Fork the repo
2. Branch off of the default branch
3. Pull request back to the default branch
4. Lettuce know if you have questions along the way
1. Fork the repo.
2. Branch off of the default branch and make your changes.
3. Validate changes by running `gradle test` and ensure that there are no lint warnings by running `gradle detekt`.
4. Run `gradle detektFormat` to make sure the code is properly formatted.
5. Pull request back to the default branch, we'll review as soon as we can.
6. Let us know if you have questions along the way.
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#### Issue Summary
# Summary
A brief but thorough description of the issue.

#### Reproduction Steps
## Reproduction Steps
Detailed steps to reproduce the issue.

#### Expected Behavior
## Expected Behavior
What do you expect to happen as a result of the reproduction steps?

#### Actual Behavior
## Actual Behavior
What currently happens as a result of the reproduction steps?
11 changes: 5 additions & 6 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#### Issue
(If applicable)
- https://github.com/vimeo//vimeo-networking-java/issues/NUMBER
# Summary
A summary of the changes. If applicable, include a link to the issue that this closes.

#### Summary
## Description
A brief but thorough description of the changes.

#### How to Test
Detailed list of what to test and how to test it. Include all edge cases.
## How to Test
Detailed list of what to test and how to test it.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Change Log
==========

Version 2.0.0 *(2021-07-15)*
----------------------------
- Initial release!
15 changes: 8 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.3)
addressable (2.7.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
atomos (0.1.3)
babosa (1.0.4)
Expand All @@ -18,7 +18,7 @@ GEM
highline (~> 1.7.2)
cork (0.3.0)
colored2 (~> 3.1)
danger (8.2.3)
danger (8.3.1)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
colored2 (~> 3.1)
Expand All @@ -41,7 +41,7 @@ GEM
unf (>= 0.0.5, < 1.0.0)
dotenv (2.7.6)
emoji_regex (1.0.1)
excon (0.82.0)
excon (0.84.0)
faraday (0.17.4)
multipart-post (>= 1.2, < 3)
faraday-cookie_jar (0.0.7)
Expand Down Expand Up @@ -94,7 +94,7 @@ GEM
nokogiri
terminal-table
gh_inspector (1.1.3)
git (1.8.1)
git (1.9.1)
rchardet (~> 1.8)
google-api-client (0.23.9)
addressable (~> 2.5, >= 2.5.1)
Expand Down Expand Up @@ -135,7 +135,7 @@ GEM
memoist (0.16.2)
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2021.0225)
mime-types-data (3.2021.0704)
mini_magick (4.11.0)
mini_portile2 (2.5.3)
multi_json (1.15.0)
Expand All @@ -157,7 +157,7 @@ GEM
plist (3.6.0)
public_suffix (2.0.5)
racc (1.5.2)
rake (13.0.3)
rake (13.0.6)
rchardet (1.8.0)
representable (3.1.1)
declarative (< 0.1.0)
Expand Down Expand Up @@ -194,12 +194,13 @@ GEM
unf_ext (0.0.7.7)
unicode-display_width (1.7.0)
word_wrap (1.0.0)
xcodeproj (1.19.0)
xcodeproj (1.20.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)
rexml (~> 3.2.4)
xcpretty (0.3.0)
rouge (~> 2.0.7)
xcpretty-travis-formatter (1.0.1)
Expand Down
481 changes: 245 additions & 236 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object ApiConstants {
}

/**
* Parameters
* Parameters.
*/
object Parameters {
// Common parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,4 @@ sealed class VimeoResponse<out T>(open val httpStatusCode: Int) {

private const val NA = "N/A"
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.vimeo.networking2.config

import com.vimeo.networking2.Scopes
import okhttp3.Credentials

/**
* The authentication method that will be used to access the API.
*
* @param basicAuthHeader The authentication header that will be used when there is no available logged in account.
*/
sealed class AuthenticationMethod(val basicAuthHeader: String) {

/**
* A fixed access token that will be used to access the Vimeo API and disallows auth requests.
*
* @param accessToken The access token that will be used.
*/
class AccessToken(accessToken: String) : AuthenticationMethod("Bearer $accessToken")

/**
* The client credentials, including the identifier and secret, that will be used to authenticate with the API.
*
* @param clientId The Vimeo API client ID. Should be obtained from [https://developer.vimeo.com/apps].
* @param clientSecret The Vimeo API client secret. Should be obtained from [https://developer.vimeo.com/apps].
* @param scopes The permission scopes requested by the client.
*/
class ClientCredentials(
val clientId: String,
clientSecret: String,
val scopes: Scopes
) : AuthenticationMethod(Credentials.basic(clientId, clientSecret))
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,4 @@ class RetrofitServicesCache(private val retrofit: Retrofit) {
fun clear() {
cache.clear()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,19 @@ object RetrofitSetupModule {
.client(okHttpClient)
.addConverterFactory(VimeoParametersConverterFactory())
.addConverterFactory(MoshiConverterFactory.create(moshi))
.addCallAdapterFactory(ErrorHandlingCallAdapterFactory(VimeoLogger(
vimeoApiConfiguration.logDelegate,
vimeoApiConfiguration.logLevel
)))
.addCallAdapterFactory(
ErrorHandlingCallAdapterFactory(
VimeoLogger(
vimeoApiConfiguration.logDelegate,
vimeoApiConfiguration.logLevel
)
)
)
.build()

/**
* Creates a cache for storing Retrofit services.
*/
@JvmStatic
fun retrofitCache(retrofit: Retrofit) = RetrofitServicesCache(retrofit)

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import com.vimeo.networking2.ScopeType
import com.vimeo.networking2.Scopes
import com.vimeo.networking2.account.AccountStore
import com.vimeo.networking2.account.InMemoryAccountStore
import com.vimeo.networking2.logging.LogDelegate
import com.vimeo.networking2.logging.DefaultLogDelegate
import com.vimeo.networking2.logging.LogDelegate
import okhttp3.Cache
import okhttp3.Interceptor
import java.io.File
Expand All @@ -37,11 +37,8 @@ import java.util.Locale
* The configuration for the client.
*
* @param baseUrl The base API URL to which all requests will be made.
* @param clientId The Vimeo API ID of the client application. Should be obtained from
* [https://developer.vimeo.com/apps].
* @param clientSecret The Vimeo API secret of the client application. Should be obtained from
* [https://developer.vimeo.com/apps].
* @param scope The [Scopes] required by the client application.
* @param authenticationMethod The authentication method that will be used, either fixed authentication with an access
* token or authentication using client credentials.
* @param codeGrantRedirectUri The code grant redirect used for OAuth. This URL must be specified on the
* [https://developer.vimeo.com/apps] page in order for the API to accept it. This is the URL which the API will
* redirect back to.
Expand All @@ -66,9 +63,8 @@ import java.util.Locale
data class VimeoApiConfiguration(
val baseUrl: String,

val clientId: String,
val clientSecret: String,
val scope: Scopes,
val authenticationMethod: AuthenticationMethod,

val codeGrantRedirectUri: String,

val locales: List<Locale>,
Expand Down Expand Up @@ -98,18 +94,16 @@ data class VimeoApiConfiguration(
internal val cache: Cache? = cacheDirectory?.let { Cache(it, cacheMaxSizeBytes) }

/**
* The builder for the [VimeoApiConfiguration].
*
* @param clientId The Vimeo API client ID, required to construct an instance. Should be obtained from
* [https://developer.vimeo.com/apps].
* @param clientSecret The Vimeo API client secret, required to construct an instance. Should be obtained from
* [https://developer.vimeo.com/apps].
* @param scopes The permission scopes requested by the client, required to construct an instance.
* The builder for the [VimeoApiConfiguration], supports creation using the client credentials available to the
* consumer or with a fixed access token.
*/
class Builder(private val clientId: String, private val clientSecret: String, private val scopes: List<ScopeType>) {
class Builder {

private val authenticationMethod: AuthenticationMethod

private var baseUrl: String = ApiConstants.BASE_URL

private var codeGrantRedirectUrl: String = "vimeo$clientId://auth"
private var codeGrantRedirectUrl: String = "vimeo://auth"

private var locales: List<Locale> = listOf(Locale.US)

Expand All @@ -131,6 +125,28 @@ data class VimeoApiConfiguration(
private var cacheMaxSizeBytes: Long = DEFAULT_CACHE_SIZE
private var cacheMaxAgeSeconds: Int = DEFAULT_CACHE_MAX_AGE

/**
* @param clientId The Vimeo API client ID, required to construct an instance. Should be obtained from
* [https://developer.vimeo.com/apps].
* @param clientSecret The Vimeo API client secret, required to construct an instance. Should be obtained from
* [https://developer.vimeo.com/apps].
* @param scopes The permission scopes requested by the client, required to construct an instance.
*/
constructor(clientId: String, clientSecret: String, scopes: List<ScopeType>) {
authenticationMethod = AuthenticationMethod.ClientCredentials(
clientId,
clientSecret,
Scopes(scopes.also { require(it.isNotEmpty()) { "You must specify at least one scope" } })
)
}

/**
* @param accessToken The access token that should be used to make requests.
*/
constructor(accessToken: String) {
authenticationMethod = AuthenticationMethod.AccessToken(accessToken)
}

/**
* Specify a base URL. Defaults to [ApiConstants.BASE_URL].
*
Expand Down Expand Up @@ -244,9 +260,7 @@ data class VimeoApiConfiguration(
*/
fun build(): VimeoApiConfiguration = VimeoApiConfiguration(
baseUrl = baseUrl,
clientId = clientId,
clientSecret = clientSecret,
scope = Scopes(scopes.also { require(it.isNotEmpty()) { "You must specify at least one scope" } }),
authenticationMethod = authenticationMethod,
codeGrantRedirectUri = codeGrantRedirectUrl,
locales = locales,
accountStore = accountStore,
Expand Down Expand Up @@ -283,7 +297,5 @@ data class VimeoApiConfiguration(
* An unspecified user agent.
*/
const val DEFAULT_USER_AGENT = "UNSPECIFIED"

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
*/
package com.vimeo.networking2.internal

import com.vimeo.networking2.*
import com.vimeo.networking2.ApiConstants
import com.vimeo.networking2.ApiError
import com.vimeo.networking2.CancellableVimeoRequest
import com.vimeo.networking2.NoOpVimeoRequest
import com.vimeo.networking2.VimeoCallback
import com.vimeo.networking2.VimeoRequest
import com.vimeo.networking2.VimeoResponse
import com.vimeo.networking2.logging.VimeoLogger
import okhttp3.ResponseBody
import retrofit2.Call
Expand Down Expand Up @@ -61,11 +67,13 @@ internal class VimeoCallAdapter<T : Any>(
override fun onResponse(call: Call<T>, response: Response<T>) {
if (response.hasBody()) {
callbackExecutor.execute {
callback.onSuccess(VimeoResponse.Success(
requireNotNull(response.body()),
response.determineOrigin(),
response.code()
))
callback.onSuccess(
VimeoResponse.Success(
requireNotNull(response.body()),
response.determineOrigin(),
response.code()
)
)
}
} else {
val vimeoResponseError = response.parseErrorResponse(responseBodyConverter, vimeoLogger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
*/
package com.vimeo.networking2.internal

import com.vimeo.networking2.*
import com.vimeo.networking2.ApiConstants
import com.vimeo.networking2.ApiError
import com.vimeo.networking2.CancellableVimeoRequest
import com.vimeo.networking2.NoOpVimeoRequest
import com.vimeo.networking2.VimeoCallback
import com.vimeo.networking2.VimeoRequest
import com.vimeo.networking2.VimeoResponse
import com.vimeo.networking2.logging.VimeoLogger
import okhttp3.ResponseBody
import retrofit2.Call
Expand Down Expand Up @@ -57,11 +63,13 @@ internal class VimeoCallEmptyResponseAdapter(
override fun onResponse(call: Call<Unit>, response: Response<Unit>) {
if (response.isSuccessful) {
callbackExecutor.execute {
callback.onSuccess(VimeoResponse.Success(
Unit,
response.determineOrigin(),
response.code()
))
callback.onSuccess(
VimeoResponse.Success(
Unit,
response.determineOrigin(),
response.code()
)
)
}
} else {
val vimeoResponseError = response.parseErrorResponse(responseBodyConverter, vimeoLogger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ class HostValidationInterceptor(private val vimeoApiConfiguration: VimeoApiConfi

override fun intercept(chain: Interceptor.Chain): Response =
if (chain.request().url().host() != httpUrl?.host()) {
throw IOException("Host must match specified base URL, was ${chain.request().url().host()}, " +
"expected ${httpUrl?.host()}")
throw IOException(
"Host must match specified base URL, was ${chain.request().url().host()}, expected ${httpUrl?.host()}"
)
} else {
chain.proceed(chain.request())
}
Expand Down
Loading

0 comments on commit 72dbb96

Please sign in to comment.