Skip to content

Commit

Permalink
For mozilla-mobile#12171 - Add a PocketStory supertype for all Pocket…
Browse files Browse the repository at this point in the history
… stories types
  • Loading branch information
Mugurell committed May 18, 2022
1 parent 780c462 commit 0c5e572
Show file tree
Hide file tree
Showing 16 changed files with 157 additions and 92 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package mozilla.components.service.pocket

import android.content.Context
import androidx.annotation.VisibleForTesting
import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory
import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory
import mozilla.components.service.pocket.spocs.SpocsUseCases
import mozilla.components.service.pocket.stories.PocketStoriesUseCases
import mozilla.components.service.pocket.update.PocketStoriesRefreshScheduler
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package mozilla.components.service.pocket

/**
* A Pocket story downloaded from the Internet and intended to be displayed in the application.
*/
sealed class PocketStory {
/**
* Title of the story.
*/
abstract val title: String

/**
* Url where the story can be full read.
*/
abstract val url: String

/**
* A Pocket recommended story.
*
* @property title The title of the story.
* @property url A "pocket.co" shortlink for the original story's page.
* @property imageUrl A url to a still image representing the story.
* @property publisher Optional publisher name/domain, e.g. "The New Yorker" / "nationalgeographic.co.uk"".
* **May be empty**.
* @property category Topic of interest under which similar stories are grouped.
* @property timeToRead Inferred time needed to read the entire story. **May be -1**.
*/
data class PocketRecommendedStory(
override val title: String,
override val url: String,
val imageUrl: String,
val publisher: String,
val category: String,
val timeToRead: Int,
val timesShown: Long
) : PocketStory()

/**
* A Pocket sponsored story.
*
* @property title The title of the story.
* @property url 3rd party url containing the original story.
* @property imageUrl A url to a still image representing the story.
* Contains a "resize" parameter in the form of "resize=w618-h310" allowing to get the image
* with a specific resolution and the CENTER_CROP ScaleType.
* @property sponsor 3rd party sponsor of this story, e.g. "NextAdvisor".
* @property shim Unique identifiers for when the user interacts with this story.
*/
data class PocketSponsoredStory(
override val title: String,
override val url: String,
val imageUrl: String,
val sponsor: String,
val shim: PocketSponsoredStoryShim,
) : PocketStory()

/**
* Sponsored story unique identifiers intended to be used in telemetry.
*
* @property click Unique identifier for when the sponsored story is clicked.
* @property impression Unique identifier for when the user sees this sponsored story.
*/
data class PocketSponsoredStoryShim(
val click: String,
val impression: String,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
package mozilla.components.service.pocket.ext

import androidx.annotation.VisibleForTesting
import mozilla.components.service.pocket.PocketRecommendedStory
import mozilla.components.service.pocket.PocketSponsoredStory
import mozilla.components.service.pocket.PocketSponsoredStoryShim
import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory
import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory
import mozilla.components.service.pocket.PocketStory.PocketSponsoredStoryShim
import mozilla.components.service.pocket.spocs.api.ApiSpoc
import mozilla.components.service.pocket.spocs.db.SpocEntity
import mozilla.components.service.pocket.stories.api.PocketApiStory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package mozilla.components.service.pocket.spocs

import android.content.Context
import androidx.annotation.VisibleForTesting
import mozilla.components.service.pocket.PocketSponsoredStory
import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory
import mozilla.components.service.pocket.ext.toLocalSpoc
import mozilla.components.service.pocket.ext.toPocketSponsoredStory
import mozilla.components.service.pocket.spocs.api.ApiSpoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package mozilla.components.service.pocket.spocs
import android.content.Context
import androidx.annotation.VisibleForTesting
import mozilla.components.concept.fetch.Client
import mozilla.components.service.pocket.PocketSponsoredStory
import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory
import mozilla.components.service.pocket.spocs.api.SpocsEndpoint
import mozilla.components.service.pocket.stories.api.PocketResponse.Failure
import mozilla.components.service.pocket.stories.api.PocketResponse.Success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package mozilla.components.service.pocket.stories

import android.content.Context
import androidx.annotation.VisibleForTesting
import mozilla.components.service.pocket.PocketRecommendedStory
import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory
import mozilla.components.service.pocket.ext.toPartialTimeShownUpdate
import mozilla.components.service.pocket.ext.toPocketLocalStory
import mozilla.components.service.pocket.ext.toPocketRecommendedStory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package mozilla.components.service.pocket.stories
import android.content.Context
import androidx.annotation.VisibleForTesting
import mozilla.components.concept.fetch.Client
import mozilla.components.service.pocket.PocketRecommendedStory
import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory
import mozilla.components.service.pocket.stories.api.PocketEndpoint
import mozilla.components.service.pocket.stories.api.PocketResponse

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import mozilla.components.concept.fetch.Client
import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory
import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory
import mozilla.components.service.pocket.helpers.assertConstructorsVisibility
import mozilla.components.service.pocket.spocs.SpocsUseCases
import mozilla.components.service.pocket.spocs.SpocsUseCases.DeleteProfile
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package mozilla.components.service.pocket

import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory
import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory
import mozilla.components.service.pocket.helpers.assertConstructorsVisibility
import mozilla.components.support.test.mock
import org.junit.Assert.assertEquals
import org.junit.Test
import kotlin.reflect.KVisibility

class PocketStoryTest {
@Test
fun `GIVEN PocketSponsoredStory THEN it should be publicly available`() {
assertConstructorsVisibility(PocketSponsoredStory::class, KVisibility.PUBLIC)
}

@Test
fun `GIVEN PocketRecommendedStory THEN it should be publicly available`() {
assertConstructorsVisibility(PocketRecommendedStory::class, KVisibility.PUBLIC)
}

@Test
fun `GIVEN a PocketRecommendedStory WHEN it's title is accessed from parent THEN it returns the previously set value`() {
val pocketRecommendedStory = PocketRecommendedStory(
title = "testTitle", url = "", imageUrl = "", publisher = "", category = "", timeToRead = 0, timesShown = 0
)

val result = (pocketRecommendedStory as PocketStory).title

assertEquals("testTitle", result)
}

@Test
fun `GIVEN a PocketRecommendedStory WHEN it's url is accessed from parent THEN it returns the previously set value`() {
val pocketRecommendedStory = PocketRecommendedStory(
title = "", url = "testUrl", imageUrl = "", publisher = "", category = "", timeToRead = 0, timesShown = 0
)

val result = (pocketRecommendedStory as PocketStory).url

assertEquals("testUrl", result)
}

@Test
fun `GIVEN a PocketSponsoredStory WHEN it's title is accessed from parent THEN it returns the previously set value`() {
val pocketRecommendedStory = PocketSponsoredStory(
title = "testTitle", url = "", imageUrl = "", sponsor = "", shim = mock()
)

val result = (pocketRecommendedStory as PocketStory).title

assertEquals("testTitle", result)
}

@Test
fun `GIVEN a PocketSponsoredStory WHEN it's url is accessed from parent THEN it returns the previously set value`() {
val pocketRecommendedStory = PocketSponsoredStory(
title = "", url = "testUrl", imageUrl = "", sponsor = "", shim = mock()
)

val result = (pocketRecommendedStory as PocketStory).url

assertEquals("testUrl", result)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package mozilla.components.service.pocket.helpers

import mozilla.components.service.pocket.PocketRecommendedStory
import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory
import mozilla.components.service.pocket.spocs.api.ApiSpoc
import mozilla.components.service.pocket.spocs.api.ApiSpocShim
import mozilla.components.service.pocket.spocs.db.SpocEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import mozilla.components.concept.fetch.Client
import mozilla.components.service.pocket.PocketRecommendedStory
import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory
import mozilla.components.service.pocket.helpers.PocketTestResources
import mozilla.components.service.pocket.helpers.assertClassVisibility
import mozilla.components.service.pocket.spocs.SpocsUseCases.RefreshSponsoredStories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import mozilla.components.concept.fetch.Client
import mozilla.components.service.pocket.PocketRecommendedStory
import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory
import mozilla.components.service.pocket.helpers.PocketTestResources
import mozilla.components.service.pocket.helpers.assertClassVisibility
import mozilla.components.service.pocket.stories.api.PocketEndpoint
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ permalink: /changelog/
* [Gecko](https://github.com/mozilla-mobile/android-components/blob/main/buildSrc/src/main/java/Gecko.kt)
* [Configuration](https://github.com/mozilla-mobile/android-components/blob/main/.config.yml)

* **service-pocket**
* Add a new `PocketStory` supertype for all Pocket stories. [#12171](https://github.com/mozilla-mobile/android-components/issues/12171)

* **service-pocket**
* 🌟️ Add support for Pocket sponsored stories.
* See component's [README](https://github.com/mozilla-mobile/android-components/blob/main/components/service/pocket/README.md) to get more info.
Expand Down

0 comments on commit 0c5e572

Please sign in to comment.