Skip to content

Commit

Permalink
Implement Cinemax API key provider (#16)
Browse files Browse the repository at this point in the history
* Add core-data module

* Add core-data:data-remote module

* Implement CinemaxApiKeyProvider

* Add tests for CinemaxApiKeyProvider

* Integrate Cinemax API key in build.gradle.kts

* Integrate Cinemax API key in Cinemax CI

* Add DataModule

* Add provider for CinemaxApiKeyProvider in DataModule
  • Loading branch information
AfigAliyev committed Aug 11, 2022
1 parent d1af694 commit 218918d
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .github/workflows/cinemax-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
needs: validation
name: Analyze code
runs-on: ubuntu-latest
env:
CINEMAX_API_KEY: ${{ secrets.CINEMAX_API_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -36,6 +38,8 @@ jobs:
needs: analyze-code
name: Tests
runs-on: ubuntu-latest
env:
CINEMAX_API_KEY: ${{ secrets.CINEMAX_API_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -51,6 +55,8 @@ jobs:
needs: tests
name: Build debug
runs-on: ubuntu-latest
env:
CINEMAX_API_KEY: ${{ secrets.CINEMAX_API_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -66,6 +72,8 @@ jobs:
needs: tests
name: Build release
runs-on: ubuntu-latest
env:
CINEMAX_API_KEY: ${{ secrets.CINEMAX_API_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
17 changes: 17 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,23 @@
* limitations under the License.
*/

import java.util.Properties

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.kapt)
alias(libs.plugins.dagger.hilt.android)
}

val localProperties = Properties()
val localPropertiesFile = File(rootDir, "local.properties")
if (localPropertiesFile.exists() && localPropertiesFile.isFile) {
localPropertiesFile.inputStream().use { input ->
localProperties.load(input)
}
}

android {
compileSdk = libs.versions.android.compileSdk.get().toInt()

Expand All @@ -35,6 +45,11 @@ android {
vectorDrawables {
useSupportLibrary = true
}

val cinemaxApiKey = checkNotNull(
localProperties.getProperty("cinemax.apikey") ?: System.getenv("CINEMAX_API_KEY")
)
buildConfigField("String", "CINEMAX_API_KEY", "\"$cinemaxApiKey\"")
}

buildTypes {
Expand Down Expand Up @@ -72,6 +87,8 @@ android {
}

dependencies {
implementation(project(":core:core-data"))
implementation(project(":core:core-data:data-remote"))
implementation(project(":core:core-presentation"))

implementation(libs.dagger.hilt.android)
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/kotlin/com/maximillianleonov/cinemax/di/DataModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2022 Maximillian Leonov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.maximillianleonov.cinemax.di

import com.maximillianleonov.cinemax.BuildConfig
import com.maximillianleonov.cinemax.core.data.remote.api.CinemaxApiKeyProvider
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

@[Module InstallIn(SingletonComponent::class)]
object DataModule {
@Provides
fun provideCinemaxApiKeyProvider() = object : CinemaxApiKeyProvider {
override val apiKey: String = BuildConfig.CINEMAX_API_KEY
}
}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.kapt) apply false
alias(libs.plugins.dagger.hilt.android) apply false
alias(libs.plugins.spotless)
Expand Down
1 change: 1 addition & 0 deletions core/core-data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
25 changes: 25 additions & 0 deletions core/core-data/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2022 Maximillian Leonov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
alias(libs.plugins.kotlin.jvm)
id(libs.plugins.java.library.get().pluginId)
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
1 change: 1 addition & 0 deletions core/core-data/data-remote/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
31 changes: 31 additions & 0 deletions core/core-data/data-remote/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2022 Maximillian Leonov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
alias(libs.plugins.kotlin.jvm)
id(libs.plugins.java.library.get().pluginId)
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

dependencies {
api(project(":core:core-data"))

testImplementation(libs.bundles.test)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2022 Maximillian Leonov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.maximillianleonov.cinemax.core.data.remote.api

interface CinemaxApiKeyProvider {
val apiKey: String?
}

internal fun CinemaxApiKeyProvider.requireApiKey() = checkNotNull(apiKey)
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2022 Maximillian Leonov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.maximillianleonov.cinemax.core.data.remote.api

import io.mockk.MockKAnnotations
import io.mockk.confirmVerified
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertThrows
import org.junit.Before
import org.junit.Test

class CinemaxApiKeyProviderTest {
@MockK
lateinit var cinemaxApiKeyProvider: CinemaxApiKeyProvider

@Before
fun setUp() = MockKAnnotations.init(this)

@Test
fun `requireApiKey() should return not null value`() {
val expected = ""
every { cinemaxApiKeyProvider.apiKey } returns expected
val actual = cinemaxApiKeyProvider.requireApiKey()
verify { checkNotNull(cinemaxApiKeyProvider.apiKey) }
confirmVerified(cinemaxApiKeyProvider)
assertEquals(expected, actual)
}

@Test
fun `requireApiKey() should throw IllegalStateException`() {
every { cinemaxApiKeyProvider.apiKey } returns null
assertThrows(IllegalStateException::class.java) { cinemaxApiKeyProvider.requireApiKey() }
}
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ debug = [
android-application = { id = "com.android.application", version.ref = "android-gradle-plugin" }
android-library = { id = "com.android.library", version.ref = "android-gradle-plugin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
java-library = { id = "java-library" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
dagger-hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "dagger" }
7 changes: 6 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ dependencyResolutionManagement {

rootProject.name = "Cinemax"

include(":app", ":core:core-presentation")
include(
":app",
":core:core-data",
":core:core-data:data-remote",
":core:core-presentation"
)

0 comments on commit 218918d

Please sign in to comment.